xlnt
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
xlnt::datetime Struct Reference

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...
 

Detailed Description

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!

Constructor & Destructor Documentation

◆ datetime() [1/3]

xlnt::datetime::datetime ( const date d,
const time t 
)

Constructs a datetime from a date and a time.

◆ datetime() [2/3]

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.

◆ datetime() [3/3]

xlnt::datetime::datetime ( )
default

Constructs an empty datetime (a call to is_null() will return true).

Member Function Documentation

◆ from_iso_string()

static datetime xlnt::datetime::from_iso_string ( const std::string &  iso_string)
static

Returns a datetime equivalent to the ISO-formatted string iso_string.

◆ from_number()

static datetime xlnt::datetime::from_number ( double  number,
calendar  base_date 
)
static

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.

◆ get_day()

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.

◆ get_hour()

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.

◆ get_microsecond()

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.

◆ get_minute()

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.

◆ get_month()

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.

◆ get_second()

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.

◆ get_year()

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.

◆ is_null()

bool xlnt::datetime::is_null ( ) const
inline

Returns whether the date is in an empty/invalid state.

◆ now()

static datetime xlnt::datetime::now ( )
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).

◆ operator==()

bool xlnt::datetime::operator== ( const datetime comparand) const

Returns true if this datetime is equivalent to comparand.

◆ to_iso_string()

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.

◆ to_number()

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.

◆ to_string()

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.

◆ today()

static datetime xlnt::datetime::today ( )
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).

◆ weekday()

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.

Member Data Documentation

◆ day

int xlnt::datetime::day = 0

The day

◆ hour

int xlnt::datetime::hour = 0

The hour

◆ microsecond

int xlnt::datetime::microsecond = 0

The microsecond

◆ minute

int xlnt::datetime::minute = 0

The minute

◆ month

int xlnt::datetime::month = 0

The month

◆ second

int xlnt::datetime::second = 0

The second

◆ year

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


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