#include <date.h>
Public Member Functions | |
Date () | |
Default constructor, initializes to ``now''. | |
Date (time_t secs) | |
Date(time_t t) assumes that t is number of seconds since Jan 1, 1970. | |
Date (unsigned int year, unsigned int month, unsigned int day, unsigned int hrs=0, unsigned int min=0, unsigned int sec=0) | |
Initialize Date, note that january = 0. | |
Date (const std::string &s) throw (std::runtime_error) | |
Construct a date from a string representation. | |
std::string | str (const char *fmt=0) const |
Produce a string representing the date, according to format. | |
std::string | gmt (const char *fmt=0) const |
Like str() but formats in GMT time zone, e.g. | |
long int | gmt_offset () const |
Seconds east of UTC (GMT) of this date. | |
unsigned short | year () const |
Return number of years. | |
unsigned short | month () const |
Return month of Date. | |
int | isdst () const |
Is daylight savings time (DST) in effect? See man mktime. | |
unsigned short | day () const |
Return day-in-month of Date. | |
unsigned short | hours () const |
Return the hour in the day of Date. | |
unsigned short | minutes () const |
Return the minutes in the hour of this Date. | |
unsigned short | seconds () const |
Return the seconds in the minute of this Date. | |
unsigned short | wday (bool monday_is_0=false) const |
Return the day in the week of this Date. | |
unsigned short | yday () const |
Return the day in the year of this Date. | |
unsigned short | yweek () const |
Return the number of the week in the year of this Date. | |
unsigned long | week_since_epoch () const |
Return the number of the week since the epoch. | |
unsigned long | days_since_epoch () const |
Return the number days since the epoch. | |
void | year (unsigned short yr) |
Set year. | |
void | month (unsigned short mo) |
Set month. | |
void | day (unsigned short day) |
Set day in month. | |
void | hours (unsigned short hrs) |
Set hours. | |
void | minutes (unsigned short mins) |
Set minutes. | |
void | seconds (unsigned short secs) |
Set seconds. | |
void | yday (unsigned short yday) |
Set date to date with this yday in same year. | |
time_t | time () const |
Returns number of secs since 1/1/1970. | |
void | time (time_t time) |
Set time. | |
bool | operator< (const Date &d) const |
Date comparison respects chronological order. | |
bool | operator== (const Date &d) const |
Date comparison respects chronological order. | |
bool | operator> (const Date &d) const |
Date comparison respects chronological order. | |
bool | operator!= (const Date &d) const |
Date comparison respects chronological order. | |
bool | operator>= (const Date &d) const |
Date comparison respects chronological order. | |
bool | operator<= (const Date &d) const |
Date comparison respects chronological order. | |
Date & | operator+= (const Duration &duration) |
Add a duration to a Date. | |
Private Attributes | |
time_t | time_ |
A simple Date class.
It provides a convenient interface to system functions such as locatime_r() etc. Its only data member is a time_t value. Note that only dates since Jan 1, 1970 can be represented.
The default copy constructor and assignment operations are available.
Definition at line 26 of file date.h.
Dv::Date::Date | ( | ) |
Default constructor, initializes to ``now''.
Dv::Date::Date | ( | time_t | secs | ) |
Date(time_t t) assumes that t is number of seconds since Jan 1, 1970.
Dv::Date::Date | ( | unsigned int | year, | |
unsigned int | month, | |||
unsigned int | day, | |||
unsigned int | hrs = 0 , |
|||
unsigned int | min = 0 , |
|||
unsigned int | sec = 0 | |||
) |
Initialize Date, note that january = 0.
Dv::Date::Date | ( | const std::string & | s | ) | throw (std::runtime_error) |
Construct a date from a string representation.
This constructor uses the gnu getdate parsing function which accepts a number of formats, e.g.
* 1970-09-17 # ISO 8601. * 1970-09-17 20:02:00 * 70-9-17 # This century assumed by default. * 70-09-17 # Leading zeros are ignored. * 9/17/72 # Common U.S. writing. * 24 September 1972 * 24 Sept 72 # September has a special abbreviation. * 24 Sep 72 # Three-letter abbreviations always allowed. * Sep 24, 1972 * 24-sep-72 * 24sep72 * * 20:02:0 * 20:02 * 8:02pm * 20:02-0500 # In EST (Eastern U.S. Standard Time) *
and many others (see the gnu fileutils documentation).
As a special case, it also accepts the Mysql timestamp format, i.e. strings of the form YYYYMMDDHHMMSS, e.g. "20051023170328".
std::string Dv::Date::str | ( | const char * | fmt = 0 |
) | const |
Produce a string representing the date, according to format.
The format is any string acceptable to strftime. If fmt=0, the default is "\%a \%b \%d \%H:\%M:\%S \%Y" e.g.
"Wed Aug 12 18:38:10 1998"
The default format is acceptable to the parser.
std::string Dv::Date::gmt | ( | const char * | fmt = 0 |
) | const |
Like str() but formats in GMT time zone, e.g.
03:00 MET DST is 02:00 GMT.
long int Dv::Date::gmt_offset | ( | ) | const |
Seconds east of UTC (GMT) of this date.
unsigned short Dv::Date::year | ( | ) | const |
Return number of years.
unsigned short Dv::Date::month | ( | ) | const |
int Dv::Date::isdst | ( | ) | const |
Is daylight savings time (DST) in effect? See man mktime.
unsigned short Dv::Date::day | ( | ) | const |
unsigned short Dv::Date::hours | ( | ) | const |
unsigned short Dv::Date::minutes | ( | ) | const |
unsigned short Dv::Date::seconds | ( | ) | const |
unsigned short Dv::Date::wday | ( | bool | monday_is_0 = false |
) | const |
Return the day in the week of this Date.
monday_is_0 | if true, use (monday = 0, tuesday = 1, .., sunday = 6) representation, otherwise use (sunday = 0, monday = 1, tuesday = 1, .., saturday = 6) representation. |
unsigned short Dv::Date::yday | ( | ) | const |
unsigned short Dv::Date::yweek | ( | ) | const |
Return the number of the week in the year of this Date.
From http://www.merlyn.demon.co.uk/: All ISO weeks are Monday = 1 to Sunday = 7, and week 01 of the numbering year is the one containing the first Thursday of the Gregorian year. Thus up to three days of the first and last weeks for a year number can be in the adjacent Gregorian year; December 29 to January 03 can have a numbering year differing from the Gregorian.
unsigned long Dv::Date::week_since_epoch | ( | ) | const |
Return the number of the week since the epoch.
Jan 1st 1970 is a thursday, so the first ISO week (with number 1) starts on monday Jan 5th 1970.
unsigned long Dv::Date::days_since_epoch | ( | ) | const |
Return the number days since the epoch.
Jan 1st 1970 is day 0. From http://www.merlyn.demon.co.uk/: All ISO weeks are Monday = 1 to Sunday = 7, and week 01 of the numbering year is the one containing the first Thursday of the Gregorian year. Thus up to three days of the first and last weeks for a year number can be in the adjacent Gregorian year; December 29 to January 03 can have a numbering year differing from the Gregorian.
void Dv::Date::year | ( | unsigned short | yr | ) |
void Dv::Date::month | ( | unsigned short | mo | ) |
Set month.
Functions that set part of the Date object. Values that are too large will be converted, e.g. to next day. E.g.
Date d("Mon Jan 01 23:00:00 CET 2001"); d.hours(36); cout<< d.str();
will print "Tue Jan 02 12:00:00 CET 2001".
mo | month (jan=0, .., dec=11) |
void Dv::Date::day | ( | unsigned short | day | ) |
Set day in month.
Functions that set part of the Date object. Values that are too large will be converted, e.g. to next day. E.g.
Date d("Mon Jan 01 23:00:00 CET 2001"); d.hours(36); cout<< d.str();
will print "Tue Jan 02 12:00:00 CET 2001".
day | (1..31) |
void Dv::Date::hours | ( | unsigned short | hrs | ) |
Set hours.
Functions that set part of the Date object. Values that are too large will be converted, e.g. to next day. E.g.
Date d("Mon Jan 01 23:00:00 CET 2001"); d.hours(36); cout<< d.str();
will print "Tue Jan 02 12:00:00 CET 2001".
hrs | (0..23) |
void Dv::Date::minutes | ( | unsigned short | mins | ) |
Set minutes.
Functions that set part of the Date object. Values that are too large will be converted, e.g. to next day. E.g.
Date d("Mon Jan 01 23:00:00 CET 2001"); d.hours(36); cout<< d.str();
will print "Tue Jan 02 12:00:00 CET 2001".
mins | (0..59) |
void Dv::Date::seconds | ( | unsigned short | secs | ) |
Set seconds.
Functions that set part of the Date object. Values that are too large will be converted, e.g. to next day. E.g.
Date d("Mon Jan 01 23:00:00 CET 2001"); d.hours(36); cout<< d.str();
will print "Tue Jan 02 12:00:00 CET 2001".
secs | (0..59) |
void Dv::Date::yday | ( | unsigned short | yday | ) |
Set date to date with this yday in same year.
Values that are too large will be converted, e.g. to next day. E.g.
Date d("Mon Jan 01 23:00:00 CET 2001"); d.hours(36); cout<< d.str();
will print "Tue Jan 02 12:00:00 CET 2001".
yday | (0..365) |
time_t Dv::Date::time | ( | ) | const [inline] |
Returns number of secs since 1/1/1970.
Definition at line 282 of file date.h.
References time_.
Referenced by operator<(), and operator==().
void Dv::Date::time | ( | time_t | time | ) |
Set time.
time | number of secs since the epoch (Jan 1st 1970 00:00 GMT, or Jan 1st 1970 01:00 MET). |
bool Dv::Date::operator< | ( | const Date & | d | ) | const [inline] |
bool Dv::Date::operator== | ( | const Date & | d | ) | const [inline] |
bool Dv::Date::operator> | ( | const Date & | d | ) | const [inline] |
bool Dv::Date::operator!= | ( | const Date & | d | ) | const [inline] |
bool Dv::Date::operator>= | ( | const Date & | d | ) | const [inline] |
bool Dv::Date::operator<= | ( | const Date & | d | ) | const [inline] |
Add a duration to a Date.
duration | to add |
time_t Dv::Date::time_ [private] |
dvutil-1.0.10 | [ 5 December, 2009] |