DateTime Class Reference

#include <Pt/DateTime.h>

Combined Date and Time value. More...

Public Member Functions

 DateTime ()
 Default Constructor.
 
 DateTime (int y, unsigned mon, unsigned d, unsigned h=0, unsigned min=0, unsigned s=0, unsigned ms=0)
 Construct to date and time.
 
 DateTime (const DateTime &dateTime)
 Copy Constructor.
 
const Datedate () const
 Gets the date.
 
Datedate ()
 Gets the date.
 
unsigned day () const
 Returns the day-part of the date.
 
void get (int &year, unsigned &month, unsigned &day, unsigned &hour, unsigned &min, unsigned &sec, unsigned &msec) const
 Gets the date and time.
 
unsigned hour () const
 Returns the hour-part of the Time.
 
unsigned minute () const
 Returns the minute-part of the Time.
 
unsigned month () const
 Returns the month-part of the date.
 
unsigned msec () const
 Returns the millisecond-part of the Time.
 
DateTimeoperator+= (const Timespan &ts)
 Assignment by sum operator.
 
DateTimeoperator-= (const Timespan &ts)
 Assignment by difference operator.
 
DateTimeoperator= (const DateTime &dateTime)
 Assignment operator.
 
unsigned second () const
 Returns the second-part of the Time.
 
void set (int year, unsigned month, unsigned day, unsigned hour=0, unsigned min=0, unsigned sec=0, unsigned msec=0)
 Sets the date and time.
 
DateTimesetDate (const Date &dt)
 Sets the date.
 
DateTimesetTime (const Time &t)
 Sets the time.
 
const Timetime () const
 Gets the time.
 
Timetime ()
 Gets the time.
 
std::string toIsoString () const
 Returns the date and time in ISO-format.
 
int year () const
 Returns the year-part of the date.
 

Static Public Member Functions

static DateTime fromIsoString (const std::string &s)
 Interprets a string as a date and time in ISO-format.
 
static bool isValid (int year, unsigned month, unsigned day, unsigned hour, unsigned minute, unsigned second, unsigned msec)
 Returns true if values are a valid date and time.
 

Related Functions

bool operator!= (const DateTime &a, const DateTime &b)
 Returns true if not equal.
 
DateTime operator+ (const DateTime &dt, const Timespan &ts)
 Add a timespan.
 
Timespan operator- (const DateTime &first, const DateTime &second)
 Subtract two DateTimes.
 
DateTime operator- (const DateTime &dt, const Timespan &ts)
 Subtract a timespan.
 
bool operator< (const DateTime &a, const DateTime &b)
 Less-than comparison operator.
 
void operator<<= (SerializationInfo &si, const DateTime &dt)
 Serialize a DateTime.
 
bool operator<= (const DateTime &a, const DateTime &b)
 Less-than-equal comparison operator.
 
bool operator== (const DateTime &a, const DateTime &b)
 Returns true if equal.
 
bool operator> (const DateTime &a, const DateTime &b)
 Greater-than comparison operator.
 
bool operator>= (const DateTime &a, const DateTime &b)
 Greater-than-equal comparison operator.
 
void operator>>= (const SerializationInfo &si, DateTime &dt)
 Deserialize a DateTime.
 

Detailed Description

Pt::DateTime combines a Pt::Date and a Pt::Time object into one instance. It can either be constructed from the corrsponding numeric values or a string in ISO format. The date and time parts can be accessed with date() and time(). When two DateTimes are compared, one is considered less, if its date is earlier or if the time is earlier in case of equal dates. A Pt::Timespan can be added or subtracted from a DateTime and this is also the result when two DateTimes are subtracted. To avoid the exceptions thrown by the underlying time and date, isValid() can be used to check numeric date and time values.