Holds absolute and relative date/time values in Qore with precision to the microsecond. More...
#include <DateTime.h>
Public Member Functions | |
DLLEXPORT | DateTime (bool r=false) |
constructor for an empty object | |
DLLEXPORT | DateTime (int n_year, int n_month, int n_day, int n_hour=0, int n_minute=0, int n_second=0, short n_ms=0, bool n_relative=false) |
constructor for setting all parameters | |
DLLEXPORT | DateTime (int64 seconds) |
constructor for setting an absolute date based on the number of seconds from January 1, 1970 | |
DLLEXPORT | DateTime (int64 seconds, int ms) |
constructor for setting an absolute date based on the number of seconds from January 1, 1970 (plus milliseconds) | |
DLLEXPORT | DateTime (const char *date) |
constructor for setting the date from a string in the format YYYYMMDDHHmmSS | |
DLLEXPORT | DateTime (const struct tm *tms) |
constructor for setting an absolute date based on a "struct tm" | |
DLLEXPORT | DateTime (const DateTime &dt) |
copy constructor | |
DLLEXPORT | ~DateTime () |
destroys the object and frees all memory | |
DLLEXPORT void | getTM (struct tm *tms) const |
sets a "struct tm" from the current date/time value for the time zone for the object; use DateTime::getInfo() instead | |
DLLEXPORT void | setDate (int64 seconds) |
sets the absolute date value based on the number of seconds from January 1, 1970 | |
DLLEXPORT void | setDate (int64 seconds, int ms) |
sets the absolute date value based on the number of seconds from January 1, 1970 UTC (plus milliseconds) | |
DLLEXPORT void | setDate (const AbstractQoreZoneInfo *zone, int64 seconds, int us) |
sets the absolute date value based on the number of seconds from January 1, 1970 UTC (plus microseconds) | |
DLLEXPORT void | setLocalDate (const AbstractQoreZoneInfo *zone, int64 seconds, int us) |
sets the absolute date value based on the number of seconds from January 1, 1970 in the given time zone (plus microseconds) | |
DLLEXPORT void | setDate (const AbstractQoreZoneInfo *n_zone, int n_year, int n_month, int n_day, int n_hour=0, int n_minute=0, int n_second=0, int n_us=0) |
sets the date to an absolute date/time as given | |
DLLEXPORT void | setDate (const char *str) |
sets an absolute date value from a string in the format YYYYMMDDHHmmSS | |
DLLEXPORT void | setRelativeDate (const char *str) |
sets a relative date from a string in the format YYYYMMDDHHmmSS | |
DLLEXPORT void | setDate (const struct tm *tms, short ms=0) |
sets the absolute date from a "struct tm" pointer and millisecond value | |
DLLEXPORT void | setDate (const DateTime &date) |
sets the date from a DateTime reference | |
DLLEXPORT void | setTime (int h, int m, int s, short ms=0) |
sets the time from hours, minutes, seconds, and milliseconds | |
DLLEXPORT int64 | getEpochSeconds () const |
gets the number of seconds since January 1, 1970 for the current date offset in local time | |
DLLEXPORT int64 | getEpochSecondsUTC () const |
gets the number of seconds since January 1, 1970Z for the current date | |
DLLEXPORT int64 | getEpochMicrosecondsUTC () const |
gets the number of microseconds since January 1, 1970Z for the current date | |
DLLEXPORT int64 | getEpochMillisecondsUTC () const |
gets the number of milliseconds since January 1, 1970Z for the current date | |
DLLEXPORT int | getDayNumber () const |
returns the ordinal number of the day in the year for absolute dates, sometimes (mistakenly) referred to as the Julian date | |
DLLEXPORT int | getDayOfWeek () const |
returns the day of week for the current date (0-6, Sun-Sat) | |
DLLEXPORT void | getISOWeek (int &year, int &week, int &day) const |
returns the ISO-8601 week information | |
DLLEXPORT void | format (QoreString &str, const char *fmt) const |
formats the date/time value to a QoreString | |
DLLEXPORT bool | isRelative () const |
returns true if the value is a relative date-time value | |
DLLEXPORT bool | isAbsolute () const |
returns true if the value is an absolute date-time value | |
DLLEXPORT short | getYear () const |
returns the year portion of the date-time value (in local time according to the time zone for absolute date/time values) | |
DLLEXPORT int | getMonth () const |
returns the month portion of the date-time value (in local time according to the time zone for absolute date/time values) | |
DLLEXPORT int | getDay () const |
returns the day portion of the date-time value (in local time according to the time zone for absolute date/time values) | |
DLLEXPORT int | getHour () const |
returns the hour portion of the date-time value (in local time according to the time zone for absolute date/time values) | |
DLLEXPORT int | getMinute () const |
returns the minute portion of the date-time value (in local time according to the time zone for absolute date/time values) | |
DLLEXPORT int | getSecond () const |
returns the second portion of the date-time value (in local time according to the time zone for absolute date/time values) | |
DLLEXPORT int | getMillisecond () const |
returns the microsecond portion of the date-time value divided by 1000 | |
DLLEXPORT int | getMicrosecond () const |
returns the microsecond portion of the date-time value | |
DLLEXPORT int64 | getRelativeSeconds () const |
returns the difference as the number of seconds between the date/time value and the local time at the moment of the call for absolute date/time values; for relative date/time values, the duration is converted to seconds and returned as an integer | |
DLLEXPORT int64 | getRelativeMilliseconds () const |
returns the difference as the number of milliseconds between the date/time value and the local time at the moment of the call, for absolute date/time values; for relative date/time values, the duration is converted to milliseconds and returned as an integer | |
DLLEXPORT int64 | getRelativeMicroseconds () const |
returns the difference as the number of microseconds between the date/time value and the local time at the moment of the call, for absolute date/time values; for relative date/time values, the duration is converted to microseconds and returned as an integer | |
DLLEXPORT bool | hasValue () const |
returns true if the object has a value, false if not (zero value = 1970-01-01Z for absolute times, or all relative components = 0) | |
DLLEXPORT DateTime * | unaryMinus () const |
returns the negative time from the current time | |
DLLEXPORT void | unaryMinusInPlace () |
converts the current value to the negative of itself | |
DLLEXPORT void | getInfo (const AbstractQoreZoneInfo *n_zone, qore_tm &info) const |
returns the broken-down time in the given time zone (n_zone = 0 means UTC) | |
DLLEXPORT void | getInfo (qore_tm &info) const |
returns the broken-down time in the current time zone | |
DLLEXPORT void | setZone (const AbstractQoreZoneInfo *n_zone) |
changes the time zone for the time without updating the epoch offset | |
Static Public Member Functions | |
static DLLEXPORT bool | isLeapYear (int year) |
returns true if the year passed is a leap year according to a proleptic gregorian calendar | |
static DLLEXPORT int | getLastDayOfMonth (int month, int year) |
returns the number of days in the month given according to a proleptic gregorian calendar | |
static DLLEXPORT DateTime * | getDateFromISOWeek (int year, int week, int day, ExceptionSink *xsink) |
returns a DateTime value from ISO-8601 week and day offsets | |
static DLLEXPORT int | compareDates (const DateTime *left, const DateTime *right) |
returns -1, 0, or 1 if the left date is less than, equal, or greater than the right date | |
static DLLEXPORT DateTime * | makeAbsolute (const AbstractQoreZoneInfo *n_zone, int n_year, int n_month, int n_day, int n_hour=0, int n_minute=0, int n_second=0, int n_us=0) |
static "constructor" to create an absolute time, including microseconds | |
static DLLEXPORT DateTime * | makeAbsolute (const AbstractQoreZoneInfo *zone, int64 seconds, int us=0) |
static "constructor" to create an absolute time as an offset from the epoch, including microseconds | |
static DLLEXPORT DateTime * | makeAbsoluteLocal (const AbstractQoreZoneInfo *zone, int64 seconds, int us=0) |
static "constructor" to create an absolute time as an offset from the given time zone's epoch, including microseconds | |
static DLLEXPORT DateTime * | makeRelative (int n_year, int n_month, int n_day, int n_hour=0, int n_minute=0, int n_second=0, int n_us=0) |
static "constructor" to create a relative time, including microseconds | |
Protected Member Functions | |
DLLLOCAL DateTime & | operator= (const DateTime &) |
this function is not implemented; it is here as a private function in order to prohibit it from being used | |
DLLLOCAL | DateTime (qore_date_private *n_priv) |
this constructor is not exported in the library | |
Protected Attributes | |
struct qore_date_private * | priv |
private date data - most are ints so relative dates can hold a lot of data | |
Friends | |
class | DateTimeNode |
Holds absolute and relative date/time values in Qore with precision to the microsecond.
Date arithmetic and date formatting is supported by this class. As of qore 0.8.0, the internal representation for absolute date/time values has changed. Now, absolute date/time values are stored internally as a 64-bit offset in seconds since the UNIX epoch (January 1, 1970 UTC), plus a 4-byte integer microseconds offset, plus a pointer to an AbstractQoreZoneInfo object, which gives the time zone information (UTC offset, daylights savings time transitions, if any, etc).
Therefore, for absolute date/time values, it is expensive to call functions that get discrete values for the date (DateTime::getYear(), DateTime::getMonth(), and DateTime::getDay()), because for each call, all broken-down components are calculated for each call. In the case that more than one component of an absolute date/time value is required, it's recommended to call DateTime::getInfo() instead.
Relative date/time values are stored with discrete values for years, months, days, hours, minutes, seconds, and microseconds.
This is a "normal" (i.e. not reference counted) class, for the equivalent Qore value type, see DateTimeNode
DLLEXPORT DateTime::DateTime | ( | bool | r = false |
) |
constructor for an empty object
r | sets the "relative" flag for the object |
DLLEXPORT DateTime::DateTime | ( | int | n_year, | |
int | n_month, | |||
int | n_day, | |||
int | n_hour = 0 , |
|||
int | n_minute = 0 , |
|||
int | n_second = 0 , |
|||
short | n_ms = 0 , |
|||
bool | n_relative = false | |||
) |
constructor for setting all parameters
note that for absolute date/time values, the local time zone will be assumed
n_year | the year value | |
n_month | the months value | |
n_day | the days value | |
n_hour | the hours value | |
n_minute | the minutes value | |
n_second | the seconds value | |
n_ms | the milliseconds value | |
n_relative | the relative flag |
DLLEXPORT DateTime::DateTime | ( | int64 | seconds | ) |
constructor for setting an absolute date based on the number of seconds from January 1, 1970
note that the local time zone will be assumed
seconds | the number of seconds from January 1, 1970 |
DLLEXPORT DateTime::DateTime | ( | int64 | seconds, | |
int | ms | |||
) |
constructor for setting an absolute date based on the number of seconds from January 1, 1970 (plus milliseconds)
note that the local time zone will be assumed
seconds | the number of seconds from January 1, 1970 | |
ms | the milliseconds portion of the time |
DLLEXPORT DateTime::DateTime | ( | const char * | date | ) |
constructor for setting the date from a string in the format YYYYMMDDHHmmSS
additionally a milliseconds value can be appended with a period and 3 integers in the format [.xxx]
date | the string to use to set the date in the format YYYYMMDDHHmmSS[.xxx] |
DLLEXPORT DateTime::DateTime | ( | const struct tm * | tms | ) |
constructor for setting an absolute date based on a "struct tm"
tms | a structure giving the absolute date to set |
DLLEXPORT void DateTime::format | ( | QoreString & | str, | |
const char * | fmt | |||
) | const |
formats the date/time value to a QoreString
the formatted date/time value will be appended to the QoreString argument according to the format string Format codes are as follows:
str | the QoreString where the formatted date data will be written (appended) | |
fmt | the format string as per the above description |
static DLLEXPORT DateTime* DateTime::getDateFromISOWeek | ( | int | year, | |
int | week, | |||
int | day, | |||
ExceptionSink * | xsink | |||
) | [static] |
returns a DateTime value from ISO-8601 week and day offsets
note that ISO-8601 week days go from 1 - 7 = Mon - Sun a 0 return value means an exception was raised
year | the year portion of the date in which the ISO-8601 week is found in | |
week | the ISO-8601 week number | |
day | the day offset in the week (1-7 = Mon-Sun) | |
xsink | if an error occurs, the Qore-language exception information will be added here |
Reimplemented in DateTimeNode.
DLLEXPORT int DateTime::getDay | ( | ) | const |
returns the day portion of the date-time value (in local time according to the time zone for absolute date/time values)
DLLEXPORT int DateTime::getDayNumber | ( | ) | const |
returns the ordinal number of the day in the year for absolute dates, sometimes (mistakenly) referred to as the Julian date
does not return sensible values for relative dates
DLLEXPORT int DateTime::getDayOfWeek | ( | ) | const |
returns the day of week for the current date (0-6, Sun-Sat)
DLLEXPORT int64 DateTime::getEpochMicrosecondsUTC | ( | ) | const |
gets the number of microseconds since January 1, 1970Z for the current date
DLLEXPORT int64 DateTime::getEpochMillisecondsUTC | ( | ) | const |
gets the number of milliseconds since January 1, 1970Z for the current date
DLLEXPORT int64 DateTime::getEpochSeconds | ( | ) | const |
gets the number of seconds since January 1, 1970 for the current date offset in local time
DLLEXPORT int64 DateTime::getEpochSecondsUTC | ( | ) | const |
gets the number of seconds since January 1, 1970Z for the current date
DLLEXPORT int DateTime::getHour | ( | ) | const |
returns the hour portion of the date-time value (in local time according to the time zone for absolute date/time values)
DLLEXPORT void DateTime::getISOWeek | ( | int & | year, | |
int & | week, | |||
int & | day | |||
) | const |
returns the ISO-8601 week information
NOTE: the year may be different than the actual year
year | the year portion of the ISO-9601 week information | |
week | the ISO-9601 week number | |
day | the day offset in the week (1-7 = Mon-Sun) |
DLLEXPORT int DateTime::getMicrosecond | ( | ) | const |
returns the microsecond portion of the date-time value
DLLEXPORT int DateTime::getMillisecond | ( | ) | const |
returns the microsecond portion of the date-time value divided by 1000
DLLEXPORT int DateTime::getMinute | ( | ) | const |
returns the minute portion of the date-time value (in local time according to the time zone for absolute date/time values)
DLLEXPORT int DateTime::getMonth | ( | ) | const |
returns the month portion of the date-time value (in local time according to the time zone for absolute date/time values)
DLLEXPORT int64 DateTime::getRelativeMicroseconds | ( | ) | const |
returns the difference as the number of microseconds between the date/time value and the local time at the moment of the call, for absolute date/time values; for relative date/time values, the duration is converted to microseconds and returned as an integer
DLLEXPORT int64 DateTime::getRelativeMilliseconds | ( | ) | const |
returns the difference as the number of milliseconds between the date/time value and the local time at the moment of the call, for absolute date/time values; for relative date/time values, the duration is converted to milliseconds and returned as an integer
DLLEXPORT int64 DateTime::getRelativeSeconds | ( | ) | const |
returns the difference as the number of seconds between the date/time value and the local time at the moment of the call for absolute date/time values; for relative date/time values, the duration is converted to seconds and returned as an integer
DLLEXPORT int DateTime::getSecond | ( | ) | const |
returns the second portion of the date-time value (in local time according to the time zone for absolute date/time values)
DLLEXPORT short DateTime::getYear | ( | ) | const |
returns the year portion of the date-time value (in local time according to the time zone for absolute date/time values)
DLLEXPORT bool DateTime::isAbsolute | ( | ) | const |
returns true if the value is an absolute date-time value
DLLEXPORT bool DateTime::isRelative | ( | ) | const |
returns true if the value is a relative date-time value
static DLLEXPORT DateTime* DateTime::makeAbsolute | ( | const AbstractQoreZoneInfo * | zone, | |
int64 | seconds, | |||
int | us = 0 | |||
) | [static] |
static "constructor" to create an absolute time as an offset from the epoch, including microseconds
zone | time zone for the date/time value, 0 = UTC, |
seconds | the number of seconds from January 1, 1970Z | |
us | the microseconds portion of the time |
Reimplemented in DateTimeNode.
static DLLEXPORT DateTime* DateTime::makeAbsoluteLocal | ( | const AbstractQoreZoneInfo * | zone, | |
int64 | seconds, | |||
int | us = 0 | |||
) | [static] |
static "constructor" to create an absolute time as an offset from the given time zone's epoch, including microseconds
zone | time zone for the date/time value, 0 = UTC, |
seconds | the number of seconds from January 1, 1970 in the time zone passed as the first argument | |
us | the microseconds portion of the time |
Reimplemented in DateTimeNode.
DLLEXPORT void DateTime::setDate | ( | const char * | str | ) |
sets an absolute date value from a string in the format YYYYMMDDHHmmSS
additionally a milliseconds value can be appended with a period and 3 integers in the format [.xxx] note that the local time zone will be assumed
str | the string to use to set the date in the format YYYYMMDDHHmmSS[.xxx] |
DLLEXPORT void DateTime::setDate | ( | const AbstractQoreZoneInfo * | zone, | |
int64 | seconds, | |||
int | us | |||
) |
sets the absolute date value based on the number of seconds from January 1, 1970 UTC (plus microseconds)
zone | the time zone for the time | |
seconds | the number of seconds from January 1, 1970 UTC | |
us | the microseconds portion of the time |
DLLEXPORT void DateTime::setDate | ( | int64 | seconds, | |
int | ms | |||
) |
sets the absolute date value based on the number of seconds from January 1, 1970 UTC (plus milliseconds)
note that the local time zone will be assumed
seconds | the number of seconds from January 1, 1970 UTC | |
ms | the milliseconds portion of the time |
DLLEXPORT void DateTime::setDate | ( | int64 | seconds | ) |
sets the absolute date value based on the number of seconds from January 1, 1970
note that the local time zone will be assumed
seconds | the number of seconds from January 1, 1970 |
DLLEXPORT void DateTime::setLocalDate | ( | const AbstractQoreZoneInfo * | zone, | |
int64 | seconds, | |||
int | us | |||
) |
sets the absolute date value based on the number of seconds from January 1, 1970 in the given time zone (plus microseconds)
zone | the time zone for the time | |
seconds | the number of seconds from January 1, 1970 in the given time zone | |
us | the microseconds portion of the time |
DLLEXPORT void DateTime::setTime | ( | int | h, | |
int | m, | |||
int | s, | |||
short | ms = 0 | |||
) |
sets the time from hours, minutes, seconds, and milliseconds
h | the hours value | |
m | the minutes value | |
s | the seconds value | |
ms | the milliseconds value |