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)
2364 static constexpr _Duration
2365 _S_abs(_Duration __d)
2374 static constexpr unsigned fractional_width = {_S_fractional_width()};
2378 chrono::seconds::rep>,
2379 ratio<1, __detail::__pow10(fractional_width)>>;
2381 constexpr hh_mm_ss()
noexcept =
default;
2384 hh_mm_ss(_Duration __d)
2385 : hh_mm_ss(_S_abs(__d), __d < _Duration::zero())
2389 is_negative()
const noexcept
2391 if constexpr (!_S_is_unsigned)
2398 hours()
const noexcept
2402 minutes()
const noexcept
2406 seconds()
const noexcept
2410 subseconds()
const noexcept
2411 {
return static_cast<precision
>(_M_ss); }
2414 operator precision()
const noexcept
2415 {
return to_duration(); }
2418 to_duration()
const noexcept
2420 if constexpr (!_S_is_unsigned)
2422 return -(_M_h + _M_m + _M_s + subseconds());
2423 return _M_h + _M_m + _M_s + subseconds();
2427 static constexpr bool _S_is_unsigned
2428 = __and_v<is_integral<typename _Duration::rep>,
2431 template<
typename _Ratio>
2435 template<
typename _Dur>
2438 typename _Dur::rep _M_r{};
2441 operator _Dur()
const noexcept
2442 {
return _Dur(_M_r); }
2446 template<
typename _Rep>
2447 requires (!treat_as_floating_point_v<_Rep>)
2455 template<
typename _Rep,
typename _Period>
2456 requires (!treat_as_floating_point_v<_Rep>)
2461 unsigned char _M_r{};
2468 template<
typename _Rep,
typename _Period>
2469 requires (!treat_as_floating_point_v<_Rep>)
2474 uint_least32_t _M_r{};
2482 __byte_duration<ratio<60>> _M_m{};
2483 __byte_duration<ratio<1>> _M_s{};
2485 __subseconds<precision> _M_ss{};
2491 is_am(
const hours& __h)
noexcept
2492 {
return 0h <= __h && __h <= 11h; }
2495 is_pm(
const hours& __h)
noexcept
2496 {
return 12h <= __h && __h <= 23h; }
2499 make12(
const hours& __h)
noexcept
2509 make24(
const hours& __h,
bool __is_pm)
noexcept
2528#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2544 static constexpr int unique = 0;
2545 static constexpr int nonexistent = 1;
2546 static constexpr int ambiguous = 2;
2553 class nonexistent_local_time :
public runtime_error
2556 template<
typename _Duration>
2557 nonexistent_local_time(
const local_time<_Duration>& __tp,
2558 const local_info& __i)
2559 : runtime_error(_S_make_what_str(__tp, __i))
2560 { __glibcxx_assert(__i.result == local_info::nonexistent); }
2563 template<
typename _Duration>
2565 _S_make_what_str(
const local_time<_Duration>& __tp,
2566 const local_info& __i)
2569 __os << __tp <<
" is in a gap between\n"
2570 << local_seconds(__i.first.end.time_since_epoch())
2571 + __i.first.offset <<
' ' << __i.first.abbrev <<
" and\n"
2572 << local_seconds(__i.second.begin.time_since_epoch())
2573 + __i.second.offset <<
' ' << __i.second.abbrev
2574 <<
" which are both equivalent to\n"
2575 << __i.first.end <<
" UTC";
2580 class ambiguous_local_time :
public runtime_error
2583 template<
typename _Duration>
2584 ambiguous_local_time(
const local_time<_Duration>& __tp,
2585 const local_info& __i)
2586 : runtime_error(_S_make_what_str(__tp, __i))
2587 { __glibcxx_assert(__i.result == local_info::ambiguous); }
2590 template<
typename _Duration>
2592 _S_make_what_str(
const local_time<_Duration>& __tp,
2593 const local_info& __i)
2596 __os << __tp <<
" is ambiguous. It could be\n"
2597 << __tp <<
' ' << __i.first.abbrev <<
" == "
2598 << __tp - __i.first.offset <<
" UTC or\n"
2599 << __tp <<
' ' << __i.second.abbrev <<
" == "
2600 << __tp - __i.second.offset <<
" UTC";
2605 template<
typename _Duration>
2607 __throw_bad_local_time(
const local_time<_Duration>& __tp,
2608 const local_info& __i)
2611 if (__i.result == local_info::nonexistent)
2612 throw nonexistent_local_time(__tp, __i);
2613 throw ambiguous_local_time(__tp, __i);
2619 enum class choose { earliest, latest };
2624 time_zone(time_zone&&) =
default;
2625 time_zone& operator=(time_zone&&) =
default;
2630 string_view name() const noexcept {
return _M_name; }
2632 template<
typename _Duration>
2634 get_info(
const sys_time<_Duration>& __st)
const
2635 {
return _M_get_sys_info(chrono::floor<seconds>(__st)); }
2637 template<
typename _Duration>
2639 get_info(
const local_time<_Duration>& __tp)
const
2640 {
return _M_get_local_info(chrono::floor<seconds>(__tp)); }
2642 template<
typename _Duration>
2643 sys_time<common_type_t<_Duration, seconds>>
2644 to_sys(
const local_time<_Duration>& __tp)
const
2646 local_info __info = get_info(__tp);
2648 if (__info.result != local_info::unique)
2649 __throw_bad_local_time(__tp, __info);
2651 return sys_time<_Duration>(__tp.time_since_epoch())
2652 - __info.first.offset;
2655 template<
typename _Duration>
2656 sys_time<common_type_t<_Duration, seconds>>
2657 to_sys(
const local_time<_Duration>& __tp, choose __z)
const
2659 local_info __info = get_info(__tp);
2661 if (__info.result == local_info::nonexistent)
2662 return __info.first.end;
2664 sys_time<_Duration> __st(__tp.time_since_epoch());
2666 if (__info.result == local_info::ambiguous && __z == choose::latest)
2667 return __st - __info.second.offset;
2670 return __st - __info.first.offset;
2673 template<
typename _Duration>
2674 local_time<common_type_t<_Duration, seconds>>
2675 to_local(
const sys_time<_Duration>& __tp)
const
2677 auto __d = (__tp + get_info(__tp).offset).time_since_epoch();
2678 return local_time<common_type_t<_Duration, seconds>>(__d);
2681 [[nodiscard]]
friend bool
2682 operator==(
const time_zone& __x,
const time_zone& __y)
noexcept
2683 {
return __x._M_name == __y._M_name; }
2685 [[nodiscard]]
friend strong_ordering
2686 operator<=>(
const time_zone& __x,
const time_zone& __y)
noexcept
2687 {
return __x._M_name <=> __y._M_name; }
2690 sys_info _M_get_sys_info(sys_seconds)
const;
2691 local_info _M_get_local_info(local_seconds)
const;
2693 friend const tzdb& reload_tzdb();
2695 friend class tzdb_list;
2699 explicit time_zone(unique_ptr<_Impl> __p);
2701 unique_ptr<_Impl> _M_impl;
2704 const time_zone* locate_zone(string_view __tz_name);
2705 const time_zone* current_zone();
2726 tzdb_list(
const tzdb_list&) =
delete;
2727 tzdb_list& operator=(
const tzdb_list&) =
delete;
2736 class const_iterator
2739 using value_type = tzdb;
2740 using reference =
const tzdb&;
2741 using pointer =
const tzdb*;
2742 using difference_type = ptrdiff_t;
2745 constexpr const_iterator() =
default;
2746 const_iterator(
const const_iterator&) =
default;
2747 const_iterator(const_iterator&&) =
default;
2748 const_iterator& operator=(
const const_iterator&) =
default;
2749 const_iterator& operator=(const_iterator&&) =
default;
2751 reference operator*()
const noexcept;
2752 pointer operator->()
const noexcept {
return &**
this; }
2753 const_iterator& operator++();
2754 const_iterator operator++(
int);
2756 bool operator==(
const const_iterator&)
const noexcept =
default;
2761 friend class tzdb_list;
2764 void* _M_reserved =
nullptr;
2794 const_iterator
cbegin() const noexcept {
return begin(); }
2795 const_iterator
cend() const noexcept {
return end(); }
2798 constexpr explicit tzdb_list(nullptr_t);
2800 friend tzdb_list& get_tzdb_list();
2801 friend const tzdb& get_tzdb();
2802 friend const tzdb& reload_tzdb();
2804 friend class leap_second;
2805 friend struct time_zone::_Impl;
2806 friend class time_zone_link;
2809 class time_zone_link
2812 time_zone_link(time_zone_link&&) =
default;
2813 time_zone_link& operator=(time_zone_link&&) =
default;
2815 string_view name() const noexcept {
return _M_name; }
2816 string_view target() const noexcept {
return _M_target; }
2819 operator==(
const time_zone_link& __x,
const time_zone_link& __y)
noexcept
2820 {
return __x.name() == __y.name(); }
2822 friend strong_ordering
2823 operator<=>(
const time_zone_link& __x,
const time_zone_link& __y)
noexcept
2824 {
return __x.name() <=> __y.name(); }
2827 friend const tzdb& reload_tzdb();
2828 friend struct tzdb_list::_Node;
2830 explicit time_zone_link(nullptr_t) { }
2839 leap_second(
const leap_second&) =
default;
2840 leap_second& operator=(
const leap_second&) =
default;
2843 constexpr sys_seconds
2844 date() const noexcept
2846 if (_M_s >= _M_s.zero()) [[likely]]
2847 return sys_seconds(_M_s);
2848 return sys_seconds(-_M_s);
2853 value() const noexcept
2855 if (_M_s >= _M_s.zero()) [[likely]]
2862 [[nodiscard]]
friend constexpr bool
2863 operator==(
const leap_second&,
const leap_second&)
noexcept =
default;
2865 [[nodiscard]]
friend constexpr strong_ordering
2866 operator<=>(
const leap_second& __x,
const leap_second& __y)
noexcept
2867 {
return __x.date() <=> __y.date(); }
2869 template<
typename _Duration>
2870 [[nodiscard]]
friend constexpr bool
2871 operator==(
const leap_second& __x,
2872 const sys_time<_Duration>& __y)
noexcept
2873 {
return __x.date() == __y; }
2875 template<
typename _Duration>
2876 [[nodiscard]]
friend constexpr bool
2878 const sys_time<_Duration>& __y)
noexcept
2879 {
return __x.date() < __y; }
2881 template<
typename _Duration>
2882 [[nodiscard]]
friend constexpr bool
2883 operator<(
const sys_time<_Duration>& __x,
2884 const leap_second& __y)
noexcept
2885 {
return __x < __y.date(); }
2887 template<
typename _Duration>
2888 [[nodiscard]]
friend constexpr bool
2890 const sys_time<_Duration>& __y)
noexcept
2891 {
return __y < __x.date(); }
2893 template<
typename _Duration>
2894 [[nodiscard]]
friend constexpr bool
2895 operator>(
const sys_time<_Duration>& __x,
2896 const leap_second& __y)
noexcept
2897 {
return __y.date() < __x; }
2899 template<
typename _Duration>
2900 [[nodiscard]]
friend constexpr bool
2902 const sys_time<_Duration>& __y)
noexcept
2903 {
return !(__y < __x.date()); }
2905 template<
typename _Duration>
2906 [[nodiscard]]
friend constexpr bool
2908 const leap_second& __y)
noexcept
2909 {
return !(__y.date() < __x); }
2911 template<
typename _Duration>
2912 [[nodiscard]]
friend constexpr bool
2914 const sys_time<_Duration>& __y)
noexcept
2915 {
return !(__x.date() < __y); }
2917 template<
typename _Duration>
2918 [[nodiscard]]
friend constexpr bool
2920 const leap_second& __y)
noexcept
2921 {
return !(__x < __y.date()); }
2925 template<three_way_comparable_with<seconds> _Duration>
2926 [[nodiscard]]
friend constexpr auto
2927 operator<=>(
const leap_second& __x,
2928 const sys_time<_Duration>& __y)
noexcept
2929 {
return __x.date() <=> __y; }
2932 explicit leap_second(seconds::rep __s) : _M_s(__s) { }
2934 friend struct tzdb_list::_Node;
2936 friend const tzdb& reload_tzdb();
2938 template<
typename _Duration>
2939 friend leap_second_info
2940 get_leap_second_info(
const utc_time<_Duration>&);
2945 template<
class _Tp>
struct zoned_traits { };
2948 struct zoned_traits<const time_zone*>
2950 static const time_zone*
2952 {
return std::chrono::locate_zone(
"UTC"); }
2954 static const time_zone*
2955 locate_zone(string_view __name)
2956 {
return std::chrono::locate_zone(__name); }
2962 _GLIBCXX_STD_C::vector<time_zone> zones;
2963 _GLIBCXX_STD_C::vector<time_zone_link> links;
2964 _GLIBCXX_STD_C::vector<leap_second> leap_seconds;
2967 locate_zone(string_view __tz_name)
const;
2970 current_zone()
const;
2973 friend const tzdb& reload_tzdb();
2974 friend class time_zone;
2975 friend struct tzdb_list::_Node;
2978 tzdb_list& get_tzdb_list();
2979 const tzdb& get_tzdb();
2981 const tzdb& reload_tzdb();
2982 string remote_version();
2984 template<
typename _Duration,
typename _TimeZonePtr = const time_zone*>
2987 static_assert(__is_duration_v<_Duration>);
2989 using _Traits = zoned_traits<_TimeZonePtr>;
2993 using string_view = type_identity_t<std::string_view>;
2996 using duration = common_type_t<_Duration, seconds>;
2998 zoned_time()
requires requires { _Traits::default_zone(); }
3001 zoned_time(
const zoned_time&) =
default;
3002 zoned_time& operator=(
const zoned_time&) =
default;
3004 zoned_time(
const sys_time<_Duration>& __st)
3005 requires requires { _Traits::default_zone(); }
3010 zoned_time(_TimeZonePtr __z) : _M_zone(std::
move(__z)) { }
3013 zoned_time(string_view __name)
3015 _TimeZonePtr{_Traits::locate_zone(std::string_view{})};
3017 : _M_zone(_Traits::locate_zone(__name))
3020 template<
typename _Duration2>
3021 zoned_time(
const zoned_time<_Duration2, _TimeZonePtr>& __zt)
3022 requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
3023 : _M_zone(__zt._M_zone), _M_tp(__zt._M_tp)
3026 zoned_time(_TimeZonePtr __z,
const sys_time<_Duration>& __st)
3027 : _M_zone(std::
move(__z)), _M_tp(__st)
3030 zoned_time(string_view __name,
const sys_time<_Duration>& __st)
3031 : zoned_time(_Traits::locate_zone(__name), __st)
3034 zoned_time(_TimeZonePtr __z,
const local_time<_Duration>& __tp)
3036 { __z->to_sys(__tp) } -> convertible_to<sys_time<_Duration>>;
3038 : _M_zone(
std::move(__z)), _M_tp(_M_zone->to_sys(__tp))
3041 zoned_time(string_view __name,
const local_time<_Duration>& __tp)
3042 requires requires (_TimeZonePtr __z) {
3043 { _Traits::locate_zone(__name) } -> convertible_to<_TimeZonePtr>;
3044 { __z->to_sys(__tp) } -> convertible_to<sys_time<_Duration>>;
3046 : zoned_time(_Traits::locate_zone(__name), __tp)
3049 zoned_time(_TimeZonePtr __z,
const local_time<_Duration>& __tp,
3052 { __z->to_sys(__tp, __c) } -> convertible_to<sys_time<_Duration>>;
3054 : _M_zone(
std::move(__z)), _M_tp(_M_zone->to_sys(__tp, __c))
3057 zoned_time(string_view __name,
const local_time<_Duration>& __tp,
3059 requires requires (_TimeZonePtr __z) {
3060 { _Traits::locate_zone(__name) } -> convertible_to<_TimeZonePtr>;
3061 { __z->to_sys(__tp, __c) } -> convertible_to<sys_time<_Duration>>;
3063 : _M_zone(_Traits::locate_zone(__name)),
3064 _M_tp(_M_zone->to_sys(__tp, __c))
3067 template<
typename _Duration2,
typename _TimeZonePtr2>
3068 zoned_time(_TimeZonePtr __z,
3069 const zoned_time<_Duration2, _TimeZonePtr2>& __zt)
3070 requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
3071 : _M_zone(__z), _M_tp(__zt._M_tp)
3074 template<
typename _Duration2,
typename _TimeZonePtr2>
3075 zoned_time(_TimeZonePtr __z,
3076 const zoned_time<_Duration2, _TimeZonePtr2>& __zt,
3078 requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
3079 : _M_zone(__z), _M_tp(__zt._M_tp)
3082 template<
typename _Duration2,
typename _TimeZonePtr2>
3083 zoned_time(string_view __name,
3084 const zoned_time<_Duration2, _TimeZonePtr2>& __zt)
3085 requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
3087 { _Traits::locate_zone(__name) } -> convertible_to<_TimeZonePtr>;
3089 : _M_zone(_Traits::locate_zone(__name)), _M_tp(__zt._M_tp)
3092 template<
typename _Duration2,
typename _TimeZonePtr2>
3093 zoned_time(string_view __name,
3094 const zoned_time<_Duration2, _TimeZonePtr2>& __zt,
3096 requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
3098 { _Traits::locate_zone(__name) } -> convertible_to<_TimeZonePtr>;
3100 : _M_zone(_Traits::locate_zone(__name)), _M_tp(__zt._M_tp)
3104 operator=(
const sys_time<_Duration>& __st)
3111 operator=(
const local_time<_Duration>& __lt)
3113 _M_tp = _M_zone->to_sys(__lt);
3118 operator sys_time<duration>()
const {
return _M_tp; }
3121 explicit operator local_time<duration>()
const
3122 {
return get_local_time(); }
3126 get_time_zone()
const
3130 local_time<duration>
3131 get_local_time()
const
3132 {
return _M_zone->to_local(_M_tp); }
3136 get_sys_time()
const
3142 {
return _M_zone->get_info(_M_tp); }
3144 [[nodiscard]]
friend bool
3145 operator==(
const zoned_time&,
const zoned_time&) =
default;
3148 _TimeZonePtr _M_zone{ _Traits::default_zone() };
3149 sys_time<duration> _M_tp{};
3151 template<
typename _Duration2,
typename _TimeZonePtr2>
3152 friend class zoned_time;
3155 zoned_time() -> zoned_time<seconds>;
3157 template<
typename _Duration>
3158 zoned_time(sys_time<_Duration>)
3159 -> zoned_time<common_type_t<_Duration, seconds>>;
3162 template<
typename _TimeZonePtrOrName>
3163 using __time_zone_representation
3164 = __conditional_t<is_convertible_v<_TimeZonePtrOrName, string_view>,
3166 remove_cvref_t<_TimeZonePtrOrName>>;
3169 template<
typename _TimeZonePtrOrName>
3170 zoned_time(_TimeZonePtrOrName&&)
3171 -> zoned_time<seconds, __time_zone_representation<_TimeZonePtrOrName>>;
3173 template<
typename _TimeZonePtrOrName,
typename _Duration>
3174 zoned_time(_TimeZonePtrOrName&&, sys_time<_Duration>)
3175 -> zoned_time<common_type_t<_Duration, seconds>,
3176 __time_zone_representation<_TimeZonePtrOrName>>;
3178 template<
typename _TimeZonePtrOrName,
typename _Duration>
3179 zoned_time(_TimeZonePtrOrName&&, local_time<_Duration>,
3180 choose = choose::earliest)
3181 -> zoned_time<common_type_t<_Duration, seconds>,
3182 __time_zone_representation<_TimeZonePtrOrName>>;
3184 template<
typename _Duration,
typename _TimeZonePtrOrName,
3185 typename _TimeZonePtr2>
3186 zoned_time(_TimeZonePtrOrName&&, zoned_time<_Duration, _TimeZonePtr2>,
3187 choose = choose::earliest)
3188 -> zoned_time<common_type_t<_Duration, seconds>,
3189 __time_zone_representation<_TimeZonePtrOrName>>;
3191 template<
typename _Dur1,
typename _TZPtr1,
typename _Dur2,
typename _TZPtr2>
3194 operator==(
const zoned_time<_Dur1, _TZPtr1>& __x,
3195 const zoned_time<_Dur2, _TZPtr2>& __y)
3197 return __x.get_time_zone() == __y.get_time_zone()
3198 && __x.get_sys_time() == __y.get_sys_time();
3201 using zoned_seconds = zoned_time<seconds>;
3206 inline leap_second_info
3207 __get_leap_second_info(sys_seconds __ss,
bool __is_utc)
3209 if (__ss < sys_seconds{}) [[unlikely]]
3212 const seconds::rep __leaps[] {
3243 const sys_seconds __expires(1766880000s);
3245#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
3246 if (__ss > __expires)
3251 auto __db = get_tzdb_list().begin();
3252 auto __first = __db->leap_seconds.
begin() + __n;
3253 auto __last = __db->leap_seconds.end();
3254 auto __pos = std::upper_bound(__first, __last, __ss);
3256 for (
auto __i = __first; __i != __pos; ++__i)
3257 __elapsed += __i->value();
3264 if (__pos != __first && __ss < __pos[-1])
3266 if ((__ss + 1s) >= __pos[-1])
3267 return {
true, __elapsed};
3268 __elapsed -= __pos[-1].value();
3271 return {
false, __elapsed};
3276 seconds::rep __s = __ss.time_since_epoch().count();
3277 const seconds::rep* __first =
std::begin(__leaps);
3278 const seconds::rep* __last =
std::end(__leaps);
3281 if (__s > (__last[-1] + (__last - __first) + 1))
3282 return {
false,
seconds(__last - __first) };
3284 auto __pos = std::upper_bound(__first, __last, __s);
3285 seconds __elapsed{__pos - __first};
3289 __s -= __elapsed.count();
3291 if (__pos != __first && __s < __pos[-1])
3293 if ((__s + 1) >= __pos[-1])
3294 return {
true, __elapsed};
3298 return {
false, __elapsed};
3303 template<
typename _Duration>
3305 inline leap_second_info
3306 get_leap_second_info(
const utc_time<_Duration>& __ut)
3308 auto __s = chrono::duration_cast<seconds>(__ut.time_since_epoch());
3309 return __detail::__get_leap_second_info(sys_seconds(__s),
true);
3312 template<
typename _Duration>
3314 inline utc_time<common_type_t<_Duration, seconds>>
3315 utc_clock::from_sys(
const sys_time<_Duration>& __t)
3317 using _CDur = common_type_t<_Duration, seconds>;
3318 auto __s = chrono::time_point_cast<seconds>(__t);
3319 const auto __li = __detail::__get_leap_second_info(__s,
false);
3320 return utc_time<_CDur>{__t.time_since_epoch()} + __li.elapsed;
3328#if __glibcxx_chrono_cxx20 >= 202306
3331 template<
typename _Tp>
3332 concept __is_nothrow_copy_hashable =
requires(
const _Tp& __t) {
3333 {
hash<_Tp>{}(_Tp(__t)) }
noexcept -> same_as<size_t>;
3338 template<
typename _T1,
typename... _Ts>
3339 [[__gnu__::__always_inline__]]
3341 __pack_ints(_T1 __v1, _Ts... __vs)
3343 using _ResT =
decltype([] {
3344 constexpr size_t __tsize = (
sizeof(_T1) + ... +
sizeof(_Ts));
3345 if constexpr (__tsize <= 1)
3346 return static_cast<unsigned char>(0);
3347 else if constexpr (__tsize <= 2)
3348 return static_cast<__UINT16_TYPE__
>(0);
3349 else if constexpr (__tsize <= 4)
3350 return static_cast<__UINT32_TYPE__
>(0);
3351 else if constexpr (__tsize <= 8)
3352 return static_cast<__UINT64_TYPE__
>(0);
3354 static_assert(__tsize <= 8);
3358 ((__res = (__res << (
sizeof(_Ts) * __CHAR_BIT__) | _ResT(__vs))), ...);
3362 template<
typename _Tp>
3363 [[__gnu__::__always_inline__]]
3367 if constexpr (is_same_v<_Tp, year>)
3368 return static_cast<unsigned short>(
static_cast<int>(__val));
3369 else if constexpr (is_same_v<_Tp, month> || is_same_v<_Tp, day>)
3370 return static_cast<unsigned char>(
static_cast<unsigned>(__val));
3371 else if constexpr (is_same_v<_Tp, weekday>)
3372 return static_cast<unsigned char>(__val.c_encoding());
3373 else if constexpr (is_same_v<_Tp, weekday_indexed>)
3374 return __pack_ints(chrono::__as_int(__val.weekday()),
3375 static_cast<unsigned char>(__val.index()));
3376 else if constexpr (is_same_v<_Tp, weekday_last>)
3377 return chrono::__as_int(__val.weekday());
3379 static_assert(
false);
3382 template<
typename _Arg,
typename... _Args>
3384 __int_hash(_Arg __arg, _Args... __args)
3386 static_assert((is_integral_v<_Arg> && ... && is_integral_v<_Args>));
3389 using _Hasher = _Hash_impl;
3390 size_t __result = _Hasher::hash(__arg);
3391 ((__result = _Hasher::__hash_combine(__args, __result)), ...);
3395 template<
typename... _Tps>
3396 [[__gnu__::__always_inline__]]
3398 __hash(_Tps... __vals)
3400 if constexpr (
sizeof...(_Tps) == 1)
3401 return chrono::__int_hash(chrono::__as_int(__vals)...);
3404 auto __res = chrono::__pack_ints(chrono::__as_int(__vals)...);
3405 return chrono::__int_hash(__res);
3411 template<
typename _Rep,
typename _Period>
3412 requires __is_hash_enabled_for<_Rep>
3416 operator()(
const chrono::duration<_Rep, _Period>& __val)
const
3417 noexcept(__is_nothrow_copy_hashable<_Rep>)
3419 if constexpr (is_integral_v<_Rep>)
3420 return chrono::__int_hash(__val.count());
3422 return hash<_Rep>{}(__val.count());
3426 template<
typename _Rep,
typename _Period>
3432 template<
typename _Clock,
typename _Dur>
3433 requires __is_hash_enabled_for<_Dur>
3434 struct hash<
chrono::time_point<_Clock, _Dur>>
3437 operator()(
const chrono::time_point<_Clock, _Dur>& __val)
const
3438 noexcept(__is_nothrow_copy_hashable<_Dur>)
3439 {
return hash<_Dur>{}(__val.time_since_epoch()); }
3442 template<
typename _Clock,
typename _Dur>
3452 operator()(chrono::day __val)
const noexcept
3453 {
return chrono::__hash(__val); }
3461 operator()(chrono::month __val)
const noexcept
3462 {
return chrono::__hash(__val); }
3470 operator()(chrono::year __val)
const noexcept
3471 {
return chrono::__hash(__val); }
3479 operator()(chrono::weekday __val)
const noexcept
3480 {
return chrono::__hash(__val); }
3488 operator()(chrono::weekday_indexed __val)
const noexcept
3489 {
return chrono::__hash(__val); }
3497 operator()(chrono::weekday_last __val)
const noexcept
3498 {
return chrono::__hash(__val); }
3506 operator()(chrono::month_day __val)
const noexcept
3507 {
return chrono::__hash(__val.month(), __val.day()); }
3514 size_t operator()(chrono::month_day_last __val)
const noexcept
3515 {
return chrono::__hash(__val.month()); }
3523 operator()(chrono::month_weekday __val)
const noexcept
3524 {
return chrono::__hash(__val.month(), __val.weekday_indexed()); }
3532 operator()(chrono::month_weekday_last __val)
const noexcept
3533 {
return chrono::__hash(__val.month(), __val.weekday_last()); }
3541 operator()(chrono::year_month __val)
const noexcept
3542 {
return chrono::__hash(__val.year(), __val.month()); }
3550 operator()(chrono::year_month_day __val)
const noexcept
3551 {
return chrono::__hash(__val.year(), __val.month(), __val.day()); }
3559 operator()(chrono::year_month_day_last __val)
const noexcept
3560 {
return chrono::__hash(__val.year(), __val.month()); }
3568 operator()(chrono::year_month_weekday __val)
const noexcept
3570 return chrono::__hash(__val.year(), __val.month(),
3571 __val.weekday_indexed());
3580 operator()(chrono::year_month_weekday_last __val)
const noexcept
3582 return chrono::__hash(__val.year(), __val.month(),
3583 __val.weekday_last());
3588#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
3590 template<
typename _Duration,
typename _TimeZonePtr>
3591 requires __is_hash_enabled_for<
3592 typename chrono::zoned_time<_Duration, _TimeZonePtr>::duration>
3593 && __is_hash_enabled_for<_TimeZonePtr>
3594 struct hash<
chrono::zoned_time<_Duration, _TimeZonePtr>>
3597 using _ActualDuration =
3598 typename chrono::zoned_time<_Duration, _TimeZonePtr>::duration;
3602 operator()(
const chrono::zoned_time<_Duration, _TimeZonePtr>& __val)
const
3603 noexcept(__is_nothrow_copy_hashable<_ActualDuration>
3604 && __is_nothrow_copy_hashable<_TimeZonePtr>)
3606 const auto __iduration = [&] {
3607 const _ActualDuration __sd = __val.get_sys_time().time_since_epoch();
3608 if constexpr (is_integral_v<typename _ActualDuration::rep>)
3609 return __sd.count();
3611 return hash<_ActualDuration>{}(__sd);
3614 const auto __izone = [&] {
3615 const _TimeZonePtr __tz = __val.get_time_zone();
3616 if constexpr (is_same_v<_TimeZonePtr, const chrono::time_zone*>)
3617 return reinterpret_cast<uintptr_t
>(__tz);
3619 return hash<_TimeZonePtr>{}(__tz);
3622 return chrono::__int_hash(__iduration, __izone);
3626 template<
typename _Duration,
typename _TimeZonePtr>
3628 : __and_<__is_fast_hash<hash<
3629 typename chrono::zoned_time<_Duration, _TimeZonePtr>::duration>>,
3630 __is_fast_hash<hash<_TimeZonePtr>>>
3638 operator()(chrono::leap_second __val)
const noexcept
3640 return chrono::__int_hash(
3641 __val.date().time_since_epoch().count(),
3642 __val.value().count());
3649#ifdef __glibcxx_chrono_cxx20
3656#pragma GCC diagnostic push
3657#pragma GCC diagnostic ignored "-Wliteral-suffix"
3660 constexpr chrono::day
3661 operator""d(
unsigned long long __d)
noexcept
3662 {
return chrono::day{
static_cast<unsigned>(__d)}; }
3666 constexpr chrono::year
3667 operator""y(
unsigned long long __y)
noexcept
3668 {
return chrono::year{
static_cast<int>(__y)}; }
3669#pragma GCC diagnostic pop
3675_GLIBCXX_END_NAMESPACE_VERSION
3678#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