Public Types |
typedef MLint32 | DateTimeIntType |
| Specify data type for year, month, day, hour and minute type as MLint32.
|
typedef MLdouble | DateTimeFloatType |
| Specify data type for seconds and fractions of other time units.
|
Public Member Functions |
|
| DateTime () |
| DateTime (const DateTime &dt) |
| DateTime (DateTimeIntType yearV, DateTimeIntType monthV, DateTimeIntType dayV, DateTimeIntType hourV=0, DateTimeIntType minuteV=0, DateTimeFloatType secondV=0) |
| DateTime (const char *dtString, const char *format=0) |
| DateTime (DateTimeIntType linearDaysV, DateTimeFloatType linearSecondsV) |
|
DateTime & | operator= (const DateTime &dt) |
bool | set (DateTimeIntType yearV, DateTimeIntType monthV, DateTimeIntType dayV, DateTimeIntType hourV=0, DateTimeIntType minuteV=0, DateTimeFloatType secondV=0) |
bool | set (const char *dtString, const char *format=0) |
bool | set (DateTimeIntType linDaysV, DateTimeFloatType linSecondsV) |
bool | setYMD (DateTimeIntType yearV, DateTimeIntType monthV, DateTimeIntType dayV) |
bool | setHMS (DateTimeIntType hourV, DateTimeIntType minuteV, DateTimeFloatType secondV) |
DateTime & | now () |
|
void | get (DateTimeIntType *yearV, DateTimeIntType *monthV, DateTimeIntType *dayV, DateTimeIntType *hourV=0, DateTimeIntType *minuteV=0, DateTimeFloatType *secondV=0) const |
void | get (char *dtString, const char *format=0) const |
void | getYMD (DateTimeIntType *yearV, DateTimeIntType *monthV, DateTimeIntType *dayV) const |
void | getHMS (DateTimeIntType *hourV, DateTimeIntType *minuteV, DateTimeFloatType *secondV) const |
DateTimeIntType | year () const |
DateTimeIntType | month () const |
DateTimeIntType | day () const |
DateTimeIntType | hour () const |
DateTimeIntType | minute () const |
DateTimeFloatType | second () const |
DateTimeIntType | dayInYear () const |
DateTimeIntType | linearDays () const |
DateTimeFloatType | linearSeconds () const |
| operator void * () const |
bool | operator! () const |
|
void | addDays (DateTimeIntType daysV) |
void | addDays (DateTimeFloatType daysV) |
void | addSeconds (DateTimeFloatType secondsV) |
DateTimeFloatType | daysSince (const DateTime &dateTime) const |
DateTimeFloatType | secondsSince (const DateTime &dateTime) const |
|
bool | operator== (const DateTime &dt) const |
bool | operator!= (const DateTime &dt) const |
bool | operator< (const DateTime &dt) const |
bool | operator<= (const DateTime &dt) const |
bool | operator>= (const DateTime &dt) const |
bool | operator> (const DateTime &dt) const |
Protected Member Functions |
|
void | normalize () |
Special date methods |
DateTimeIntType | daysOfMonth () const |
DateTimeIntType | daysOfYear () const |
bool | isLeapYear () const |
static bool | validYMD (DateTimeIntType yearV, DateTimeIntType monthV, DateTimeIntType dayV) |
static bool | validHMS (DateTimeIntType hourV, DateTimeIntType minuteV, DateTimeFloatType secondV) |
static DateTimeIntType | daysOfMonth (DateTimeIntType monthV, DateTimeIntType yearV) |
static DateTimeIntType | daysOfYear (DateTimeIntType yearV) |
static bool | isLeapYear (DateTimeIntType yearV) |
Deprecated |
typedef MLint32 | DTIType |
typedef MLdouble | DTFType |
DateTimeIntType | linDays () const |
DateTimeFloatType | linSeconds () const |
Class for performing date/time arithmetics, comparisons and formatting.
Thread-safety: This class is reentrant.
This class represents points in a time continuum by
- a linear day counter, counting days passed since some fictitious "day zero", and
- a linear seconds counter, counting seconds since 0:00 am.
The class provides member functions to convert between the internal representation and the usual one using year, month, day, hour, minute and second. There are also functions to compare two dates and to perform simple arithmetics, as adding/subtracting a number of days or seconds and computing the difference between two dates in either days or seconds.
Years, months, days, hours, minutes are represented by the type DateTime::DateTimeIntType which is a normal integer type.
Seconds and fractions of other time units are represented as DateTime::DateTimeFloatType, a normal floating point type.
The seconds counter is implemented as a double precision variable, hence it is able to measure fractions of a second with a precision in the nanosecond range.
The linear day counter counts days passed since the (non-existing) date 01-Jan-0000, assuming that the modern leap year rules would have been valid since the beginning of time. It is well known that this is not true, so computations involving dates before 1752 (the year the Gregorian calendar has been established) are
A year is considered a leap year if
- it is a multiple of 400, or
- it is a multiple of 4 but not of 100.
Leap seconds and time zones are not supported.
The class supports three different time and date representations:
- Linear time: This is the internal representation using linear day and seconds counter as described above.
- Calendar time: This is the usual representation using integer values for year, month, day, hour and minute and a double precision value for seconds. The valid ranges for these values are:
1 <= month <= 12 1 <= day <= Number of days in month 0 <= hour <= 23 0 <= minute <= 59 0 <= second < 60
The year number can be arbitrary, although numbers smaller than 1752 might make no sense (cf above). There is no implicit assumption on the century, i.e., the year 99 is NOT the year 1999, and 01 is NOT 2001.
Specifications outside the valid range are signaled as invalid but are nevertheless converted into a valid internal representation by "extrapolation". For example, the dates 2000-02-30 and 2000-03-01 are considered the same, 12:61:00 is the same as 13:01:00 and 24:15:30 is really 0:15:30 the next day.
- String representation: There are get() and set() methods for formatting the time as a string and for reading the time from a string. In both cases, the format of the string has to specified using the following field specifiers:
y : Year, two digits (only get()) Y : Year, four digits m : Month d, D : Day h, H : Hour M : Minute s, S : Second (as an integer)
If no format is specified, the default format
Y-m-d H:M:S
is used.
Definition at line 121 of file mlDateTime.h.