MT Core (C++)
Core library for replacing C++ standard in project usage
Loading...
Searching...
No Matches
egyptian.hpp
Go to the documentation of this file.
1/*
2
3Copyright 2025 Matthew Tolman
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16
17*/
18
19#ifndef MTCORE_CALENDARS_EGYPTIAN_HPP
20#define MTCORE_CALENDARS_EGYPTIAN_HPP
21
25#include <string_view>
26
33 struct Egyptian {
34 static constexpr auto EPOCH = EGYPTIAN_EPOCH;
35 static constexpr std::string_view name = "Egyptian";
52
60 Month month = Month::Thoth;
64 u8 day = 1;
65
66 [[nodiscard]] constexpr auto operator<=>(const Egyptian &o) const noexcept {
67 if (const auto c = year <=> o.year; c != std::strong_ordering::equivalent) {
68 return c;
69 }
70 if (const auto c = month <=> o.month; c != std::strong_ordering::equivalent) {
71 return c;
72 }
73 if (const auto c = day <=> o.day; c != std::strong_ordering::equivalent) {
74 return c;
75 }
76 return std::strong_ordering::equivalent;
77 }
78
79 [[nodiscard]] static constexpr Egyptian from_fixed(const Fixed &rdDate) noexcept {
80 const auto days = rdDate.day - EPOCH;
81 const auto egyptianYear = math::floor<double, int64_t>(static_cast<double>(days) / 365.0) + 1;
82 const auto egyptianMonth = math::floor<double, int64_t>(math::mod(static_cast<double>(days), 365) / 30.0) + 1;
83 const auto egyptianDay = days - 365 * (egyptianYear - 1) - 30 * (egyptianMonth - 1) + 1;
84 return Egyptian{static_cast<decltype(year)>(egyptianYear), static_cast<decltype(month)>(egyptianMonth),
85 static_cast<decltype(day)>(egyptianDay)};
86 }
87
88 [[nodiscard]] constexpr Fixed to_fixed() const noexcept {
89 return Fixed{EPOCH + ((365 * (static_cast<i32>(year) - 1) + 30 * (static_cast<i32>(month) - 1) +
90 static_cast<i32>(day - 1)))};
91 }
92 };
93
94 static_assert(IsDayCalendarSystem<Egyptian>);
95} // namespace mtcore::calendars::systems
96
97#endif // MTCORE_CALENDARS_EGYPTIAN_HPP
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.
constexpr i32 EGYPTIAN_EPOCH
Definition epochs.hpp:27
Base calendar system tracking the number of days since its epoch.
Definition fixed.hpp:38
Represents the ancient Egyptian calendaring system.
Definition egyptian.hpp:33
static constexpr std::string_view name
Definition egyptian.hpp:35
static constexpr Egyptian from_fixed(const Fixed &rdDate) noexcept
Definition egyptian.hpp:79
constexpr Fixed to_fixed() const noexcept
Definition egyptian.hpp:88
AstronomicalYear year
Year of the date.
Definition egyptian.hpp:56
constexpr auto operator<=>(const Egyptian &o) const noexcept
Definition egyptian.hpp:66
u8 day
Day of the month: 1-30 (epagomenae 1-5)
Definition egyptian.hpp:64
Month month
MONTH of the year (1-13)
Definition egyptian.hpp:60