CONZEPT 16 C++ API
C16::Value::Date Class Reference

Period of time covering a day. More...

#include "C16/Value/Date.hpp"

Detailed Description

Period of time covering a day.

Static Public Attributes

static const int YEAR_EPOCH = 1900
 Epoch year of dates. More...
 
static const int YEAR_MINIMUM = 1900
 Minimum year of a date. More...
 
static const int YEAR_MAXIMUM = 2154
 Maximum year of a date. More...
 
static const Date EMPTY
 Empty date (0000-00-00). More...
 
static const Date MINIMUM
 Minimum date (1900-01-01). More...
 
static const Date MAXIMUM
 Maximum date (2154-12-31). More...
 

Static Public Member Functions

static Date now ()
 Gets the current date (UTC) of the system. More...
 
static Date now_local ()
 Gets the current date of the local timezone of the system. More...
 
static bool leap_year (int year)
 Gets if a year is a leap year. More...
 
static int days_in_month (int year, int month)
 Gets the days in a month. More...
 
static bool validate (int year, int month, int day)
 Validates a date by means of its year, month and day (of the month). More...
 
static bool validate (long int serial)
 Validates a date by means of its serial in units of days since the epoch. More...
 
static void validate_throw (int year, int month, int day)
 Validates a date by means of its year, month and day (of the month). More...
 
static void validate_throw (long int serial)
 Validates a date by means of its serial in units of days since the epoch. More...
 

Public Member Functions

 Date ()
 Constructs an empty date. More...
 
 Date (int year, int month, int day)
 Constructs a date by means of its year, month and day (of the month). More...
 
 Date (long int serial)
 Constructs a date by means of a serial in units of days since the epoch. More...
 
 Date (const Date &other)
 Constructs a date by copying another date. More...
 
Dateoperator= (const Date &other)
 Assigns the date from another date. More...
 
int compare (const Date &other) const
 Compares the date with another date. More...
 
bool operator== (const Date &other) const
 Gets if the date is equal to another date. More...
 
bool operator!= (const Date &other) const
 Gets if the date is unequal to another date. More...
 
bool operator< (const Date &other) const
 Gets if the date is earlier than another date. More...
 
bool operator<= (const Date &other) const
 Gets if the date is equal to or earlier than another date. More...
 
bool operator>= (const Date &other) const
 Gets if the date is equal to or later than another date. More...
 
bool operator> (const Date &other) const
 Gets if the date is later than another date. More...
 
bool empty () const
 Gets if the date is empty. More...
 
int year () const
 Gets the year of the date. More...
 
int month () const
 Gets the month of the date. More...
 
int day () const
 Gets the day (of the month) of the date. More...
 
int day_of_year () const
 Gets the day of the year of the date. More...
 
int day_of_week () const
 Gets the day of the week of the date. More...
 
int week () const
 Gets the week (according to ISO 8601) of the date. More...
 
int week_year () const
 Gets the year of the week (according to ISO 8601) of the date. More...
 
bool leap_year () const
 Gets if the date lies in a leap year. More...
 
long int serial () const
 Gets the serial of the date in units of days since the epoch. More...
 
void clear ()
 Empties the date. More...
 
void assign (int year, int month, int day)
 Assigns the date by means of its year, month and day (of the month). More...
 
void assign (long int serial)
 Assigns the date by means of its serial in units of days since the epoch. More...
 

Member Data Documentation

◆ YEAR_EPOCH

const int C16::Value::Date::YEAR_EPOCH = 1900
static

Epoch year of dates.

◆ YEAR_MINIMUM

const int C16::Value::Date::YEAR_MINIMUM = 1900
static

Minimum year of a date.

◆ YEAR_MAXIMUM

const int C16::Value::Date::YEAR_MAXIMUM = 2154
static

Maximum year of a date.

◆ EMPTY

const Date C16::Value::Date::EMPTY
static

Empty date (0000-00-00).

◆ MINIMUM

const Date C16::Value::Date::MINIMUM
static

Minimum date (1900-01-01).

◆ MAXIMUM

const Date C16::Value::Date::MAXIMUM
static

Maximum date (2154-12-31).

Constructor & Destructor Documentation

◆ Date() [1/4]

C16::Value::Date::Date ( )

Constructs an empty date.

◆ Date() [2/4]

C16::Value::Date::Date ( int  year,
int  month,
int  day 
)

Constructs a date by means of its year, month and day (of the month).

Parameters
yearYear of the date (YEAR_MINIMUM to YEAR_MAXIMUM)
monthMonth of the date (1 to 12)
dayDay (of the month) of the date (1 to days_in_month)
Exceptions
Exception::InvalidityYear invalid.
Exception::InvalidityMonth invalid.
Exception::InvalidityDay invalid.

◆ Date() [3/4]

C16::Value::Date::Date ( long int  serial)
explicit

Constructs a date by means of a serial in units of days since the epoch.

Parameters
serialSerial of the date (0 to MAXIMUM.serial())
Exceptions
Exception::InvaliditySerial invalid.

◆ Date() [4/4]

C16::Value::Date::Date ( const Date other)

Constructs a date by copying another date.

Parameters
otherAnother date

Member Function Documentation

◆ now()

static Date C16::Value::Date::now ( )
static

Gets the current date (UTC) of the system.

Exceptions
Exception::InvalidityYear invalid.
Year of current date (UTC) of the system is an invalid year of date (YEAR_MINIMUM to YEAR_MAXIMUM).

◆ now_local()

static Date C16::Value::Date::now_local ( )
static

Gets the current date of the local timezone of the system.

Exceptions
Exception::InvalidityYear invalid.
Year of current date of the local timezone of the system is an invalid year of date (YEAR_MINIMUM to YEAR_MAXIMUM).

◆ leap_year() [1/2]

static bool C16::Value::Date::leap_year ( int  year)
static

Gets if a year is a leap year.

Parameters
yearYear (YEAR_MINIMUM to YEAR_MAXIMUM)
Exceptions
Exception::InvalidityYear invalid.

◆ days_in_month()

static int C16::Value::Date::days_in_month ( int  year,
int  month 
)
static

Gets the days in a month.

Parameters
yearYear of the month (YEAR_MINIMUM to YEAR_MAXIMUM)
monthMonth (1 to 12)
Exceptions
Exception::InvalidityYear invalid.
Exception::InvalidityMonth invalid.

◆ validate() [1/2]

static bool C16::Value::Date::validate ( int  year,
int  month,
int  day 
)
static

Validates a date by means of its year, month and day (of the month).

Parameters
yearYear of the date (YEAR_MINIMUM to YEAR_MAXIMUM)
monthMonth of the date (1 to 12)
dayDay (of the month) of the date (1 to days_in_month)
Returns
Validity of the date

◆ validate() [2/2]

static bool C16::Value::Date::validate ( long int  serial)
static

Validates a date by means of its serial in units of days since the epoch.

Parameters
serialSerial of the date (0 to MAXIMUM.serial())
Returns
Validity of the date

◆ validate_throw() [1/2]

static void C16::Value::Date::validate_throw ( int  year,
int  month,
int  day 
)
static

Validates a date by means of its year, month and day (of the month).

Parameters
yearYear of the date (YEAR_MINIMUM to YEAR_MAXIMUM)
monthMonth of the date (1 to 12)
dayDay (of the month) of the date (1 to days_in_month)
Exceptions
Exception::InvalidityYear invalid.
Exception::InvalidityMonth invalid.
Exception::InvalidityDay invalid.

◆ validate_throw() [2/2]

static void C16::Value::Date::validate_throw ( long int  serial)
static

Validates a date by means of its serial in units of days since the epoch.

Parameters
serialSerial of the date (0 to MAXIMUM.serial())
Exceptions
Exception::InvaliditySerial invalid.

◆ operator=()

Date& C16::Value::Date::operator= ( const Date other)

Assigns the date from another date.

Parameters
otherAnother date
Returns
This date

◆ compare()

int C16::Value::Date::compare ( const Date other) const

Compares the date with another date.

Parameters
otherAnother date
Returns
Difference of the dates
Return values
0The date is equal to the other date.
< 0The date is earlier than the other date.
> 0The date is later than the other date.

◆ operator==()

bool C16::Value::Date::operator== ( const Date other) const

Gets if the date is equal to another date.

Parameters
otherAnother date

◆ operator!=()

bool C16::Value::Date::operator!= ( const Date other) const

Gets if the date is unequal to another date.

Parameters
otherAnother date

◆ operator<()

bool C16::Value::Date::operator< ( const Date other) const

Gets if the date is earlier than another date.

Parameters
otherAnother date

◆ operator<=()

bool C16::Value::Date::operator<= ( const Date other) const

Gets if the date is equal to or earlier than another date.

Parameters
otherAnother date

◆ operator>=()

bool C16::Value::Date::operator>= ( const Date other) const

Gets if the date is equal to or later than another date.

Parameters
otherAnother date

◆ operator>()

bool C16::Value::Date::operator> ( const Date other) const

Gets if the date is later than another date.

Parameters
otherAnother date

◆ empty()

bool C16::Value::Date::empty ( ) const

Gets if the date is empty.

◆ year()

int C16::Value::Date::year ( ) const

Gets the year of the date.

Return values
0Date empty.

◆ month()

int C16::Value::Date::month ( ) const

Gets the month of the date.

Return values
0Date empty.

◆ day()

int C16::Value::Date::day ( ) const

Gets the day (of the month) of the date.

Return values
0Date empty.

◆ day_of_year()

int C16::Value::Date::day_of_year ( ) const

Gets the day of the year of the date.

Return values
0Date empty.

◆ day_of_week()

int C16::Value::Date::day_of_week ( ) const

Gets the day of the week of the date.

Return values
0Date empty.
1Monday
2Tuesday
3Wednesday
4Thursday
5Friday
6Saturday
7Sunday

◆ week()

int C16::Value::Date::week ( ) const

Gets the week (according to ISO 8601) of the date.

Return values
0Date empty.

◆ week_year()

int C16::Value::Date::week_year ( ) const

Gets the year of the week (according to ISO 8601) of the date.

Return values
0Date empty.

◆ leap_year() [2/2]

bool C16::Value::Date::leap_year ( ) const

Gets if the date lies in a leap year.

Note
Returns false if empty.

◆ serial()

long int C16::Value::Date::serial ( ) const

Gets the serial of the date in units of days since the epoch.

Note
Returns 0 if empty.

◆ clear()

void C16::Value::Date::clear ( )

Empties the date.

◆ assign() [1/2]

void C16::Value::Date::assign ( int  year,
int  month,
int  day 
)

Assigns the date by means of its year, month and day (of the month).

Parameters
yearYear of the date (YEAR_MINIMUM to YEAR_MAXIMUM)
monthMonth of the date (1 to 12)
dayDay (of the month) of the date (1 to days_in_month)
Exceptions
Exception::InvalidityYear invalid.
Exception::InvalidityMonth invalid.
Exception::InvalidityDay invalid.

◆ assign() [2/2]

void C16::Value::Date::assign ( long int  serial)

Assigns the date by means of its serial in units of days since the epoch.

Parameters
serialSerial of the date (0 to MAXIMUM.serial())
Exceptions
Exception::InvaliditySerial invalid.