32#ifndef _GLIBCXX_CHRONO
33#define _GLIBCXX_CHRONO 1
36#pragma GCC system_header
39#ifdef _GLIBCXX_NO_FREESTANDING_CHRONO
43#if __cplusplus < 201103L
47#define __glibcxx_want_chrono
48#define __glibcxx_want_chrono_udls
53#if __cpp_lib_bitops >= 201907L
56#ifdef __glibcxx_chrono_cxx20
60#if __cpp_lib_chrono >= 201803L
67#if __glibcxx_chrono_cxx20 >= 202306L
71namespace std _GLIBCXX_VISIBILITY(default)
73_GLIBCXX_BEGIN_NAMESPACE_VERSION
90#ifdef __glibcxx_chrono_cxx20
94 template<
typename _Duration>
96 using local_seconds = local_time<seconds>;
97 using local_days = local_time<days>;
104 template<
typename _Duration>
106 using utc_seconds = utc_time<seconds>;
108 template<
typename _Duration>
110 using tai_seconds = tai_time<seconds>;
112 template<
typename _Duration>
114 using gps_seconds = gps_time<seconds>;
120 template<>
inline constexpr bool is_clock_v<utc_clock> =
true;
121 template<>
inline constexpr bool is_clock_v<tai_clock> =
true;
122 template<>
inline constexpr bool is_clock_v<gps_clock> =
true;
124 struct leap_second_info
130 template<
typename _Duration>
132 get_leap_second_info(
const utc_time<_Duration>& __ut);
143 using rep = system_clock::rep;
144 using period = system_clock::period;
147 static constexpr bool is_steady =
false;
152 {
return from_sys(system_clock::now()); }
154 template<
typename _Duration>
156 static sys_time<common_type_t<_Duration, seconds>>
157 to_sys(
const utc_time<_Duration>& __t)
160 const auto __li = chrono::get_leap_second_info(__t);
161 sys_time<_CDur> __s{__t.time_since_epoch() - __li.elapsed};
162 if (__li.is_leap_second)
167 template<
typename _Duration>
169 static utc_time<common_type_t<_Duration, seconds>>
170 from_sys(
const sys_time<_Duration>& __t);
182 using rep = system_clock::rep;
183 using period = system_clock::period;
186 static constexpr bool is_steady =
false;
192 template<
typename _Duration>
194 static utc_time<common_type_t<_Duration, seconds>>
195 to_utc(
const tai_time<_Duration>& __t)
198 return utc_time<_CDur>{__t.time_since_epoch()} - 378691210s;
201 template<
typename _Duration>
203 static tai_time<common_type_t<_Duration, seconds>>
204 from_utc(
const utc_time<_Duration>& __t)
207 return tai_time<_CDur>{__t.time_since_epoch()} + 378691210s;
220 using rep = system_clock::rep;
221 using period = system_clock::period;
224 static constexpr bool is_steady =
false;
230 template<
typename _Duration>
232 static utc_time<common_type_t<_Duration, seconds>>
233 to_utc(
const gps_time<_Duration>& __t)
236 return utc_time<_CDur>{__t.time_since_epoch()} + 315964809s;
239 template<
typename _Duration>
241 static gps_time<common_type_t<_Duration, seconds>>
242 from_utc(
const utc_time<_Duration>& __t)
245 return gps_time<_CDur>{__t.time_since_epoch()} - 315964809s;
250 template<
typename _DestClock,
typename _SourceClock>
251 struct clock_time_conversion
256 template<
typename _Clock>
257 struct clock_time_conversion<_Clock, _Clock>
259 template<
typename _Duration>
260 time_point<_Clock, _Duration>
261 operator()(
const time_point<_Clock, _Duration>& __t)
const
269 template<
typename _Duration>
271 operator()(
const sys_time<_Duration>& __t)
const
278 template<
typename _Duration>
280 operator()(
const utc_time<_Duration>& __t)
const
289 template<
typename _Duration>
290 utc_time<common_type_t<_Duration, seconds>>
291 operator()(
const sys_time<_Duration>& __t)
const
292 {
return utc_clock::from_sys(__t); }
298 template<
typename _Duration>
299 sys_time<common_type_t<_Duration, seconds>>
300 operator()(
const utc_time<_Duration>& __t)
const
301 {
return utc_clock::to_sys(__t); }
304 template<
typename _Tp,
typename _Clock>
305 inline constexpr bool __is_time_point_for_v =
false;
307 template<
typename _Clock,
typename _Duration>
308 inline constexpr bool
309 __is_time_point_for_v<time_point<_Clock, _Duration>, _Clock> =
true;
313 template<
typename _SourceClock>
314 struct clock_time_conversion<
system_clock, _SourceClock>
316 template<
typename _Duration,
typename _Src = _SourceClock>
318 operator()(
const time_point<_SourceClock, _Duration>& __t)
const
319 ->
decltype(_Src::to_sys(__t))
321 using _Ret =
decltype(_SourceClock::to_sys(__t));
322 static_assert(__is_time_point_for_v<_Ret, system_clock>);
323 return _SourceClock::to_sys(__t);
327 template<
typename _DestClock>
330 template<
typename _Duration,
typename _Dest = _DestClock>
332 operator()(
const sys_time<_Duration>& __t)
const
333 ->
decltype(_Dest::from_sys(__t))
335 using _Ret =
decltype(_DestClock::from_sys(__t));
336 static_assert(__is_time_point_for_v<_Ret, _DestClock>);
337 return _DestClock::from_sys(__t);
343 template<
typename _SourceClock>
344 struct clock_time_conversion<
utc_clock, _SourceClock>
346 template<
typename _Duration,
typename _Src = _SourceClock>
348 operator()(
const time_point<_SourceClock, _Duration>& __t)
const
349 ->
decltype(_Src::to_utc(__t))
351 using _Ret =
decltype(_SourceClock::to_utc(__t));
352 static_assert(__is_time_point_for_v<_Ret, utc_clock>);
353 return _SourceClock::to_utc(__t);
357 template<
typename _DestClock>
358 struct clock_time_conversion<_DestClock,
utc_clock>
360 template<
typename _Duration,
typename _Dest = _DestClock>
362 operator()(
const utc_time<_Duration>& __t)
const
363 ->
decltype(_Dest::from_utc(__t))
365 using _Ret =
decltype(_DestClock::from_utc(__t));
366 static_assert(__is_time_point_for_v<_Ret, _DestClock>);
367 return _DestClock::from_utc(__t);
375 template<
typename _DestClock,
typename _SourceClock,
typename _Duration>
376 concept __clock_convs
377 =
requires (
const time_point<_SourceClock, _Duration>& __t) {
378 clock_time_conversion<_DestClock, _SourceClock>{}(__t);
382 template<
typename _DestClock,
typename _SourceClock,
typename _Duration>
383 concept __clock_convs_sys
384 =
requires (
const time_point<_SourceClock, _Duration>& __t) {
385 clock_time_conversion<_DestClock, system_clock>{}(
386 clock_time_conversion<system_clock, _SourceClock>{}(__t));
389 template<
typename _DestClock,
typename _SourceClock,
typename _Duration>
390 concept __clock_convs_utc
391 =
requires (
const time_point<_SourceClock, _Duration>& __t) {
392 clock_time_conversion<_DestClock, utc_clock>{}(
393 clock_time_conversion<utc_clock, _SourceClock>{}(__t));
396 template<
typename _DestClock,
typename _SourceClock,
typename _Duration>
397 concept __clock_convs_sys_utc
398 =
requires (
const time_point<_SourceClock, _Duration>& __t) {
399 clock_time_conversion<_DestClock, utc_clock>{}(
400 clock_time_conversion<utc_clock, system_clock>{}(
401 clock_time_conversion<system_clock, _SourceClock>{}(__t)));
404 template<
typename _DestClock,
typename _SourceClock,
typename _Duration>
405 concept __clock_convs_utc_sys
406 =
requires (
const time_point<_SourceClock, _Duration>& __t) {
407 clock_time_conversion<_DestClock, system_clock>{}(
408 clock_time_conversion<system_clock, utc_clock>{}(
409 clock_time_conversion<utc_clock, _SourceClock>{}(__t)));
416 template<
typename _DestClock,
typename _SourceClock,
typename _Duration>
420 requires __detail::__clock_convs<_DestClock, _SourceClock, _Duration>
422 || __detail::__clock_convs_sys<_DestClock, _SourceClock, _Duration>
423 || __detail::__clock_convs_utc<_DestClock, _SourceClock, _Duration>
424 || __detail::__clock_convs_sys_utc<_DestClock, _SourceClock, _Duration>
425 || __detail::__clock_convs_utc_sys<_DestClock, _SourceClock, _Duration>
428 constexpr bool __direct
429 = __detail::__clock_convs<_DestClock, _SourceClock, _Duration>;
430 if constexpr (__direct)
432 return clock_time_conversion<_DestClock, _SourceClock>{}(__t);
437 constexpr bool __convert_via_sys_clock
438 = __detail::__clock_convs_sys<_DestClock, _SourceClock, _Duration>;
439 constexpr bool __convert_via_utc_clock
440 = __detail::__clock_convs_utc<_DestClock, _SourceClock, _Duration>;
441 if constexpr (__convert_via_sys_clock)
443 static_assert(!__convert_via_utc_clock,
444 "clock_cast requires a unique best conversion, but "
445 "conversion is possible via system_clock and also via"
447 return clock_time_conversion<_DestClock, system_clock>{}(
448 clock_time_conversion<system_clock, _SourceClock>{}(__t));
450 else if constexpr (__convert_via_utc_clock)
452 return clock_time_conversion<_DestClock, utc_clock>{}(
453 clock_time_conversion<utc_clock, _SourceClock>{}(__t));
457 constexpr bool __convert_via_sys_and_utc_clocks
458 = __detail::__clock_convs_sys_utc<_DestClock,
462 if constexpr (__convert_via_sys_and_utc_clocks)
464 constexpr bool __convert_via_utc_and_sys_clocks
465 = __detail::__clock_convs_utc_sys<_DestClock,
468 static_assert(!__convert_via_utc_and_sys_clocks,
469 "clock_cast requires a unique best conversion, but "
470 "conversion is possible via system_clock followed by "
471 "utc_clock, and also via utc_clock followed by "
473 return clock_time_conversion<_DestClock, utc_clock>{}(
474 clock_time_conversion<utc_clock, system_clock>{}(
475 clock_time_conversion<system_clock, _SourceClock>{}(__t)));
479 return clock_time_conversion<_DestClock, system_clock>{}(
480 clock_time_conversion<system_clock, utc_clock>{}(
481 clock_time_conversion<utc_clock, _SourceClock>{}(__t)));
495 class weekday_indexed;
498 class month_day_last;
500 class month_weekday_last;
502 class year_month_day;
503 class year_month_day_last;
504 class year_month_weekday;
505 class year_month_weekday_last;
509 explicit last_spec() =
default;
511 friend constexpr month_day_last
514 friend constexpr month_day_last
518 inline constexpr last_spec last{};
523 template <
unsigned __d,
typename _Tp>
528 auto constexpr __a = _Up(-1) - _Up(255 + __d - 2);
529 auto constexpr __b = _Up(__d * (__a / __d) - 1);
531 return _Up(-1) - __b;
537 template <
unsigned __d,
typename _Tp>
539 __add_modulo(
unsigned __x, _Tp __y)
551 auto const __offset = __y >= 0 ? _Up(0) : __modulo_offset<__d, _Tp>();
552 return (__x + _Up(__y) - __offset) % __d;
556 template <
unsigned __d,
typename _Tp>
558 __sub_modulo(
unsigned __x, _Tp __y)
561 auto const __offset = __y <= 0 ? _Up(0) : __modulo_offset<__d, _Tp>();
562 return (__x - _Up(__y) - __offset) % __d;
565 inline constexpr unsigned __days_per_month[12]
566 = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
580 day(
unsigned __d) noexcept
585 operator++() noexcept
592 operator++(
int)
noexcept
600 operator--() noexcept
607 operator--(
int)
noexcept
615 operator+=(
const days& __d)
noexcept
622 operator-=(
const days& __d)
noexcept
629 operator unsigned() const noexcept
634 {
return 1 <= _M_d && _M_d <= 31; }
636 friend constexpr bool
637 operator==(
const day& __x,
const day& __y)
noexcept
638 {
return unsigned{__x} ==
unsigned{__y}; }
640 friend constexpr strong_ordering
641 operator<=>(
const day& __x,
const day& __y)
noexcept
642 {
return unsigned{__x} <=>
unsigned{__y}; }
645 operator+(
const day& __x,
const days& __y)
noexcept
646 {
return day(
unsigned{__x} + __y.count()); }
649 operator+(
const days& __x,
const day& __y)
noexcept
650 {
return __y + __x; }
653 operator-(
const day& __x,
const days& __y)
noexcept
654 {
return __x + -__y; }
656 friend constexpr days
657 operator-(
const day& __x,
const day& __y)
noexcept
658 {
return days{int(
unsigned{__x}) -
int(
unsigned{__y})}; }
660 friend constexpr month_day
661 operator/(
const month& __m,
const day& __d)
noexcept;
663 friend constexpr month_day
664 operator/(
int __m,
const day& __d)
noexcept;
666 friend constexpr month_day
667 operator/(
const day& __d,
const month& __m)
noexcept;
669 friend constexpr month_day
670 operator/(
const day& __d,
int __m)
noexcept;
672 friend constexpr year_month_day
673 operator/(
const year_month& __ym,
const day& __d)
noexcept;
687 month(
unsigned __m) noexcept
692 operator++() noexcept
699 operator++(
int)
noexcept
707 operator--() noexcept
714 operator--(
int)
noexcept
722 operator+=(
const months& __m)
noexcept
729 operator-=(
const months& __m)
noexcept
736 operator unsigned() const noexcept
741 {
return 1 <= _M_m && _M_m <= 12; }
743 friend constexpr bool
744 operator==(
const month& __x,
const month& __y)
noexcept
745 {
return unsigned{__x} ==
unsigned{__y}; }
747 friend constexpr strong_ordering
748 operator<=>(
const month& __x,
const month& __y)
noexcept
749 {
return unsigned{__x} <=>
unsigned{__y}; }
751 friend constexpr month
752 operator+(
const month& __x,
const months& __y)
noexcept
756 return month{1 + __detail::__add_modulo<12>(
757 unsigned{__x} + 11, __y.count())};
760 friend constexpr month
761 operator+(
const months& __x,
const month& __y)
noexcept
762 {
return __y + __x; }
764 friend constexpr month
765 operator-(
const month& __x,
const months& __y)
noexcept
769 return month{1 + __detail::__sub_modulo<12>(
770 unsigned{__x} + 11, __y.count())};
774 operator-(
const month& __x,
const month& __y)
noexcept
776 const auto __dm = int(
unsigned(__x)) - int(
unsigned(__y));
777 return months{__dm < 0 ? 12 + __dm : __dm};
780 friend constexpr year_month
781 operator/(
const year& __y,
const month& __m)
noexcept;
783 friend constexpr month_day
784 operator/(
const month& __m,
int __d)
noexcept;
786 friend constexpr month_day_last
787 operator/(
const month& __m, last_spec)
noexcept;
789 friend constexpr month_day_last
790 operator/(last_spec,
const month& __m)
noexcept;
792 friend constexpr month_weekday
793 operator/(
const month& __m,
const weekday_indexed& __wdi)
noexcept;
795 friend constexpr month_weekday
796 operator/(
const weekday_indexed& __wdi,
const month& __m)
noexcept;
798 friend constexpr month_weekday_last
799 operator/(
const month& __m,
const weekday_last& __wdl)
noexcept;
801 friend constexpr month_weekday_last
802 operator/(
const weekday_last& __wdl,
const month& __m)
noexcept;
805 inline constexpr month January{1};
806 inline constexpr month February{2};
807 inline constexpr month March{3};
808 inline constexpr month April{4};
809 inline constexpr month May{5};
810 inline constexpr month June{6};
811 inline constexpr month July{7};
812 inline constexpr month August{8};
813 inline constexpr month September{9};
814 inline constexpr month October{10};
815 inline constexpr month November{11};
816 inline constexpr month December{12};
829 year(
int __y) noexcept
830 : _M_y{
static_cast<short>(__y)}
833 static constexpr year
835 {
return year{-32767}; }
837 static constexpr year
839 {
return year{32767}; }
842 operator++() noexcept
849 operator++(
int)
noexcept
857 operator--() noexcept
864 operator--(
int)
noexcept
872 operator+=(
const years& __y)
noexcept
879 operator-=(
const years& __y)
noexcept
886 operator+() const noexcept
890 operator-() const noexcept
891 {
return year{-_M_y}; }
894 is_leap() const noexcept
918 return (_M_y & (_M_y % 25 == 0 ? 15 : 3)) == 0;
922 operator int() const noexcept
927 {
return min()._M_y <= _M_y && _M_y <= max()._M_y; }
929 friend constexpr bool
930 operator==(
const year& __x,
const year& __y)
noexcept
931 {
return int{__x} ==
int{__y}; }
933 friend constexpr strong_ordering
934 operator<=>(
const year& __x,
const year& __y)
noexcept
935 {
return int{__x} <=>
int{__y}; }
937 friend constexpr year
938 operator+(
const year& __x,
const years& __y)
noexcept
939 {
return year{
int{__x} +
static_cast<int>(__y.count())}; }
941 friend constexpr year
942 operator+(
const years& __x,
const year& __y)
noexcept
943 {
return __y + __x; }
945 friend constexpr year
946 operator-(
const year& __x,
const years& __y)
noexcept
947 {
return __x + -__y; }
949 friend constexpr years
950 operator-(
const year& __x,
const year& __y)
noexcept
951 {
return years{
int{__x} -
int{__y}}; }
953 friend constexpr year_month
954 operator/(
const year& __y,
int __m)
noexcept;
956 friend constexpr year_month_day
957 operator/(
const year& __y,
const month_day& __md)
noexcept;
959 friend constexpr year_month_day
960 operator/(
const month_day& __md,
const year& __y)
noexcept;
962 friend constexpr year_month_day_last
963 operator/(
const year& __y,
const month_day_last& __mdl)
noexcept;
965 friend constexpr year_month_day_last
966 operator/(
const month_day_last& __mdl,
const year& __y)
noexcept;
968 friend constexpr year_month_weekday
969 operator/(
const year& __y,
const month_weekday& __mwd)
noexcept;
971 friend constexpr year_month_weekday
972 operator/(
const month_weekday& __mwd,
const year& __y)
noexcept;
974 friend constexpr year_month_weekday_last
975 operator/(
const year& __y,
const month_weekday_last& __mwdl)
noexcept;
977 friend constexpr year_month_weekday_last
978 operator/(
const month_weekday_last& __mwdl,
const year& __y)
noexcept;
988 static constexpr weekday
989 _S_from_days(
const days& __d)
991 return weekday{__detail::__add_modulo<7>(4, __d.count())};
998 weekday(
unsigned __wd) noexcept
999 : _M_wd(__wd == 7 ? 0 : __wd)
1003 weekday(
const sys_days& __dp) noexcept
1004 : weekday{_S_from_days(__dp.time_since_epoch())}
1008 weekday(
const local_days& __dp) noexcept
1009 : weekday{sys_days{__dp.time_since_epoch()}}
1013 operator++() noexcept
1020 operator++(
int)
noexcept
1028 operator--() noexcept
1035 operator--(
int)
noexcept
1043 operator+=(
const days& __d)
noexcept
1045 *
this = *
this + __d;
1050 operator-=(
const days& __d)
noexcept
1052 *
this = *
this - __d;
1057 c_encoding() const noexcept
1061 iso_encoding() const noexcept
1062 {
return _M_wd == 0u ? 7u : _M_wd; }
1066 {
return _M_wd <= 6; }
1068 constexpr weekday_indexed
1069 operator[](
unsigned __index)
const noexcept;
1071 constexpr weekday_last
1072 operator[](last_spec)
const noexcept;
1074 friend constexpr bool
1075 operator==(
const weekday& __x,
const weekday& __y)
noexcept
1076 {
return __x._M_wd == __y._M_wd; }
1078 friend constexpr weekday
1079 operator+(
const weekday& __x,
const days& __y)
noexcept
1081 return weekday{__detail::__add_modulo<7>(__x._M_wd, __y.count())};
1084 friend constexpr weekday
1085 operator+(
const days& __x,
const weekday& __y)
noexcept
1086 {
return __y + __x; }
1088 friend constexpr weekday
1089 operator-(
const weekday& __x,
const days& __y)
noexcept
1091 return weekday{__detail::__sub_modulo<7>(__x._M_wd, __y.count())};
1094 friend constexpr days
1095 operator-(
const weekday& __x,
const weekday& __y)
noexcept
1097 const auto __n = __x.c_encoding() - __y.c_encoding();
1098 return static_cast<int>(__n) >= 0 ?
days{__n} :
days{__n + 7};
1102 inline constexpr weekday Sunday{0};
1103 inline constexpr weekday Monday{1};
1104 inline constexpr weekday Tuesday{2};
1105 inline constexpr weekday Wednesday{3};
1106 inline constexpr weekday Thursday{4};
1107 inline constexpr weekday Friday{5};
1108 inline constexpr weekday Saturday{6};
1112 class weekday_indexed
1115 chrono::weekday _M_wd;
1116 unsigned char _M_index;
1119 weekday_indexed() =
default;
1122 weekday_indexed(
const chrono::weekday& __wd,
unsigned __index) noexcept
1123 : _M_wd(__wd), _M_index(__index)
1126 constexpr chrono::weekday
1127 weekday() const noexcept
1131 index() const noexcept
1132 {
return _M_index; };
1136 {
return _M_wd.ok() && 1 <= _M_index && _M_index <= 5; }
1138 friend constexpr bool
1139 operator==(
const weekday_indexed& __x,
const weekday_indexed& __y)
noexcept
1140 {
return __x.weekday() == __y.weekday() && __x.index() == __y.index(); }
1142 friend constexpr month_weekday
1143 operator/(
const month& __m,
const weekday_indexed& __wdi)
noexcept;
1145 friend constexpr month_weekday
1146 operator/(
int __m,
const weekday_indexed& __wdi)
noexcept;
1148 friend constexpr month_weekday
1149 operator/(
const weekday_indexed& __wdi,
const month& __m)
noexcept;
1151 friend constexpr month_weekday
1152 operator/(
const weekday_indexed& __wdi,
int __m)
noexcept;
1154 friend constexpr year_month_weekday
1155 operator/(
const year_month& __ym,
const weekday_indexed& __wdi)
noexcept;
1158 constexpr weekday_indexed
1159 weekday::operator[](
unsigned __index)
const noexcept
1160 {
return {*
this, __index}; }
1167 chrono::weekday _M_wd;
1171 weekday_last(
const chrono::weekday& __wd) noexcept
1175 constexpr chrono::weekday
1176 weekday() const noexcept
1181 {
return _M_wd.ok(); }
1183 friend constexpr bool
1184 operator==(
const weekday_last& __x,
const weekday_last& __y)
noexcept
1185 {
return __x.weekday() == __y.weekday(); }
1187 friend constexpr month_weekday_last
1188 operator/(
int __m,
const weekday_last& __wdl)
noexcept;
1190 friend constexpr month_weekday_last
1191 operator/(
const weekday_last& __wdl,
int __m)
noexcept;
1193 friend constexpr year_month_weekday_last
1194 operator/(
const year_month& __ym,
const weekday_last& __wdl)
noexcept;
1197 constexpr weekday_last
1198 weekday::operator[](last_spec)
const noexcept
1199 {
return weekday_last{*
this}; }
1210 month_day() =
default;
1213 month_day(
const chrono::month& __m,
const chrono::day& __d) noexcept
1214 : _M_m{__m}, _M_d{__d}
1217 constexpr chrono::month
1218 month() const noexcept
1221 constexpr chrono::day
1222 day() const noexcept
1229 && 1u <= unsigned(_M_d)
1230 && unsigned(_M_d) <= __detail::__days_per_month[unsigned(_M_m) - 1];
1233 friend constexpr bool
1234 operator==(
const month_day& __x,
const month_day& __y)
noexcept
1235 {
return __x.month() == __y.month() && __x.day() == __y.day(); }
1237 friend constexpr strong_ordering
1238 operator<=>(
const month_day& __x,
const month_day& __y)
noexcept
1241 friend constexpr month_day
1242 operator/(
const chrono::month& __m,
const chrono::day& __d)
noexcept
1243 {
return {__m, __d}; }
1245 friend constexpr month_day
1246 operator/(
const chrono::month& __m,
int __d)
noexcept
1247 {
return {__m, chrono::day(
unsigned(__d))}; }
1249 friend constexpr month_day
1250 operator/(
int __m,
const chrono::day& __d)
noexcept
1251 {
return {chrono::month(
unsigned(__m)), __d}; }
1253 friend constexpr month_day
1254 operator/(
const chrono::day& __d,
const chrono::month& __m)
noexcept
1255 {
return {__m, __d}; }
1257 friend constexpr month_day
1258 operator/(
const chrono::day& __d,
int __m)
noexcept
1259 {
return {chrono::month(
unsigned(__m)), __d}; }
1261 friend constexpr year_month_day
1262 operator/(
int __y,
const month_day& __md)
noexcept;
1264 friend constexpr year_month_day
1265 operator/(
const month_day& __md,
int __y)
noexcept;
1270 class month_day_last
1277 month_day_last(
const chrono::month& __m) noexcept
1281 constexpr chrono::month
1282 month() const noexcept
1287 {
return _M_m.ok(); }
1289 friend constexpr bool
1290 operator==(
const month_day_last& __x,
const month_day_last& __y)
noexcept
1291 {
return __x.month() == __y.month(); }
1293 friend constexpr strong_ordering
1294 operator<=>(
const month_day_last& __x,
const month_day_last& __y)
noexcept
1297 friend constexpr month_day_last
1298 operator/(
const chrono::month& __m, last_spec)
noexcept
1299 {
return month_day_last{__m}; }
1301 friend constexpr month_day_last
1302 operator/(
int __m, last_spec)
noexcept
1303 {
return chrono::month(
unsigned(__m)) / last; }
1305 friend constexpr month_day_last
1306 operator/(last_spec,
const chrono::month& __m)
noexcept
1307 {
return __m / last; }
1309 friend constexpr month_day_last
1310 operator/(last_spec,
int __m)
noexcept
1311 {
return __m / last; }
1313 friend constexpr year_month_day_last
1314 operator/(
int __y,
const month_day_last& __mdl)
noexcept;
1316 friend constexpr year_month_day_last
1317 operator/(
const month_day_last& __mdl,
int __y)
noexcept;
1326 chrono::weekday_indexed _M_wdi;
1330 month_weekday(
const chrono::month& __m,
1331 const chrono::weekday_indexed& __wdi) noexcept
1332 : _M_m{__m}, _M_wdi{__wdi}
1335 constexpr chrono::month
1336 month() const noexcept
1339 constexpr chrono::weekday_indexed
1340 weekday_indexed() const noexcept
1345 {
return _M_m.ok() && _M_wdi.ok(); }
1347 friend constexpr bool
1348 operator==(
const month_weekday& __x,
const month_weekday& __y)
noexcept
1350 return __x.month() == __y.month()
1351 && __x.weekday_indexed() == __y.weekday_indexed();
1354 friend constexpr month_weekday
1355 operator/(
const chrono::month& __m,
1356 const chrono::weekday_indexed& __wdi)
noexcept
1357 {
return {__m, __wdi}; }
1359 friend constexpr month_weekday
1360 operator/(
int __m,
const chrono::weekday_indexed& __wdi)
noexcept
1361 {
return chrono::month(
unsigned(__m)) / __wdi; }
1363 friend constexpr month_weekday
1364 operator/(
const chrono::weekday_indexed& __wdi,
1365 const chrono::month& __m)
noexcept
1366 {
return __m / __wdi; }
1368 friend constexpr month_weekday
1369 operator/(
const chrono::weekday_indexed& __wdi,
int __m)
noexcept
1370 {
return __m / __wdi; }
1372 friend constexpr year_month_weekday
1373 operator/(
int __y,
const month_weekday& __mwd)
noexcept;
1375 friend constexpr year_month_weekday
1376 operator/(
const month_weekday& __mwd,
int __y)
noexcept;
1381 class month_weekday_last
1385 chrono::weekday_last _M_wdl;
1389 month_weekday_last(
const chrono::month& __m,
1390 const chrono::weekday_last& __wdl) noexcept
1391 :_M_m{__m}, _M_wdl{__wdl}
1394 constexpr chrono::month
1395 month() const noexcept
1398 constexpr chrono::weekday_last
1399 weekday_last() const noexcept
1404 {
return _M_m.ok() && _M_wdl.ok(); }
1406 friend constexpr bool
1407 operator==(
const month_weekday_last& __x,
1408 const month_weekday_last& __y)
noexcept
1410 return __x.month() == __y.month()
1411 && __x.weekday_last() == __y.weekday_last();
1414 friend constexpr month_weekday_last
1415 operator/(
const chrono::month& __m,
1416 const chrono::weekday_last& __wdl)
noexcept
1417 {
return {__m, __wdl}; }
1419 friend constexpr month_weekday_last
1420 operator/(
int __m,
const chrono::weekday_last& __wdl)
noexcept
1421 {
return chrono::month(
unsigned(__m)) / __wdl; }
1423 friend constexpr month_weekday_last
1424 operator/(
const chrono::weekday_last& __wdl,
1425 const chrono::month& __m)
noexcept
1426 {
return __m / __wdl; }
1428 friend constexpr month_weekday_last
1429 operator/(
const chrono::weekday_last& __wdl,
int __m)
noexcept
1430 {
return chrono::month(
unsigned(__m)) / __wdl; }
1432 friend constexpr year_month_weekday_last
1433 operator/(
int __y,
const month_weekday_last& __mwdl)
noexcept;
1435 friend constexpr year_month_weekday_last
1436 operator/(
const month_weekday_last& __mwdl,
int __y)
noexcept;
1455 using __months_years_conversion_disambiguator = void;
1465 year_month() =
default;
1468 year_month(
const chrono::year& __y,
const chrono::month& __m) noexcept
1469 : _M_y{__y}, _M_m{__m}
1472 constexpr chrono::year
1473 year() const noexcept
1476 constexpr chrono::month
1477 month() const noexcept
1480 template<
typename = __detail::__months_years_conversion_disambiguator>
1481 constexpr year_month&
1482 operator+=(
const months& __dm)
noexcept
1484 *
this = *
this + __dm;
1488 template<
typename = __detail::__months_years_conversion_disambiguator>
1489 constexpr year_month&
1490 operator-=(
const months& __dm)
noexcept
1492 *
this = *
this - __dm;
1496 constexpr year_month&
1497 operator+=(
const years& __dy)
noexcept
1499 *
this = *
this + __dy;
1503 constexpr year_month&
1504 operator-=(
const years& __dy)
noexcept
1506 *
this = *
this - __dy;
1512 {
return _M_y.ok() && _M_m.ok(); }
1514 friend constexpr bool
1515 operator==(
const year_month& __x,
const year_month& __y)
noexcept
1516 {
return __x.year() == __y.year() && __x.month() == __y.month(); }
1518 friend constexpr strong_ordering
1519 operator<=>(
const year_month& __x,
const year_month& __y)
noexcept
1522 template<
typename = __detail::__months_years_conversion_disambiguator>
1523 friend constexpr year_month
1524 operator+(
const year_month& __ym,
const months& __dm)
noexcept
1527 auto __m = __ym.month() + __dm;
1528 auto __i = int(
unsigned(__ym.month())) - 1 + __dm.count();
1530 ? __ym.year() +
years{(__i - 11) / 12}
1531 : __ym.year() +
years{__i / 12});
1535 template<
typename = __detail::__months_years_conversion_disambiguator>
1536 friend constexpr year_month
1537 operator+(
const months& __dm,
const year_month& __ym)
noexcept
1538 {
return __ym + __dm; }
1540 template<
typename = __detail::__months_years_conversion_disambiguator>
1541 friend constexpr year_month
1542 operator-(
const year_month& __ym,
const months& __dm)
noexcept
1543 {
return __ym + -__dm; }
1546 operator-(
const year_month& __x,
const year_month& __y)
noexcept
1548 return (__x.year() - __y.year()
1549 +
months{static_cast<int>(unsigned{__x.month()})
1550 -
static_cast<int>(
unsigned{__y.month()})});
1553 friend constexpr year_month
1555 {
return (__ym.year() + __dy) / __ym.month(); }
1557 friend constexpr year_month
1559 {
return __ym + __dy; }
1561 friend constexpr year_month
1563 {
return __ym + -__dy; }
1565 friend constexpr year_month
1566 operator/(
const chrono::year& __y,
const chrono::month& __m)
noexcept
1567 {
return {__y, __m}; }
1569 friend constexpr year_month
1570 operator/(
const chrono::year& __y,
int __m)
noexcept
1571 {
return {__y, chrono::month(
unsigned(__m))}; }
1573 friend constexpr year_month_day
1574 operator/(
const year_month& __ym,
int __d)
noexcept;
1576 friend constexpr year_month_day_last
1577 operator/(
const year_month& __ym, last_spec)
noexcept;
1582 class year_month_day
1589 static constexpr year_month_day _S_from_days(
const days& __dp)
noexcept;
1591 constexpr days _M_days_since_epoch() const noexcept;
1594 year_month_day() = default;
1597 year_month_day(const chrono::year& __y, const chrono::month& __m,
1598 const chrono::day& __d) noexcept
1599 : _M_y{__y}, _M_m{__m}, _M_d{__d}
1603 year_month_day(
const year_month_day_last& __ymdl)
noexcept;
1606 year_month_day(
const sys_days& __dp) noexcept
1607 : year_month_day(_S_from_days(__dp.time_since_epoch()))
1611 year_month_day(
const local_days& __dp) noexcept
1612 : year_month_day(sys_days{__dp.time_since_epoch()})
1615 template<
typename = __detail::__months_years_conversion_disambiguator>
1616 constexpr year_month_day&
1617 operator+=(
const months& __m)
noexcept
1619 *
this = *
this + __m;
1623 template<
typename = __detail::__months_years_conversion_disambiguator>
1624 constexpr year_month_day&
1625 operator-=(
const months& __m)
noexcept
1627 *
this = *
this - __m;
1631 constexpr year_month_day&
1632 operator+=(
const years& __y)
noexcept
1634 *
this = *
this + __y;
1638 constexpr year_month_day&
1639 operator-=(
const years& __y)
noexcept
1641 *
this = *
this - __y;
1645 constexpr chrono::year
1646 year() const noexcept
1649 constexpr chrono::month
1650 month() const noexcept
1653 constexpr chrono::day
1654 day() const noexcept
1658 operator sys_days() const noexcept
1659 {
return sys_days{_M_days_since_epoch()}; }
1662 operator local_days() const noexcept
1663 {
return local_days{sys_days{*
this}.time_since_epoch()}; }
1665 constexpr bool ok() const noexcept;
1667 friend constexpr
bool
1668 operator==(const year_month_day& __x, const year_month_day& __y) noexcept
1670 return __x.year() == __y.year()
1671 && __x.month() == __y.month()
1672 && __x.day() == __y.day();
1675 friend constexpr strong_ordering
1676 operator<=>(
const year_month_day& __x,
const year_month_day& __y)
noexcept
1679 template<
typename = __detail::__months_years_conversion_disambiguator>
1680 friend constexpr year_month_day
1681 operator+(
const year_month_day& __ymd,
const months& __dm)
noexcept
1682 {
return (__ymd.year() / __ymd.month() + __dm) / __ymd.day(); }
1684 template<
typename = __detail::__months_years_conversion_disambiguator>
1685 friend constexpr year_month_day
1686 operator+(
const months& __dm,
const year_month_day& __ymd)
noexcept
1687 {
return __ymd + __dm; }
1689 friend constexpr year_month_day
1690 operator+(
const year_month_day& __ymd,
const years& __dy)
noexcept
1691 {
return (__ymd.year() + __dy) / __ymd.month() / __ymd.day(); }
1693 friend constexpr year_month_day
1694 operator+(
const years& __dy,
const year_month_day& __ymd)
noexcept
1695 {
return __ymd + __dy; }
1697 template<
typename = __detail::__months_years_conversion_disambiguator>
1698 friend constexpr year_month_day
1699 operator-(
const year_month_day& __ymd,
const months& __dm)
noexcept
1700 {
return __ymd + -__dm; }
1702 friend constexpr year_month_day
1703 operator-(
const year_month_day& __ymd,
const years& __dy)
noexcept
1704 {
return __ymd + -__dy; }
1706 friend constexpr year_month_day
1707 operator/(
const year_month& __ym,
const chrono::day& __d)
noexcept
1708 {
return {__ym.year(), __ym.month(), __d}; }
1710 friend constexpr year_month_day
1711 operator/(
const year_month& __ym,
int __d)
noexcept
1712 {
return __ym / chrono::day{unsigned(__d)}; }
1714 friend constexpr year_month_day
1715 operator/(
const chrono::year& __y,
const month_day& __md)
noexcept
1716 {
return __y / __md.month() / __md.day(); }
1718 friend constexpr year_month_day
1719 operator/(
int __y,
const month_day& __md)
noexcept
1720 {
return chrono::year{__y} / __md; }
1722 friend constexpr year_month_day
1723 operator/(
const month_day& __md,
const chrono::year& __y)
noexcept
1724 {
return __y / __md; }
1726 friend constexpr year_month_day
1727 operator/(
const month_day& __md,
int __y)
noexcept
1728 {
return chrono::year(__y) / __md; }
1735 constexpr year_month_day
1736 year_month_day::_S_from_days(
const days& __dp)
noexcept
1738 constexpr auto __z2 =
static_cast<uint32_t
>(-1468000);
1739 constexpr auto __r2_e3 =
static_cast<uint32_t
>(536895458);
1741 const auto __r0 =
static_cast<uint32_t
>(__dp.count()) + __r2_e3;
1743 const auto __n1 = 4 * __r0 + 3;
1744 const auto __q1 = __n1 / 146097;
1745 const auto __r1 = __n1 % 146097 / 4;
1747 constexpr auto __p32 =
static_cast<uint64_t
>(1) << 32;
1748 const auto __n2 = 4 * __r1 + 3;
1749 const auto __u2 =
static_cast<uint64_t
>(2939745) * __n2;
1750 const auto __q2 =
static_cast<uint32_t
>(__u2 / __p32);
1751 const auto __r2 =
static_cast<uint32_t
>(__u2 % __p32) / 2939745 / 4;
1753 constexpr auto __p16 =
static_cast<uint32_t
>(1) << 16;
1754 const auto __n3 = 2141 * __r2 + 197913;
1755 const auto __q3 = __n3 / __p16;
1756 const auto __r3 = __n3 % __p16 / 2141;
1758 const auto __y0 = 100 * __q1 + __q2;
1759 const auto __m0 = __q3;
1760 const auto __d0 = __r3;
1762 const auto __j = __r2 >= 306;
1763 const auto __y1 = __y0 + __j;
1764 const auto __m1 = __j ? __m0 - 12 : __m0;
1765 const auto __d1 = __d0 + 1;
1767 return year_month_day{chrono::year{
static_cast<int>(__y1 + __z2)},
1768 chrono::month{__m1}, chrono::day{__d1}};
1776 year_month_day::_M_days_since_epoch() const noexcept
1778 auto constexpr __z2 =
static_cast<uint32_t
>(-1468000);
1779 auto constexpr __r2_e3 =
static_cast<uint32_t
>(536895458);
1781 const auto __y1 =
static_cast<uint32_t
>(
static_cast<int>(_M_y)) - __z2;
1782 const auto __m1 =
static_cast<uint32_t
>(
static_cast<unsigned>(_M_m));
1783 const auto __d1 =
static_cast<uint32_t
>(
static_cast<unsigned>(_M_d));
1785 const auto __j =
static_cast<uint32_t
>(__m1 < 3);
1786 const auto __y0 = __y1 - __j;
1787 const auto __m0 = __j ? __m1 + 12 : __m1;
1788 const auto __d0 = __d1 - 1;
1790 const auto __q1 = __y0 / 100;
1791 const auto __yc = 1461 * __y0 / 4 - __q1 + __q1 / 4;
1792 const auto __mc = (979 *__m0 - 2919) / 32;
1793 const auto __dc = __d0;
1795 return days{
static_cast<int32_t
>(__yc + __mc + __dc - __r2_e3)};
1800 class year_month_day_last
1804 chrono::month_day_last _M_mdl;
1808 year_month_day_last(
const chrono::year& __y,
1809 const chrono::month_day_last& __mdl) noexcept
1810 : _M_y{__y}, _M_mdl{__mdl}
1813 template<
typename = __detail::__months_years_conversion_disambiguator>
1814 constexpr year_month_day_last&
1815 operator+=(
const months& __m)
noexcept
1817 *
this = *
this + __m;
1821 template<
typename = __detail::__months_years_conversion_disambiguator>
1822 constexpr year_month_day_last&
1823 operator-=(
const months& __m)
noexcept
1825 *
this = *
this - __m;
1829 constexpr year_month_day_last&
1830 operator+=(
const years& __y)
noexcept
1832 *
this = *
this + __y;
1836 constexpr year_month_day_last&
1837 operator-=(
const years& __y)
noexcept
1839 *
this = *
this - __y;
1843 constexpr chrono::year
1844 year() const noexcept
1847 constexpr chrono::month
1848 month() const noexcept
1849 {
return _M_mdl.month(); }
1851 constexpr chrono::month_day_last
1852 month_day_last() const noexcept
1856 constexpr chrono::day
1857 day() const noexcept
1859 const auto __m =
static_cast<unsigned>(month());
1879 return chrono::day{__m != 2 ? (__m ^ (__m >> 3)) | 30
1880 : _M_y.is_leap() ? 29 : 28};
1884 operator sys_days() const noexcept
1885 {
return sys_days{year() / month() / day()}; }
1888 operator local_days() const noexcept
1889 {
return local_days{sys_days{*
this}.time_since_epoch()}; }
1893 {
return _M_y.ok() && _M_mdl.ok(); }
1895 friend constexpr bool
1896 operator==(
const year_month_day_last& __x,
1897 const year_month_day_last& __y)
noexcept
1899 return __x.year() == __y.year()
1900 && __x.month_day_last() == __y.month_day_last();
1903 friend constexpr strong_ordering
1904 operator<=>(
const year_month_day_last& __x,
1905 const year_month_day_last& __y)
noexcept
1908 template<
typename = __detail::__months_years_conversion_disambiguator>
1909 friend constexpr year_month_day_last
1910 operator+(
const year_month_day_last& __ymdl,
1911 const months& __dm)
noexcept
1912 {
return (__ymdl.year() / __ymdl.month() + __dm) / last; }
1914 template<
typename = __detail::__months_years_conversion_disambiguator>
1915 friend constexpr year_month_day_last
1917 const year_month_day_last& __ymdl)
noexcept
1918 {
return __ymdl + __dm; }
1920 template<
typename = __detail::__months_years_conversion_disambiguator>
1921 friend constexpr year_month_day_last
1922 operator-(
const year_month_day_last& __ymdl,
1923 const months& __dm)
noexcept
1924 {
return __ymdl + -__dm; }
1926 friend constexpr year_month_day_last
1927 operator+(
const year_month_day_last& __ymdl,
1928 const years& __dy)
noexcept
1929 {
return {__ymdl.year() + __dy, __ymdl.month_day_last()}; }
1931 friend constexpr year_month_day_last
1933 const year_month_day_last& __ymdl)
noexcept
1934 {
return __ymdl + __dy; }
1936 friend constexpr year_month_day_last
1937 operator-(
const year_month_day_last& __ymdl,
1938 const years& __dy)
noexcept
1939 {
return __ymdl + -__dy; }
1941 friend constexpr year_month_day_last
1942 operator/(
const year_month& __ym, last_spec)
noexcept
1943 {
return {__ym.year(), chrono::month_day_last{__ym.month()}}; }
1945 friend constexpr year_month_day_last
1947 const chrono::month_day_last& __mdl)
noexcept
1948 {
return {__y, __mdl}; }
1950 friend constexpr year_month_day_last
1951 operator/(
int __y,
const chrono::month_day_last& __mdl)
noexcept
1952 {
return chrono::year(__y) / __mdl; }
1954 friend constexpr year_month_day_last
1955 operator/(
const chrono::month_day_last& __mdl,
1956 const chrono::year& __y)
noexcept
1957 {
return __y / __mdl; }
1959 friend constexpr year_month_day_last
1960 operator/(
const chrono::month_day_last& __mdl,
int __y)
noexcept
1961 {
return chrono::year(__y) / __mdl; }
1966 year_month_day::year_month_day(
const year_month_day_last& __ymdl) noexcept
1967 : _M_y{__ymdl.year()}, _M_m{__ymdl.month()}, _M_d{__ymdl.day()}
1971 year_month_day::ok() const noexcept
1973 if (!_M_y.ok() || !_M_m.ok())
1975 return chrono::day{1} <= _M_d && _M_d <= (_M_y / _M_m / last).day();
1980 class year_month_weekday
1985 chrono::weekday_indexed _M_wdi;
1987 static constexpr year_month_weekday
1988 _S_from_sys_days(
const sys_days& __dp)
1990 year_month_day __ymd{__dp};
1991 chrono::weekday __wd{__dp};
1992 auto __index = __wd[(
unsigned{__ymd.day()} - 1) / 7 + 1];
1993 return {__ymd.year(), __ymd.month(), __index};
1997 year_month_weekday() =
default;
2000 year_month_weekday(
const chrono::year& __y,
const chrono::month& __m,
2001 const chrono::weekday_indexed& __wdi) noexcept
2002 : _M_y{__y}, _M_m{__m}, _M_wdi{__wdi}
2006 year_month_weekday(
const sys_days& __dp) noexcept
2007 : year_month_weekday{_S_from_sys_days(__dp)}
2011 year_month_weekday(
const local_days& __dp) noexcept
2012 : year_month_weekday{sys_days{__dp.time_since_epoch()}}
2015 template<
typename = __detail::__months_years_conversion_disambiguator>
2016 constexpr year_month_weekday&
2017 operator+=(
const months& __m)
noexcept
2019 *
this = *
this + __m;
2023 template<
typename = __detail::__months_years_conversion_disambiguator>
2024 constexpr year_month_weekday&
2025 operator-=(
const months& __m)
noexcept
2027 *
this = *
this - __m;
2031 constexpr year_month_weekday&
2032 operator+=(
const years& __y)
noexcept
2034 *
this = *
this + __y;
2038 constexpr year_month_weekday&
2039 operator-=(
const years& __y)
noexcept
2041 *
this = *
this - __y;
2045 constexpr chrono::year
2046 year() const noexcept
2049 constexpr chrono::month
2050 month() const noexcept
2053 constexpr chrono::weekday
2054 weekday() const noexcept
2055 {
return _M_wdi.weekday(); }
2058 index() const noexcept
2059 {
return _M_wdi.index(); }
2061 constexpr chrono::weekday_indexed
2062 weekday_indexed() const noexcept
2066 operator sys_days() const noexcept
2068 auto __d = sys_days{year() / month() / 1};
2069 return __d + (weekday() - chrono::weekday(__d)
2070 +
days{(
static_cast<int>(index())-1)*7});
2074 operator local_days() const noexcept
2075 {
return local_days{sys_days{*
this}.time_since_epoch()}; }
2080 if (!_M_y.ok() || !_M_m.ok() || !_M_wdi.ok())
2082 if (_M_wdi.index() <= 4)
2084 days __d = (_M_wdi.weekday()
2085 - chrono::weekday{sys_days{_M_y / _M_m / 1}}
2086 +
days((_M_wdi.index()-1)*7 + 1));
2087 __glibcxx_assert(__d.count() >= 1);
2088 return (
unsigned)__d.count() <= (unsigned)(_M_y / _M_m / last).day();
2091 friend constexpr bool
2092 operator==(
const year_month_weekday& __x,
2093 const year_month_weekday& __y)
noexcept
2095 return __x.year() == __y.year()
2096 && __x.month() == __y.month()
2097 && __x.weekday_indexed() == __y.weekday_indexed();
2100 template<
typename = __detail::__months_years_conversion_disambiguator>
2101 friend constexpr year_month_weekday
2102 operator+(
const year_month_weekday& __ymwd,
const months& __dm)
noexcept
2104 return ((__ymwd.year() / __ymwd.month() + __dm)
2105 / __ymwd.weekday_indexed());
2108 template<
typename = __detail::__months_years_conversion_disambiguator>
2109 friend constexpr year_month_weekday
2110 operator+(
const months& __dm,
const year_month_weekday& __ymwd)
noexcept
2111 {
return __ymwd + __dm; }
2113 friend constexpr year_month_weekday
2114 operator+(
const year_month_weekday& __ymwd,
const years& __dy)
noexcept
2115 {
return {__ymwd.year() + __dy, __ymwd.month(), __ymwd.weekday_indexed()}; }
2117 friend constexpr year_month_weekday
2118 operator+(
const years& __dy,
const year_month_weekday& __ymwd)
noexcept
2119 {
return __ymwd + __dy; }
2121 template<
typename = __detail::__months_years_conversion_disambiguator>
2122 friend constexpr year_month_weekday
2123 operator-(
const year_month_weekday& __ymwd,
const months& __dm)
noexcept
2124 {
return __ymwd + -__dm; }
2126 friend constexpr year_month_weekday
2127 operator-(
const year_month_weekday& __ymwd,
const years& __dy)
noexcept
2128 {
return __ymwd + -__dy; }
2130 friend constexpr year_month_weekday
2132 const chrono::weekday_indexed& __wdi)
noexcept
2133 {
return {__ym.year(), __ym.month(), __wdi}; }
2135 friend constexpr year_month_weekday
2136 operator/(
const chrono::year& __y,
const month_weekday& __mwd)
noexcept
2137 {
return {__y, __mwd.month(), __mwd.weekday_indexed()}; }
2139 friend constexpr year_month_weekday
2140 operator/(
int __y,
const month_weekday& __mwd)
noexcept
2141 {
return chrono::year(__y) / __mwd; }
2143 friend constexpr year_month_weekday
2144 operator/(
const month_weekday& __mwd,
const chrono::year& __y)
noexcept
2145 {
return __y / __mwd; }
2147 friend constexpr year_month_weekday
2148 operator/(
const month_weekday& __mwd,
int __y)
noexcept
2149 {
return chrono::year(__y) / __mwd; }
2154 class year_month_weekday_last
2159 chrono::weekday_last _M_wdl;
2163 year_month_weekday_last(
const chrono::year& __y,
const chrono::month& __m,
2164 const chrono::weekday_last& __wdl) noexcept
2165 : _M_y{__y}, _M_m{__m}, _M_wdl{__wdl}
2168 template<
typename = __detail::__months_years_conversion_disambiguator>
2169 constexpr year_month_weekday_last&
2170 operator+=(
const months& __m)
noexcept
2172 *
this = *
this + __m;
2176 template<
typename = __detail::__months_years_conversion_disambiguator>
2177 constexpr year_month_weekday_last&
2178 operator-=(
const months& __m)
noexcept
2180 *
this = *
this - __m;
2184 constexpr year_month_weekday_last&
2185 operator+=(
const years& __y)
noexcept
2187 *
this = *
this + __y;
2191 constexpr year_month_weekday_last&
2192 operator-=(
const years& __y)
noexcept
2194 *
this = *
this - __y;
2198 constexpr chrono::year
2199 year() const noexcept
2202 constexpr chrono::month
2203 month() const noexcept
2206 constexpr chrono::weekday
2207 weekday() const noexcept
2208 {
return _M_wdl.weekday(); }
2210 constexpr chrono::weekday_last
2211 weekday_last() const noexcept
2215 operator sys_days() const noexcept
2217 const auto __d = sys_days{_M_y / _M_m / last};
2218 return sys_days{(__d - (chrono::weekday{__d}
2219 - _M_wdl.weekday())).time_since_epoch()};
2223 operator local_days() const noexcept
2224 {
return local_days{sys_days{*
this}.time_since_epoch()}; }
2228 {
return _M_y.ok() && _M_m.ok() && _M_wdl.ok(); }
2230 friend constexpr bool
2231 operator==(
const year_month_weekday_last& __x,
2232 const year_month_weekday_last& __y)
noexcept
2234 return __x.year() == __y.year()
2235 && __x.month() == __y.month()
2236 && __x.weekday_last() == __y.weekday_last();
2239 template<
typename = __detail::__months_years_conversion_disambiguator>
2240 friend constexpr year_month_weekday_last
2241 operator+(
const year_month_weekday_last& __ymwdl,
2242 const months& __dm)
noexcept
2244 return ((__ymwdl.year() / __ymwdl.month() + __dm)
2245 / __ymwdl.weekday_last());
2248 template<
typename = __detail::__months_years_conversion_disambiguator>
2249 friend constexpr year_month_weekday_last
2251 const year_month_weekday_last& __ymwdl)
noexcept
2252 {
return __ymwdl + __dm; }
2254 friend constexpr year_month_weekday_last
2255 operator+(
const year_month_weekday_last& __ymwdl,
2256 const years& __dy)
noexcept
2257 {
return {__ymwdl.year() + __dy, __ymwdl.month(), __ymwdl.weekday_last()}; }
2259 friend constexpr year_month_weekday_last
2261 const year_month_weekday_last& __ymwdl)
noexcept
2262 {
return __ymwdl + __dy; }
2264 template<
typename = __detail::__months_years_conversion_disambiguator>
2265 friend constexpr year_month_weekday_last
2266 operator-(
const year_month_weekday_last& __ymwdl,
2267 const months& __dm)
noexcept
2268 {
return __ymwdl + -__dm; }
2270 friend constexpr year_month_weekday_last
2271 operator-(
const year_month_weekday_last& __ymwdl,
2272 const years& __dy)
noexcept
2273 {
return __ymwdl + -__dy; }
2275 friend constexpr year_month_weekday_last
2277 const chrono::weekday_last& __wdl)
noexcept
2278 {
return {__ym.year(), __ym.month(), __wdl}; }
2280 friend constexpr year_month_weekday_last
2282 const chrono::month_weekday_last& __mwdl)
noexcept
2283 {
return {__y, __mwdl.month(), __mwdl.weekday_last()}; }
2285 friend constexpr year_month_weekday_last
2286 operator/(
int __y,
const chrono::month_weekday_last& __mwdl)
noexcept
2287 {
return chrono::year(__y) / __mwdl; }
2289 friend constexpr year_month_weekday_last
2290 operator/(
const chrono::month_weekday_last& __mwdl,
2291 const chrono::year& __y)
noexcept
2292 {
return __y / __mwdl; }
2294 friend constexpr year_month_weekday_last
2295 operator/(
const chrono::month_weekday_last& __mwdl,
int __y)
noexcept
2296 {
return chrono::year(__y) / __mwdl; }
2305 __pow10(
unsigned __n)
2322 template<
typename _Duration>
2325 static_assert( __is_duration<_Duration>::value );
2328 static consteval int
2329 _S_fractional_width()
2331 auto __den = _Duration::period::den;
2332 const int __multiplicity_2 = std::__countr_zero((uintmax_t)__den);
2333 __den >>= __multiplicity_2;
2334 int __multiplicity_5 = 0;
2335 while ((__den % 5) == 0)
2343 int __width = (__multiplicity_2 > __multiplicity_5
2344 ? __multiplicity_2 : __multiplicity_5);
2351 hh_mm_ss(_Duration __d,
bool __is_neg)
2357 auto __ss = __d - hours() - minutes() - seconds();
2358 if constexpr (treat_as_floating_point_v<typename precision::rep>)
2359 _M_ss._M_r = __ss.count();
2360 else if constexpr (precision::period::den != 1)
2366 static constexpr _Duration
2367 _S_abs(_Duration __d)
2376 static constexpr unsigned fractional_width = {_S_fractional_width()};
2380 chrono::seconds::rep>,
2381 ratio<1, __detail::__pow10(fractional_width)>>;
2383 constexpr hh_mm_ss()
noexcept =
default;
2386 hh_mm_ss(_Duration __d)
2387 : hh_mm_ss(_S_abs(__d), __d < _Duration::zero())
2391 is_negative()
const noexcept
2393 if constexpr (!_S_is_unsigned)
2400 hours()
const noexcept
2404 minutes()
const noexcept
2408 seconds()
const noexcept
2412 subseconds()
const noexcept
2413 {
return static_cast<precision
>(_M_ss); }
2416 operator precision()
const noexcept
2417 {
return to_duration(); }
2420 to_duration()
const noexcept
2422 if constexpr (!_S_is_unsigned)
2424 return -(_M_h + _M_m + _M_s + subseconds());
2425 return _M_h + _M_m + _M_s + subseconds();
2429 static constexpr bool _S_is_unsigned
2430 = __and_v<is_integral<typename _Duration::rep>,
2433 template<
typename _Ratio>
2437 template<
typename _Dur>
2440 typename _Dur::rep _M_r{};
2443 operator _Dur()
const noexcept
2444 {
return _Dur(_M_r); }
2448 template<
typename _Rep>
2449 requires (!treat_as_floating_point_v<_Rep>)
2457 template<
typename _Rep,
typename _Period>
2458 requires (!treat_as_floating_point_v<_Rep>)
2463 unsigned char _M_r{};
2470 template<
typename _Rep,
typename _Period>
2471 requires (!treat_as_floating_point_v<_Rep>)
2476 uint_least32_t _M_r{};
2484 __byte_duration<ratio<60>> _M_m{};
2485 __byte_duration<ratio<1>> _M_s{};
2487 __subseconds<precision> _M_ss{};
2493 is_am(
const hours& __h)
noexcept
2494 {
return 0h <= __h && __h <= 11h; }
2497 is_pm(
const hours& __h)
noexcept
2498 {
return 12h <= __h && __h <= 23h; }
2501 make12(
const hours& __h)
noexcept
2511 make24(
const hours& __h,
bool __is_pm)
noexcept
2530#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2546 static constexpr int unique = 0;
2547 static constexpr int nonexistent = 1;
2548 static constexpr int ambiguous = 2;
2555 class nonexistent_local_time :
public runtime_error
2558 template<
typename _Duration>
2559 nonexistent_local_time(
const local_time<_Duration>& __tp,
2560 const local_info& __i)
2561 : runtime_error(_S_make_what_str(__tp, __i))
2562 { __glibcxx_assert(__i.result == local_info::nonexistent); }
2565 template<
typename _Duration>
2567 _S_make_what_str(
const local_time<_Duration>& __tp,
2568 const local_info& __i)
2571 __os << __tp <<
" is in a gap between\n"
2572 << local_seconds(__i.first.end.time_since_epoch())
2573 + __i.first.offset <<
' ' << __i.first.abbrev <<
" and\n"
2574 << local_seconds(__i.second.begin.time_since_epoch())
2575 + __i.second.offset <<
' ' << __i.second.abbrev
2576 <<
" which are both equivalent to\n"
2577 << __i.first.end <<
" UTC";
2582 class ambiguous_local_time :
public runtime_error
2585 template<
typename _Duration>
2586 ambiguous_local_time(
const local_time<_Duration>& __tp,
2587 const local_info& __i)
2588 : runtime_error(_S_make_what_str(__tp, __i))
2589 { __glibcxx_assert(__i.result == local_info::ambiguous); }
2592 template<
typename _Duration>
2594 _S_make_what_str(
const local_time<_Duration>& __tp,
2595 const local_info& __i)
2598 __os << __tp <<
" is ambiguous. It could be\n"
2599 << __tp <<
' ' << __i.first.abbrev <<
" == "
2600 << __tp - __i.first.offset <<
" UTC or\n"
2601 << __tp <<
' ' << __i.second.abbrev <<
" == "
2602 << __tp - __i.second.offset <<
" UTC";
2607 template<
typename _Duration>
2609 __throw_bad_local_time(
const local_time<_Duration>& __tp,
2610 const local_info& __i)
2613 if (__i.result == local_info::nonexistent)
2614 throw nonexistent_local_time(__tp, __i);
2615 throw ambiguous_local_time(__tp, __i);
2621 enum class choose { earliest, latest };
2626 time_zone(time_zone&&) =
default;
2627 time_zone& operator=(time_zone&&) =
default;
2632 string_view name() const noexcept {
return _M_name; }
2634 template<
typename _Duration>
2636 get_info(
const sys_time<_Duration>& __st)
const
2637 {
return _M_get_sys_info(chrono::floor<seconds>(__st)); }
2639 template<
typename _Duration>
2641 get_info(
const local_time<_Duration>& __tp)
const
2642 {
return _M_get_local_info(chrono::floor<seconds>(__tp)); }
2644 template<
typename _Duration>
2645 sys_time<common_type_t<_Duration, seconds>>
2646 to_sys(
const local_time<_Duration>& __tp)
const
2648 local_info __info = get_info(__tp);
2650 if (__info.result != local_info::unique)
2651 __throw_bad_local_time(__tp, __info);
2653 return sys_time<_Duration>(__tp.time_since_epoch())
2654 - __info.first.offset;
2657 template<
typename _Duration>
2658 sys_time<common_type_t<_Duration, seconds>>
2659 to_sys(
const local_time<_Duration>& __tp, choose __z)
const
2661 local_info __info = get_info(__tp);
2663 if (__info.result == local_info::nonexistent)
2664 return __info.first.end;
2666 sys_time<_Duration> __st(__tp.time_since_epoch());
2668 if (__info.result == local_info::ambiguous && __z == choose::latest)
2669 return __st - __info.second.offset;
2672 return __st - __info.first.offset;
2675 template<
typename _Duration>
2676 local_time<common_type_t<_Duration, seconds>>
2677 to_local(
const sys_time<_Duration>& __tp)
const
2679 auto __d = (__tp + get_info(__tp).offset).time_since_epoch();
2680 return local_time<common_type_t<_Duration, seconds>>(__d);
2683 [[nodiscard]]
friend bool
2684 operator==(
const time_zone& __x,
const time_zone& __y)
noexcept
2685 {
return __x._M_name == __y._M_name; }
2687 [[nodiscard]]
friend strong_ordering
2688 operator<=>(
const time_zone& __x,
const time_zone& __y)
noexcept
2689 {
return __x._M_name <=> __y._M_name; }
2692 sys_info _M_get_sys_info(sys_seconds)
const;
2693 local_info _M_get_local_info(local_seconds)
const;
2695 friend const tzdb& reload_tzdb();
2697 friend class tzdb_list;
2701 explicit time_zone(unique_ptr<_Impl> __p);
2703 unique_ptr<_Impl> _M_impl;
2706 const time_zone* locate_zone(string_view __tz_name);
2707 const time_zone* current_zone();
2728 tzdb_list(
const tzdb_list&) =
delete;
2729 tzdb_list& operator=(
const tzdb_list&) =
delete;
2738 class const_iterator
2741 using value_type = tzdb;
2742 using reference =
const tzdb&;
2743 using pointer =
const tzdb*;
2744 using difference_type = ptrdiff_t;
2747 constexpr const_iterator() =
default;
2748 const_iterator(
const const_iterator&) =
default;
2749 const_iterator(const_iterator&&) =
default;
2750 const_iterator& operator=(
const const_iterator&) =
default;
2751 const_iterator& operator=(const_iterator&&) =
default;
2753 reference operator*()
const noexcept;
2754 pointer operator->()
const noexcept {
return &**
this; }
2755 const_iterator& operator++();
2756 const_iterator operator++(
int);
2758 bool operator==(
const const_iterator&)
const noexcept =
default;
2763 friend class tzdb_list;
2766 void* _M_reserved =
nullptr;
2796 const_iterator
cbegin() const noexcept {
return begin(); }
2797 const_iterator
cend() const noexcept {
return end(); }
2800 constexpr explicit tzdb_list(nullptr_t);
2802 friend tzdb_list& get_tzdb_list();
2803 friend const tzdb& get_tzdb();
2804 friend const tzdb& reload_tzdb();
2806 friend class leap_second;
2807 friend struct time_zone::_Impl;
2808 friend class time_zone_link;
2811 class time_zone_link
2814 time_zone_link(time_zone_link&&) =
default;
2815 time_zone_link& operator=(time_zone_link&&) =
default;
2817 string_view name() const noexcept {
return _M_name; }
2818 string_view target() const noexcept {
return _M_target; }
2821 operator==(
const time_zone_link& __x,
const time_zone_link& __y)
noexcept
2822 {
return __x.name() == __y.name(); }
2824 friend strong_ordering
2825 operator<=>(
const time_zone_link& __x,
const time_zone_link& __y)
noexcept
2826 {
return __x.name() <=> __y.name(); }
2829 friend const tzdb& reload_tzdb();
2830 friend struct tzdb_list::_Node;
2832 explicit time_zone_link(nullptr_t) { }
2841 leap_second(
const leap_second&) =
default;
2842 leap_second& operator=(
const leap_second&) =
default;
2845 constexpr sys_seconds
2846 date() const noexcept
2848 if (_M_s >= _M_s.zero()) [[likely]]
2849 return sys_seconds(_M_s);
2850 return sys_seconds(-_M_s);
2855 value() const noexcept
2857 if (_M_s >= _M_s.zero()) [[likely]]
2864 [[nodiscard]]
friend constexpr bool
2865 operator==(
const leap_second&,
const leap_second&)
noexcept =
default;
2867 [[nodiscard]]
friend constexpr strong_ordering
2868 operator<=>(
const leap_second& __x,
const leap_second& __y)
noexcept
2869 {
return __x.date() <=> __y.date(); }
2871 template<
typename _Duration>
2872 [[nodiscard]]
friend constexpr bool
2873 operator==(
const leap_second& __x,
2874 const sys_time<_Duration>& __y)
noexcept
2875 {
return __x.date() == __y; }
2877 template<
typename _Duration>
2878 [[nodiscard]]
friend constexpr bool
2880 const sys_time<_Duration>& __y)
noexcept
2881 {
return __x.date() < __y; }
2883 template<
typename _Duration>
2884 [[nodiscard]]
friend constexpr bool
2885 operator<(
const sys_time<_Duration>& __x,
2886 const leap_second& __y)
noexcept
2887 {
return __x < __y.date(); }
2889 template<
typename _Duration>
2890 [[nodiscard]]
friend constexpr bool
2892 const sys_time<_Duration>& __y)
noexcept
2893 {
return __y < __x.date(); }
2895 template<
typename _Duration>
2896 [[nodiscard]]
friend constexpr bool
2897 operator>(
const sys_time<_Duration>& __x,
2898 const leap_second& __y)
noexcept
2899 {
return __y.date() < __x; }
2901 template<
typename _Duration>
2902 [[nodiscard]]
friend constexpr bool
2904 const sys_time<_Duration>& __y)
noexcept
2905 {
return !(__y < __x.date()); }
2907 template<
typename _Duration>
2908 [[nodiscard]]
friend constexpr bool
2910 const leap_second& __y)
noexcept
2911 {
return !(__y.date() < __x); }
2913 template<
typename _Duration>
2914 [[nodiscard]]
friend constexpr bool
2916 const sys_time<_Duration>& __y)
noexcept
2917 {
return !(__x.date() < __y); }
2919 template<
typename _Duration>
2920 [[nodiscard]]
friend constexpr bool
2922 const leap_second& __y)
noexcept
2923 {
return !(__x < __y.date()); }
2927 template<three_way_comparable_with<seconds> _Duration>
2928 [[nodiscard]]
friend constexpr auto
2929 operator<=>(
const leap_second& __x,
2930 const sys_time<_Duration>& __y)
noexcept
2931 {
return __x.date() <=> __y; }
2934 explicit leap_second(seconds::rep __s) : _M_s(__s) { }
2936 friend struct tzdb_list::_Node;
2938 friend const tzdb& reload_tzdb();
2940 template<
typename _Duration>
2941 friend leap_second_info
2942 get_leap_second_info(
const utc_time<_Duration>&);
2947 template<
class _Tp>
struct zoned_traits { };
2950 struct zoned_traits<const time_zone*>
2952 static const time_zone*
2954 {
return std::chrono::locate_zone(
"UTC"); }
2956 static const time_zone*
2957 locate_zone(string_view __name)
2958 {
return std::chrono::locate_zone(__name); }
2964 _GLIBCXX_STD_C::vector<time_zone> zones;
2965 _GLIBCXX_STD_C::vector<time_zone_link> links;
2966 _GLIBCXX_STD_C::vector<leap_second> leap_seconds;
2969 locate_zone(string_view __tz_name)
const;
2972 current_zone()
const;
2975 friend const tzdb& reload_tzdb();
2976 friend class time_zone;
2977 friend struct tzdb_list::_Node;
2980 tzdb_list& get_tzdb_list();
2981 const tzdb& get_tzdb();
2983 const tzdb& reload_tzdb();
2984 string remote_version();
2986 template<
typename _Duration,
typename _TimeZonePtr = const time_zone*>
2989 static_assert(__is_duration_v<_Duration>);
2991 using _Traits = zoned_traits<_TimeZonePtr>;
2995 using string_view = type_identity_t<std::string_view>;
2998 using duration = common_type_t<_Duration, seconds>;
3000 zoned_time()
requires requires { _Traits::default_zone(); }
3003 zoned_time(
const zoned_time&) =
default;
3004 zoned_time& operator=(
const zoned_time&) =
default;
3006 zoned_time(
const sys_time<_Duration>& __st)
3007 requires requires { _Traits::default_zone(); }
3012 zoned_time(_TimeZonePtr __z) : _M_zone(std::move(__z)) { }
3015 zoned_time(string_view __name)
3017 _TimeZonePtr{_Traits::locate_zone(std::string_view{})};
3019 : _M_zone(_Traits::locate_zone(__name))
3022 template<
typename _Duration2>
3023 zoned_time(
const zoned_time<_Duration2, _TimeZonePtr>& __zt)
3024 requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
3025 : _M_zone(__zt._M_zone), _M_tp(__zt._M_tp)
3028 zoned_time(_TimeZonePtr __z,
const sys_time<_Duration>& __st)
3029 : _M_zone(std::move(__z)), _M_tp(__st)
3032 zoned_time(string_view __name,
const sys_time<_Duration>& __st)
3033 : zoned_time(_Traits::locate_zone(__name), __st)
3036 zoned_time(_TimeZonePtr __z,
const local_time<_Duration>& __tp)
3038 { __z->to_sys(__tp) } -> convertible_to<sys_time<_Duration>>;
3040 : _M_zone(
std::move(__z)), _M_tp(_M_zone->to_sys(__tp))
3043 zoned_time(string_view __name,
const local_time<_Duration>& __tp)
3044 requires requires (_TimeZonePtr __z) {
3045 { _Traits::locate_zone(__name) } -> convertible_to<_TimeZonePtr>;
3046 { __z->to_sys(__tp) } -> convertible_to<sys_time<_Duration>>;
3048 : zoned_time(_Traits::locate_zone(__name), __tp)
3051 zoned_time(_TimeZonePtr __z,
const local_time<_Duration>& __tp,
3054 { __z->to_sys(__tp, __c) } -> convertible_to<sys_time<_Duration>>;
3056 : _M_zone(
std::move(__z)), _M_tp(_M_zone->to_sys(__tp, __c))
3059 zoned_time(string_view __name,
const local_time<_Duration>& __tp,
3061 requires requires (_TimeZonePtr __z) {
3062 { _Traits::locate_zone(__name) } -> convertible_to<_TimeZonePtr>;
3063 { __z->to_sys(__tp, __c) } -> convertible_to<sys_time<_Duration>>;
3065 : _M_zone(_Traits::locate_zone(__name)),
3066 _M_tp(_M_zone->to_sys(__tp, __c))
3069 template<
typename _Duration2,
typename _TimeZonePtr2>
3070 zoned_time(_TimeZonePtr __z,
3071 const zoned_time<_Duration2, _TimeZonePtr2>& __zt)
3072 requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
3073 : _M_zone(__z), _M_tp(__zt._M_tp)
3076 template<
typename _Duration2,
typename _TimeZonePtr2>
3077 zoned_time(_TimeZonePtr __z,
3078 const zoned_time<_Duration2, _TimeZonePtr2>& __zt,
3080 requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
3081 : _M_zone(__z), _M_tp(__zt._M_tp)
3084 template<
typename _Duration2,
typename _TimeZonePtr2>
3085 zoned_time(string_view __name,
3086 const zoned_time<_Duration2, _TimeZonePtr2>& __zt)
3087 requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
3089 { _Traits::locate_zone(__name) } -> convertible_to<_TimeZonePtr>;
3091 : _M_zone(_Traits::locate_zone(__name)), _M_tp(__zt._M_tp)
3094 template<
typename _Duration2,
typename _TimeZonePtr2>
3095 zoned_time(string_view __name,
3096 const zoned_time<_Duration2, _TimeZonePtr2>& __zt,
3098 requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
3100 { _Traits::locate_zone(__name) } -> convertible_to<_TimeZonePtr>;
3102 : _M_zone(_Traits::locate_zone(__name)), _M_tp(__zt._M_tp)
3106 operator=(
const sys_time<_Duration>& __st)
3113 operator=(
const local_time<_Duration>& __lt)
3115 _M_tp = _M_zone->to_sys(__lt);
3120 operator sys_time<duration>()
const {
return _M_tp; }
3123 explicit operator local_time<duration>()
const
3124 {
return get_local_time(); }
3128 get_time_zone()
const
3132 local_time<duration>
3133 get_local_time()
const
3134 {
return _M_zone->to_local(_M_tp); }
3138 get_sys_time()
const
3144 {
return _M_zone->get_info(_M_tp); }
3146 [[nodiscard]]
friend bool
3147 operator==(
const zoned_time&,
const zoned_time&) =
default;
3150 _TimeZonePtr _M_zone{ _Traits::default_zone() };
3151 sys_time<duration> _M_tp{};
3153 template<
typename _Duration2,
typename _TimeZonePtr2>
3154 friend class zoned_time;
3157 zoned_time() -> zoned_time<seconds>;
3159 template<
typename _Duration>
3160 zoned_time(sys_time<_Duration>)
3161 -> zoned_time<common_type_t<_Duration, seconds>>;
3164 template<
typename _TimeZonePtrOrName>
3165 using __time_zone_representation
3166 = __conditional_t<is_convertible_v<_TimeZonePtrOrName, string_view>,
3168 remove_cvref_t<_TimeZonePtrOrName>>;
3171 template<
typename _TimeZonePtrOrName>
3172 zoned_time(_TimeZonePtrOrName&&)
3173 -> zoned_time<seconds, __time_zone_representation<_TimeZonePtrOrName>>;
3175 template<
typename _TimeZonePtrOrName,
typename _Duration>
3176 zoned_time(_TimeZonePtrOrName&&, sys_time<_Duration>)
3177 -> zoned_time<common_type_t<_Duration, seconds>,
3178 __time_zone_representation<_TimeZonePtrOrName>>;
3180 template<
typename _TimeZonePtrOrName,
typename _Duration>
3181 zoned_time(_TimeZonePtrOrName&&, local_time<_Duration>,
3182 choose = choose::earliest)
3183 -> zoned_time<common_type_t<_Duration, seconds>,
3184 __time_zone_representation<_TimeZonePtrOrName>>;
3186 template<
typename _Duration,
typename _TimeZonePtrOrName,
3187 typename _TimeZonePtr2>
3188 zoned_time(_TimeZonePtrOrName&&, zoned_time<_Duration, _TimeZonePtr2>,
3189 choose = choose::earliest)
3190 -> zoned_time<common_type_t<_Duration, seconds>,
3191 __time_zone_representation<_TimeZonePtrOrName>>;
3193 template<
typename _Dur1,
typename _TZPtr1,
typename _Dur2,
typename _TZPtr2>
3196 operator==(
const zoned_time<_Dur1, _TZPtr1>& __x,
3197 const zoned_time<_Dur2, _TZPtr2>& __y)
3199 return __x.get_time_zone() == __y.get_time_zone()
3200 && __x.get_sys_time() == __y.get_sys_time();
3203 using zoned_seconds = zoned_time<seconds>;
3208 inline leap_second_info
3209 __get_leap_second_info(sys_seconds __ss,
bool __is_utc)
3211 if (__ss < sys_seconds{}) [[unlikely]]
3214 const seconds::rep __leaps[] {
3245 constexpr sys_seconds __expires(1782604800s);
3247#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
3248 if (__ss > __expires)
3253 auto __db = get_tzdb_list().begin();
3254 auto __first = __db->leap_seconds.
begin() + __n;
3255 auto __last = __db->leap_seconds.end();
3256 auto __pos = std::upper_bound(__first, __last, __ss);
3258 for (
auto __i = __first; __i != __pos; ++__i)
3259 __elapsed += __i->value();
3266 if (__pos != __first && __ss < __pos[-1])
3268 if ((__ss + 1s) >= __pos[-1])
3269 return {
true, __elapsed};
3270 __elapsed -= __pos[-1].value();
3273 return {
false, __elapsed};
3278 seconds::rep __s = __ss.time_since_epoch().count();
3279 const seconds::rep* __first =
std::begin(__leaps);
3280 const seconds::rep* __last =
std::end(__leaps);
3283 if (__s > (__last[-1] + (__last - __first) + 1))
3284 return {
false,
seconds(__last - __first) };
3286 auto __pos = std::upper_bound(__first, __last, __s);
3287 seconds __elapsed{__pos - __first};
3291 __s -= __elapsed.count();
3293 if (__pos != __first && __s < __pos[-1])
3295 if ((__s + 1) >= __pos[-1])
3296 return {
true, __elapsed};
3300 return {
false, __elapsed};
3305 template<
typename _Duration>
3307 inline leap_second_info
3308 get_leap_second_info(
const utc_time<_Duration>& __ut)
3310 auto __s = chrono::duration_cast<seconds>(__ut.time_since_epoch());
3311 return __detail::__get_leap_second_info(sys_seconds(__s),
true);
3314 template<
typename _Duration>
3316 inline utc_time<common_type_t<_Duration, seconds>>
3317 utc_clock::from_sys(
const sys_time<_Duration>& __t)
3319 using _CDur = common_type_t<_Duration, seconds>;
3320 auto __s = chrono::time_point_cast<seconds>(__t);
3321 const auto __li = __detail::__get_leap_second_info(__s,
false);
3322 return utc_time<_CDur>{__t.time_since_epoch()} + __li.elapsed;
3330#if __glibcxx_chrono_cxx20 >= 202306
3333 template<
typename _Tp>
3334 concept __is_nothrow_copy_hashable =
requires(
const _Tp& __t) {
3340 template<
typename _T1,
typename... _Ts>
3341 [[__gnu__::__always_inline__]]
3343 __pack_ints(_T1 __v1, _Ts... __vs)
3345 using _ResT =
decltype([] {
3346 constexpr size_t __tsize = (
sizeof(_T1) + ... +
sizeof(_Ts));
3347 if constexpr (__tsize <= 1)
3348 return static_cast<unsigned char>(0);
3349 else if constexpr (__tsize <= 2)
3350 return static_cast<__UINT16_TYPE__
>(0);
3351 else if constexpr (__tsize <= 4)
3352 return static_cast<__UINT32_TYPE__
>(0);
3353 else if constexpr (__tsize <= 8)
3354 return static_cast<__UINT64_TYPE__
>(0);
3356 static_assert(__tsize <= 8);
3360 ((__res = (__res << (
sizeof(_Ts) * __CHAR_BIT__) | _ResT(__vs))), ...);
3364 template<
typename _Tp>
3365 [[__gnu__::__always_inline__]]
3369 if constexpr (is_same_v<_Tp, year>)
3370 return static_cast<unsigned short>(
static_cast<int>(__val));
3371 else if constexpr (is_same_v<_Tp, month> || is_same_v<_Tp, day>)
3372 return static_cast<unsigned char>(
static_cast<unsigned>(__val));
3373 else if constexpr (is_same_v<_Tp, weekday>)
3374 return static_cast<unsigned char>(__val.c_encoding());
3375 else if constexpr (is_same_v<_Tp, weekday_indexed>)
3376 return __pack_ints(chrono::__as_int(__val.weekday()),
3377 static_cast<unsigned char>(__val.index()));
3378 else if constexpr (is_same_v<_Tp, weekday_last>)
3379 return chrono::__as_int(__val.weekday());
3381 static_assert(
false);
3384 template<
typename _Arg,
typename... _Args>
3386 __int_hash(_Arg __arg, _Args... __args)
3388 static_assert((is_integral_v<_Arg> && ... && is_integral_v<_Args>));
3391 using _Hasher = _Hash_impl;
3392 size_t __result = _Hasher::hash(__arg);
3393 ((__result = _Hasher::__hash_combine(__args, __result)), ...);
3397 template<
typename... _Tps>
3398 [[__gnu__::__always_inline__]]
3400 __hash(_Tps... __vals)
3402 if constexpr (
sizeof...(_Tps) == 1)
3403 return chrono::__int_hash(chrono::__as_int(__vals)...);
3406 auto __res = chrono::__pack_ints(chrono::__as_int(__vals)...);
3407 return chrono::__int_hash(__res);
3413 template<
typename _Rep,
typename _Period>
3414 requires __is_hash_enabled_for<_Rep>
3418 operator()(
const chrono::duration<_Rep, _Period>& __val)
const
3419 noexcept(__is_nothrow_copy_hashable<_Rep>)
3421 if constexpr (is_integral_v<_Rep>)
3422 return chrono::__int_hash(__val.count());
3424 return hash<_Rep>{}(__val.count());
3428 template<
typename _Rep,
typename _Period>
3434 template<
typename _Clock,
typename _Dur>
3435 requires __is_hash_enabled_for<_Dur>
3436 struct hash<
chrono::time_point<_Clock, _Dur>>
3439 operator()(
const chrono::time_point<_Clock, _Dur>& __val)
const
3440 noexcept(__is_nothrow_copy_hashable<_Dur>)
3441 {
return hash<_Dur>{}(__val.time_since_epoch()); }
3444 template<
typename _Clock,
typename _Dur>
3454 operator()(chrono::day __val)
const noexcept
3455 {
return chrono::__hash(__val); }
3463 operator()(chrono::month __val)
const noexcept
3464 {
return chrono::__hash(__val); }
3472 operator()(chrono::year __val)
const noexcept
3473 {
return chrono::__hash(__val); }
3481 operator()(chrono::weekday __val)
const noexcept
3482 {
return chrono::__hash(__val); }
3490 operator()(chrono::weekday_indexed __val)
const noexcept
3491 {
return chrono::__hash(__val); }
3499 operator()(chrono::weekday_last __val)
const noexcept
3500 {
return chrono::__hash(__val); }
3508 operator()(chrono::month_day __val)
const noexcept
3509 {
return chrono::__hash(__val.month(), __val.day()); }
3516 size_t operator()(chrono::month_day_last __val)
const noexcept
3517 {
return chrono::__hash(__val.month()); }
3525 operator()(chrono::month_weekday __val)
const noexcept
3526 {
return chrono::__hash(__val.month(), __val.weekday_indexed()); }
3534 operator()(chrono::month_weekday_last __val)
const noexcept
3535 {
return chrono::__hash(__val.month(), __val.weekday_last()); }
3543 operator()(chrono::year_month __val)
const noexcept
3544 {
return chrono::__hash(__val.year(), __val.month()); }
3552 operator()(chrono::year_month_day __val)
const noexcept
3553 {
return chrono::__hash(__val.year(), __val.month(), __val.day()); }
3561 operator()(chrono::year_month_day_last __val)
const noexcept
3562 {
return chrono::__hash(__val.year(), __val.month()); }
3570 operator()(chrono::year_month_weekday __val)
const noexcept
3572 return chrono::__hash(__val.year(), __val.month(),
3573 __val.weekday_indexed());
3582 operator()(chrono::year_month_weekday_last __val)
const noexcept
3584 return chrono::__hash(__val.year(), __val.month(),
3585 __val.weekday_last());
3590#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
3592 template<
typename _Duration,
typename _TimeZonePtr>
3593 requires __is_hash_enabled_for<
3594 typename chrono::zoned_time<_Duration, _TimeZonePtr>::duration>
3595 && __is_hash_enabled_for<_TimeZonePtr>
3596 struct hash<
chrono::zoned_time<_Duration, _TimeZonePtr>>
3599 using _ActualDuration =
3600 typename chrono::zoned_time<_Duration, _TimeZonePtr>::duration;
3604 operator()(
const chrono::zoned_time<_Duration, _TimeZonePtr>& __val)
const
3605 noexcept(__is_nothrow_copy_hashable<_ActualDuration>
3606 && __is_nothrow_copy_hashable<_TimeZonePtr>)
3608 const auto __iduration = [&] {
3609 const _ActualDuration __sd = __val.get_sys_time().time_since_epoch();
3610 if constexpr (is_integral_v<typename _ActualDuration::rep>)
3611 return __sd.count();
3613 return hash<_ActualDuration>{}(__sd);
3616 const auto __izone = [&] {
3617 const _TimeZonePtr __tz = __val.get_time_zone();
3618 if constexpr (is_same_v<_TimeZonePtr, const chrono::time_zone*>)
3619 return reinterpret_cast<uintptr_t
>(__tz);
3621 return hash<_TimeZonePtr>{}(__tz);
3624 return chrono::__int_hash(__iduration, __izone);
3628 template<
typename _Duration,
typename _TimeZonePtr>
3630 : __and_<__is_fast_hash<hash<
3631 typename chrono::zoned_time<_Duration, _TimeZonePtr>::duration>>,
3632 __is_fast_hash<hash<_TimeZonePtr>>>
3640 operator()(chrono::leap_second __val)
const noexcept
3642 return chrono::__int_hash(
3643 __val.date().time_since_epoch().count(),
3644 __val.value().count());
3651#ifdef __glibcxx_chrono_cxx20
3658#pragma GCC diagnostic push
3659#pragma GCC diagnostic ignored "-Wliteral-suffix"
3662 constexpr chrono::day
3663 operator""d(
unsigned long long __d)
noexcept
3664 {
return chrono::day{
static_cast<unsigned>(__d)}; }
3668 constexpr chrono::year
3669 operator""y(
unsigned long long __y)
noexcept
3670 {
return chrono::year{
static_cast<int>(__y)}; }
3671#pragma GCC diagnostic pop
3677_GLIBCXX_END_NAMESPACE_VERSION
3680#if defined __glibcxx_chrono_cxx20 && _GLIBCXX_HOSTED
constexpr __enable_if_is_duration< _ToDur > floor(const duration< _Rep, _Period > &__d)
duration< int64_t, ratio< 2629746 > > months
months
duration< int64_t, ratio< 86400 > > days
days
duration< int64_t, ratio< 31556952 > > years
years
constexpr bool operator<=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
duration< int64_t, ratio< 3600 > > hours
hours
constexpr bool operator>=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
auto clock_cast(const time_point< _SourceClock, _Duration > &__t)
Convert a time point to a different clock.
constexpr enable_if_t< numeric_limits< _Rep >::is_signed, duration< _Rep, _Period > > abs(duration< _Rep, _Period > __d)
duration< int64_t, ratio< 60 > > minutes
minutes
constexpr time_point< _Clock, typename common_type< duration< _Rep1, _Period1 >, _Dur2 >::type > operator+(const duration< _Rep1, _Period1 > &__lhs, const time_point< _Clock, _Dur2 > &__rhs)
Adjust a time point forwards by the given duration.
constexpr bool operator<(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
duration< int64_t > seconds
seconds
constexpr bool operator>(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr common_type< duration< _Rep1, _Period1 >, duration< _Rep2, _Period2 > >::type operator-(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
The difference between two durations.
constexpr duration< __common_rep_t< _Rep1, __disable_if_is_duration< _Rep2 > >, _Period > operator/(const duration< _Rep1, _Period > &__d, const _Rep2 &__s)
constexpr __enable_if_is_duration< _ToDur > duration_cast(const duration< _Rep, _Period > &__d)
constexpr complex< _Tp > operator-(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x minus y.
constexpr complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
constexpr complex< _Tp > operator/(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x divided by y.
basic_ostringstream< char > ostringstream
Class for char output memory streams.
__bool_constant< true > true_type
The type used as a compile-time boolean with true value.
typename common_type< _Tp... >::type common_type_t
Alias template for common_type.
typename make_unsigned< _Tp >::type make_unsigned_t
Alias template for make_unsigned.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
_Tp * end(valarray< _Tp > &__va) noexcept
Return an iterator pointing to one past the last element of the valarray.
_Tp * begin(valarray< _Tp > &__va) noexcept
Return an iterator pointing to the first element of the valarray.
ISO C++ entities toplevel namespace is std.
constexpr auto cend(const _Container &__cont) noexcept(noexcept(std::end(__cont))) -> decltype(std::end(__cont))
Return an iterator pointing to one past the last element of the const container.
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
constexpr auto cbegin(const _Container &__cont) noexcept(noexcept(std::begin(__cont))) -> decltype(std::begin(__cont))
Return an iterator pointing to the first element of the const container.
ISO C++ inline namespace for literal suffixes.
ISO C++ 2011 namespace for date and time utilities.
const tzdb & front() const noexcept
const_iterator erase_after(const_iterator __p)
static constexpr bool is_signed
Provides compile-time rational arithmetic.
Primary class template hash.
chrono::duration represents a distance between two points in time
chrono::time_point represents a point in time as measured by a clock
A smart pointer with reference-counted copy semantics.
Forward iterators support a superset of input iterator operations.
constexpr iterator begin() noexcept
[concept.same], concept same_as