#include <datetime.h>
At some point developers have to deal with times, dates and timezones. This topic can promote headaches because it can be quite complex. In general you have to be aware of differences in timezones, especially when your software runs on mobile devices are you let the user share data across countries (or even within the same country).
In this header file you find some convenient helper functions and classes to reduce the amount of effort you have to put into to handle this topic to a minimum. The implementation and definition of the classes rely on the ISO 8601. Use the UniversalDateTime whenever possible to store normalized time and date values and convert them to a LocalDateTime instance as late as possible (e.g. for a local string output). An object representing a local 'time and date' of the current system time. All members are public and are allowed to be modified for custom needs. Keep in mind that you have to ensure that the values are correct and valid when converting an object back to UniversalDateTime, otherwise the behavior is undefined.
Public Member Functions | |
Bool | IsLeapYear () const |
DAYOFWEEK | GetDayOfWeek () const |
UniversalDateTime | ConvertToUniversalDateTime () const |
Bool | operator== (const LocalDateTime &x) const |
Bool | operator!= (const LocalDateTime &x) const |
void | Reset () |
String | FormatTime (const Char *formatString) const |
String | ToString (const FormatStatement *formatStatement=nullptr) const |
HashInt | GetHashCode () const |
Static Public Member Functions | |
static TimeValue | GetTimezoneOffset (Bool *daylightSavingTime=nullptr) |
static Bool | IsLeapYear (Int year) |
static DAYOFWEEK | GetDayOfWeek (Int lYear, Int lMonth, Int lDay) |
static LocalDateTime | GetNow () |
static Result< LocalDateTime > | FromString (const String &dateTimeStr, const Char *formatString) |
static Result< LocalDateTime > | FromValues (Int32 year, UChar month, UChar day, UChar hour, UChar minute, UChar second, DST daylightSavingTime=DST::AUTOMATIC) |
static LocalDateTime | FromUnixTimestamp (UInt64 timestamp) |
Public Attributes | |
Int32 | _year |
UChar | _month |
UChar | _day |
UChar | _hour |
UChar | _minute |
UChar | _second |
DST | _daylightSavingTime |
Bool IsLeapYear | ( | ) | const |
Check if the set year is a leap year.
DAYOFWEEK GetDayOfWeek | ( | ) | const |
Return the day of the set time.
UniversalDateTime ConvertToUniversalDateTime | ( | ) | const |
Converts the local time to the universal date-time
Bool operator== | ( | const LocalDateTime & | x | ) | const |
Compare operator ==. The objects must represent a date and time in the same timezone. The Daylight Saving Time is not compared.
Bool operator!= | ( | const LocalDateTime & | x | ) | const |
void Reset | ( | ) |
Resets the date-time object and sets all members to 0.
Formats the time into a specific format defined be the format string.
[in] | formatString | Optional. OS depending C lib format string (see strftime). "%Y-%m-%d %H:%M:%S" is used if formatString is nullptr. |
String ToString | ( | const FormatStatement * | formatStatement = nullptr | ) | const |
HashInt GetHashCode | ( | ) | const |
Returns the hash value of this object. This value can be used for all HashSet<>/HashMap<> classes.
Return the current timezone offset to the universal time coordinate (UTC).
[out] | daylightSavingTime | True if Daylight Saving Time effects the local time. |
Check if the passed year is a leap year.
[in] | year | Year value. |
Return the day of the passed date.
[in] | lYear | Year value. |
[in] | lMonth | Month value. |
[in] | lDay | Day value. |
|
static |
Return the current date-time object of the current time zone.
|
static |
Creates a date-time object by the passed string and its passed format string. An example:
[in] | dateTimeStr | The time string. |
[in] | formatString | The matching format string. |
|
static |
Creates a local date-time object by the passed date values.
[in] | year | Year value [e.g. 2015] |
[in] | month | Month value value [1-12] |
[in] | day | Day value [1-31] |
[in] | hour | Hour value [0-23] |
[in] | minute | Minute value [0-59] |
[in] | second | Second value [0-59] |
[in] | daylightSavingTime | Optional Daylight Saving Time information. See DST. |
|
static |
Create a local date-time object by passing a Unix time stamp.
[in] | timestamp | The local Unix time stamp where 0 represents the 01/01/1970-00:00 in the current timezone. |
Int32 _year |
Full year, e.g. 2014.
UChar _month |
1..12
UChar _day |
1..31
UChar _hour |
0..23
UChar _minute |
0..59
UChar _second |
0..59
DST _daylightSavingTime |