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.
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
calendar_date Class Reference

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_dateoperator= (jdn_t)
 
calendar_dateoperator= (ymd_t)
 
calendar_dateoperator++ ()
 
calendar_dateoperator-- ()
 
calendar_dateoperator+= (int)
 
calendar_dateoperator-= (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_
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ calendar_date() [1/4]

calendar_date::calendar_date ( )

◆ calendar_date() [2/4]

calendar_date::calendar_date ( jdn_t  z)
explicit

◆ calendar_date() [3/4]

calendar_date::calendar_date ( ymd_t  z)
explicit

◆ calendar_date() [4/4]

calendar_date::calendar_date ( int  year,
int  month,
int  day 
)

Member Function Documentation

◆ assign_from_gregorian()

void calendar_date::assign_from_gregorian ( int  year,
int  month,
int  day 
)
private

◆ cache_gregorian_elements()

void calendar_date::cache_gregorian_elements ( ) const
private

◆ day()

int calendar_date::day ( ) const

◆ days_in_month()

int calendar_date::days_in_month ( ) const

◆ days_in_year()

int calendar_date::days_in_year ( ) const

◆ is_leap_year()

bool calendar_date::is_leap_year ( ) const

◆ is_verified_jdn()

bool calendar_date::is_verified_jdn ( int  z)
static

◆ julian_day_number() [1/2]

int calendar_date::julian_day_number ( ) const

◆ julian_day_number() [2/2]

int calendar_date::julian_day_number ( int  z)

◆ month()

int calendar_date::month ( ) const

◆ operator!=()

bool calendar_date::operator!= ( calendar_date const &  z) const

◆ operator++()

calendar_date & calendar_date::operator++ ( )

◆ operator+=()

calendar_date & calendar_date::operator+= ( int  i)

◆ operator--()

calendar_date & calendar_date::operator-- ( )

◆ operator-=()

calendar_date & calendar_date::operator-= ( int  i)

◆ operator<()

bool calendar_date::operator< ( calendar_date const &  z) const

◆ operator<=()

bool calendar_date::operator<= ( calendar_date const &  z) const

◆ operator=() [1/2]

calendar_date & calendar_date::operator= ( jdn_t  j)

◆ operator=() [2/2]

calendar_date & calendar_date::operator= ( ymd_t  ymd)

◆ operator==()

bool calendar_date::operator== ( calendar_date const &  z) const

◆ str()

std::string calendar_date::str ( ) const

◆ year()

int calendar_date::year ( ) const

Member Data Documentation

◆ cached_day_

int calendar_date::cached_day_
mutableprivate

◆ cached_month_

int calendar_date::cached_month_
mutableprivate

◆ cached_year_

int calendar_date::cached_year_
mutableprivate

◆ gregorian_epoch_jdn

constexpr int calendar_date::gregorian_epoch_jdn {2361222}
staticconstexpr

◆ jdn_

int calendar_date::jdn_
private

◆ last_yyyy_date_jdn

constexpr int calendar_date::last_yyyy_date_jdn {5373484}
staticconstexpr

◆ max_verified_jdn

constexpr int calendar_date::max_verified_jdn {9999999}
staticconstexpr

◆ min_verified_jdn

constexpr int calendar_date::min_verified_jdn {1721120}
staticconstexpr

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