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;
97 uint32_t year_seconds_past_4year_period =
99 if (seconds_past_4year_period >=
103 uint32_t seconds_past_march =
104 seconds_past_4year_period - year_seconds_past_4year_period;
108 month = month <= 11 ? month : 11;
109 if (cumulative_month_epoch_starts[month] > seconds_past_march) {
112 return (month + 2) % 12 + 1;
116 STATIC_QUAL const uint32_t cumulative_quarter_epoch_starts[4] = {
117 0, 7776000, 15638400, 23587200};
118 STATIC_QUAL const uint32_t cumulative_quarter_epoch_starts_leap_year[4] = {
119 0, 7862400, 15724800, 23673600};
123 uint32_t base_year_leap_years = (year - 1) / 4;
124 uint32_t base_year_seconds =
126 bool is_leap_year = year % 4 == 0 && year != 0;
127 const uint32_t* quarter_offsets = is_leap_year
128 ? cumulative_quarter_epoch_starts_leap_year
129 : cumulative_quarter_epoch_starts;
130 uint32_t partial_year_seconds = seconds_1900 % base_year_seconds;
131 uint32_t quarter = partial_year_seconds / (90 *
kUSecsPerDay);
132 quarter = quarter <= 3 ? quarter : 3;
133 if (quarter_offsets[quarter] > partial_year_seconds) {
142 const uint32_t year =
164 unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
165 unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
166 unsigned const moy = (5 * doy + 2) / 153;
167 return doy - (153 * moy + 2) / 5 + 1;
173 unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
174 unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
175 return doy + (doy <
MARJAN ? 1 +
JANMAR + (yoe % 4 == 0 && (yoe % 100 != 0 || yoe == 0))
179 template <
unsigned OFFSET>
183 unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
184 unsigned week_start = week_start_from_yoe<OFFSET>(yoe);
185 if (doe < week_start) {
188 return (doe + OFFSET) / 7 + 9;
190 week_start = week_start_from_yoe<OFFSET>(yoe - 1);
193 return (doe - week_start) / 7 + 1;
197 return extract_week<MONDAY>(timeval);
201 return extract_week<SUNDAY>(timeval);
205 return extract_week<SATURDAY>(timeval);
214 unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
215 unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
216 unsigned const moy = (5 * doy + 2) / 153;
217 return moy + (moy < 10 ? 3 : -9);
224 constexpr int64_t quarter[12]{1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 1, 1};
227 unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
228 unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
229 unsigned const moy = (5 * doy + 2) / 153;
240 unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
241 unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
242 return 2000 + era * 400 + yoe + (
MARJAN <= doy);
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept