Let me illustrate…
Copyright (C) 1998-2023 Gregory W. Chicares. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.
|
Class calendar_date represents a gregorian-calendar date in the range [1752-09-14, 9999-12-31]. More...
#include <calendar_date.hpp>
Public Member Functions | |
calendar_date () | |
calendar_date (jdn_t) | |
calendar_date (ymd_t) | |
calendar_date (int year, int month, int day) | |
calendar_date & | operator= (jdn_t) |
calendar_date & | operator= (ymd_t) |
calendar_date & | operator++ () |
calendar_date & | operator-- () |
calendar_date & | operator+= (int) |
calendar_date & | operator-= (int) |
int | julian_day_number (int) |
int | julian_day_number () const |
bool | operator== (calendar_date const &) const |
bool | operator!= (calendar_date const &) const |
bool | operator< (calendar_date const &) const |
bool | operator<= (calendar_date const &) const |
int | year () const |
int | month () const |
int | day () const |
int | days_in_month () const |
int | days_in_year () const |
bool | is_leap_year () const |
std::string | str () const |
Static Public Member Functions | |
static bool | is_verified_jdn (int) |
Static Public Attributes | |
static constexpr int | gregorian_epoch_jdn {2361222} |
static constexpr int | last_yyyy_date_jdn {5373484} |
static constexpr int | min_verified_jdn {1721120} |
static constexpr int | max_verified_jdn {9999999} |
Private Member Functions | |
void | assign_from_gregorian (int year, int month, int day) |
void | cache_gregorian_elements () const |
Private Attributes | |
int | jdn_ |
int | cached_year_ |
int | cached_month_ |
int | cached_day_ |
Class calendar_date represents a gregorian-calendar date in the range [1752-09-14, 9999-12-31].
Date calculations are probably valid for later dates, and for earlier dates on the proleptic gregorian calendar, though only the given range is tested. The gregorian epoch is assumed to be 1752-09-14, the value predominant among the English-speaking peoples. The range limits are available as [gregorian_epoch(), last_yyyy_date()].
A date is internally represented as its 'julian day number', which is defined as number of days since January 1, 4713 BC according to the proleptic julian calendar. Seemingly-similar terms such as 'julian date' and 'julian day' are rendered irredeemably vague by diverse lay usage: they might be intended to mean the date on the julian as opposed to the gregorian calendar, or perhaps the number of days elapsed since the beginning of the current year. Which variant of julian day number the internal representation signifies need not be specified, and deliberately is not: astronomers may regard days as beginning at noon UTC, while most others probably think of days as beginning at midnight and respecting civil time in a local timezone, with appropriate daylight-saving adjustments. Such concerns are irrelevant to this class, which represents only a date, not a time of day.
The default ctor uses the current date.
By convention, the interface presents year, month, and day in origin one, so that concatenating their numeric representations as YYYYMMDD produces a valid ISO8601 date. Thus, the ranges of those elements are: year: [1752 | 1753, 9999] month: [1, 12] day: [1, 28 | 29 | 30 | 31] depending on context.
Functions that increment a date by a given number of months or years support two different conventions:
Implicitly-declared special member functions do the right thing.
calendar_date::calendar_date | ( | ) |
|
explicit |
|
explicit |
calendar_date::calendar_date | ( | int | year, |
int | month, | ||
int | day | ||
) |
|
private |
|
private |
int calendar_date::day | ( | ) | const |
int calendar_date::days_in_month | ( | ) | const |
int calendar_date::days_in_year | ( | ) | const |
bool calendar_date::is_leap_year | ( | ) | const |
|
static |
int calendar_date::julian_day_number | ( | ) | const |
int calendar_date::julian_day_number | ( | int | z | ) |
int calendar_date::month | ( | ) | const |
bool calendar_date::operator!= | ( | calendar_date const & | z | ) | const |
calendar_date & calendar_date::operator++ | ( | ) |
calendar_date & calendar_date::operator+= | ( | int | i | ) |
calendar_date & calendar_date::operator-- | ( | ) |
calendar_date & calendar_date::operator-= | ( | int | i | ) |
bool calendar_date::operator< | ( | calendar_date const & | z | ) | const |
bool calendar_date::operator<= | ( | calendar_date const & | z | ) | const |
calendar_date & calendar_date::operator= | ( | jdn_t | j | ) |
calendar_date & calendar_date::operator= | ( | ymd_t | ymd | ) |
bool calendar_date::operator== | ( | calendar_date const & | z | ) | const |
std::string calendar_date::str | ( | ) | const |
int calendar_date::year | ( | ) | const |
|
mutableprivate |
|
mutableprivate |
|
mutableprivate |
|
staticconstexpr |
|
private |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |