3#ifndef _TIME_SHIELD_DETAIL_FAST_DATE_HPP_INCLUDED
4#define _TIME_SHIELD_DETAIL_FAST_DATE_HPP_INCLUDED
63 const int month_adjust = (p_month <= 2 ? 1 : 0);
64 const int64_t y = p_year - month_adjust;
71 const uint64_t y_u =
static_cast<uint64_t
>(y);
72 const uint64_t era = y_u / 400U;
73 const uint64_t yoe = y_u - era * 400U;
74 const uint64_t doy =
static_cast<uint64_t
>(k_doy_from_march[m]) +
static_cast<uint64_t
>(p_day - 1);
75 const uint64_t doe = yoe * 365U + yoe / 4U - yoe / 100U + doy;
76 return static_cast<int64_t
>(era * 146097U + doe) - 719468;
79 const int64_t era = (y - 399) / 400;
80 const int64_t yoe = y - era * 400;
81 const int64_t doy =
static_cast<int64_t
>(k_doy_from_march[m]) +
static_cast<int64_t
>(p_day - 1);
82 const int64_t doe = yoe * 365 + yoe / 4 - yoe / 100 + doy;
83 return era * 146097 + doe - 719468;
91 const int month_adjust = (p_month <= 2 ? 1 : 0);
92 const int64_t y = p_year - month_adjust;
99 const uint64_t y_u =
static_cast<uint64_t
>(y);
100 const uint64_t era = y_u / 400U;
101 const uint64_t yoe = y_u - era * 400U;
102 const uint64_t doy =
static_cast<uint64_t
>(k_doy_from_march[m]) +
static_cast<uint64_t
>(p_day - 1);
103 const uint64_t doe = yoe * 365U + yoe / 4U - yoe / 100U + doy;
104 return static_cast<int64_t
>(era * 146097U + doe) - 719468;
107 const int64_t era = (y - 399) / 400;
108 const int64_t yoe = y - era * 400;
109 const int64_t doy =
static_cast<int64_t
>(k_doy_from_march[m]) +
static_cast<int64_t
>(p_day - 1);
110 const int64_t doe = yoe * 365 + yoe / 4 - yoe / 100 + doy;
111 return era * 146097 + doe - 719468;
119 constexpr uint64_t ERAS = 4726498270ULL;
120 constexpr int64_t D_SHIFT =
static_cast<int64_t
>(146097ULL * ERAS - 719469ULL);
121 constexpr int64_t Y_SHIFT =
static_cast<int64_t
>(400ULL * ERAS - 1ULL);
122 constexpr uint64_t C1 = 505054698555331ULL;
123 constexpr uint64_t C2 = 50504432782230121ULL;
124 constexpr uint64_t C3 = 8619973866219416ULL;
125 constexpr uint64_t YPT_SCALE = 782432ULL;
126 constexpr uint64_t YPT_BUMP_THRESHOLD = 126464ULL;
127 constexpr uint64_t SHIFT_JAN_FEB = 191360ULL;
128 constexpr uint64_t SHIFT_OTHER = 977792ULL;
130 const uint64_t rev =
static_cast<uint64_t
>(D_SHIFT - p_days);
132 const uint64_t jul = rev + cen - (cen / 4U);
135 const uint64_t num_low = jul * C2;
136 const uint64_t yrs =
static_cast<uint64_t
>(Y_SHIFT) - num_hi;
139 const bool bump = ypt < YPT_BUMP_THRESHOLD;
140 const uint64_t shift = bump ? SHIFT_JAN_FEB : SHIFT_OTHER;
142 const uint64_t N = (yrs & 3ULL) * 512ULL + shift - ypt;
146 static_cast<int64_t
>(yrs + (bump ? 1U : 0U)),
147 static_cast<int>(N >> 16),
148 static_cast<int>(d + 1U)
157 constexpr uint64_t ERAS = 4726498270ULL;
158 constexpr int64_t D_SHIFT =
static_cast<int64_t
>(146097ULL * ERAS - 719469ULL);
159 constexpr int64_t Y_SHIFT =
static_cast<int64_t
>(400ULL * ERAS - 1ULL);
160 constexpr uint64_t C1 = 505054698555331ULL;
161 constexpr uint64_t C2 = 50504432782230121ULL;
162 constexpr uint64_t C3 = 8619973866219416ULL;
163 constexpr uint64_t YPT_SCALE = 782432ULL;
164 constexpr uint64_t YPT_BUMP_THRESHOLD = 126464ULL;
165 constexpr uint64_t SHIFT_JAN_FEB = 191360ULL;
166 constexpr uint64_t SHIFT_OTHER = 977792ULL;
168 const uint64_t rev =
static_cast<uint64_t
>(D_SHIFT - p_days);
170 const uint64_t jul = rev + cen - (cen / 4U);
173 const uint64_t num_low = jul * C2;
174 const uint64_t yrs =
static_cast<uint64_t
>(Y_SHIFT) - num_hi;
177 const bool bump = ypt < YPT_BUMP_THRESHOLD;
178 const uint64_t shift = bump ? SHIFT_JAN_FEB : SHIFT_OTHER;
180 const uint64_t N = (yrs & 3ULL) * 512ULL + shift - ypt;
184 result.
day =
static_cast<int>(d + 1U);
185 result.month =
static_cast<int>(N >> 16);
186 result.year =
static_cast<int64_t
>(yrs + (bump ? 1U : 0U));
195 constexpr uint64_t ERAS = 4726498270ULL;
196 constexpr int64_t D_SHIFT =
static_cast<int64_t
>(146097ULL * ERAS - 719469ULL);
197 constexpr int64_t Y_SHIFT =
static_cast<int64_t
>(400ULL * ERAS - 1ULL);
198 constexpr uint64_t C1 = 505054698555331ULL;
199 constexpr uint64_t C2 = 50504432782230121ULL;
200 constexpr uint64_t YPT_SCALE = 782432ULL;
201 constexpr uint64_t YPT_BUMP_THRESHOLD = 126464ULL;
203 const uint64_t rev =
static_cast<uint64_t
>(D_SHIFT - p_days);
205 const uint64_t jul = rev + cen - (cen / 4U);
208 const uint64_t num_low = jul * C2;
209 const uint64_t yrs =
static_cast<uint64_t
>(Y_SHIFT) - num_hi;
212 const bool bump = ypt < YPT_BUMP_THRESHOLD;
213 return static_cast<int64_t
>(yrs + (bump ? 1U : 0U));
221 constexpr uint64_t ERAS = 4726498270ULL;
222 constexpr int64_t D_SHIFT =
static_cast<int64_t
>(146097ULL * ERAS - 719469ULL);
223 constexpr int64_t Y_SHIFT =
static_cast<int64_t
>(400ULL * ERAS - 1ULL);
224 constexpr uint64_t C1 = 505054698555331ULL;
225 constexpr uint64_t C2 = 50504432782230121ULL;
226 constexpr uint64_t YPT_SCALE = 782432ULL;
227 constexpr uint64_t YPT_BUMP_THRESHOLD = 126464ULL;
229 const uint64_t rev =
static_cast<uint64_t
>(D_SHIFT - p_days);
231 const uint64_t jul = rev + cen - (cen / 4U);
234 const uint64_t num_low = jul * C2;
235 const uint64_t yrs =
static_cast<uint64_t
>(Y_SHIFT) - num_hi;
238 const bool bump = ypt < YPT_BUMP_THRESHOLD;
239 return static_cast<int64_t
>(yrs + (bump ? 1U : 0U));
constexpr int64_t SEC_PER_DAY
Seconds per day.
constexpr T days(ts_t start, ts_t stop) noexcept
Alias for days_between function.
bool sec_of_day(const std::string &str, T &sec)
Parse time of day string to seconds of day.
int64_t ts_t
Unix timestamp in seconds since 1970‑01‑01T00:00:00Z.
Helpers for 64-bit multiply-high operations.
constexpr int16_t k_doy_from_march[12]
uint64_t mul_shift_u64(uint64_t p_x, uint64_t p_c) noexcept
Alias for mul_hi_u64 used for shift-by-64 operations.
TIME_SHIELD_CONSTEXPR FastDate fast_date_from_days_constexpr(int64_t p_days) noexcept
Convert days since Unix epoch to date using a fast constexpr algorithm.
TIME_SHIELD_CONSTEXPR DaySplit split_unix_day(ts_t p_ts) noexcept
Split UNIX seconds into whole days and seconds-of-day.
TIME_SHIELD_CONSTEXPR uint64_t mul_shift_u64_constexpr(uint64_t p_x, uint64_t p_c) noexcept
Alias for mul_hi_u64_constexpr used for shift-by-64 operations.
int64_t fast_year_from_days(int64_t p_days) noexcept
Convert days since Unix epoch to year using a fast algorithm.
TIME_SHIELD_CONSTEXPR int64_t fast_year_from_days_constexpr(int64_t p_days) noexcept
Convert days since Unix epoch to year using a fast constexpr algorithm.
FastDate fast_date_from_days(int64_t p_days) noexcept
Convert days since Unix epoch to date using a fast algorithm.
TIME_SHIELD_CONSTEXPR int64_t fast_days_from_date_constexpr(int64_t p_year, int p_month, int p_day) noexcept
Convert date to days since Unix epoch using a fast constexpr algorithm.
int64_t fast_days_from_date(int64_t p_year, int p_month, int p_day) noexcept
Convert date to days since Unix epoch using a fast algorithm.
Main namespace for the Time Shield library.