A class that holds a date and time. More...
#include <libppbase/base/DateTime.h>
Public Member Functions | |
DateTime () | |
Constructor for an empty object (null date). | |
DateTime (const String &s, bool utc=false) | |
Constructor that constructs a new date from a string. | |
void | addDays (int n) |
Increases this date by days. | |
void | addHours (int n) |
Increases this date by hours. | |
void | addMinutes (int n) |
Increases this date by minutes. | |
void | addMonths (int n) |
Increases this date by months. | |
void | addSeconds (int n) |
Increases this date by seconds. | |
void | addYears (int n) |
Increases this date by years. | |
unsigned char | getDay () const |
Gets the day. | |
unsigned char | getDayOfWeek () const |
Gets the number of the day in the week. | |
unsigned | getDayOfYear () const |
Gets the number of the day in the year. | |
unsigned char | getHour () const |
Gets the hour. | |
unsigned | getMilliSecondOfDay () const |
Gets the current millisecond of the day. | |
unsigned short | getMilliSeconds () const |
Gets the milliseconds. | |
unsigned char | getMinute () const |
Gets the minute. | |
unsigned char | getMonth () const |
Gets the month. | |
unsigned char | getMonthDays () const |
Returns the number of days for the current month in year. | |
unsigned char | getSecond () const |
Gets the second. | |
unsigned | getSecondOfDay () const |
Gets the second of the day. | |
short | getYear () const |
Gets the year. | |
unsigned short | getYearDays () const |
Returns the number of days for the current year. | |
bool | isLeapYear () const |
Checks if the year of this date is a leap year. Leap years have 366 instead of 365 days. | |
bool | isNull () const |
Checks if this date is a null date (00.00.0000). | |
bool | isUTC () const |
Checks if the stored date and time is UTC time. | |
void | nextDay () |
Increases the date by one day. | |
void | nextHour () |
Increases the date by one hour. | |
void | nextMinute () |
Increases the date by one minute. | |
void | nextMonth () |
Increases the date by one month. | |
void | nextYear () |
Increases the date by one year. | |
void | prevDay () |
Decreases the date by one day. | |
void | prevHour () |
Decreases the date by one hour. | |
void | prevMinute () |
Decreases the date by one minute. | |
void | prevMonth () |
Decreases the date by one month. | |
void | prevYear () |
Decreases the date by one year. | |
bool | set (const String &str, bool utc=false) |
Sets the date. | |
void | setCurrent (bool utc=false, bool millis=false) |
Sets this object to the system's current date and time. | |
void | setDate (unsigned char day, unsigned char month, short year) |
Sets the date part. | |
void | setUTC (bool utc) |
Sets the utc information. | |
void | setTime (unsigned char hour, unsigned char minute, unsigned char second, unsigned short millis=0) |
Sets the time part. | |
String | toString (const char *format=NULL) const |
Returns the date/time in string representation. | |
bool | valid () const |
Checks if the object contains a valid date and time. | |
void | operator= (const String &s) |
Assignment operator. | |
bool | operator! () const |
Null operator. | |
bool | operator== (const DateTime &d) const |
Equal operator. | |
bool | operator!= (const DateTime &d) const |
Not equal operator. | |
bool | operator< (const DateTime &d) const |
Less operator. | |
bool | operator<= (const DateTime &d) const |
Less or equal operator. | |
bool | operator> (const DateTime &d) const |
Greater operator. | |
bool | operator>= (const DateTime &d) const |
Greater or equal operator. | |
Static Public Member Functions | |
static int | compare (const DateTime &lhs, const DateTime &rhs, bool time=true, bool millis=true) |
Compares two dates. | |
static int | compareDate (const DateTime &lhs, const DateTime &rhs) |
Compares the date part of two objects. | |
static int | compareTime (const DateTime &lhs, const DateTime &rhs, bool millis=true) |
Compares the time part of two objects. | |
static bool | diff (const DateTime &lhs, const DateTime &rhs, unsigned *rdays, unsigned char *rhours=NULL, unsigned char *rminutes=NULL, unsigned char *rseconds=NULL, unsigned short *rmillis=NULL) |
Calculates the difference between two dates. | |
static int | diffSeconds (const DateTime &lhs, const DateTime &rhs) |
Calculates the difference between two dates in seconds. | |
static unsigned | getDayOfYear (unsigned char day, unsigned char month, short year) |
Gets the number of the day in the year. | |
static unsigned char | getMonthDays (unsigned char month, short year) |
Returns the number of days for the given month and year. | |
static unsigned short | getYearDays (short year) |
Returns the number of days for the given year. | |
static bool | isLeapYear (short year) |
Checks if a year is a leap year. Leap years have 366 instead of 365 days. |
A class that holds a date and time.
The rules for leap years are related to protestant Britian. They adopted the gregorian calendar in 1752. This means that 1752 was the first year to adopt the new leap year rules, while all years before 1752 have the old leap year rules. This also means that September 1752 has only 19 days, with September 3rd to September 13th missing.
base::DateTime::DateTime | ( | const String & | s, | |
bool | utc = false | |||
) |
Constructor that constructs a new date from a string.
s | string containing the date | |
utc | true for UTC time, false for local time |
void base::DateTime::addDays | ( | int | n | ) |
Increases this date by days.
n | number of days, a negative value decreases the date |
void base::DateTime::addHours | ( | int | n | ) |
Increases this date by hours.
n | number of hours, a negative value decreases the date |
void base::DateTime::addMinutes | ( | int | n | ) |
Increases this date by minutes.
n | number of minutes, a negative value decreases the date |
void base::DateTime::addMonths | ( | int | n | ) |
Increases this date by months.
n | number of months, a negative value decreases the date |
void base::DateTime::addSeconds | ( | int | n | ) |
Increases this date by seconds.
n | number of seconds, a negative value decreases the date |
void base::DateTime::addYears | ( | int | n | ) |
Increases this date by years.
n | number of years, a negative value decreases the date |
static int base::DateTime::compare | ( | const DateTime & | lhs, | |
const DateTime & | rhs, | |||
bool | time = true , |
|||
bool | millis = true | |||
) | [static] |
Compares two dates.
lhs | the first date | |
rhs | the second date | |
time | flag: compare time too | |
millis | flag: compare milliseconds too |
Compares the date part of two objects.
lhs | the first object | |
rhs | the second object |
static int base::DateTime::compareTime | ( | const DateTime & | lhs, | |
const DateTime & | rhs, | |||
bool | millis = true | |||
) | [static] |
Compares the time part of two objects.
lhs | the first object | |
rhs | the second object | |
millis,: | flag: compare milliseconds too |
static bool base::DateTime::diff | ( | const DateTime & | lhs, | |
const DateTime & | rhs, | |||
unsigned * | rdays, | |||
unsigned char * | rhours = NULL , |
|||
unsigned char * | rminutes = NULL , |
|||
unsigned char * | rseconds = NULL , |
|||
unsigned short * | rmillis = NULL | |||
) | [static] |
Calculates the difference between two dates.
Calculates abs(lhs - rhs)
lhs | the first date | |
rhs | the second date | |
rdays | returns the day difference | |
rhours | returns the hours difference | |
rminutes | returns the minutes difference | |
rseconds | returns the seconds difference | |
rmillis | returns the milliseconds difference |
Calculates the difference between two dates in seconds.
Calculates lhs - rhs
lhs | the first date | |
rhs | the second date |
unsigned char base::DateTime::getDay | ( | ) | const |
Gets the day.
unsigned char base::DateTime::getDayOfWeek | ( | ) | const |
Gets the number of the day in the week.
static unsigned base::DateTime::getDayOfYear | ( | unsigned char | day, | |
unsigned char | month, | |||
short | year | |||
) | [static] |
Gets the number of the day in the year.
day | the day of the month | |
month | the month | |
year | the year |
unsigned base::DateTime::getDayOfYear | ( | ) | const |
Gets the number of the day in the year.
unsigned char base::DateTime::getHour | ( | ) | const |
Gets the hour.
unsigned base::DateTime::getMilliSecondOfDay | ( | ) | const |
Gets the current millisecond of the day.
unsigned short base::DateTime::getMilliSeconds | ( | ) | const |
Gets the milliseconds.
unsigned char base::DateTime::getMinute | ( | ) | const |
Gets the minute.
unsigned char base::DateTime::getMonth | ( | ) | const |
Gets the month.
unsigned char base::DateTime::getMonthDays | ( | ) | const |
Returns the number of days for the current month in year.
static unsigned char base::DateTime::getMonthDays | ( | unsigned char | month, | |
short | year | |||
) | [static] |
Returns the number of days for the given month and year.
month | the given month | |
year | the given year |
unsigned char base::DateTime::getSecond | ( | ) | const |
Gets the second.
unsigned base::DateTime::getSecondOfDay | ( | ) | const |
Gets the second of the day.
short base::DateTime::getYear | ( | ) | const |
Gets the year.
unsigned short base::DateTime::getYearDays | ( | ) | const |
Returns the number of days for the current year.
static unsigned short base::DateTime::getYearDays | ( | short | year | ) | [static] |
Returns the number of days for the given year.
year | the given year |
bool base::DateTime::isLeapYear | ( | ) | const |
Checks if the year of this date is a leap year. Leap years have 366 instead of 365 days.
static bool base::DateTime::isLeapYear | ( | short | year | ) | [static] |
Checks if a year is a leap year. Leap years have 366 instead of 365 days.
year | the year to check |
bool base::DateTime::isNull | ( | ) | const |
Checks if this date is a null date (00.00.0000).
bool base::DateTime::isUTC | ( | ) | const |
Checks if the stored date and time is UTC time.
bool base::DateTime::operator! | ( | ) | const |
Null operator.
bool base::DateTime::operator!= | ( | const DateTime & | d | ) | const |
Not equal operator.
d | date to compare this date to |
bool base::DateTime::operator< | ( | const DateTime & | d | ) | const |
Less operator.
d | date to compare this date to |
bool base::DateTime::operator<= | ( | const DateTime & | d | ) | const |
Less or equal operator.
d | date to compare this date to |
void base::DateTime::operator= | ( | const String & | s | ) |
Assignment operator.
s | new date and time, recognized formats are YYYY-MM-DD [HH:MM:SS[.MS]] and DD.MM.YYYY [HH:MM:SS[.MS]] |
bool base::DateTime::operator== | ( | const DateTime & | d | ) | const |
Equal operator.
d | date to compare this date to |
bool base::DateTime::operator> | ( | const DateTime & | d | ) | const |
Greater operator.
d | date to compare this date to |
bool base::DateTime::operator>= | ( | const DateTime & | d | ) | const |
Greater or equal operator.
d | date to compare this date to |
bool base::DateTime::set | ( | const String & | str, | |
bool | utc = false | |||
) |
Sets the date.
str | new date and time, recognized formats are YYYY-MM-DD [HH:MM:SS] and DD.MM.YYYY [HH:MM:SS] | |
utc | true for UTC time, false for local time |
void base::DateTime::setCurrent | ( | bool | utc = false , |
|
bool | millis = false | |||
) |
Sets this object to the system's current date and time.
utc | true to store the UTC time, false to store the local time | |
millis | true to store milliseconds, false to set the to 0 |
void base::DateTime::setDate | ( | unsigned char | day, | |
unsigned char | month, | |||
short | year | |||
) |
Sets the date part.
day | the day | |
month | the month | |
year | the year |
void base::DateTime::setTime | ( | unsigned char | hour, | |
unsigned char | minute, | |||
unsigned char | second, | |||
unsigned short | millis = 0 | |||
) |
Sets the time part.
hour | the day | |
minute | the month | |
second | the year | |
millis | the milliseconds |
void base::DateTime::setUTC | ( | bool | utc | ) |
Sets the utc information.
utc | true if the stored time is UTC time, false if it is local time zone |
String base::DateTime::toString | ( | const char * | format = NULL |
) | const |
Returns the date/time in string representation.
format | the format to use, a subset of the strftime format (NULL to use a default format) |
bool base::DateTime::valid | ( | ) | const |
Checks if the object contains a valid date and time.