Gorgon Game Engine
Date Class Reference

This class represents a specific date including time information. More...

Public Types

enum  MonthType {
  Empty, Jan, Feb, Mar,
  Apr, May, Jun, Jul,
  Agu, Sep, Oct, Nov,
  Dec
}
 Months, january is 1. More...
 
enum  WeekdayType {
  Sunday, Monday, Tuesday, Wednesday,
  Thursday, Friday, Saturday
}
 Days of week. Starts from sunday. More...
 

Public Member Functions

 Date ()
 Default constructor, zero initializes the class, making it an unset time. More...
 
 Date (const std::string &isodate)
 Creates a new date object from the given ISO-8601 date string. More...
 
 Date (std::istream &source)
 Reads a new date object from a binary stream. More...
 
void AddDays (int days)
 Adds specified amount of days to the date. More...
 
void AddHours (int hours)
 Adds specified amount of hours to the date. More...
 
void AddMinutes (int minutes)
 Adds specified amount of minutes to the date. More...
 
void AddMonths (int months)
 Adds specified amount of months to the date. More...
 
void AddSeconds (int seconds)
 Adds specified amount of seconds to the date. More...
 
void AddYears (int years)
 Adds specified amount of years to the date. More...
 
std::string Date_En () const
 Returns stored date in day monthname year, weekday format with English names for month and weekday. More...
 
bool DetermineWeekday ()
 Determines the weekday from the stored date. More...
 
std::string ISODate () const
 ISO compliant date format. Contains only date. More...
 
std::string ISODateTime (bool timezone=true) const
 ISO compliant date/time. This format should be used to serialize as text. More...
 
bool IsSet () const
 Checks whether the stored time is actually set. More...
 
bool Load (std::istream &source)
 Loads date object from a binary stream. More...
 
const std::string & MonthName_En () const
 Returns currently stored month's name in English. More...
 
double operator- (const Date &other)
 Gives the difference between two dates. More...
 
bool operator== (const Date &other) const
 Compares 2 dates. More...
 
bool Parse (std::string isodate)
 Creates a new date object from the given ISO-8601 date string. More...
 
bool Save (std::ostream &target)
 Writes date object to a binary stream. More...
 
std::string ShortDate_En () const
 Returns stored date in day intmonthname year format with English names for month. More...
 
const std::string & ShortMonthName_En () const
 Returns currently stored month's int name in English. More...
 
std::string ShortTime () const
 Returns stored time in hour:minute format. More...
 
const std::string & ShortWeekdayName_En () const
 Returns currently stored week day's int name in English. More...
 
std::string Time () const
 Returns stored time in hour:minute:second format. More...
 
std::string Timezone_GMT () const
 Returns stored timezone. More...
 
void Unset ()
 Unsets the stored time. More...
 
const std::string & WeekdayName_En () const
 Returns currently stored week day's name in English. More...
 

Static Public Member Functions

static int LocalTimezone ()
 Returns the system timezone in minutes. Might be negative. More...
 
static Date Now ()
 Returns current time. More...
 

Public Attributes

unsigned int Day
 Day in month. More...
 
unsigned int Hour
 Hour in 24 hour format. More...
 
unsigned int Millisecond
 This value is from the last second tick. More...
 
unsigned int Minute
 Minute. More...
 
MonthType Month
 Month starts from jan = 1. More...
 
unsigned int Second
 Second. More...
 
int Timezone
 Timezone in minutes, can be negative. More...
 
WeekdayType Weekday
 Day of the week, starts from sunday = 0. More...
 
unsigned int Year
 Full year. More...
 

Detailed Description

This class represents a specific date including time information.

Can be obtained using GetDateTime function. An Empty month marks the time as unset.

Member Enumeration Documentation

◆ MonthType

enum MonthType

Months, january is 1.

Enumerator
Empty 
Jan 
Feb 
Mar 
Apr 
May 
Jun 
Jul 
Agu 
Sep 
Oct 
Nov 
Dec 

◆ WeekdayType

Days of week. Starts from sunday.

Enumerator
Sunday 
Monday 
Tuesday 
Wednesday 
Thursday 
Friday 
Saturday 

Constructor & Destructor Documentation

◆ Date() [1/3]

Date ( )

Default constructor, zero initializes the class, making it an unset time.

◆ Date() [2/3]

Date ( const std::string &  isodate)

Creates a new date object from the given ISO-8601 date string.

See also
Parse
Exceptions
std::runtime_errorif the string is malformed or data is not valid

References Date::Parse().

◆ Date() [3/3]

Date ( std::istream &  source)

Reads a new date object from a binary stream.

See also
Save for details.
Exceptions
std::runtime_errorif checksum is wrong or data is not valid

References Date::Load().

Member Function Documentation

◆ AddDays()

void AddDays ( int  days)

Adds specified amount of days to the date.

References Gorgon::Time::fromtm(), and Gorgon::Time::totm().

◆ AddHours()

void AddHours ( int  hours)

Adds specified amount of hours to the date.

References Gorgon::Time::fromtm(), and Gorgon::Time::totm().

◆ AddMinutes()

void AddMinutes ( int  minutes)

Adds specified amount of minutes to the date.

References Gorgon::Time::fromtm(), and Gorgon::Time::totm().

◆ AddMonths()

void AddMonths ( int  months)

Adds specified amount of months to the date.

References Gorgon::Time::fromtm(), and Gorgon::Time::totm().

◆ AddSeconds()

void AddSeconds ( int  seconds)

Adds specified amount of seconds to the date.

References Gorgon::Time::fromtm(), and Gorgon::Time::totm().

◆ AddYears()

void AddYears ( int  years)

Adds specified amount of years to the date.

References Gorgon::Time::fromtm(), and Gorgon::Time::totm().

◆ Date_En()

std::string Date_En ( ) const

Returns stored date in day monthname year, weekday format with English names for month and weekday.

References Date::Day, Date::MonthName_En(), Date::WeekdayName_En(), and Date::Year.

◆ DetermineWeekday()

bool DetermineWeekday ( )

Determines the weekday from the stored date.

Returns
true if successful

References Gorgon::Time::totm(), and Date::Weekday.

◆ ISODate()

std::string ISODate ( ) const

ISO compliant date format. Contains only date.

References Date::Day, Date::Month, and Date::Year.

◆ ISODateTime()

std::string ISODateTime ( bool  timezone = true) const

ISO compliant date/time. This format should be used to serialize as text.

References Date::Day, Date::Hour, Date::Minute, Date::Month, Date::Second, Date::Timezone, and Date::Year.

◆ IsSet()

bool IsSet ( ) const

Checks whether the stored time is actually set.

References Date::Empty, and Date::Month.

◆ Load()

bool Load ( std::istream &  source)

Loads date object from a binary stream.

See also
Save for details.
Returns
true if successful.

References Date::Day, Date::DetermineWeekday(), Date::Hour, Date::Millisecond, Date::Minute, Date::Month, Date::Second, Date::Timezone, and Date::Year.

◆ LocalTimezone()

int LocalTimezone ( )
static

Returns the system timezone in minutes. Might be negative.

◆ MonthName_En()

const std::string & MonthName_En ( ) const

Returns currently stored month's name in English.

Month 0 is valid and returns "".

Exceptions
std::logic_error(debug only) if month is invalid.

References Date::Dec, and Date::Month.

◆ Now()

static Date Now ( )
static

Returns current time.

References Gorgon::Time::GetDate().

◆ operator-()

double operator- ( const Date other)

Gives the difference between two dates.

References Gorgon::Time::totm().

◆ operator==()

bool operator== ( const Date other) const

Compares 2 dates.

References Gorgon::Time::totm().

◆ Parse()

bool Parse ( std::string  isodate)

Creates a new date object from the given ISO-8601 date string.

Requires full information. Following format is recognized: [YYYY]-[MM]-[DD]T[HH]:[mm]:SS[TT][tt]

  • YYYY: 4 digit year
  • MM : 2 digit month
  • DD : 2 digit day
  • HH : 2 digit hour
  • mm : 2 digit minute
  • SS : 2 digit second
  • TT : 2 digit timezone hour
  • tt : 2 digit timezone minute Timezone is optional, if omitted default is system timezone. It can also be specified as Z meaning UTC.
    Returns
    true if successful.

TODO Check for - and :

References Date::Day, Date::DetermineWeekday(), Date::Hour, Date::LocalTimezone(), Date::Millisecond, Date::Minute, Date::Month, Date::Second, Date::Timezone, Gorgon::String::Trim(), and Date::Year.

◆ Save()

bool Save ( std::ostream &  target)

Writes date object to a binary stream.

Format is given below. numbers after names are number of bytes.

/// <year:2><month:1><day:1><hour:1><minute:1><millis:2><timezone:2><checksum:1>
/// 

checksum is the sum of all numbers in base 256.

Returns
true if successful. An empty date will be saved correctly.

References Date::Day, Date::Hour, Date::Millisecond, Date::Minute, Date::Month, Date::Second, Date::Timezone, and Date::Year.

◆ ShortDate_En()

std::string ShortDate_En ( ) const

Returns stored date in day intmonthname year format with English names for month.

References Date::Day, Date::ShortMonthName_En(), and Date::Year.

◆ ShortMonthName_En()

const std::string & ShortMonthName_En ( ) const

Returns currently stored month's int name in English.

Month 0 is valid and returns "".

Exceptions
std::logic_error(debug only) if month is invalid.

References Date::Dec, and Date::Month.

◆ ShortTime()

std::string ShortTime ( ) const

Returns stored time in hour:minute format.

References Date::Hour, and Date::Minute.

◆ ShortWeekdayName_En()

const std::string & ShortWeekdayName_En ( ) const

Returns currently stored week day's int name in English.

Exceptions
std::logic_error(debug only) if weekday is invalid.

References Date::Month, Date::Saturday, and Date::Weekday.

◆ Time()

std::string Time ( ) const

Returns stored time in hour:minute:second format.

References Date::Hour, Date::Minute, and Date::Second.

◆ Timezone_GMT()

std::string Timezone_GMT ( ) const

Returns stored timezone.

Format depends on the actual timezone. If the timezone offset contains only hours, the format is GMT+H or GMT-H. If there is minute offset, timezone is returned in GMT+H:MM or GMT-H:MM format. H is the hour without any leading zeroes, MM is the minute in two digit format.

References Date::Timezone.

◆ Unset()

◆ WeekdayName_En()

const std::string & WeekdayName_En ( ) const

Returns currently stored week day's name in English.

Exceptions
std::logic_error(debug only) if weekday is invalid.

References Date::Saturday, and Date::Weekday.

Member Data Documentation

◆ Day

unsigned int Day

Day in month.

◆ Hour

unsigned int Hour

Hour in 24 hour format.

◆ Millisecond

unsigned int Millisecond

This value is from the last second tick.

◆ Minute

unsigned int Minute

Minute.

◆ Month

MonthType Month

Month starts from jan = 1.

◆ Second

unsigned int Second

Second.

◆ Timezone

int Timezone

Timezone in minutes, can be negative.

Note that some time zones has minute offset.

◆ Weekday

WeekdayType Weekday

Day of the week, starts from sunday = 0.

◆ Year

unsigned int Year

Full year.


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