ALib C++ Library
Library Version: 2312 R0
Documentation generated by doxygen
Public Methods | Protected Fields | List of all members
CalendarDate Class Reference

#include <calendar.hpp>

Class Description


Represents a date in the systems calendar without the provision of a clock time. This class internally uses types DateTime and CalendarDateTime to perform operators +, -, += and -=, but is much more efficient with in- and decrement operators ++ and . Furthermore it uses only 32-bits of storage.

Besides storing clock-time agnostic date values, the type is useful to securely iterate over dates, because there is no risk of false comparisons due to mixed time-zone and daylight saving properties and in general due to arbitrarily set clock times.

Another small difference is that field DayOfWeek is always kept in a reliable (correct) state, which is not the case with field CalendarDateTime::DayOfWeek.

Internally, the values are stored a 32-bit storage word using the following scheme

Definition at line 370 of file calendar.hpp.

Public Methods

 CalendarDate ()=default
 
 CalendarDate (CalendarDate &&) noexcept=default
 
 CalendarDate (const CalendarDate &) noexcept=default
 
ALIB_API CalendarDate (const CalendarDateTime &calendarDateTime)
 
 CalendarDate (const DateTime &dateTime, Timezone timezone)
 
 CalendarDate (int year, int month, int day, int dayOfWeek=-1)
 
 CalendarDate (Timezone timezone)
 
 ~CalendarDate () noexcept=default
 
int Day () const
 
int DayOfWeek () const
 
ALIB_API DateTime Get (Timezone timezone=Timezone::Local, int hour=12, int minute=0, int second=0) const
 
int Month () const
 
bool operator!= (const CalendarDate &other) const
 
ALIB_API CalendarDate operator+ (int daysToAdd) const
 
ALIB_API CalendarDate operator++ ()
 
CalendarDate operator++ (int)
 
CalendarDate operator+= (int daysToAdd)
 
CalendarDate operator- (int daysToSubtract) const
 
ALIB_API CalendarDate operator-- ()
 
CalendarDate operator-- (int)
 
CalendarDate operator-= (int daysToSubtract)
 
bool operator< (const CalendarDate &other) const
 
bool operator<= (const CalendarDate &other) const
 
CalendarDateoperator= (CalendarDate &&) noexcept=default
 
CalendarDateoperator= (const CalendarDate &) noexcept=default
 
bool operator== (const CalendarDate &other) const
 
bool operator> (const CalendarDate &other) const
 
bool operator>= (const CalendarDate &other) const
 
ALIB_API void Set (const DateTime &dateTime, Timezone timezone)
 
ALIB_API void Set (int year, int month, int day, int dayOfWeek=-1)
 
ALIB_API CalendarDateTime ToCalendarDateTime () const
 
int Year () const
 

Protected Fields

uint32_t stamp
 Encoded date value.
 

Constructor & Destructor Documentation

◆ CalendarDate() [1/7]

CalendarDate ( )
default

Default constructor leaving this object uninitialized (random value).

◆ CalendarDate() [2/7]

CalendarDate ( const CalendarDate )
defaultnoexcept

Trivial default copy constructor.

◆ CalendarDate() [3/7]

CalendarDate ( CalendarDate &&  )
defaultnoexcept

Trivial default move constructor.

◆ ~CalendarDate()

~CalendarDate ( )
defaultnoexcept

Trivial default destructor.

◆ CalendarDate() [4/7]

CalendarDate ( int  year,
int  month,
int  day,
int  dayOfWeek = -1 
)
inline

Constructor taking the date as separated values.

Parameters
yearThe year to use. Must be between 0 and 1,048,575
monthThe month to use. Must be between 1 and 12
dayThe day to use. Must be between 1 and 31
dayOfWeekThe day of week that results from the previous values. Defaults to -1 wich instructs this constructor to retrieve that correct value.
If given, values must be between 0 (Sunday) and 6 (Saturday). In debug compilations an assertion will be raised if the value is out of range or inconsistent.

Definition at line 411 of file calendar.hpp.

Here is the call graph for this function:

◆ CalendarDate() [5/7]

CalendarDate ( Timezone  timezone)
inlineexplicit

Constructor creating a date that represents "today".

Parameters
timezoneDetermines whether the local time zone should be used or UTC.

Definition at line 421 of file calendar.hpp.

Here is the call graph for this function:

◆ CalendarDate() [6/7]

ALIB_API CalendarDate ( const CalendarDateTime calendarDateTime)
inlineexplicit

Constructor taking a DateTime value.

Parameters
calendarDateTimeThe value to take the date from.

Definition at line 431 of file calendar.hpp.

Here is the call graph for this function:

◆ CalendarDate() [7/7]

CalendarDate ( const DateTime dateTime,
Timezone  timezone 
)
inline

Constructor taking a DateTime value.

Parameters
dateTimeThe value to take the date from.
timezoneDetermines whether the local time zone should be used or UTC.

Definition at line 444 of file calendar.hpp.

Here is the call graph for this function:

Member Function Documentation

◆ Day()

int Day ( ) const
inline

Extracts the day of month from this date as a value between 1 and 31.

Returns
The calendar day of month.

Definition at line 512 of file calendar.hpp.

◆ DayOfWeek()

int DayOfWeek ( ) const
inline

Extracts the day of week from this date as a value between 0 (representing sunday) and 6 (representing Saturday) in accordance with field CalendarDateTime::DayOfWeek.

Returns
The calendar day of month.

Definition at line 518 of file calendar.hpp.

◆ Get()

DateTime Get ( Timezone  timezone = Timezone::Local,
int  hour = 12,
int  minute = 0,
int  second = 0 
) const

Creates a DateTime object from this calendar date.

Attention
The resolution and possible time range of class DateTime is platform dependent. This method must not be used if inconsistent values are stored.
Parameters
timezoneDenote if the time that is calculated should be local or UTC. Defaults to TimeZone::Local.
hourThe hour of day (0..23) that the value returned should represent. Defaults to noon time (12).
minuteThe minute of the hour (0..59) that the value returned should represent. Defaults to 0.
secondThe second of the minute (0..59) that the value returned should represent. Defaults to 0.
Returns
The point in time represented by this class and the given clock values.

Definition at line 245 of file calendar.cpp.

Here is the call graph for this function:

◆ Month()

int Month ( ) const
inline

Extracts the month from this date as a value between 1 and 12.

Returns
The calendar day of month.

Definition at line 508 of file calendar.hpp.

◆ operator!=()

bool operator!= ( const CalendarDate other) const
inline

Not equal to operator.

Parameters
otherThe date stamp to compare.
Returns
The result of the comparison.

Definition at line 613 of file calendar.hpp.

◆ operator+()

CalendarDate operator+ ( int  daysToAdd) const

Adds the given number of days to this date.

Parameters
daysToAddThe days to add. May be negative for subtraction.
Returns
A copy of this object after modification.

Definition at line 250 of file calendar.cpp.

Here is the call graph for this function:

◆ operator++() [1/2]

CalendarDate operator++ ( )

Prefix increment operator.

Returns
A copy of this object after modification.

Definition at line 258 of file calendar.cpp.

Here is the call graph for this function:

◆ operator++() [2/2]

CalendarDate operator++ ( int  )
inline

Postfix increment operator.

Returns
A copy of this object prior to its modification.

Definition at line 558 of file calendar.hpp.

◆ operator+=()

CalendarDate operator+= ( int  daysToAdd)
inline

Adds the given number of days to this date.

Parameters
daysToAddThe days to add. May be negative for subtraction.
Returns
A copy of this object after modification.

Definition at line 581 of file calendar.hpp.

◆ operator-()

CalendarDate operator- ( int  daysToSubtract) const
inline

Subtracts the given number of days to this date.

Parameters
daysToSubtractThe days to add. May be negative for additions.
Returns
A copy of this object after modification.

Definition at line 535 of file calendar.hpp.

◆ operator--() [1/2]

CalendarDate operator-- ( )

Prefix decrement operator.

Returns
A copy of this object after modification.

Definition at line 291 of file calendar.cpp.

Here is the call graph for this function:

◆ operator--() [2/2]

CalendarDate operator-- ( int  )
inline

Postfix decrement operator.

Returns
A copy of this object prior to its modification.

Definition at line 569 of file calendar.hpp.

◆ operator-=()

CalendarDate operator-= ( int  daysToSubtract)
inline

Subtracts the given number of days to this date.

Parameters
daysToSubtractThe days to add. May be negative for additons.
Returns
A copy of this object after modification.

Definition at line 591 of file calendar.hpp.

◆ operator<()

bool operator< ( const CalendarDate other) const
inline

Less than operator.

Parameters
otherThe date stamp to compare.
Returns
A reference to this object.

Definition at line 623 of file calendar.hpp.

◆ operator<=()

bool operator<= ( const CalendarDate other) const
inline

Less than or equal to operator.

Parameters
otherThe date stamp to compare.
Returns
The result of the comparison.

Definition at line 633 of file calendar.hpp.

◆ operator=() [1/2]

CalendarDate& operator= ( CalendarDate &&  )
defaultnoexcept

Trivial default move assign operator.

Returns
A reference to this.

◆ operator=() [2/2]

CalendarDate& operator= ( const CalendarDate )
defaultnoexcept

Trivial default copy assign operator.

Returns
A reference to this.

◆ operator==()

bool operator== ( const CalendarDate other) const
inline

Equal to operator.

Parameters
otherThe date stamp to compare.
Returns
The result of the comparison.

Definition at line 603 of file calendar.hpp.

◆ operator>()

bool operator> ( const CalendarDate other) const
inline

Greater than operator.

Parameters
otherThe date stamp to compare.
Returns
The result of the comparison.

Definition at line 643 of file calendar.hpp.

◆ operator>=()

bool operator>= ( const CalendarDate other) const
inline

Greater than or equal to operator.

Parameters
otherThe date stamp to compare.
Returns
The result of the comparison.

Definition at line 653 of file calendar.hpp.

◆ Set() [1/2]

void Set ( const DateTime dateTime,
Timezone  timezone 
)

Sets this class to the date represented by the given DateTime instance.

Parameters
dateTimeThe value to take the date from.
timezoneDetermines whether the local time zone applies to dateTime or whether it refers to UTC.

Definition at line 209 of file calendar.cpp.

◆ Set() [2/2]

void Set ( int  year,
int  month,
int  day,
int  dayOfWeek = -1 
)

Sets this class to the given values.

Parameters
yearThe year to use. Must be between 0 and 1,048,575
monthThe month to use. Must be between 1 and 12
dayThe day to use. Must be between 1 and 31
dayOfWeekThe day of week that results from the previous values. Defaults to -1 wich instructs this constructor to retrieve that correct value.
If given, values must be between 0 (Sunday) and 6 (Saturday). In debug compilations an assertion will be raised if the value is out of range or inconsistent.

Definition at line 217 of file calendar.cpp.

Here is the call graph for this function:

◆ ToCalendarDateTime()

ALIB_API CalendarDateTime ToCalendarDateTime ( ) const

Returns a date and time value, by adding 12 o'clock noon time.

Returns
A corresponding DateTime value.

◆ Year()

int Year ( ) const
inline

Extracts the day of month from this date as a value between 1 and 31.

Returns
The calendar day of month.

Definition at line 504 of file calendar.hpp.


The documentation for this class was generated from the following files: