xlnt
|
A datetime is a combination of a date and a time. IMPORTANT: The datetime could be in an empty/invalid state, so you may want to call is_null() before calling any functions! More...
#include <datetime.hpp>
Public Member Functions | |
datetime (const date &d, const time &t) | |
Constructs a datetime from a date and a time. More... | |
datetime (int year_, int month_, int day_, int hour_=0, int minute_=0, int second_=0, int microsecond_=0) | |
Constructs a datetime from a year, month, and day plus optional hour, minute, second, and microsecond. More... | |
datetime ()=default | |
Constructs an empty datetime (a call to is_null() will return true). More... | |
std::string | to_string () const |
Returns a string represenation of this date and time. The date could be in an empty/invalid state, so you may want to call is_null() first! If this function is called when having an empty/invalid state, an empty string will be returned. More... | |
std::string | to_iso_string () const |
Returns an ISO-formatted string representation of this date and time. The date could be in an empty/invalid state, so you may want to call is_null() first! If this function is called when having an empty/invalid state, an empty string will be returned. More... | |
double | to_number (calendar base_date) const |
Returns this datetime as a number of seconds since 1900 or 1904 (depending on base_date provided). The date could be in an empty/invalid state, so you may want to call is_null() first! If this function is called when having an empty/invalid state, an xlnt::invalid_attribute exception will be thrown. More... | |
bool | operator== (const datetime &comparand) const |
Returns true if this datetime is equivalent to comparand. More... | |
int | weekday () const |
Calculates and returns the day of the week that this date represents in the range 0 to 6 where 0 represents Sunday. Returns -1 if the weekday could not be determined. More... | |
int | get_year () const |
Returns the year of the datetime. The datetime could be in an empty/invalid state, so you may want to call is_null() first! If this function is called when having an empty/invalid state, an xlnt::invalid_attribute exception will be thrown. More... | |
int | get_month () const |
Returns the month of the datetime. The datetime could be in an empty/invalid state, so you may want to call is_null() first! If this function is called when having an empty/invalid state, an xlnt::invalid_attribute exception will be thrown. More... | |
int | get_day () const |
Returns the day of the datetime. The datetime could be in an empty/invalid state, so you may want to call is_null() first! If this function is called when having an empty/invalid state, an xlnt::invalid_attribute exception will be thrown. More... | |
int | get_hour () const |
Returns the hour of the datetime. The datetime could be in an empty/invalid state, so you may want to call is_null() first! If this function is called when having an empty/invalid state, an xlnt::invalid_attribute exception will be thrown. More... | |
int | get_minute () const |
Returns the minute of the datetime. The datetime could be in an empty/invalid state, so you may want to call is_null() first! If this function is called when having an empty/invalid state, an xlnt::invalid_attribute exception will be thrown. More... | |
int | get_second () const |
Returns the second of the datetime. The datetime could be in an empty/invalid state, so you may want to call is_null() first! If this function is called when having an empty/invalid state, an xlnt::invalid_attribute exception will be thrown. More... | |
int | get_microsecond () const |
Returns the microsecond of the datetime. The datetime could be in an empty/invalid state, so you may want to call is_null() first! If this function is called when having an empty/invalid state, an xlnt::invalid_attribute exception will be thrown. More... | |
bool | is_null () const |
Returns whether the date is in an empty/invalid state. More... | |
Static Public Member Functions | |
static datetime | now () |
Returns the current date and time according to the system time. If the current date could not be determined, the date will be in an empty state (is_null() will return true). More... | |
static datetime | today () |
Returns the current date and time according to the system time. This is equivalent to datetime::now(). If the current date could not be determined, the date will be in an empty state (is_null() will return true). More... | |
static datetime | from_number (double number, calendar base_date) |
Returns a datetime from number by converting the integer part into a date and the fractional part into a time according to date::from_number and time::from_number. More... | |
static datetime | from_iso_string (const std::string &iso_string) |
Returns a datetime equivalent to the ISO-formatted string iso_string. More... | |
Public Attributes | |
int | year = 0 |
–— TODO IMPORTANT: accessing the members directly is DEPRECATED and will be changed in a further release! Please use the getters instead! More... | |
int | month = 0 |
The month More... | |
int | day = 0 |
The day More... | |
int | hour = 0 |
The hour More... | |
int | minute = 0 |
The minute More... | |
int | second = 0 |
The second More... | |
int | microsecond = 0 |
The microsecond More... | |
A datetime is a combination of a date and a time. IMPORTANT: The datetime could be in an empty/invalid state, so you may want to call is_null() before calling any functions!
Constructs a datetime from a date and a time.
xlnt::datetime::datetime | ( | int | year_, |
int | month_, | ||
int | day_, | ||
int | hour_ = 0 , |
||
int | minute_ = 0 , |
||
int | second_ = 0 , |
||
int | microsecond_ = 0 |
||
) |
Constructs a datetime from a year, month, and day plus optional hour, minute, second, and microsecond.
|
default |
Constructs an empty datetime (a call to is_null() will return true).
|
static |
Returns a datetime equivalent to the ISO-formatted string iso_string.
Returns a datetime from number by converting the integer part into a date and the fractional part into a time according to date::from_number and time::from_number.
int xlnt::datetime::get_day | ( | ) | const |
Returns the day of the datetime. The datetime could be in an empty/invalid state, so you may want to call is_null() first! If this function is called when having an empty/invalid state, an xlnt::invalid_attribute exception will be thrown.
int xlnt::datetime::get_hour | ( | ) | const |
Returns the hour of the datetime. The datetime could be in an empty/invalid state, so you may want to call is_null() first! If this function is called when having an empty/invalid state, an xlnt::invalid_attribute exception will be thrown.
int xlnt::datetime::get_microsecond | ( | ) | const |
Returns the microsecond of the datetime. The datetime could be in an empty/invalid state, so you may want to call is_null() first! If this function is called when having an empty/invalid state, an xlnt::invalid_attribute exception will be thrown.
int xlnt::datetime::get_minute | ( | ) | const |
Returns the minute of the datetime. The datetime could be in an empty/invalid state, so you may want to call is_null() first! If this function is called when having an empty/invalid state, an xlnt::invalid_attribute exception will be thrown.
int xlnt::datetime::get_month | ( | ) | const |
Returns the month of the datetime. The datetime could be in an empty/invalid state, so you may want to call is_null() first! If this function is called when having an empty/invalid state, an xlnt::invalid_attribute exception will be thrown.
int xlnt::datetime::get_second | ( | ) | const |
Returns the second of the datetime. The datetime could be in an empty/invalid state, so you may want to call is_null() first! If this function is called when having an empty/invalid state, an xlnt::invalid_attribute exception will be thrown.
int xlnt::datetime::get_year | ( | ) | const |
Returns the year of the datetime. The datetime could be in an empty/invalid state, so you may want to call is_null() first! If this function is called when having an empty/invalid state, an xlnt::invalid_attribute exception will be thrown.
|
inline |
Returns whether the date is in an empty/invalid state.
|
static |
Returns the current date and time according to the system time. If the current date could not be determined, the date will be in an empty state (is_null() will return true).
bool xlnt::datetime::operator== | ( | const datetime & | comparand | ) | const |
Returns true if this datetime is equivalent to comparand.
std::string xlnt::datetime::to_iso_string | ( | ) | const |
Returns an ISO-formatted string representation of this date and time. The date could be in an empty/invalid state, so you may want to call is_null() first! If this function is called when having an empty/invalid state, an empty string will be returned.
double xlnt::datetime::to_number | ( | calendar | base_date | ) | const |
Returns this datetime as a number of seconds since 1900 or 1904 (depending on base_date provided). The date could be in an empty/invalid state, so you may want to call is_null() first! If this function is called when having an empty/invalid state, an xlnt::invalid_attribute exception will be thrown.
std::string xlnt::datetime::to_string | ( | ) | const |
Returns a string represenation of this date and time. The date could be in an empty/invalid state, so you may want to call is_null() first! If this function is called when having an empty/invalid state, an empty string will be returned.
|
static |
Returns the current date and time according to the system time. This is equivalent to datetime::now(). If the current date could not be determined, the date will be in an empty state (is_null() will return true).
int xlnt::datetime::weekday | ( | ) | const |
Calculates and returns the day of the week that this date represents in the range 0 to 6 where 0 represents Sunday. Returns -1 if the weekday could not be determined.
int xlnt::datetime::day = 0 |
The day
int xlnt::datetime::hour = 0 |
The hour
int xlnt::datetime::microsecond = 0 |
The microsecond
int xlnt::datetime::minute = 0 |
The minute
int xlnt::datetime::month = 0 |
The month
int xlnt::datetime::second = 0 |
The second
int xlnt::datetime::year = 0 |
–— TODO IMPORTANT: accessing the members directly is DEPRECATED and will be changed in a further release! Please use the getters instead!
The year