ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::strings::util::CalendarDate Class Reference

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

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

  • bits 1-3 encode the day of week (from 0 (= Sunday) to 6 (= Saturday)
  • bits 4-8 encode the calendar day (1..31)
  • bits 9-12 encode the calendar month (1..12)
  • bits 13-32 encode the calendar year consequently, for the calendar year 20 bits are available, which evaluates to a range of 1,048,576 years. For simplicity and speed, the values are not defined in accordance to class CalendarDateTime, where a value of 0 represents year 1900. This class just stores the year value as is and does not allow negative values. As a result, this class is capable of storing values between 1/1/0000 and 12/31/1,048,576.

Definition at line 296 of file calendar.hpp.

#include <calendar.hpp>

Public Method Index:

 CalendarDate ()=default
 Default constructor leaving this object uninitialized (random value).
 CalendarDate (CalendarDate &&) noexcept=default
 Trivial default move constructor.
 CalendarDate (const CalendarDate &) noexcept=default
 Trivial default copy constructor.
 CalendarDate (const CalendarDateTime &calendarDateTime)
 CalendarDate (const DateTime &dateTime, lang::Timezone timezone)
 CalendarDate (int year, int month, int day, int dayOfWeek=-1)
 CalendarDate (lang::Timezone timezone)
 ~CalendarDate () noexcept=default
 Trivial default destructor.
int Day () const
int DayOfWeek () const
DateTime Get (lang::Timezone timezone=lang::Timezone::Local, int hour=12, int minute=0, int second=0) const
int Month () const
bool operator!= (const CalendarDate &other) const
CalendarDate operator+ (int daysToAdd) const
CalendarDate operator++ ()
CalendarDate operator++ (int)
CalendarDate operator+= (int daysToAdd)
CalendarDate operator- (int daysToSubtract) const
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
void Set (const DateTime &dateTime, lang::Timezone timezone)
void Set (int year, int month, int day, int dayOfWeek=-1)
CalendarDateTime ToCalendarDateTime () const
int Year () const

Protected Field Index:

uint32_t stamp
 Encoded date value.

Field Details:

◆ stamp

uint32_t alib::strings::util::CalendarDate::stamp
protected

Encoded date value.

Definition at line 298 of file calendar.hpp.

Constructor(s) / Destructor Details:

◆ CalendarDate() [1/4]

alib::strings::util::CalendarDate::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 which 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 334 of file calendar.hpp.

Here is the call graph for this function:

◆ CalendarDate() [2/4]

alib::strings::util::CalendarDate::CalendarDate ( lang::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 340 of file calendar.hpp.

Here is the call graph for this function:

◆ CalendarDate() [3/4]

alib::strings::util::CalendarDate::CalendarDate ( const CalendarDateTime & calendarDateTime)
inlineexplicit

Constructor taking a DateTime value.

Parameters
calendarDateTimeThe value to take the date from.

Definition at line 346 of file calendar.hpp.

Here is the call graph for this function:

◆ CalendarDate() [4/4]

alib::strings::util::CalendarDate::CalendarDate ( const DateTime & dateTime,
lang::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 356 of file calendar.hpp.

Here is the call graph for this function:

Method Details:

◆ Day()

int alib::strings::util::CalendarDate::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 413 of file calendar.hpp.

◆ DayOfWeek()

int alib::strings::util::CalendarDate::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 DayOfWeek.

Returns
The calendar day of month.

Definition at line 419 of file calendar.hpp.

◆ Get()

DateTime alib::strings::util::CalendarDate::Get ( lang::Timezone timezone = lang::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 211 of file calendar.cpp.

Here is the call graph for this function:

◆ Month()

int alib::strings::util::CalendarDate::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 409 of file calendar.hpp.

◆ operator!=()

bool alib::strings::util::CalendarDate::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 480 of file calendar.hpp.

Here is the call graph for this function:

◆ operator+()

CalendarDate alib::strings::util::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 214 of file calendar.cpp.

Here is the call graph for this function:

◆ operator++() [1/2]

CalendarDate alib::strings::util::CalendarDate::operator++ ( )

Prefix increment operator.

Returns
A copy of this object after modification.

Definition at line 221 of file calendar.cpp.

Here is the call graph for this function:

◆ operator++() [2/2]

CalendarDate alib::strings::util::CalendarDate::operator++ ( int )
inline

Postfix increment operator.

Returns
A copy of this object before its modification.

Definition at line 446 of file calendar.hpp.

Here is the call graph for this function:

◆ operator+=()

CalendarDate alib::strings::util::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 463 of file calendar.hpp.

Here is the call graph for this function:

◆ operator-()

CalendarDate alib::strings::util::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 432 of file calendar.hpp.

Here is the call graph for this function:

◆ operator--() [1/2]

CalendarDate alib::strings::util::CalendarDate::operator-- ( )

Prefix decrement operator.

Returns
A copy of this object after modification.

Definition at line 249 of file calendar.cpp.

Here is the call graph for this function:

◆ operator--() [2/2]

CalendarDate alib::strings::util::CalendarDate::operator-- ( int )
inline

Postfix decrement operator.

Returns
A copy of this object before its modification.

Definition at line 454 of file calendar.hpp.

Here is the call graph for this function:

◆ operator-=()

CalendarDate alib::strings::util::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 468 of file calendar.hpp.

Here is the call graph for this function:

◆ operator<()

bool alib::strings::util::CalendarDate::operator< ( const CalendarDate & other) const
inline

Less than operator.

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

Definition at line 485 of file calendar.hpp.

Here is the call graph for this function:

◆ operator<=()

bool alib::strings::util::CalendarDate::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 490 of file calendar.hpp.

Here is the call graph for this function:

◆ operator=() [1/2]

CalendarDate & alib::strings::util::CalendarDate::operator= ( CalendarDate && )
defaultnoexcept

Trivial default move assign operator.

Returns
A reference to this.
Here is the call graph for this function:

◆ operator=() [2/2]

CalendarDate & alib::strings::util::CalendarDate::operator= ( const CalendarDate & )
defaultnoexcept

Trivial default copy assign operator.

Returns
A reference to this.
Here is the call graph for this function:

◆ operator==()

bool alib::strings::util::CalendarDate::operator== ( const CalendarDate & other) const
inline

Equal to operator.

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

Definition at line 475 of file calendar.hpp.

Here is the call graph for this function:

◆ operator>()

bool alib::strings::util::CalendarDate::operator> ( const CalendarDate & other) const
inline

Greater than operator.

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

Definition at line 496 of file calendar.hpp.

Here is the call graph for this function:

◆ operator>=()

bool alib::strings::util::CalendarDate::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 501 of file calendar.hpp.

Here is the call graph for this function:

◆ Set() [1/2]

void alib::strings::util::CalendarDate::Set ( const DateTime & dateTime,
lang::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 178 of file calendar.cpp.

◆ Set() [2/2]

void alib::strings::util::CalendarDate::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 which 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 185 of file calendar.cpp.

Here is the call graph for this function:

◆ ToCalendarDateTime()

CalendarDateTime alib::strings::util::CalendarDate::ToCalendarDateTime ( ) const

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

Returns
A corresponding DateTime value.

◆ Year()

int alib::strings::util::CalendarDate::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 405 of file calendar.hpp.


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