Pyro higlevel API
Classes | Public Member Functions | Static Public Member Functions | List of all members
os::DateTime Class Reference

Abstract datatype for date and time. More...

Inheritance diagram for os::DateTime:
os::Flattenable

Classes

class  Private
 

Public Member Functions

 DateTime ()
 Default constructor. More...
 
 DateTime (const DateTime &cDateTime)
 Copy constructor. More...
 
 DateTime (const String &cTime)
 Constructor: string. More...
 
 DateTime (struct tm *psTime)
 Constructor: struct tm. More...
 
 DateTime (int nTime)
 Constructor: Unix Epoch. More...
 
 DateTime (int nYear, int nMonth, int nDay)
 Constructor: Date. More...
 
 DateTime (int nHour, int nMin, int nSec, int nUSec)
 Constructor: Time. More...
 
 ~DateTime ()
 
int GetDay () const
 Get day of month. More...
 
int GetMonth () const
 Get month of year. More...
 
int GetYear () const
 Get year. More...
 
int GetHour () const
 Get hours. More...
 
int GetMin () const
 Get minutes. More...
 
int GetSec () const
 Get seconds. More...
 
int GetUSec () const
 
int GetDayOfWeek () const
 
double GetDaycount () const
 Get number of days. More...
 
double GetJulianDate () const
 Get Julian date. More...
 
time_t GetEpoch () const
 Get Unix Epoch. More...
 
String GetDate () const
 
void SetTime (int nHour, int nMin, int nSec, int nUSec)
 Set time value. More...
 
void SetDate (int nYear, int nMonth, int nDay)
 Set date value. More...
 
bool SetDate (const String &cDate)
 
bool IsValid () const
 Check if date is valid. More...
 
DateTimeoperator= (const DateTime &cTime)
 Assign a DateTime value. More...
 
DateTime operator+ (const DateTime &cTime) const
 Add a DateTime value. More...
 
DateTime operator+ (double vDays) const
 Add a number of days to date. More...
 
DateTime operator- (const DateTime &cTime) const
 Subtract a DateTime value. More...
 
DateTime operator- (double vDays) const
 Subtract a number of days from date. More...
 
DateTimeoperator+= (const DateTime &cTime)
 Add a DateTime value. More...
 
DateTimeoperator+= (double vDays)
 Add a number of days to date. More...
 
DateTimeoperator-= (const DateTime &cTime)
 Subtract a DateTime value. More...
 
DateTimeoperator-= (double vDays)
 Subtract a number of days from date. More...
 
int operator== (const DateTime &cTime) const
 Compare dates. More...
 
int operator!= (const DateTime &cTime) const
 Compare dates. More...
 
int operator< (const DateTime &cTime) const
 Compare dates. More...
 
int operator> (const DateTime &cTime) const
 Compare dates. More...
 
 operator time_t () const
 
 operator std::string () const
 
 operator os::String () const
 
virtual size_t GetFlattenedSize (void) const
 
virtual status_t Flatten (uint8 *pBuffer, size_t nSize) const
 
virtual status_t Unflatten (const uint8 *pBuffer)
 
virtual int GetType (void) const
 
- Public Member Functions inherited from os::Flattenable
virtual bool TypeIsCompatible (int nType) const
 

Static Public Member Functions

static DateTime Now ()
 Get current date and time. More...
 

Detailed Description

Description:
DateTime is a storage class for date and time values. It also facilitates a number of arithmetic operations.
Examples:
DateTime cTomorrow = cToday + 24.0;
DateTime cLastYear = cToday - DateTime( 1, 0, 0 );
double vNumberOfDays = ( cToday - DateTime( 2003, 8, 30 ) ).GetDaycount();
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

Constructor & Destructor Documentation

DateTime::DateTime ( )
Description:
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

Referenced by Now().

DateTime::DateTime ( const DateTime cDateTime)
Description:
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::DateTime::Private::Copy().

DateTime::DateTime ( const String cDate)
Description:
Creates a DateTime object from a string.
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References SetDate().

DateTime::DateTime ( struct tm *  psTime)
DateTime::DateTime ( int  nTime)
Description:
Creates a DateTime object from a Unix Epoch number (ie. the number of seconds since 1970-01-01 00:00:00).
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::DateTime::Private::m_bJulian, os::DateTime::Private::m_nDay, os::DateTime::Private::m_nMonth, os::DateTime::Private::m_nYear, os::DateTime::Private::m_vSec, and os::DateTime::Private::ToJulian().

DateTime::DateTime ( int  nYear,
int  nMonth,
int  nDay 
)
DateTime::DateTime ( int  nHour,
int  nMin,
int  nSec,
int  nUSec 
)
DateTime::~DateTime ( )

Member Function Documentation

status_t DateTime::Flatten ( uint8 *  pBuffer,
size_t  nSize 
) const
virtual
String DateTime::GetDate ( ) const

References GetEpoch().

int DateTime::GetDay ( ) const
Description:
Returns the day of month (1 - 31), or the number of days, if this DateTime object is used to represent a duration.
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::DateTime::Private::m_nDay, and os::DateTime::Private::ToGregorian().

Referenced by os::CalendarView::Update().

double DateTime::GetDaycount ( ) const
Description:
Returns the number of days since year 0. Use this method to get the difference between two dates as a number of days.
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::DateTime::Private::GetJulianDate().

int DateTime::GetDayOfWeek ( ) const
time_t DateTime::GetEpoch ( ) const
Description:
Returns the number of seconds since 1970-01-01 00:00:00.
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::DateTime::Private::GetJulianDate().

Referenced by GetDate().

size_t DateTime::GetFlattenedSize ( void  ) const
virtual
int DateTime::GetHour ( ) const
Description:
Returns hours since midnight, or the number of hours if this DateTime object is used to represent a duration.
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::DateTime::Private::m_vSec, and os::DateTime::Private::ToGregorian().

double DateTime::GetJulianDate ( ) const
Description:
Returns the number of days since 4712 B.C.
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::DateTime::Private::GetJulianDate().

int DateTime::GetMin ( ) const
Description:
Returns minutes since the hour (0-59).
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::DateTime::Private::m_vSec, and os::DateTime::Private::ToGregorian().

int DateTime::GetMonth ( ) const
Description:
Returns the month of year (1 - 12), or the number of months, if this DateTime object is used to represent a duration.
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::DateTime::Private::m_nMonth, and os::DateTime::Private::ToGregorian().

Referenced by os::CalendarView::HandleMessage(), and os::CalendarView::Update().

int DateTime::GetSec ( ) const
Description:
Returns seconds (0-59).
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::DateTime::Private::m_vSec, and os::DateTime::Private::ToGregorian().

int DateTime::GetType ( void  ) const
virtual

Implements os::Flattenable.

References os::T_DATETIME.

int os::DateTime::GetUSec ( ) const
int DateTime::GetYear ( ) const
Description:
Returns the year, or the number of years, if this DateTime object is used to represent a duration.
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::DateTime::Private::m_nYear, and os::DateTime::Private::ToGregorian().

Referenced by os::CalendarView::HandleMessage(), and os::CalendarView::Update().

bool DateTime::IsValid ( ) const
Description:
Returns true if the object contains a valid date. Examples of invalid dates include "2003-13-01", "2003-00-01", "2003-02-30" etc.
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::DateTime::Private::IsDateValid().

DateTime DateTime::Now ( )
static
Description:
Returns a DateTime object containing the current date and time.
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References DateTime().

Referenced by os::DateView::Private::Private(), and os::CalendarView::Update().

os::DateTime::operator os::String ( ) const
inline
os::DateTime::operator std::string ( ) const
inline
os::DateTime::operator time_t ( ) const
inline
int DateTime::operator!= ( const DateTime cTime) const
Description:
Dates are compared according to their Julian date equivalents. This means that 2003-08-30 13:39 is considered equal to 2003-08-29 37:39.
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::DateTime::Private::GetJulianDate().

DateTime DateTime::operator+ ( const DateTime cTime) const
Description:
Add one DateTime value to another. The result will be a valid Gregorian calendar date (months and years will be adjusted automatically), even if the operands are not valied dates.
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)
DateTime DateTime::operator+ ( double  vDays) const
Description:
Add a number of days, or a fraction of a day, to the DateTime value. The result is a valid Gregorian calendar date (months and years will be adjusted automatically).
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)
DateTime & DateTime::operator+= ( const DateTime cTime)
Description:
Add one DateTime value to another. The result will be a valid Gregorian calendar date (months and years will be adjusted automatically), even if the operands are not valied dates.
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::DateTime::Private::m_nDay, os::DateTime::Private::m_nMonth, os::DateTime::Private::m_nYear, os::DateTime::Private::ToGregorian(), and os::DateTime::Private::ToJulian().

DateTime & DateTime::operator+= ( double  vDays)
Description:
Add a number of days, or a fraction of a day, to the DateTime value. The result is a valid Gregorian calendar date (months and years will be adjusted automatically).
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::DateTime::Private::m_vTimeVal, and os::DateTime::Private::ToJulian().

DateTime DateTime::operator- ( const DateTime cTime) const
Description:
Subtract one DateTime value from another. The result will be a valid Gregorian calendar date (months and value. The result is a valid Gregorian calendar date (months and years will be adjusted automatically), even if the operands are not valied dates.
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)
DateTime DateTime::operator- ( double  vDays) const
Description:
Subtract a number of days, or a fraction of a day, from the DateTime value. The result is a valid Gregorian calendar date (months and years will be adjusted automatically).
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)
DateTime & DateTime::operator-= ( const DateTime cTime)
Description:
Subtract one DateTime value from another. The result will be a valid Gregorian calendar date (months and value. The result is a valid Gregorian calendar date (months and years will be adjusted automatically), even if the operands are not valied dates.
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::DateTime::Private::m_nDay, os::DateTime::Private::m_nMonth, os::DateTime::Private::m_nYear, os::DateTime::Private::ToGregorian(), and os::DateTime::Private::ToJulian().

DateTime & DateTime::operator-= ( double  vDays)
Description:
Subtract a number of days, or a fraction of a day, from the DateTime value. The result is a valid Gregorian calendar date (months and years will be adjusted automatically).
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::DateTime::Private::m_vTimeVal, and os::DateTime::Private::ToJulian().

int DateTime::operator< ( const DateTime cTime) const
Description:
Dates are compared according to their Julian date equivalents. This means that 2003-08-30 13:39 is considered equal to 2003-08-29 37:39.
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::DateTime::Private::GetJulianDate().

DateTime & DateTime::operator= ( const DateTime cTime)
Description:
Makes an exact copy of the source object.
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::DateTime::Private::Copy().

int DateTime::operator== ( const DateTime cTime) const
Description:
Dates are compared according to their Julian date equivalents. This means that 2003-08-30 13:39 is considered equal to 2003-08-29 37:39.
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::DateTime::Private::GetJulianDate().

int DateTime::operator> ( const DateTime cTime) const
Description:
Dates are compared according to their Julian date equivalents. This means that 2003-08-30 13:39 is considered equal to 2003-08-29 37:39.
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::DateTime::Private::GetJulianDate().

void DateTime::SetDate ( int  nYear,
int  nMonth,
int  nDay 
)
Description:
Set the date value of a DateTime object. The time value is left unchanged. No validity checking is performed, this method will happily accept a date like 2003-13-32. (This would be interpreted as 1 Feb 2004.)
Parameters
nYearYear
nMonthMonth
nDayYear
See Also
SetTime()
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::DateTime::Private::m_nDay, os::DateTime::Private::m_nMonth, os::DateTime::Private::m_nYear, and os::DateTime::Private::ToGregorian().

Referenced by DateTime(), and SetDate().

bool DateTime::SetDate ( const String cDate)
void DateTime::SetTime ( int  nHour,
int  nMin,
int  nSec,
int  nUSec 
)
Description:
Set the time value of a DateTime object. The date value is left unchanged. No validity checking is performed.
Parameters
nHourHours since midnight
nMinMinutes past the hour
nSecSeconds
nUSecMicroseconds
See Also
SetDate()
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::DateTime::Private::m_vSec, and os::DateTime::Private::ToGregorian().

Referenced by SetDate().

status_t DateTime::Unflatten ( const uint8 *  pBuffer)
virtual