38 template <
unsigned OFFSET>
40 unsigned const march1 = yoe * 365 + yoe / 4 - yoe / 100;
41 unsigned const jan4 = march1 + (
MARJAN + 3);
42 unsigned const jan4dow = (jan4 + OFFSET) % 7;
43 return jan4 - jan4dow;
105 uint32_t year_seconds_past_4year_period =
107 if (seconds_past_4year_period >=
111 uint32_t seconds_past_march =
112 seconds_past_4year_period - year_seconds_past_4year_period;
116 month = month <= 11 ? month : 11;
117 if (cumulative_month_epoch_starts[month] > seconds_past_march) {
120 return (month + 2) % 12 + 1;
124 STATIC_QUAL const uint32_t cumulative_quarter_epoch_starts[4] = {
125 0, 7776000, 15638400, 23587200};
126 STATIC_QUAL const uint32_t cumulative_quarter_epoch_starts_leap_year[4] = {
127 0, 7862400, 15724800, 23673600};
131 uint32_t base_year_leap_years = (year - 1) / 4;
132 uint32_t base_year_seconds =
134 bool is_leap_year = year % 4 == 0 && year != 0;
135 const uint32_t* quarter_offsets = is_leap_year
136 ? cumulative_quarter_epoch_starts_leap_year
137 : cumulative_quarter_epoch_starts;
138 uint32_t partial_year_seconds = seconds_1900 % base_year_seconds;
139 uint32_t quarter = partial_year_seconds / (90 *
kUSecsPerDay);
140 quarter = quarter <= 3 ? quarter : 3;
141 if (quarter_offsets[quarter] > partial_year_seconds) {
150 const uint32_t year =
176 unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
177 unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
178 unsigned const moy = (5 * doy + 2) / 153;
179 return doy - (153 * moy + 2) / 5 + 1;
186 unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
187 unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
188 return doy + (doy <
MARJAN ? 1 +
JANMAR + (yoe % 4 == 0 && (yoe % 100 != 0 || yoe == 0))
192 template <
unsigned OFFSET>
196 unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
197 unsigned week_start = week_start_from_yoe<OFFSET>(yoe);
198 if (doe < week_start) {
201 return (doe + OFFSET) / 7 + 9;
203 week_start = week_start_from_yoe<OFFSET>(yoe - 1);
206 return (doe - week_start) / 7 + 1;
211 return extract_week<MONDAY>(timeval);
216 return extract_week<SUNDAY>(timeval);
221 return extract_week<SATURDAY>(timeval);
231 unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
232 unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
233 unsigned const moy = (5 * doy + 2) / 153;
234 return moy + (moy < 10 ? 3 : -9);
242 constexpr int64_t quarter[12]{1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 1, 1};
245 unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
246 unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
247 unsigned const moy = (5 * doy + 2) / 153;
259 unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
260 unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
261 return 2000 + era * 400 + yoe + (
MARJAN <= doy);
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept