This class provides simple date representation. More...

#include <date.hpp>

Public Member Functions

 date ()
 
 date (int julian_date)
 
 date (int day, int month, int year)
 
 date (const char *stamp, const char *format="%d.%m.%Y")
 
 date (const date &x)
 
 date (date &&x)=default
 
dateoperator= (const date &x)
 
dateoperator= (date &&x)=default
 
dateoperator= (int julian_date)
 
dateoperator+= (int days)
 
dateoperator-= (int days)
 
dateoperator++ ()
 
date operator++ (int)
 
dateoperator-- ()
 
date operator-- (int)
 
void set (const char *datestr, const char *format="%d.%m.%Y")
 
void set (int day, int month, int year)
 
void set (int julian_date)
 
int day () const
 
int month () const
 
int year () const
 
dateday (int d)
 
datemonth (int m)
 
dateyear (int y)
 
bool is_leapyear () const
 
bool is_daylight_saving () const
 
int julian_date () const
 
virtual int difference (const date &x) const
 

Static Public Member Functions

static date parse (const std::string &dstr, const char *format)
 
static bool is_leapyear (int year)
 
static bool is_valid_date (int year, int month, int day)
 
static bool is_daylight_saving (int year, int month, int day)
 

Friends

OOS_UTILS_API bool operator== (const date &a, const date &b)
 
OOS_UTILS_API bool operator!= (const date &a, const date &b)
 
OOS_UTILS_API date operator+ (date a, int days)
 
OOS_UTILS_API date operator- (date a, int days)
 
OOS_UTILS_API bool operator< (const date &a, const date &b)
 
OOS_UTILS_API bool operator> (const date &a, const date &b)
 
OOS_UTILS_API bool operator<= (const date &a, const date &b)
 
OOS_UTILS_API bool operator>= (const date &a, const date &b)
 
OOS_UTILS_API std::ostream & operator<< (std::ostream &out, const date &d)
 

Detailed Description

This class provides simple date representation.

This class provides simple date representation with julian calendar for date calculation.

A date can be constructed either from

  • a julian date
  • year, month and day values
  • from a date string and its format
  • copied from another date

Constructor & Destructor Documentation

◆ date() [1/6]

matador::date::date ( )

Creates a date of now

◆ date() [2/6]

matador::date::date ( int  julian_date)
explicit

Creates a date from the given julian date

Parameters
julian_dateThe julian date to create a date from

◆ date() [3/6]

matador::date::date ( int  day,
int  month,
int  year 
)

Creates a date from given year, month and day

Parameters
dayDates day
monthDates month
yearDates year

◆ date() [4/6]

matador::date::date ( const char *  stamp,
const char *  format = "%d.%m.%Y" 
)
explicit

Creates a date from a given date/time string and a format string

Parameters
stampThe date/time string to parse
formatThe format to use for parsing

◆ date() [5/6]

matador::date::date ( const date x)

Copy date from given date

Parameters
xDate to copy from.

◆ date() [6/6]

matador::date::date ( date &&  x)
default

Copy move date from given date

Parameters
xDate to copy from.

Member Function Documentation

◆ day() [1/2]

int matador::date::day ( ) const

Returns the day part of date

Returns
The day part of date.

◆ day() [2/2]

date & matador::date::day ( int  d)

Sets the day part of the date and returns a reference to the date

Parameters
dThe day part of the date
Returns
Reference to the date

◆ difference()

virtual int matador::date::difference ( const date x) const
virtual

Returns the difference of two dates in days.

Parameters
xThe date to calculate the difference with.
Returns
The difference in days.

◆ is_daylight_saving() [1/2]

bool matador::date::is_daylight_saving ( ) const

Returns true if date is in daylight saving range which depends one the country.

Returns
True if date is in daylight saving range.

◆ is_daylight_saving() [2/2]

static bool matador::date::is_daylight_saving ( int  year,
int  month,
int  day 
)
static

Returns true if time is in daylight saving range which depends one the country.

Returns
True if time is in daylight saving range.

◆ is_leapyear() [1/2]

bool matador::date::is_leapyear ( ) const

Returns true if dates year is a leap year.

Returns
True If year of date is leap year.

◆ is_leapyear() [2/2]

static bool matador::date::is_leapyear ( int  year)
static

Returns true if dates year is a leap year.

Parameters
yearThe year to check.
Returns
True If year of date is leap year.

◆ is_valid_date()

static bool matador::date::is_valid_date ( int  year,
int  month,
int  day 
)
static

Checks if given date parts are valid

0 < month <= 12 Valid day with given month

Parameters
yearYear to check
monthMonth to check
dayDay to check
Returns
true if date parts are valid

◆ julian_date()

int matador::date::julian_date ( ) const

Returns the underlying julian date

Returns
The underlying julian date

◆ month() [1/2]

int matador::date::month ( ) const

Returns the month part of date

Returns
The month part of date.

◆ month() [2/2]

date & matador::date::month ( int  m)

Sets the month part of the date and returns a reference to the date

Parameters
mThe month part of the date
Returns
Reference to the date

◆ operator++() [1/2]

date & matador::date::operator++ ( )

Increment date by one day

Returns
The modified date

◆ operator++() [2/2]

date matador::date::operator++ ( int  )

Increment date by one day

Returns
The modified date

◆ operator+=()

date & matador::date::operator+= ( int  days)

Add a given number of days.

Parameters
daysDays to add
Returns
The modified date

◆ operator--() [1/2]

date & matador::date::operator-- ( )

Decrement date by one day

Returns
The modified date

◆ operator--() [2/2]

date matador::date::operator-- ( int  )

Decrement date by one day

Returns
The modified date

◆ operator-=()

date & matador::date::operator-= ( int  days)

Subtract a given number of days.

Parameters
daysDays to subtract
Returns
The modified date

◆ operator=() [1/3]

date & matador::date::operator= ( const date x)

Assign from given date

Parameters
xThe date to assign from.
Returns
Reference to the assigned date.

◆ operator=() [2/3]

date & matador::date::operator= ( date &&  x)
default

Assignment move from given date

Parameters
xThe date to assign from.
Returns
Reference to the assigned date.

◆ operator=() [3/3]

date & matador::date::operator= ( int  julian_date)

Assign a date from julian date value

Parameters
julian_dateThe julian adte to assign from
Returns
The assigned date

◆ parse()

static date matador::date::parse ( const std::string &  dstr,
const char *  format 
)
static

Parse a given date string with a valid format and return a corresponding date object.

Parameters
dstrDate string.
formatDate strings format.
Returns
A date object.

◆ set() [1/3]

void matador::date::set ( const char *  datestr,
const char *  format = "%d.%m.%Y" 
)

Sets the date from a given date/time string and a format string

Parameters
datestrThe date/time string to parse
formatThe format to use for parsing

◆ set() [2/3]

void matador::date::set ( int  day,
int  month,
int  year 
)

Sets the date from given year, month and day

Parameters
dayDates day
monthDates month
yearDates year

◆ set() [3/3]

void matador::date::set ( int  julian_date)

Sets the date from the given julian date

Parameters
julian_dateThe julian date to set

◆ year() [1/2]

int matador::date::year ( ) const

Returns the year part of date

Returns
The year part of date.

◆ year() [2/2]

date & matador::date::year ( int  y)

Sets the year part of the date and returns a reference to the date

Parameters
yThe year part of the date
Returns
Reference to the date

Friends And Related Symbol Documentation

◆ operator!=

OOS_UTILS_API bool operator!= ( const date a,
const date b 
)
friend

Check if two dates are not equal

Parameters
aThe left hand date to compare.
bThe right hand date to compare.
Returns
True if the dates are not equal.

◆ operator+

OOS_UTILS_API date operator+ ( date  a,
int  days 
)
friend

Add a number of days to a given date

Parameters
aThe date to add the days to
daysThe days to be added
Returns
a new date

◆ operator-

OOS_UTILS_API date operator- ( date  a,
int  days 
)
friend

Subtract a number of days to a given date

Parameters
aThe date to subtract the days to
daysThe days to be subtracted
Returns
a new date

◆ operator<

OOS_UTILS_API bool operator< ( const date a,
const date b 
)
friend

Checks if date a is less than date b

Parameters
aThe left hand date to compare.
bThe right hand date to compare.
Returns
True if date a less than date b

◆ operator<<

OOS_UTILS_API std::ostream & operator<< ( std::ostream &  out,
const date d 
)
friend

Writes a date to a given ostream

Parameters
outThe ostream to write to
dThe date to write
Returns
Reference to the ostream

◆ operator<=

OOS_UTILS_API bool operator<= ( const date a,
const date b 
)
friend

Checks if date a is less equal than date b

Parameters
aThe left hand date to compare.
bThe right hand date to compare.
Returns
True if date a less equal than date b

◆ operator==

OOS_UTILS_API bool operator== ( const date a,
const date b 
)
friend

Check if two dates are equal

Parameters
aThe left hand date to compare.
bThe right hand date to compare.
Returns
True if the dates are equal.

◆ operator>

OOS_UTILS_API bool operator> ( const date a,
const date b 
)
friend

Checks if date a is greater than date b

Parameters
aThe left hand date to compare.
bThe right hand date to compare.
Returns
True if date a greater than date b

◆ operator>=

OOS_UTILS_API bool operator>= ( const date a,
const date b 
)
friend

Checks if date a is greater equal than date b

Parameters
aThe left hand date to compare.
bThe right hand date to compare.
Returns
True if date a greater equal than date b

The documentation for this class was generated from the following file:
  • matador/utils/date.hpp