![]() |
Gorgon Game Engine
|
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... | |
This class represents a specific date including time information.
Can be obtained using GetDateTime function. An Empty month marks the time as unset.
enum MonthType |
enum WeekdayType |
Date | ( | ) |
Default constructor, zero initializes the class, making it an unset time.
Date | ( | const std::string & | isodate | ) |
Creates a new date object from the given ISO-8601 date string.
std::runtime_error | if the string is malformed or data is not valid |
References Date::Parse().
Date | ( | std::istream & | source | ) |
Reads a new date object from a binary stream.
std::runtime_error | if checksum is wrong or data is not valid |
References Date::Load().
void AddDays | ( | int | days | ) |
Adds specified amount of days to the date.
References Gorgon::Time::fromtm(), and Gorgon::Time::totm().
void AddHours | ( | int | hours | ) |
Adds specified amount of hours to the date.
References Gorgon::Time::fromtm(), and Gorgon::Time::totm().
void AddMinutes | ( | int | minutes | ) |
Adds specified amount of minutes to the date.
References Gorgon::Time::fromtm(), and Gorgon::Time::totm().
void AddMonths | ( | int | months | ) |
Adds specified amount of months to the date.
References Gorgon::Time::fromtm(), and Gorgon::Time::totm().
void AddSeconds | ( | int | seconds | ) |
Adds specified amount of seconds to the date.
References Gorgon::Time::fromtm(), and Gorgon::Time::totm().
void AddYears | ( | int | years | ) |
Adds specified amount of years to the date.
References Gorgon::Time::fromtm(), and Gorgon::Time::totm().
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.
bool DetermineWeekday | ( | ) |
Determines the weekday from the stored date.
References Gorgon::Time::totm(), and Date::Weekday.
std::string ISODate | ( | ) | const |
ISO compliant date format. Contains only date.
References Date::Day, Date::Month, and Date::Year.
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.
bool IsSet | ( | ) | const |
Checks whether the stored time is actually set.
References Date::Empty, and Date::Month.
bool Load | ( | std::istream & | source | ) |
Loads date object from a binary stream.
References Date::Day, Date::DetermineWeekday(), Date::Hour, Date::Millisecond, Date::Minute, Date::Month, Date::Second, Date::Timezone, and Date::Year.
|
static |
Returns the system timezone in minutes. Might be negative.
const std::string & MonthName_En | ( | ) | const |
Returns currently stored month's name in English.
Month 0 is valid and returns "".
std::logic_error | (debug only) if month is invalid. |
References Date::Dec, and Date::Month.
|
static |
Returns current time.
References Gorgon::Time::GetDate().
double operator- | ( | const Date & | other | ) |
Gives the difference between two dates.
References Gorgon::Time::totm().
bool operator== | ( | const Date & | other | ) | const |
Compares 2 dates.
References Gorgon::Time::totm().
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]
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.
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.
References Date::Day, Date::Hour, Date::Millisecond, Date::Minute, Date::Month, Date::Second, Date::Timezone, and Date::Year.
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.
const std::string & ShortMonthName_En | ( | ) | const |
Returns currently stored month's int name in English.
Month 0 is valid and returns "".
std::logic_error | (debug only) if month is invalid. |
References Date::Dec, and Date::Month.
std::string ShortTime | ( | ) | const |
Returns stored time in hour:minute
format.
References Date::Hour, and Date::Minute.
const std::string & ShortWeekdayName_En | ( | ) | const |
Returns currently stored week day's int name in English.
std::logic_error | (debug only) if weekday is invalid. |
References Date::Month, Date::Saturday, and Date::Weekday.
std::string Time | ( | ) | const |
Returns stored time in hour:minute:second
format.
References Date::Hour, Date::Minute, and Date::Second.
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.
void Unset | ( | ) |
Unsets the stored time.
References Date::Day, Date::Empty, Date::Hour, Date::Millisecond, Date::Minute, Date::Month, Date::Second, Date::Sunday, Date::Timezone, Date::Weekday, and Date::Year.
const std::string & WeekdayName_En | ( | ) | const |
Returns currently stored week day's name in English.
std::logic_error | (debug only) if weekday is invalid. |
References Date::Saturday, and Date::Weekday.
unsigned int Day |
Day in month.
unsigned int Hour |
Hour in 24 hour format.
unsigned int Millisecond |
This value is from the last second tick.
unsigned int Minute |
Minute.
MonthType Month |
Month starts from jan = 1.
unsigned int Second |
Second.
int Timezone |
Timezone in minutes, can be negative.
Note that some time zones has minute offset.
WeekdayType Weekday |
Day of the week, starts from sunday = 0.
unsigned int Year |
Full year.