Date Struct Reference

CPP API: mio::Date Struct Reference

Simple date representation as year, month, and day. More...

#include <date.h>

Public Member Functions

 Date ()=default
 default constructor. More...
 
 Date (int y, int m, int d)
 initializing constructor. More...
 
bool operator!= (const Date &other) const
 
bool operator< (const Date &other) const
 
bool operator<= (const Date &other) const
 
bool operator== (const Date &other) const
 equality comparison operators. More...
 
bool operator> (const Date &other) const
 
bool operator>= (const Date &other) const
 
template<class IOContext >
void serialize (IOContext &io) const
 serialize this. More...
 
std::string to_iso_string () const
 Formats the date into a string in ISO 8601 format (YYYY-MM-DD). More...
 

Static Public Member Functions

template<class IOContext >
static IOResult< Datedeserialize (IOContext &io)
 deserialize an object of this class. More...
 

Public Attributes

int day
 
int month
 
int year
 

Static Public Attributes

static constexpr std::array< int, 12 > month_lengths = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
 
static constexpr std::array< int, 12 > month_lengths_leap_year = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
 

Friends

std::ostream & operator<< (std::ostream &os, const Date &date)
 Overload for stream operator to use the ISO 8601 format. More...
 

Detailed Description

Simple date representation as year, month, and day.

month in [1, 12], day in [1, 31]

Constructor & Destructor Documentation

◆ Date() [1/2]

mio::Date::Date ( )
default

default constructor.

◆ Date() [2/2]

mio::Date::Date ( int  y,
int  m,
int  d 
)
inline

initializing constructor.

Parameters
yyear as int
mmonth as int, 1 - 12
dday as int, 1 - 31

Member Function Documentation

◆ deserialize()

template<class IOContext >
static IOResult<Date> mio::Date::deserialize ( IOContext &  io)
inlinestatic

deserialize an object of this class.

See also
mio::deserialize

◆ operator!=()

bool mio::Date::operator!= ( const Date other) const
inline

◆ operator<()

bool mio::Date::operator< ( const Date other) const
inline

◆ operator<=()

bool mio::Date::operator<= ( const Date other) const
inline

◆ operator==()

bool mio::Date::operator== ( const Date other) const
inline

equality comparison operators.

Parameters
otheranother date.

◆ operator>()

bool mio::Date::operator> ( const Date other) const
inline

◆ operator>=()

bool mio::Date::operator>= ( const Date other) const
inline

◆ serialize()

template<class IOContext >
void mio::Date::serialize ( IOContext &  io) const
inline

serialize this.

See also
mio::serialize

◆ to_iso_string()

std::string mio::Date::to_iso_string ( ) const
inline

Formats the date into a string in ISO 8601 format (YYYY-MM-DD).

Returns
A string representing the date in ISO 8601 format.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const Date date 
)
friend

Overload for stream operator to use the ISO 8601 format.

Parameters
osOutput stream.
dateDate to output.
Returns
Reference to the output stream.

Member Data Documentation

◆ day

int mio::Date::day

◆ month

int mio::Date::month

◆ month_lengths

constexpr std::array<int, 12> mio::Date::month_lengths = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
staticconstexpr

◆ month_lengths_leap_year

constexpr std::array<int, 12> mio::Date::month_lengths_leap_year = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
staticconstexpr

◆ year

int mio::Date::year