15 #ifndef ABSL_TIME_INTERNAL_CCTZ_CIVIL_TIME_DETAIL_H_ 16 #define ABSL_TIME_INTERNAL_CCTZ_CIVIL_TIME_DETAIL_H_ 21 #include <type_traits> 24 #if __cpp_constexpr >= 201304 || (defined(_MSC_VER) && _MSC_VER >= 1910) 25 #define CONSTEXPR_D constexpr // data 26 #define CONSTEXPR_F constexpr // function 27 #define CONSTEXPR_M constexpr // member 29 #define CONSTEXPR_D const 30 #define CONSTEXPR_F inline 35 namespace time_internal {
58 :
y(year),
m(month),
d(day),
hh(hour),
mm(minute),
ss(second) {}
81 return y % 4 == 0 && (
y % 100 != 0 ||
y % 400 == 0);
84 return (static_cast<int>((
y + (
m > 2)) % 400) + 400) % 400;
88 return 36524 + (yi == 0 || yi > 300);
92 return 1460 + (yi == 0 || yi > 300 || (yi - 1) % 100 < 96);
99 -1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
106 y += (cd / 146097) * 400;
112 y += (
d / 146097) * 400;
186 static_cast<minute_t>(
mm),
ss);
191 if (0 <=
ss &&
ss < 60) {
193 if (0 <=
mm &&
mm < 60) {
195 if (0 <=
hh &&
hh < 24) {
197 if (1 <=
d &&
d <= 28 && 1 <=
m &&
m <= 12) {
200 return fields(
y, nm, nd, nhh, nmm, nss);
202 return n_mon(
y,
m,
d, 0, nhh, nmm, nss);
215 static_cast<second_t>(
ss));
224 return impl::n_sec(f.y, f.m, f.d, f.hh, f.mm +
n / 60, f.ss +
n % 60);
227 return impl::n_min(f.y, f.m, f.d, f.hh +
n / 60, 0, f.mm +
n % 60, f.ss);
230 return impl::n_hour(f.y, f.m, f.d +
n / 24, 0, f.hh +
n % 24, f.mm, f.ss);
236 return impl::n_mon(f.y +
n / 12, f.m +
n % 12, f.d, 0, f.hh, f.mm, f.ss);
239 return fields(f.y +
n, f.m, f.d, f.hh, f.mm, f.ss);
248 return (
v < 0) ? ((
v + 1) * f +
a) - f : ((
v - 1) * f +
a) + f;
254 const diff_t eyear = (
m <= 2) ?
y - 1 :
y;
255 const diff_t era = (eyear >= 0 ? eyear : eyear - 399) / 400;
256 const diff_t yoe = eyear - era * 400;
257 const diff_t doy = (153 * (
m + (
m > 2 ? -3 : 9)) + 2) / 5 +
d - 1;
258 const diff_t doe = yoe * 365 + yoe / 4 - yoe / 100 + doy;
259 return era * 146097 + doe - 719468;
269 const diff_t a_c4_off = y1 % 400;
270 const diff_t b_c4_off = y2 % 400;
271 diff_t c4_diff = (y1 - a_c4_off) - (y2 - b_c4_off);
273 if (c4_diff > 0 && delta < 0) {
276 }
else if (c4_diff < 0 && delta > 0) {
280 return (c4_diff / 400 * 146097) + delta;
312 return fields{f.
y, f.m, f.d, f.hh, f.mm, 0};
315 return fields{f.
y, f.m, f.d, f.hh, 0, 0};
318 return fields{f.
y, f.m, f.d, 0, 0, 0};
321 return fields{f.
y, f.m, 1, 0, 0, 0};
324 return fields{f.
y, 1, 1, 0, 0, 0};
331 template <
typename H>
335 template <
typename H>
339 template <
typename H>
343 template <
typename H>
347 template <
typename H>
351 template <
typename H>
360 template <
typename T>
376 template <
typename U,
typename S>
379 template <
typename U>
383 template <
typename U>
390 const auto max_year = (std::numeric_limits<std::int_least64_t>::max)();
391 return civil_time(max_year, 12, 31, 23, 59, 59);
394 const auto min_year = (std::numeric_limits<std::int_least64_t>::min)();
408 f_ =
step(T{}, f_,
n);
412 if (
n != (std::numeric_limits<diff_t>::min)()) {
413 f_ =
step(T{}, f_, -
n);
415 f_ =
step(T{},
step(T{}, f_, -(
n + 1)), 1);
450 template <
typename H>
458 template <
typename U>
469 template <
typename T,
typename U>
483 template <
typename T1,
typename T2>
486 return (lhs.year() < rhs.year() ||
487 (lhs.year() == rhs.year() &&
488 (lhs.month() < rhs.month() ||
489 (lhs.month() == rhs.month() &&
490 (lhs.day() < rhs.day() ||
491 (lhs.day() == rhs.day() &&
492 (lhs.hour() < rhs.hour() ||
493 (lhs.hour() == rhs.hour() &&
494 (lhs.minute() < rhs.minute() ||
495 (lhs.minute() == rhs.minute() &&
496 (lhs.second() < rhs.second())))))))))));
498 template <
typename T1,
typename T2>
503 template <
typename T1,
typename T2>
508 template <
typename T1,
typename T2>
513 template <
typename T1,
typename T2>
516 return lhs.year() == rhs.year() && lhs.month() == rhs.month() &&
517 lhs.day() == rhs.day() && lhs.hour() == rhs.hour() &&
518 lhs.minute() == rhs.minute() && lhs.second() == rhs.second();
520 template <
typename T1,
typename T2>
523 return !(lhs == rhs);
547 -1, 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4,
549 year_t wd = 2400 + (cd.year() % 400) - (cd.month() < 3);
550 wd += wd / 4 - wd / 100 + wd / 400;
551 wd += k_weekday_offsets[cd.month()] + cd.day();
552 return k_weekday_by_mon_off[wd % 7 + 6];
566 for (
int i = 0;; ++
i) {
567 if (base == k_weekdays_forw[
i]) {
568 for (
int j = i + 1;; ++j) {
569 if (wd == k_weekdays_forw[j]) {
586 for (
int i = 0;; ++
i) {
587 if (base == k_weekdays_back[
i]) {
588 for (
int j = i + 1;; ++j) {
589 if (wd == k_weekdays_back[j]) {
599 -1, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334,
602 return k_month_offsets[cd.month()] + feb29 + cd.day();
624 #endif // ABSL_TIME_INTERNAL_CCTZ_CIVIL_TIME_DETAIL_H_
CONSTEXPR_F bool operator!=(const civil_time< T1 > &lhs, const civil_time< T2 > &rhs) noexcept
CONSTEXPR_F bool operator==(const civil_time< T1 > &lhs, const civil_time< T2 > &rhs) noexcept
CONSTEXPR_F int get_yearday(const civil_day &cd) noexcept
CONSTEXPR_M civil_time operator++(int) noexcept
CONSTEXPR_M civil_time(const civil_time< U > &ct, preserves_data< U, T > *=nullptr) noexcept
CONSTEXPR_M civil_time() noexcept
CONSTEXPR_M int minute() const noexcept
CONSTEXPR_M civil_time operator--(int) noexcept
H AbslHashValueImpl(second_tag, H h, fields f)
CONSTEXPR_F diff_t day_difference(year_t y1, month_t m1, day_t d1, year_t y2, month_t m2, day_t d2) noexcept
CONSTEXPR_F bool operator>(const civil_time< T1 > &lhs, const civil_time< T2 > &rhs) noexcept
CONSTEXPR_F fields n_hour(year_t y, diff_t m, diff_t d, diff_t cd, diff_t hh, minute_t mm, second_t ss) noexcept
CONSTEXPR_M int day() const noexcept
CONSTEXPR_F fields step(second_tag, fields f, diff_t n) noexcept
friend CONSTEXPR_F diff_t operator-(civil_time lhs, civil_time rhs) noexcept
CONSTEXPR_F civil_day next_weekday(civil_day cd, weekday wd) noexcept
CONSTEXPR_F weekday get_weekday(const civil_day &cd) noexcept
CONSTEXPR_M civil_time & operator--() noexcept
CONSTEXPR_F fields align(second_tag, fields f) noexcept
CONSTEXPR_F diff_t difference(year_tag, fields f1, fields f2) noexcept
friend CONSTEXPR_F civil_time operator-(civil_time a, diff_t n) noexcept
CONSTEXPR_F bool operator>=(const civil_time< T1 > &lhs, const civil_time< T2 > &rhs) noexcept
CONSTEXPR_M civil_time & operator+=(diff_t n) noexcept
CONSTEXPR_M civil_time(year_t y, diff_t m=1, diff_t d=1, diff_t hh=0, diff_t mm=0, diff_t ss=0) noexcept
CONSTEXPR_M year_t year() const noexcept
CONSTEXPR_F fields n_mon(year_t y, diff_t m, diff_t d, diff_t cd, hour_t hh, minute_t mm, second_t ss) noexcept
CONSTEXPR_F fields n_min(year_t y, diff_t m, diff_t d, diff_t hh, diff_t ch, diff_t mm, second_t ss) noexcept
CONSTEXPR_F int year_index(year_t y, month_t m) noexcept
typename std::enable_if< std::is_base_of< U, S >::value >::type preserves_data
CONSTEXPR_F int days_per_year(year_t y, month_t m) noexcept
CONSTEXPR_F int days_per_century(year_t y, month_t m) noexcept
CONSTEXPR_M int month() const noexcept
std::int_fast8_t second_t
CONSTEXPR_F civil_day prev_weekday(civil_day cd, weekday wd) noexcept
CONSTEXPR_F diff_t operator-(civil_time< T >, civil_time< U >)=delete
friend CONSTEXPR_F civil_time operator+(diff_t n, civil_time a) noexcept
CONSTEXPR_F diff_t scale_add(diff_t v, diff_t f, diff_t a) noexcept
CONSTEXPR_F fields n_day(year_t y, month_t m, diff_t d, diff_t cd, hour_t hh, minute_t mm, second_t ss) noexcept
CONSTEXPR_F int days_per_4years(year_t y, month_t m) noexcept
H AbslHashValueImpl(year_tag, H h, fields f)
friend H AbslHashValue(H h, civil_time a)
CONSTEXPR_M int second() const noexcept
CONSTEXPR_M fields(year_t year, month_t month, day_t day, hour_t hour, minute_t minute, second_t second)
CONSTEXPR_M civil_time(const civil_time< U > &ct, preserves_data< T, U > *=nullptr) noexcept
CONSTEXPR_M civil_time & operator-=(diff_t n) noexcept
CONSTEXPR_F fields n_sec(year_t y, diff_t m, diff_t d, diff_t hh, diff_t mm, diff_t ss) noexcept
CONSTEXPR_M int hour() const noexcept
friend CONSTEXPR_F civil_time operator+(civil_time a, diff_t n) noexcept
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
CONSTEXPR_F int days_per_month(year_t y, month_t m) noexcept
CONSTEXPR_M civil_time(fields f) noexcept
CONSTEXPR_M civil_time & operator++() noexcept
std::int_fast8_t minute_t
CONSTEXPR_F diff_t ymd_ord(year_t y, month_t m, day_t d) noexcept
std::ostream & operator<<(std::ostream &os, const civil_year &y)
CONSTEXPR_F bool is_leap_year(year_t y) noexcept