Description: The Date class is (originally) based on SmallTalk-80, The Language & Its Implementation, page 108 (apx) - but changed to use Gregorian instead of Julian calendar.
- Note
- This class integrates neatly with the C++20 chrono date support. You can easily go back and forth (e.g. Date{std::chrono::year_month_day...}} or d.As<year_month_day> ())
The main features of the Stroika Data class (compared to the std c++ date support):
o Simpler to use/understand (Stroika 'Date' does about the same thing as a bevy of
different chrono classes)
o Stroika Date immutable (OK - difference not clearly advantage)
o Validation (constructor DataExchange::ValidationStrategy)
(no non-ok () Date objects in Stroika). Nice clear semantics about exceptions
and assertions.
o Easier to use formatting
o ISO8601 formatting
o Wraps needlessly complicated locale/facet API for formatting dates as Strings, or
parsing them from strings.
o Builtin support for Julian calendar (again - maybe this is a difference not advantage?)
- Note
- o Date stores date's internally as Julian days, and so is valid for any date > January 1, −4713; Also note sizeof (year_month_day) == sizeof (Date) == 4
- Miscellaneous references
- o According to https://en.wikipedia.org/wiki/Gregorian_calendar Britain and the British Empire (including the eastern part of what is now the United States) adopted the Gregorian calendar in 1752 o https://aa.usno.navy.mil/data/JulianDate Best Julian date calculator I found (bad but best) o Proleptic Gregorian Calendar https://en.wikipedia.org/wiki/Gregorian_calendar#Proleptic_Gregorian_calendar o Julian Day Numer https://en.wikipedia.org/wiki/Julian_day
Class Date knows about some obvious information: -> there are seven days in a week, each day having a symbolic name and an index 1..7 -> there are twelve months in a year, each having a symbolic name and an index 1..12. -> months have 28..31 days and -> a particular year might be a leap year."
@iverbatim
NB: Date implies NO NOTION of timezone.
@endiverbatim
\note The entire Date API is immutable - meaning that all methods are const (except constructor and assignment operator)
\note Date constructors REQUIRE valid inputs, and any operations which might overflow throw range_error
instead of creating invalid values.
\note Would like to make Date inherit from Debug::AssertExternallySynchronizedMutex to assure its not accidentially modified, but
that's difficult because its sometimes uses as a constexpr
\note \em Thread-Safety <a href="Thread-Safety.mdC++-Standard-Thread-Safety">C++-Standard-Thread-Safety</a>
\note <a href="Design-Overview.mdComparisons">Comparisons: static_assert (totally_ordered<Date>);
Definition at line 327 of file Date.h.
template<typename T >
requires (Common::IAnyOf<::tm, tm, year_month_day> or Common::ITimePoint<T>)
| constexpr T Stroika::Foundation::Time::Date::As |
( |
| ) |
const |
|
constexpr |
Defined for struct tm year_month_day any std::time_point
Generally constexpr where possible.
@todo understand why on MSVC I need ::tm and tm in the IAnyOf<>
Definition at line 270 of file Date.inl.
| constexpr ReferencePoint Stroika::Foundation::Time::Date::kGregorianCalendarEpoch {1752y / September / 14d, 2361222} |
|
staticconstexpr |
See https://en.wikipedia.org/wiki/Gregorian_calendar September, 14d, 1752 (even this not sure of, but used this in Stroika v2.1)
"Algorithm 199 from Communications of the ACM, Volume 6, No. 8, (Aug. 1963), p. 444. <br>
Gregorian calendar started on Sep. 14, 1752"
Definition at line 376 of file Date.h.