DateTime

GDateTime is a structure that combines a Gregorian date and time into a single structure. It provides many conversion and methods to manipulate dates and times. Time precision is provided down to microseconds and the time can range (proleptically) from 0001-01-01 00:00:00 to 9999-12-31 23:59:59.999999. GDateTime follows POSIX time in the sense that it is oblivious to leap seconds.

GDateTime is an immutable object; once it has been created it cannot be modified further. All modifiers will create a new GDateTime. Nearly all such functions can fail due to the date or time going out of range, in which case NULL will be returned.

GDateTime is reference counted: the reference count is increased by calling g_date_time_ref() and decreased by calling g_date_time_unref(). When the reference count drops to 0, the resources allocated by the GDateTime structure are released.

Many parts of the API may produce non-obvious results. As an example, adding two months to January 31st will yield March 31st whereas adding one month and then one month again will yield either March 28th or March 29th. Also note that adding 24 hours is not always the same as adding one day (since days containing daylight savings time transitions are either 23 or 25 hours in length).

GDateTime is available since GLib 2.26.

Constructors

this
this(GDateTime* gDateTime)

Sets our main struct and passes it to the parent class

this
this(long t, bool utc)

Creates a GDateTime corresponding to the given Unix time t Unix time is the number of seconds that have elapsed since 1970-01-01 00:00:00 UTC, regardless of the local time offset.

this
this(GTimeVal tv, bool utc)

Creates a GDateTime corresponding to the given GTimeVal tv. The time contained in a GTimeVal is always stored in the form of seconds elapsed since 1970-01-01 00:00:00 UTC, regardless of the local time offset.

this
this(TimeZone tz)

Creates a GDateTime corresponding to this exact instant in the given time zone tz. The time is as accurate as the system allows, to a maximum accuracy of 1 microsecond. This function will always succeed unless the system clock is set to truly insane values (or unless GLib is still being used after the year 9999). You should release the return value by calling g_date_time_unref() when you are done with it. Since 2.26

this
this(TimeZone tz, int year, int month, int day, int hour, int minute, double seconds)

Creates a new GDateTime corresponding to the given date and time in the time zone tz. The year must be between 1 and 9999, month between 1 and 12 and day between 1 and 28, 29, 30 or 31 depending on the month and the year. hour must be between 0 and 23 and minute must be between 0 and 59. seconds must be at least 0.0 and must be strictly less than 60.0. It will be rounded down to the nearest microsecond. If the given time is not representable in the given time zone (for example, 02:30 on March 14th 2010 in Toronto, due to daylight savings time) then the time will be rounded up to the nearest existing time (in this case, 03:00). If this matters to you then you should verify the return value for containing the same as the numbers you gave. In the case that the given time is ambiguous in the given time zone (for example, 01:30 on November 7th 2010 in Toronto, due to daylight Since 2.26

Destructor

~this
~this()
Undocumented in source.

Members

Functions

add
DateTime add(GTimeSpan timespan)

Creates a copy of datetime and adds the specified timespan to the copy. Since 2.26

addDays
DateTime addDays(int days)

Creates a copy of datetime and adds the specified number of days to the copy. Since 2.26

addFull
DateTime addFull(int years, int months, int days, int hours, int minutes, double seconds)

Creates a new GDateTime adding the specified values to the current date and time in datetime. Since 2.26

addHours
DateTime addHours(int hours)

Creates a copy of datetime and adds the specified number of hours Since 2.26

addMinutes
DateTime addMinutes(int minutes)

Creates a copy of datetime adding the specified number of minutes. Since 2.26

addMonths
DateTime addMonths(int months)

Creates a copy of datetime and adds the specified number of months to the copy. Since 2.26

addSeconds
DateTime addSeconds(double seconds)

Creates a copy of datetime and adds the specified number of seconds. Since 2.26

addWeeks
DateTime addWeeks(int weeks)

Creates a copy of datetime and adds the specified number of weeks to the copy. Since 2.26

addYears
DateTime addYears(int years)

Creates a copy of datetime and adds the specified number of years to the copy. Since 2.26

difference
GTimeSpan difference(DateTime begin)

Calculates the difference in time between end and begin. The Since 2.26

doref
DateTime doref()

Atomically increments the reference count of datetime by one. Since 2.26

format
string format(string format)

Creates a newly allocated string representing the requested format. The format strings understood by this function are a subset of the strftime() format language as specified by C99. The %D, %U and %W conversions are not supported, nor is the 'E' modifier. The GNU extensions %k, %l, %s and %P are supported, however, as are the '0', '_' and '-' modifiers. In contrast to strftime(), this function always produces a UTF-8 string, regardless of the current locale. Note that the rendering of many formats is locale-dependent and may not match the strftime() output exactly. Since 2.26

getDateTimeStruct
GDateTime* getDateTimeStruct()
Undocumented in source. Be warned that the author may not have intended to support it.
getDayOfMonth
int getDayOfMonth()

Retrieves the day of the month represented by datetime in the gregorian calendar. Since 2.26

getDayOfWeek
int getDayOfWeek()

Retrieves the ISO 8601 day of the week on which datetime falls (1 is Monday, 2 is Tuesday... 7 is Sunday). Since 2.26

getDayOfYear
int getDayOfYear()

Retrieves the day of the year represented by datetime in the Gregorian calendar. Since 2.26

getHour
int getHour()

Retrieves the hour of the day represented by datetime Since 2.26

getMicrosecond
int getMicrosecond()

Retrieves the microsecond of the date represented by datetime Since 2.26

getMinute
int getMinute()

Retrieves the minute of the hour represented by datetime Since 2.26

getMonth
int getMonth()

Retrieves the month of the year represented by datetime in the Gregorian calendar. Since 2.26

getSecond
int getSecond()

Retrieves the second of the minute represented by datetime Since 2.26

getSeconds
double getSeconds()

Retrieves the number of seconds since the start of the last minute, including the fractional part. Since 2.26

getStruct
void* getStruct()

the main Gtk struct as a void*

getTimezoneAbbreviation
string getTimezoneAbbreviation()

Determines the time zone abbreviation to be used at the time and in the time zone of datetime. For example, in Toronto this is currently "EST" during the winter months and "EDT" during the summer months when daylight savings time is in effect. Since 2.26

getUtcOffset
GTimeSpan getUtcOffset()

Determines the offset to UTC in effect at the time and in the time zone of datetime. The offset is the number of microseconds that you add to UTC time to arrive at local time for the time zone (ie: negative numbers for time zones west of GMT, positive numbers for east). If datetime represents UTC time, then the offset is always zero. Since 2.26

getWeekNumberingYear
int getWeekNumberingYear()

Returns the ISO 8601 week-numbering year in which the week containing datetime falls. This function, taken together with g_date_time_get_week_of_year() and g_date_time_get_day_of_week() can be used to determine the full ISO week date on which datetime falls. This is usually equal to the normal Gregorian year (as returned by Since 2.26

getWeekOfYear
int getWeekOfYear()

Returns the ISO 8601 week number for the week containing datetime. The ISO 8601 week number is the same for every day of the week (from Moday through Sunday). That can produce some unusual results (described below). The first week of the year is week 1. This is the week that contains the first Thursday of the year. Equivalently, this is the first week that has more than 4 of its days falling within the calendar year. The value 0 is never returned by this function. Days contained within a year but occurring before the first ISO 8601 week of that year are considered as being contained in the last week of the previous year. Similarly, the final days of a calendar year may be considered as being part of the first ISO 8601 week of the next year if 4 or more days of that week are contained within the new year. Since 2.26

getYear
int getYear()

Retrieves the year represented by datetime in the Gregorian calendar. Since 2.26

getYmd
void getYmd(int year, int month, int day)

Retrieves the Gregorian day, month, and year of a given GDateTime. Since 2.26

isDaylightSavings
int isDaylightSavings()

Determines if daylight savings time is in effect at the time and in the time zone of datetime. Since 2.26

opCmp
int opCmp(Object rhs)
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(Object rhs)
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
int opEquals(Object rhs)
Undocumented in source. Be warned that the author may not have intended to support it.
toHash
hash_t toHash()
Undocumented in source. Be warned that the author may not have intended to support it.
toLocal
DateTime toLocal()

Creates a new GDateTime corresponding to the same instant in time as datetime, but in the local time zone. This call is equivalent to calling g_date_time_to_timezone() with the time zone returned by g_time_zone_new_local(). Since 2.26

toTimeval
int toTimeval(GTimeVal tv)

Stores the instant in time that datetime represents into tv. The time contained in a GTimeVal is always stored in the form of seconds elapsed since 1970-01-01 00:00:00 UTC, regardless of the time zone associated with datetime. On systems where 'long' is 32bit (ie: all 32bit systems and all Windows systems), a GTimeVal is incapable of storing the entire range of values that GDateTime is capable of expressing. On those systems, this function returns FALSE to indicate that the time is out of range. On systems where 'long' is 64bit, this function never fails. Since 2.26

toTimezone
DateTime toTimezone(TimeZone tz)

Create a new GDateTime corresponding to the same instant in time as datetime, but in the time zone tz. This call can fail in the case that the time goes out of bounds. For example, converting 0001-01-01 00:00:00 UTC to a time zone west of Greenwich will fail (due to the year 0 being out of range). You should release the return value by calling g_date_time_unref() when you are done with it. Since 2.26

toUnix
long toUnix()

Gives the Unix time corresponding to datetime, rounding down to the nearest second. Unix time is the number of seconds that have elapsed since 1970-01-01 00:00:00 UTC, regardless of the time zone associated with datetime. Since 2.26

toUtc
DateTime toUtc()

Creates a new GDateTime corresponding to the same instant in time as datetime, but in UTC. This call is equivalent to calling g_date_time_to_timezone() with the time zone returned by g_time_zone_new_utc(). Since 2.26

unref
void unref()

Atomically decrements the reference count of datetime by one. When the reference count reaches zero, the resources allocated by datetime are freed Since 2.26

Static functions

compare
int compare(DateTime dt1, DateTime dt2)

A comparison function for GDateTimes that is suitable as a GCompareFunc. Both GDateTimes must be non-NULL. Since 2.26

equal
int equal(DateTime dt1, DateTime dt2)

Checks to see if dt1 and dt2 are equal. Equal here means that they represent the same moment after converting them to the same time zone. Since 2.26

hash
uint hash(DateTime datetime)

Hashes datetime into a guint, suitable for use within GHashTable. Since 2.26

Variables

gDateTime
GDateTime* gDateTime;

the main Gtk struct

Meta