MT Core (C++)
Core library for replacing C++ standard in project usage
|
Calendars is an attempt to do more than basic date processing in Gregorian. It is an attempt to allow conversions between multiple calendaring systems, in addition to normal Gregorian operations. This allows it to better handle calculating holidays based on other calendaring systems.
Additionally, it provides a lot more primitives for easily calculating holidays, such as calculating the "nth weekday on, before, or after a certain date" which can be used to calculate the 3rd Thursday of a month, or the 1st Tuesday after the first Saturday of a month.
The calculations are based on the materials found in the book "Calendrical Calculations: The Ultimate Edition" by Edward M. Reingold and Nachum Dershowitz.
For convenience, the type aliases mtcore::Date
, mtcore::DateTime
, and mtcore::DateTimeZoned
exist for developers wishing to only use the Gregorian system, and to use this library similar to other date processing libraries.
Other aliases exist for dates using specific calendar systems (e.g. mtcore::GregorianDate
, mtcore::EgyptianDate
, etc.).
Creating a new calendar system is fairly straight forward. Simply create a new class/struct which implements either the concept mtcore::calendars::IsDayCalendarSystem
or mtcore::calendars::IsTimeCalendarSystem
. After that, simply pass your new struct as a template parameter to CalDate
(IsDayCalendarSystem
only), CalDateTime
and/or CalDateTimeZoned
and now you have a new calendar system.
Do note that the
to_fixed
/from_fixed
andto_moment
/from_moment
pairs are to dictate how your calendar relates to the Fixed date system. The Fixed date system is a count of days from December 31, 1 BC (e.g. Fixed(1) is January 1, 1 A.D). In more precise terms, Fixed is set up such thatFixed{1} == Gregorian{AstronomicalYear{1}, GregorianMonth::January, 1}
.Note that while the code interface necessary is relatively straightforward, getting the math correct can be difficult.
It's not necessary to implement a full suite of comparison operators for custom dates. Only the three-way comparison operator needs to be implemented. The wrapper code CalDate
and friends will handle filling in the other code.