You.i Engine
CYIDateTime Class Reference

Detailed Description

Utility class that requires a string as per the following format: http://en.wikipedia.org/wiki/ISO_8601 to construct an instance and provides some commmonly used parts like year, month, hour etc. in different data types and formats. All dates are in the local timezone unless otherwise specified.

#include <utility/YiDateTime.h>

Public Types

enum  StringFormat {
  StringFormat::ISO_8601,
  StringFormat::RFC_1123
}
 
typedef int64_t TimeDelta
 

Public Member Functions

 CYIDateTime (const CYIString &rDateTimeString)
 
 CYIDateTime (const time_t epochTime)
 
 CYIDateTime ()
 
virtual ~CYIDateTime ()
 
bool IsValid () const
 
uint32_t GetDay () const
 
bool SetDay (uint32_t day)
 
uint32_t GetMonth () const
 
bool SetMonth (uint32_t month)
 
uint32_t GetYear () const
 
bool SetYear (uint32_t year)
 
uint32_t GetHour () const
 
bool SetHour (uint32_t hour)
 
uint32_t GetMinute () const
 
bool SetMinute (uint32_t minute)
 
uint32_t GetSecond () const
 
bool SetSecond (uint32_t second)
 
CYIString GetMonthName () const
 
CYIString GetMonthShortName () const
 
uint32_t GetDayOfWeek () const
 
CYIString GetDayOfWeekName () const
 
CYIString GetDayOfWeekShortName () const
 
bool SetDateTime (const CYIString &rDateTimeString)
 
bool SetDateTimeRFC1123 (const CYIString &rDateTimeString)
 
CYIString FormatString (const CYIString &rFormatString) const
 
CYIString FormatString (StringFormat format=StringFormat::ISO_8601) const
 
time_t GetEpochTime () const
 
bool SetEpochTime (const time_t epochTime)
 
bool AddYears (const int32_t years)
 
bool AddMonths (const int32_t months)
 
bool AddDays (const int32_t days)
 
bool AddHours (const int32_t hours)
 
bool AddMinutes (const int32_t minutes)
 
bool AddSeconds (const int32_t seconds)
 
virtual bool operator== (const CYIDateTime &rOther) const
 
virtual bool operator!= (const CYIDateTime &rOther) const
 
virtual bool operator> (const CYIDateTime &rOther) const
 
virtual bool operator< (const CYIDateTime &rOther) const
 
virtual bool operator>= (const CYIDateTime &rOther) const
 
virtual bool operator<= (const CYIDateTime &rOther) const
 
virtual bool operator+= (TimeDelta delta)
 
virtual bool operator-= (TimeDelta delta)
 

Static Public Member Functions

static CYIDateTime GetCurrentDateTime ()
 
static uint32_t GetDaysInMonth (const uint32_t month, const uint32_t year)
 
static bool IsLeapYear (const uint32_t year)
 

Member Typedef Documentation

◆ TimeDelta

typedef int64_t CYIDateTime::TimeDelta

TimeDelta represents time difference between two CYIDateTime objects and makes such operations easier.

Member Enumeration Documentation

◆ StringFormat

Represents the different string formats for CYIDateTime.

Enumerator
ISO_8601 

Would output a string similar to: 2008-09-15T15:53:00

RFC_1123 

Would output a string similar to: Sat, 28 Nov 2009 03:50:37 GMT. Latest HTTP1.1 spec (RFC 1123) uses this format for Date header field.

Constructor & Destructor Documentation

◆ CYIDateTime() [1/3]

CYIDateTime::CYIDateTime ( const CYIString rDateTimeString)

Creates a DateTime object from a string that contains date and time information as per the ISO 8601 format (link at top).

◆ CYIDateTime() [2/3]

CYIDateTime::CYIDateTime ( const time_t  epochTime)

Creates a DateTime object from Epoch time (seconds since January 1st, 1970 00:00:00 UTC).

Note
If epochTime is less than 0 the date time object will be constructed as January 1, 1970 00:00:00 UTC.

◆ CYIDateTime() [3/3]

CYIDateTime::CYIDateTime ( )

Creates a DateTime object using the current local date and time.

◆ ~CYIDateTime()

virtual CYIDateTime::~CYIDateTime ( )
virtual

Destroys the DateTime object.

Member Function Documentation

◆ AddDays()

bool CYIDateTime::AddDays ( const int32_t  days)

Adds days to the current CYIDateTime object, maximum days is maximum int32_t value divided by 60. Returns false without modifying the date if the resultant date would be before January 1, 1970 00:00:00 UTC or after the maximum epoch (maximum time_t) value for the current system.

◆ AddHours()

bool CYIDateTime::AddHours ( const int32_t  hours)

Adds hours to the current CYIDateTime object, maximum hours is maximum int32_t value divided by 60. Returns false without modifying the date if the resultant date would be before January 1, 1970 00:00:00 UTC or after the maximum epoch (maximum time_t) value for the current system.

◆ AddMinutes()

bool CYIDateTime::AddMinutes ( const int32_t  minutes)

Adds minutes to the current CYIDateTime object, maximum minutes is maximum int32_t value divided by 60. Returns false without modifying the date if the resultant date would be before January 1, 1970 00:00:00 UTC or after the maximum epoch time that can be represented by time_t for the current system.

◆ AddMonths()

bool CYIDateTime::AddMonths ( const int32_t  months)

Adds months to the current CYIDateTime object, takes into account variation of days in month and leap years. Returns false without modifying the date if the resultant date would be before January 1, 1970 00:00:00 UTC or after the maximum epoch (maximum time_t) value for the current system.

◆ AddSeconds()

bool CYIDateTime::AddSeconds ( const int32_t  seconds)

Adds seconds to the current CYIDateTime object. Returns false without modifying the date if the resultant date would be before January 1, 1970 00:00:00 UTC or after the maximum epoch (maximum time_t) value for the current system.

◆ AddYears()

bool CYIDateTime::AddYears ( const int32_t  years)

Adds years to the current CYIDateTime object, maximum years is maximum int32_t value divided by 60. Returns false without modifying the date if the resultant date would be before January 1, 1970 00:00:00 UTC or after the maximum epoch (maximum time_t) value for the current system.

◆ FormatString() [1/2]

CYIString CYIDateTime::FormatString ( const CYIString rFormatString) const

Prints the date held by this object using the specified format, and returns the result as a CYIString. Be weary of portability issues with this function as it depends on strftime (which has different behavior on different platforms).

◆ FormatString() [2/2]

CYIString CYIDateTime::FormatString ( StringFormat  format = StringFormat::ISO_8601) const

Prints the data held by this object following the format (defaulting to ISO 8601 if not specified) and returns the result as a CYIString.

◆ GetCurrentDateTime()

static CYIDateTime CYIDateTime::GetCurrentDateTime ( )
static

Returns the system's current date and time. Equivalent to creating an instance of CYIDateTime without any arguments.

◆ GetDay()

uint32_t CYIDateTime::GetDay ( ) const

Returns the day in the range [1,31].

◆ GetDayOfWeek()

uint32_t CYIDateTime::GetDayOfWeek ( ) const

Returns the index of the day of the week (locale-dependent).

The index starts at 0 for Sunday.

◆ GetDayOfWeekName()

CYIString CYIDateTime::GetDayOfWeekName ( ) const

Returns the full name of the day (locale-dependent).

Example results: Sunday, Monday, Tuesday

◆ GetDayOfWeekShortName()

CYIString CYIDateTime::GetDayOfWeekShortName ( ) const

Returns the short name of the day (locale-dependent).

Example results: Sun, Mon, Tue

◆ GetDaysInMonth()

static uint32_t CYIDateTime::GetDaysInMonth ( const uint32_t  month,
const uint32_t  year 
)
static

Given a year and month returns the number of days in the month.

Note
month is zero based.

◆ GetEpochTime()

time_t CYIDateTime::GetEpochTime ( ) const

Generates and returns the epoch time for this class. This is defined as the number of seconds between this date and January 1st 1970 UTC. Returns -1 if the time defined by this object is invalid.

◆ GetHour()

uint32_t CYIDateTime::GetHour ( ) const

Returns the hour in the range [0,23].

◆ GetMinute()

uint32_t CYIDateTime::GetMinute ( ) const

Returns the minute in the range [0,59].

◆ GetMonth()

uint32_t CYIDateTime::GetMonth ( ) const

Returns the month in the range [0,11].

◆ GetMonthName()

CYIString CYIDateTime::GetMonthName ( ) const

Returns the full name of the month (locale-dependent).

Example results: January, February, March

◆ GetMonthShortName()

CYIString CYIDateTime::GetMonthShortName ( ) const

Returns the short name of the month (locale-dependent).

Example results: Jan, Feb, Mar

◆ GetSecond()

uint32_t CYIDateTime::GetSecond ( ) const

Returns the second in the range [0,61].

Note
The range goes to 61 rather than 59 to accomodate for leap seconds in some systems.

◆ GetYear()

uint32_t CYIDateTime::GetYear ( ) const

Returns the year in the range [1970,3000].

◆ IsLeapYear()

static bool CYIDateTime::IsLeapYear ( const uint32_t  year)
static

Given a year returns true if the year is a leap year, false otherwise.

◆ IsValid()

bool CYIDateTime::IsValid ( ) const

Returns true if this object contains a valid date.

◆ operator!=()

virtual bool CYIDateTime::operator!= ( const CYIDateTime rOther) const
virtual

◆ operator+=()

virtual bool CYIDateTime::operator+= ( TimeDelta  delta)
virtual

◆ operator-=()

virtual bool CYIDateTime::operator-= ( TimeDelta  delta)
virtual

◆ operator<()

virtual bool CYIDateTime::operator< ( const CYIDateTime rOther) const
virtual

◆ operator<=()

virtual bool CYIDateTime::operator<= ( const CYIDateTime rOther) const
virtual

◆ operator==()

virtual bool CYIDateTime::operator== ( const CYIDateTime rOther) const
virtual

◆ operator>()

virtual bool CYIDateTime::operator> ( const CYIDateTime rOther) const
virtual

◆ operator>=()

virtual bool CYIDateTime::operator>= ( const CYIDateTime rOther) const
virtual

◆ SetDateTime()

bool CYIDateTime::SetDateTime ( const CYIString rDateTimeString)

Updates the fields of the DateTime object based on information provided as per ISO 8601 (link at top) via rDateTimeString parameter. Returns true if operation succeeded, false otherwise.

◆ SetDateTimeRFC1123()

bool CYIDateTime::SetDateTimeRFC1123 ( const CYIString rDateTimeString)

Updates the fields of the DateTime object based on information provided as per RFC 1123 via rDateTimeString parameter. Returns true if operation succeeded, false otherwise.

◆ SetDay()

bool CYIDateTime::SetDay ( uint32_t  day)

Sets the day, must be in the range [1,31].

◆ SetEpochTime()

bool CYIDateTime::SetEpochTime ( const time_t  epochTime)

Sets the date time to a given epoch time. This is defined as the number of seconds between this date and January 1st 1970 UTC.

Returns false if epochTime represents a time before January 1st 1970 UTC (if epochTime is negative).

◆ SetHour()

bool CYIDateTime::SetHour ( uint32_t  hour)

Sets the hour, must be in the range [0,23].

◆ SetMinute()

bool CYIDateTime::SetMinute ( uint32_t  minute)

Sets the minute, must be in the range [0,59].

◆ SetMonth()

bool CYIDateTime::SetMonth ( uint32_t  month)

Sets the month, /a month must be in the range [0,11].

Note
If the current day is greater than the number of days in month the month and day will be adjusted.

◆ SetSecond()

bool CYIDateTime::SetSecond ( uint32_t  second)

Sets the second, must be in the range [0,61].

Note
The range goes to 61 rather than 59 to accomodate for leap seconds in some systems.

◆ SetYear()

bool CYIDateTime::SetYear ( uint32_t  year)

Sets the year, must be in the range [1970,3000].


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