Combined Date and Time value. More...

#include <tntdb/cxxtools/datetime.h>

Public Member Functions

 DateTime ()
 DateTime (const std::string &d, const std::string &fmt="%Y-%m-%d %H:%M:%S%j")
 create DateTime from string using format
 DateTime (int year, unsigned month, unsigned day, unsigned hour, unsigned minute, unsigned second, unsigned msec=0, unsigned usec=0)
 DateTime (const Date &date, const Time &time)
void set (int year, unsigned month, unsigned day, unsigned hour, unsigned min, unsigned sec, unsigned msec=0, unsigned usec=0)
 Sets the date and time.
void get (int &year, unsigned &month, unsigned &day, unsigned &hour, unsigned &min, unsigned &sec, unsigned &msec) const
 Returns the components of the date time.
void get (int &year, unsigned &month, unsigned &day, unsigned &hour, unsigned &min, unsigned &sec, unsigned &msec, unsigned &usec) const
 Returns the components of the date time.
const Datedate () const
 Returns the date part of the DateTime object.
DateTimesetDate (const Date &date)
 Set the date part and keeps the time of the DateTime object.
const Timetime () const
 Returns the time part of the DateTime object.
DateTimesetTime (const Time &time)
 Set the time part and keeps the date of the DateTime object.
unsigned day () const
 Returns the day part of the date.
unsigned month () const
 Returns the month part of the date.
int year () const
 Returns the year part of the date.
unsigned dayOfWeek () const
 Return day of the week, starting with sunday (=0)
unsigned hour () const
 Returns the hour part of the Time.
unsigned minute () const
 Returns the minute part of the Time.
unsigned second () const
 Returns the second part of the Time.
unsigned msec () const
 Returns the millisecond part of the Time.
Milliseconds msecsSinceEpoch () const
 Returns the milliseconds relative to the Unix epoch.
std::string toString (const std::string &fmt="%Y-%m-%d %H:%M:%S%j") const
 format Date into a string using a format string
std::string toIsoString () const
bool operator== (const DateTime &rhs) const
bool operator!= (const DateTime &rhs) const
DateTimeoperator+= (const Timespan &ts)
 Assignment by sum operator.
DateTimeoperator-= (const Timespan &ts)
 Assignment by difference operator.
bool operator< (const DateTime &dt) const
bool operator<= (const DateTime &dt) const
bool operator> (const DateTime &dt) const
bool operator>= (const DateTime &dt) const

Static Public Member Functions

static DateTime fromMSecsSinceEpoch (cxxtools::Milliseconds sinceEpoch)
 Creates a DateTime object relative to the Unix epoch.
static DateTime gmtime ()
 Returns the GMT time.
static DateTime localtime ()
 Returns the local time.
static DateTime fromIsoString (const std::string &s)
static bool isValid (int year, unsigned month, unsigned day, unsigned hour, unsigned minute, unsigned second, unsigned msec=0)

Friends

Timespan operator- (const DateTime &first, const DateTime &second)
DateTime operator+ (const DateTime &dt, const Timespan &ts)
DateTime operator- (const DateTime &dt, const Timespan &ts)

Detailed Description

Combined Date and Time value.

Constructor & Destructor Documentation

cxxtools::DateTime::DateTime ( )
inline
cxxtools::DateTime::DateTime ( const std::string &  d,
const std::string &  fmt = "%Y-%m-%d %H:%M:%S%j" 
)
explicit

create DateTime from string using format

Valid format codes are:

Y 4 digit year y 2 digit year m month (1-12) %2m month (01-12) d day (1-31) %2d day (01-31) H hours (0-23) %2H hours (00-23) I hours (0-11) %2I hours (00-11) M minutes (0-59) %2M minutes (00-59) S seconds (0-59) %2S seconds (00-59) j fractional seconds (1-6 digits, optionally leading '.') J fractional seconds (1-6 digits, with leading '.') K milliseconds (3 digits, with leading '.') k milliseconds (3 digits) U microseconds (6 digits, with leading '.') u microseconds (6 digits) p AM/PM ? arbitrary character skip non digit characters

cxxtools::DateTime::DateTime ( int  year,
unsigned  month,
unsigned  day,
unsigned  hour,
unsigned  minute,
unsigned  second,
unsigned  msec = 0,
unsigned  usec = 0 
)
inline
cxxtools::DateTime::DateTime ( const Date date,
const Time time 
)
inline

Member Function Documentation

const Date& cxxtools::DateTime::date ( ) const
inline

Returns the date part of the DateTime object.

unsigned cxxtools::DateTime::day ( ) const
inline

Returns the day part of the date.

unsigned cxxtools::DateTime::dayOfWeek ( ) const
inline

Return day of the week, starting with sunday (=0)

static DateTime cxxtools::DateTime::fromIsoString ( const std::string &  s)
inlinestatic
static DateTime cxxtools::DateTime::fromMSecsSinceEpoch ( cxxtools::Milliseconds  sinceEpoch)
inlinestatic

Creates a DateTime object relative to the Unix epoch.

The DateTime will be relative to the unix epoch (Jan 1st 1970) by the milli seconds specified by msecsSinceEpoch. The construction does not take care of any time zones. I.e. the milliseconds will be treated as if they were in the same time zone as the reference (January 1st 1970). Thus specifying a "time zoned" millisecond value will lead to a "time zoned" DateTime. And accordingly a "GMT" millisecond value will lead to a "GMT" DateTime.

void cxxtools::DateTime::get ( int &  year,
unsigned &  month,
unsigned &  day,
unsigned &  hour,
unsigned &  min,
unsigned &  sec,
unsigned &  msec 
) const
inline

Returns the components of the date time.

void cxxtools::DateTime::get ( int &  year,
unsigned &  month,
unsigned &  day,
unsigned &  hour,
unsigned &  min,
unsigned &  sec,
unsigned &  msec,
unsigned &  usec 
) const
inline

Returns the components of the date time.

static DateTime cxxtools::DateTime::gmtime ( )
static

Returns the GMT time.

unsigned cxxtools::DateTime::hour ( ) const
inline

Returns the hour part of the Time.

bool cxxtools::DateTime::isValid ( int  year,
unsigned  month,
unsigned  day,
unsigned  hour,
unsigned  minute,
unsigned  second,
unsigned  msec = 0 
)
inlinestatic
static DateTime cxxtools::DateTime::localtime ( )
static

Returns the local time.

unsigned cxxtools::DateTime::minute ( ) const
inline

Returns the minute part of the Time.

unsigned cxxtools::DateTime::month ( ) const
inline

Returns the month part of the date.

unsigned cxxtools::DateTime::msec ( ) const
inline

Returns the millisecond part of the Time.

Milliseconds cxxtools::DateTime::msecsSinceEpoch ( ) const

Returns the milliseconds relative to the Unix epoch.

The calculation does currently not take care of any time zones. I.e. the milliseconds will be calculated as if they were in the same time zone as the reference (January 1st 1970). Thus calling this API on a "time zoned" DateTime will lead to a "time zoned" millisecond value. And accordingly calling this API on a "GMT" DateTime will lead to a "GMT" millisecond value.

bool cxxtools::DateTime::operator!= ( const DateTime rhs) const
inline
DateTime& cxxtools::DateTime::operator+= ( const Timespan ts)

Assignment by sum operator.

DateTime& cxxtools::DateTime::operator-= ( const Timespan ts)
inline

Assignment by difference operator.

bool cxxtools::DateTime::operator< ( const DateTime dt) const
inline
bool cxxtools::DateTime::operator<= ( const DateTime dt) const
inline
bool cxxtools::DateTime::operator== ( const DateTime rhs) const
inline
bool cxxtools::DateTime::operator> ( const DateTime dt) const
inline
bool cxxtools::DateTime::operator>= ( const DateTime dt) const
inline
unsigned cxxtools::DateTime::second ( ) const
inline

Returns the second part of the Time.

void cxxtools::DateTime::set ( int  year,
unsigned  month,
unsigned  day,
unsigned  hour,
unsigned  min,
unsigned  sec,
unsigned  msec = 0,
unsigned  usec = 0 
)
inline

Sets the date and time.

DateTime& cxxtools::DateTime::setDate ( const Date date)
inline

Set the date part and keeps the time of the DateTime object.

DateTime& cxxtools::DateTime::setTime ( const Time time)
inline

Set the time part and keeps the date of the DateTime object.

const Time& cxxtools::DateTime::time ( ) const
inline

Returns the time part of the DateTime object.

std::string cxxtools::DateTime::toIsoString ( ) const
inline
std::string cxxtools::DateTime::toString ( const std::string &  fmt = "%Y-%m-%d %H:%M:%S%j") const

format Date into a string using a format string

Valid format codes are:

d day (01-31) %1d day (1-31) m month (01-12) %1m month (1-12) Y 4 digit year y 2 digit year w day of week (0-6 sunday=6) W day of week (1-7 sunday=7) H hours (00-23) %1H hours (0-23) I hours (00-11) %1I hours (0-11) M minutes (00-59) %1M minutes (0-59) S seconds (00-59) %1S seconds (0-59) j fractional seconds (1-6 digits, optionally leading '.') J fractional seconds (1-6 digits, with leading '.') K milliseconds (3 digits, with leading '.') k milliseconds (3 digits) U microseconds (6 digits, with leading '.') u microseconds (6 digits) p am/pm P AM/PM

int cxxtools::DateTime::year ( ) const
inline

Returns the year part of the date.

Friends And Related Function Documentation

DateTime operator+ ( const DateTime dt,
const Timespan ts 
)
friend
Timespan operator- ( const DateTime first,
const DateTime second 
)
friend
DateTime operator- ( const DateTime dt,
const Timespan ts 
)
friend

The documentation for this class was generated from the following file: