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;
49 const int64_t scale) {
56 const int64_t null_val) {
57 if (timeval == null_val) {
70 if (timeval == null_val) {
132 uint32_t year_seconds_past_4year_period =
134 if (seconds_past_4year_period >=
138 uint32_t seconds_past_march =
139 seconds_past_4year_period - year_seconds_past_4year_period;
143 month = month <= 11 ? month : 11;
144 if (cumulative_month_epoch_starts[month] > seconds_past_march) {
147 return (month + 2) % 12 + 1;
151 STATIC_QUAL const uint32_t cumulative_quarter_epoch_starts[4] = {
152 0, 7776000, 15638400, 23587200};
153 STATIC_QUAL const uint32_t cumulative_quarter_epoch_starts_leap_year[4] = {
154 0, 7862400, 15724800, 23673600};
158 uint32_t base_year_leap_years = (year - 1) / 4;
159 uint32_t base_year_seconds =
161 bool is_leap_year = year % 4 == 0 && year != 0;
162 const uint32_t* quarter_offsets = is_leap_year
163 ? cumulative_quarter_epoch_starts_leap_year
164 : cumulative_quarter_epoch_starts;
165 uint32_t partial_year_seconds = seconds_1900 % base_year_seconds;
166 uint32_t quarter = partial_year_seconds / (90 *
kUSecsPerDay);
167 quarter = quarter <= 3 ? quarter : 3;
168 if (quarter_offsets[quarter] > partial_year_seconds) {
177 const uint32_t year =
203 unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
204 unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
205 unsigned const moy = (5 * doy + 2) / 153;
206 return doy - (153 * moy + 2) / 5 + 1;
213 unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
214 unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
215 return doy + (doy <
MARJAN ? 1 +
JANMAR + (yoe % 4 == 0 && (yoe % 100 != 0 || yoe == 0))
219 template <
unsigned OFFSET>
223 unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
224 unsigned week_start = week_start_from_yoe<OFFSET>(yoe);
225 if (doe < week_start) {
228 return (doe + OFFSET) / 7 + 9;
230 week_start = week_start_from_yoe<OFFSET>(yoe - 1);
233 return (doe - week_start) / 7 + 1;
238 return extract_week<MONDAY>(timeval);
243 return extract_week<SUNDAY>(timeval);
248 return extract_week<SATURDAY>(timeval);
258 unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
259 unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
260 unsigned const moy = (5 * doy + 2) / 153;
261 return moy + (moy < 10 ? 3 : -9);
269 constexpr int64_t quarter[12]{1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 1, 1};
272 unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
273 unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
274 unsigned const moy = (5 * doy + 2) / 153;
286 unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
287 unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
288 return 2000 + era * 400 + yoe + (
MARJAN <= doy);
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept