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
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 361 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. ***************************************************. | |
ALIB_API | 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 |
ALIB_API 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 |
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 |
CalendarDate & | operator= (CalendarDate &&) noexcept=default |
CalendarDate & | operator= (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, lang::Timezone timezone) |
ALIB_API void | Set (int year, int month, int day, int dayOfWeek=-1) |
ALIB_API CalendarDateTime | ToCalendarDateTime () const |
int | Year () const |
Protected Field Index: | |
uint32_t | stamp |
Encoded date value. | |
|
protected |
Encoded date value.
Definition at line 364 of file calendar.hpp.
|
inline |
Constructor taking the date as separated values.
year | The year to use. Must be between 0 and 1,048,575 |
month | The month to use. Must be between 1 and 12 |
day | The day to use. Must be between 1 and 31 |
dayOfWeek | The 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 402 of file calendar.hpp.
|
inlineexplicit |
Constructor creating a date that represents "today".
timezone | Determines whether the local time zone should be used or UTC. |
Definition at line 412 of file calendar.hpp.
|
inlineexplicit |
Constructor taking a DateTime value.
calendarDateTime | The value to take the date from. |
Definition at line 422 of file calendar.hpp.
|
inline |
Constructor taking a DateTime value.
dateTime | The value to take the date from. |
timezone | Determines whether the local time zone should be used or UTC. |
Definition at line 435 of file calendar.hpp.
|
inline |
Extracts the day of month from this date as a value between 1
and 31
.
Definition at line 503 of file calendar.hpp.
|
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.
Definition at line 509 of file calendar.hpp.
DateTime 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.
timezone | Denote if the time that is calculated should be local or UTC. Defaults to TimeZone::Local . |
hour | The hour of day (0..23) that the value returned should represent. Defaults to noon time (12 ). |
minute | The minute of the hour (0..59) that the value returned should represent. Defaults to 0 . |
second | The second of the minute (0..59) that the value returned should represent. Defaults to 0 . |
Definition at line 216 of file calendar.cpp.
|
inline |
Extracts the month from this date as a value between 1
and 12
.
Definition at line 499 of file calendar.hpp.
|
inline |
Not equal to operator.
other | The date stamp to compare. |
Definition at line 604 of file calendar.hpp.
CalendarDate operator+ | ( | int | daysToAdd | ) | const |
Adds the given number of days to this date.
daysToAdd | The days to add. May be negative for subtraction. |
Definition at line 221 of file calendar.cpp.
CalendarDate operator++ | ( | ) |
Prefix increment operator.
Definition at line 229 of file calendar.cpp.
|
inline |
Postfix increment operator.
Definition at line 549 of file calendar.hpp.
|
inline |
Adds the given number of days to this date.
daysToAdd | The days to add. May be negative for subtraction. |
Definition at line 572 of file calendar.hpp.
|
inline |
Subtracts the given number of days to this date.
daysToSubtract | The days to add. May be negative for additions. |
Definition at line 526 of file calendar.hpp.
CalendarDate operator-- | ( | ) |
Prefix decrement operator.
Definition at line 262 of file calendar.cpp.
|
inline |
Postfix decrement operator.
Definition at line 560 of file calendar.hpp.
|
inline |
Subtracts the given number of days to this date.
daysToSubtract | The days to add. May be negative for additons. |
Definition at line 582 of file calendar.hpp.
|
inline |
Less than operator.
other | The date stamp to compare. |
Definition at line 614 of file calendar.hpp.
|
inline |
Less than or equal to operator.
other | The date stamp to compare. |
Definition at line 624 of file calendar.hpp.
|
defaultnoexcept |
Trivial default move assign operator.
this
. ***************************************************
|
defaultnoexcept |
Trivial default copy assign operator.
this
. ***************************************************
|
inline |
Equal to operator.
other | The date stamp to compare. |
Definition at line 594 of file calendar.hpp.
|
inline |
Greater than operator.
other | The date stamp to compare. |
Definition at line 634 of file calendar.hpp.
|
inline |
Greater than or equal to operator.
other | The date stamp to compare. |
Definition at line 644 of file calendar.hpp.
void Set | ( | const DateTime & | dateTime, |
lang::Timezone | timezone ) |
Sets this class to the date represented by the given DateTime instance.
dateTime | The value to take the date from. |
timezone | Determines whether the local time zone applies to dateTime or whether it refers to UTC. |
Definition at line 180 of file calendar.cpp.
void Set | ( | int | year, |
int | month, | ||
int | day, | ||
int | dayOfWeek = -1 ) |
Sets this class to the given values.
year | The year to use. Must be between 0 and 1,048,575 |
month | The month to use. Must be between 1 and 12 |
day | The day to use. Must be between 1 and 31 |
dayOfWeek | The 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 188 of file calendar.cpp.
ALIB_API CalendarDateTime ToCalendarDateTime | ( | ) | const |
Returns a date and time value, by adding 12 o'clock noon time.
|
inline |
Extracts the day of month from this date as a value between 1
and 31
.
Definition at line 495 of file calendar.hpp.