Rudiments
|
Public Member Functions | |
datetime () | |
~datetime () | |
bool | initialize (const char *tmstring) |
bool | initialize (time_t seconds) |
bool | initialize (const void *tmstruct) |
bool | getSystemDateAndTime () |
bool | getHardwareDateAndTime (const char *hwtz) |
bool | getAdjustedHardwareDateAndTime (const char *hwtz) |
bool | setSystemDateAndTime () |
bool | setHardwareDateAndTime (const char *hwtz) |
int32_t | getHour () const |
int32_t | getMinutes () const |
int32_t | getSeconds () const |
int32_t | getMonth () const |
const char * | getMonthName () const |
const char * | getMonthAbbreviation () const |
int32_t | getDayOfMonth () const |
int32_t | getDayOfWeek () const |
int32_t | getDayOfYear () const |
int32_t | getYear () const |
bool | isDaylightSavingsTime () const |
const char * | getTimeZoneString () const |
int32_t | getTimeZoneOffset () const |
bool | adjustTimeZone (const char *newtz) |
bool | adjustTimeZone (const char *newtz, bool ignoredst) |
bool | setSeconds (int32_t seconds) |
bool | setMinutes (int32_t minutes) |
bool | setHours (int32_t hours) |
bool | setDays (int32_t days) |
bool | setMonths (int32_t months) |
bool | setYears (int32_t years) |
bool | addSeconds (int32_t seconds) |
bool | addMinutes (int32_t minutes) |
bool | addHours (int32_t hours) |
bool | addDays (int32_t days) |
bool | addMonths (int32_t months) |
bool | addYears (int32_t years) |
const char * | getString () |
time_t | getEpoch () const |
const void * | getInternalTimeStructure () |
Static Public Member Functions | |
static char * | getString (time_t seconds) |
static char * | getString (const void *tmstruct) |
static time_t | getEpoch (const char *datestring) |
static time_t | getEpoch (const void *tmstruct) |
static const char *const | getTimeZoneAbbreviations () |
static const int32_t * | getTimeZoneOffsets () |
static bool | validDateTime (const char *string) |
static void | setTimeMutex (mutex *mtx) |
The datetime class represents a date/time combination and provides methods for getting and setting dates and times, converting date/time formats and accessing various date/time values.
datetime::datetime | ( | ) |
Creates an instance of the datetime class.
datetime::~datetime | ( | ) |
Destroys this instance of the datetime class.
bool datetime::addDays | ( | int32_t | days | ) |
Adds "days" to the date/time represented in the instance of the class.
bool datetime::addHours | ( | int32_t | hours | ) |
Adds "hours" to the date/time represented in the instance of the class.
bool datetime::addMinutes | ( | int32_t | minutes | ) |
Adds "minutes" to the date/time represented in the instance of the class.
bool datetime::addMonths | ( | int32_t | months | ) |
Adds "months" to the date/time represented in the instance of the class.
bool datetime::addSeconds | ( | int32_t | seconds | ) |
Adds "seconds" to the date/time represented in the instance of the class.
bool datetime::addYears | ( | int32_t | years | ) |
Adds "years" to the date/time represented in the instance of the class.
bool datetime::adjustTimeZone | ( | const char * | newtz | ) |
Recalculates the time currently represented in the class to correspond to the time zone "newtz".
If, in the new timezone, daylight savings time is currently in effect, the time zone will be adjusted accordingly. Ie. if "newtz" = EST and daylight savings time is in effect in EST5EDT, then EDT will be used instead.
Returns true on success and false on failure.
bool datetime::adjustTimeZone | ( | const char * | newtz, |
bool | ignoredst | ||
) |
Recalculates the time currently represented in the class to correspond to the time zone "newtz".
If ignoredst is false, this method works like adjustTimezone(const char *newtz). However if ignoredst is true, this method will not adjust EST to EDT if daylight savings time is in effect in EST5EDT.
Returns true on success and false on failure.
bool datetime::getAdjustedHardwareDateAndTime | ( | const char * | hwtz | ) |
This method only works if your system has a working real-time clock at /dev/rtc.
Gets the date and time from the hardware clock, then adjusts it to the timezone used by the system.
Returns true on success and false on failure.
int32_t datetime::getDayOfMonth | ( | ) | const |
Returns the day of the month component (1-31) of the date/time currently represented in the instance of the class.
int32_t datetime::getDayOfWeek | ( | ) | const |
Returns the day of the week component (1-7) of the date/time currently represented in the instance of the class.
int32_t datetime::getDayOfYear | ( | ) | const |
Returns the day of the year component (1-365) of the date/time currently represented in the instance of the class.
static time_t datetime::getEpoch | ( | const char * | datestring | ) | [static] |
Parses "datestring" which must be of the format: "mm/dd/yyyy hh:mm:ss TZN" and returns the number of seconds since 1970 (the epoch).
Note that TZN must be a valid timezone. Otherwise GMT is assumed.
time_t datetime::getEpoch | ( | ) | const |
Returns the number of seconds since 1970 (the epoch).
static time_t datetime::getEpoch | ( | const void * | tmstruct | ) | [static] |
Takes "tmstruct", a pointer to a platform-specific time structure (struct tm * on unix) and returns the number of seconds since 1970 (the eopch).
Note that in "tmstruct", the timezone and GMT offset must be set to valid values. Otherwise GMT is assumed.
bool datetime::getHardwareDateAndTime | ( | const char * | hwtz | ) |
This method only works if your system has a working real-time clock at /dev/rtc.
Sets the date and time represented in the class to the date and time stored in the hardware clock.
"hwtz" must be set to the timezone that the hardware clock is using.
Returns true on success and false on failure.
int32_t datetime::getHour | ( | ) | const |
Returns the hour component of the date/time currently represented in the instance of the class.
const void* datetime::getInternalTimeStructure | ( | ) |
Returns a pointer to the platform-specific time structure used by the class internally (struct tm * on unix).
int32_t datetime::getMinutes | ( | ) | const |
Returns the minute component of the date/time currently represented in the instance of the class.
int32_t datetime::getMonth | ( | ) | const |
Returns the month component (1-12) of the date/time currently represented in the instance of the class.
const char* datetime::getMonthAbbreviation | ( | ) | const |
Returns the abbreviated name of the month component of the date/time currently represented in the instance of the class.
const char* datetime::getMonthName | ( | ) | const |
Returns the full name of the month component of the date/time currently represented in the instance of the class.
int32_t datetime::getSeconds | ( | ) | const |
Returns the seconds component of the date/time currently represented in the instance of the class.
static char* datetime::getString | ( | const void * | tmstruct | ) | [static] |
Takes "tmstruct", a pointer to a platform-specific time structure (struct tm * on unix) and returns a string in "mm/dd/yyyy hh:mm:ss TZN" format.
Note that this method allocates a buffer to return the string in which must be deleted by the calling program.
const char* datetime::getString | ( | ) |
Returns a string of the format: "mm/dd/yyyy hh:mm:ss TZN" for the date/time represented in the instance of the class.
(Note that this method returns a pointer to an internal string which will be deleted if the class instance is deleted.)
static char* datetime::getString | ( | time_t | seconds | ) | [static] |
Takes "seconds" since the epoch (the number of seconds since 1970) and returns a string in "mm/dd/yyyy hh:mm:ss TZN" format.
Note that this method allocates a buffer to return the string in which must be deleted by the calling program.
bool datetime::getSystemDateAndTime | ( | ) |
Sets the date and time represented in the class to the date and time stored in the system clock.
Returns true on success and false on failure.
static const char* const datetime::getTimeZoneAbbreviations | ( | ) | [static] |
Returns a NULL terminated array of timezone abbreviations.
int32_t datetime::getTimeZoneOffset | ( | ) | const |
Returns the offset from GMT in seconds
static const int32_t* datetime::getTimeZoneOffsets | ( | ) | [static] |
Returns an array of timezone offsets from GMT (in seconds). Each element of this array corresponds to an element of the array returned b getTimeZoneAbbreviations().
const char* datetime::getTimeZoneString | ( | ) | const |
Returns a 3 character string representing the time zone
int32_t datetime::getYear | ( | ) | const |
Returns the year component (including the century) of the date/time currently represented in the instance of the class.
bool datetime::initialize | ( | const char * | tmstring | ) |
Parses "tmstring" and sets the date and time represented in the class to that time. "tmstring" must be of the format: "mm/dd/yyyy hh:mm:ss TZN".
Note that TZN must be a valid timezone. Otherwise GMT is assumed.
Returns true on success and false on failure.
bool datetime::initialize | ( | time_t | seconds | ) |
Processes "seconds" and sets the date and time represented in the class to that time. "seconds" is the number of seconds since 1970 (the epoch).
Returns true on success and false on failure.
bool datetime::initialize | ( | const void * | tmstruct | ) |
Processes "tmstruct" and sets the date and time represented in the class to that time.
"tmstruct" should be a pointer to a platform-specific time structure (struct tm * on unix)
Note that in "tmstruct", the timezone and GMT offset must be set to valid values. Otherwise GMT is assumed.
Returns true on success and false on failure.
bool datetime::isDaylightSavingsTime | ( | ) | const |
Returns true if daylight savings time is currently in effect and false if it isn't
bool datetime::setDays | ( | int32_t | days | ) |
Sets the day-of-the-month component (1-31) of the date/time represented in the instance of the class to "days".
bool datetime::setHardwareDateAndTime | ( | const char * | hwtz | ) |
This method only works if your system has a working real-time clock at /dev/rtc.
Sets the hardware clock's date and time to the date and time currently represented in the class.
"hwtz" must be set to the timezone that the system clock using.
Returns true on success and false on failure.
bool datetime::setHours | ( | int32_t | hours | ) |
Sets the hours component of the date/time represented in the instance of the class to "hours".
bool datetime::setMinutes | ( | int32_t | minutes | ) |
Sets the minutes component of the date/time represented in the instance of the class to "minutes".
bool datetime::setMonths | ( | int32_t | months | ) |
Sets the month component (1-12) of the date/time represented in the instance of the class to "months".
bool datetime::setSeconds | ( | int32_t | seconds | ) |
Sets the seconds component of the date/time represented in the instance of the class to "seconds".
bool datetime::setSystemDateAndTime | ( | ) |
Sets the system clock's date and time to the date and time currently represented in the class.
Returns true on success and false on failure.
static void datetime::setTimeMutex | ( | mutex * | mtx | ) | [static] |
Many of the functions that the datetime class uses internally are not reentrant and thus not thread-safe. Indeed, for some functions, there is no thread-safe version available on any platform.
If your application is multi-threaded, you must use this method to supply a mutex and ensure thread safety.
If you don't supply a mutex, the methods in the class will still work, but will not be thread-safe.
bool datetime::setYears | ( | int32_t | years | ) |
Sets the year component of the date/time represented in the instance of the class to "years".
static bool datetime::validDateTime | ( | const char * | string | ) | [static] |
Returns true if string represents a valid date/time and false otherwise.
For this methods to return true, "string" must be formatted like: "00/00/0000 00:00:00" optionally followed by a space and a timezone.