19#ifndef MTCORE_CALENDARS_GREGORIAN_HPP
20#define MTCORE_CALENDARS_GREGORIAN_HPP
30 static constexpr std::string_view
name =
"Gregorian";
58 if (
const auto c =
year <=> g.
year; c != std::strong_ordering::equivalent) {
61 if (
const auto c =
month <=> g.
month; c != std::strong_ordering::equivalent) {
69 const auto yearMod400 =
math::mod(y, 400);
70 return math::mod(y, 4) == 0 && yearMod400 != 100 && yearMod400 != 200 && yearMod400 != 300;
76 return {.year =
year, .month = Month::January, .day = 1};
82 return {.year =
year, .month = Month::December, .day = 31};
100 const auto year = year_from_fixed(f);
102 const auto yearStartRdDate = yearStart.to_fixed();
105 const auto marchFirstRdDate = marchFirst.
to_fixed();
106 const auto correction = (f <=> marchFirstRdDate) == std::strong_ordering::less ? 0 :
is_leap_year(
year) ? 1 : 2;
109 const auto firstOfMonthRdDate = firstOfMonth.
to_fixed();
132 case Month::December:
134 case Month::February:
138 case Month::September:
139 case Month::November:
158 const auto year = 400 * n400 + 100 * n100 + 4 * n4 + n1 + 1 -
159 static_cast<int64_t
>(
static_cast<unsigned>(n100 == 4) |
static_cast<unsigned>(n1 == 4));
164 static_assert(IsDayCalendarSystem<Gregorian>);
i32 YearBase
Year base type.
#define unreachable(...)
Marks code as unreachable.
constexpr R floor(T num) noexcept
Floors a number with support for constexpr and fast runtime compilation.
constexpr Res mod(L left, R right) noexcept
Calculates the mathematical mod of two numbers.
int32_t i32
Alias for 32-bit ints.
uint8_t u8
Alias for 8-bit unsigned ints.
uint16_t u16
Alias for 16-bit unsigned ints.
constexpr i32 GREGORIAN_EPOCH
Base calendar system tracking the number of days since its epoch.
constexpr Fixed sub_days(const i32 days) const
Subtracts n days from a date.
constexpr i32 day_difference(const Fixed &other) const
Difference between two dates in days.
constexpr Gregorian year_start() const
constexpr bool leap_year() const
void init(i32 year, Month month, u8 day)
static constexpr u16 days_in_year_for(const AstronomicalYear year)
constexpr Fixed to_fixed() const
static constexpr u8 days_in_month_for(const AstronomicalYear year, const Month month)
static constexpr Gregorian year_end_for(const AstronomicalYear year)
constexpr std::strong_ordering operator<=>(const Gregorian &g) const
static constexpr auto EPOCH
constexpr Gregorian year_end() const
static constexpr Gregorian year_start_for(const AstronomicalYear year)
static constexpr std::string_view name
constexpr u8 days_in_month() const
constexpr u16 days_in_year() const
static constexpr bool is_leap_year(const AstronomicalYear year)
static constexpr Gregorian from_fixed(const Fixed &f)