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
61#if __cpp_lib_chrono >= 201803L
68#if __glibcxx_chrono_cxx20 >= 202306L
72namespace std _GLIBCXX_VISIBILITY(default)
74_GLIBCXX_BEGIN_NAMESPACE_VERSION
91#ifdef __glibcxx_chrono_cxx20
95 template<
typename _Duration>
97 using local_seconds = local_time<seconds>;
98 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);
137 bool __recent_leap_second_info(leap_second_info&,
unsigned);
150 using rep = system_clock::rep;
151 using period = system_clock::period;
154 static constexpr bool is_steady =
false;
160 {
return from_sys(system_clock::now()); }
162 static time_point now() =
delete;
165 template<
typename _Duration>
167 static sys_time<common_type_t<_Duration, seconds>>
168 to_sys(
const utc_time<_Duration>& __t)
171 const auto __li = chrono::get_leap_second_info(__t);
172 sys_time<_CDur> __s{__t.time_since_epoch() - __li.elapsed};
173 if (__li.is_leap_second)
178 template<
typename _Duration>
180 static utc_time<common_type_t<_Duration, seconds>>
181 from_sys(
const sys_time<_Duration>& __t);
193 using rep = system_clock::rep;
194 using period = system_clock::period;
197 static constexpr bool is_steady =
false;
204 static time_point now() =
delete;
207 template<
typename _Duration>
209 static utc_time<common_type_t<_Duration, seconds>>
210 to_utc(
const tai_time<_Duration>& __t)
213 return utc_time<_CDur>{__t.time_since_epoch()} - 378691210s;
216 template<
typename _Duration>
218 static tai_time<common_type_t<_Duration, seconds>>
219 from_utc(
const utc_time<_Duration>& __t)
222 return tai_time<_CDur>{__t.time_since_epoch()} + 378691210s;
235 using rep = system_clock::rep;
236 using period = system_clock::period;
239 static constexpr bool is_steady =
false;
246 static time_point now() =
delete;
249 template<
typename _Duration>
251 static utc_time<common_type_t<_Duration, seconds>>
252 to_utc(
const gps_time<_Duration>& __t)
255 return utc_time<_CDur>{__t.time_since_epoch()} + 315964809s;
258 template<
typename _Duration>
260 static gps_time<common_type_t<_Duration, seconds>>
261 from_utc(
const utc_time<_Duration>& __t)
264 return gps_time<_CDur>{__t.time_since_epoch()} - 315964809s;
268 template<
typename _DestClock,
typename _SourceClock>
269 struct clock_time_conversion
274 template<
typename _Clock>
275 struct clock_time_conversion<_Clock, _Clock>
277 template<
typename _Duration>
278 time_point<_Clock, _Duration>
279 operator()(
const time_point<_Clock, _Duration>& __t)
const
286 template<
typename _Duration>
288 operator()(
const sys_time<_Duration>& __t)
const
295 template<
typename _Duration>
297 operator()(
const utc_time<_Duration>& __t)
const
306 template<
typename _Duration>
307 utc_time<common_type_t<_Duration, seconds>>
308 operator()(
const sys_time<_Duration>& __t)
const
309 {
return utc_clock::from_sys(__t); }
315 template<
typename _Duration>
316 sys_time<common_type_t<_Duration, seconds>>
317 operator()(
const utc_time<_Duration>& __t)
const
318 {
return utc_clock::to_sys(__t); }
322 template<
typename _Tp,
typename _Clock>
323 inline constexpr bool __is_time_point_for_v =
false;
325 template<
typename _Clock,
typename _Duration>
326 inline constexpr bool
327 __is_time_point_for_v<time_point<_Clock, _Duration>, _Clock> =
true;
332 template<
typename _SourceClock>
333 struct clock_time_conversion<
system_clock, _SourceClock>
335 template<
typename _Duration,
typename _Src = _SourceClock>
337 operator()(
const time_point<_SourceClock, _Duration>& __t)
const
338 ->
decltype(_Src::to_sys(__t))
340 using _Ret =
decltype(_SourceClock::to_sys(__t));
341 static_assert(__is_time_point_for_v<_Ret, system_clock>);
342 return _SourceClock::to_sys(__t);
346 template<
typename _DestClock>
349 template<
typename _Duration,
typename _Dest = _DestClock>
351 operator()(
const sys_time<_Duration>& __t)
const
352 ->
decltype(_Dest::from_sys(__t))
354 using _Ret =
decltype(_DestClock::from_sys(__t));
355 static_assert(__is_time_point_for_v<_Ret, _DestClock>);
356 return _DestClock::from_sys(__t);
362 template<
typename _SourceClock>
363 struct clock_time_conversion<
utc_clock, _SourceClock>
365 template<
typename _Duration,
typename _Src = _SourceClock>
367 operator()(
const time_point<_SourceClock, _Duration>& __t)
const
368 ->
decltype(_Src::to_utc(__t))
370 using _Ret =
decltype(_SourceClock::to_utc(__t));
371 static_assert(__is_time_point_for_v<_Ret, utc_clock>);
372 return _SourceClock::to_utc(__t);
376 template<
typename _DestClock>
377 struct clock_time_conversion<_DestClock,
utc_clock>
379 template<
typename _Duration,
typename _Dest = _DestClock>
381 operator()(
const utc_time<_Duration>& __t)
const
382 ->
decltype(_Dest::from_utc(__t))
384 using _Ret =
decltype(_DestClock::from_utc(__t));
385 static_assert(__is_time_point_for_v<_Ret, _DestClock>);
386 return _DestClock::from_utc(__t);
393 template<
typename _DestClock,
typename _SourceClock,
typename _Duration>
394 concept __clock_convs
395 =
requires (
const time_point<_SourceClock, _Duration>& __t) {
396 clock_time_conversion<_DestClock, _SourceClock>{}(__t);
399 template<
typename _DestClock,
typename _SourceClock,
typename _Duration>
400 concept __clock_convs_sys
401 =
requires (
const time_point<_SourceClock, _Duration>& __t) {
402 clock_time_conversion<_DestClock, system_clock>{}(
403 clock_time_conversion<system_clock, _SourceClock>{}(__t));
406 template<
typename _DestClock,
typename _SourceClock,
typename _Duration>
407 concept __clock_convs_utc
408 =
requires (
const time_point<_SourceClock, _Duration>& __t) {
409 clock_time_conversion<_DestClock, utc_clock>{}(
410 clock_time_conversion<utc_clock, _SourceClock>{}(__t));
413 template<
typename _DestClock,
typename _SourceClock,
typename _Duration>
414 concept __clock_convs_sys_utc
415 =
requires (
const time_point<_SourceClock, _Duration>& __t) {
416 clock_time_conversion<_DestClock, utc_clock>{}(
417 clock_time_conversion<utc_clock, system_clock>{}(
418 clock_time_conversion<system_clock, _SourceClock>{}(__t)));
421 template<
typename _DestClock,
typename _SourceClock,
typename _Duration>
422 concept __clock_convs_utc_sys
423 =
requires (
const time_point<_SourceClock, _Duration>& __t) {
424 clock_time_conversion<_DestClock, system_clock>{}(
425 clock_time_conversion<system_clock, utc_clock>{}(
426 clock_time_conversion<utc_clock, _SourceClock>{}(__t)));
432 template<
typename _DestClock,
typename _SourceClock,
typename _Duration>
436 requires __detail::__clock_convs<_DestClock, _SourceClock, _Duration>
437 || __detail::__clock_convs_sys<_DestClock, _SourceClock, _Duration>
438 || __detail::__clock_convs_utc<_DestClock, _SourceClock, _Duration>
439 || __detail::__clock_convs_sys_utc<_DestClock, _SourceClock, _Duration>
440 || __detail::__clock_convs_utc_sys<_DestClock, _SourceClock, _Duration>
442 constexpr bool __direct
443 = __detail::__clock_convs<_DestClock, _SourceClock, _Duration>;
444 if constexpr (__direct)
446 return clock_time_conversion<_DestClock, _SourceClock>{}(__t);
450 constexpr bool __convert_via_sys_clock
451 = __detail::__clock_convs_sys<_DestClock, _SourceClock, _Duration>;
452 constexpr bool __convert_via_utc_clock
453 = __detail::__clock_convs_utc<_DestClock, _SourceClock, _Duration>;
454 if constexpr (__convert_via_sys_clock)
456 static_assert(!__convert_via_utc_clock,
457 "clock_cast requires a unique best conversion, but "
458 "conversion is possible via system_clock and also via"
460 return clock_time_conversion<_DestClock, system_clock>{}(
461 clock_time_conversion<system_clock, _SourceClock>{}(__t));
463 else if constexpr (__convert_via_utc_clock)
465 return clock_time_conversion<_DestClock, utc_clock>{}(
466 clock_time_conversion<utc_clock, _SourceClock>{}(__t));
470 constexpr bool __convert_via_sys_and_utc_clocks
471 = __detail::__clock_convs_sys_utc<_DestClock,
475 if constexpr (__convert_via_sys_and_utc_clocks)
477 constexpr bool __convert_via_utc_and_sys_clocks
478 = __detail::__clock_convs_utc_sys<_DestClock,
481 static_assert(!__convert_via_utc_and_sys_clocks,
482 "clock_cast requires a unique best conversion, but "
483 "conversion is possible via system_clock followed by "
484 "utc_clock, and also via utc_clock followed by "
486 return clock_time_conversion<_DestClock, utc_clock>{}(
487 clock_time_conversion<utc_clock, system_clock>{}(
488 clock_time_conversion<system_clock, _SourceClock>{}(__t)));
492 return clock_time_conversion<_DestClock, system_clock>{}(
493 clock_time_conversion<system_clock, utc_clock>{}(
494 clock_time_conversion<utc_clock, _SourceClock>{}(__t)));
507 class weekday_indexed;
510 class month_day_last;
512 class month_weekday_last;
514 class year_month_day;
515 class year_month_day_last;
516 class year_month_weekday;
517 class year_month_weekday_last;
521 explicit last_spec() =
default;
523 friend constexpr month_day_last
526 friend constexpr month_day_last
530 inline constexpr last_spec last{};
536 template <
unsigned __d,
typename _Tp>
541 auto constexpr __a = _Up(-1) - _Up(255 + __d - 2);
542 auto constexpr __b = _Up(__d * (__a / __d) - 1);
544 return _Up(-1) - __b;
550 template <
unsigned __d,
typename _Tp>
552 __add_modulo(
unsigned __x, _Tp __y)
564 auto const __offset = __y >= 0 ? _Up(0) : __modulo_offset<__d, _Tp>();
565 return (__x + _Up(__y) - __offset) % __d;
569 template <
unsigned __d,
typename _Tp>
571 __sub_modulo(
unsigned __x, _Tp __y)
574 auto const __offset = __y <= 0 ? _Up(0) : __modulo_offset<__d, _Tp>();
575 return (__x - _Up(__y) - __offset) % __d;
578 inline constexpr unsigned __days_per_month[12]
579 = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
594 day(
unsigned __d) noexcept
599 operator++() noexcept
606 operator++(
int)
noexcept
614 operator--() noexcept
621 operator--(
int)
noexcept
629 operator+=(
const days& __d)
noexcept
636 operator-=(
const days& __d)
noexcept
643 operator unsigned() const noexcept
648 {
return 1 <= _M_d && _M_d <= 31; }
650 friend constexpr bool
651 operator==(
const day& __x,
const day& __y)
noexcept
652 {
return unsigned{__x} ==
unsigned{__y}; }
654 friend constexpr strong_ordering
655 operator<=>(
const day& __x,
const day& __y)
noexcept
656 {
return unsigned{__x} <=>
unsigned{__y}; }
659 operator+(
const day& __x,
const days& __y)
noexcept
660 {
return day(
unsigned{__x} + __y.count()); }
663 operator+(
const days& __x,
const day& __y)
noexcept
664 {
return __y + __x; }
667 operator-(
const day& __x,
const days& __y)
noexcept
668 {
return __x + -__y; }
670 friend constexpr days
671 operator-(
const day& __x,
const day& __y)
noexcept
672 {
return days{int(
unsigned{__x}) -
int(
unsigned{__y})}; }
674 friend constexpr month_day
675 operator/(
const month& __m,
const day& __d)
noexcept;
677 friend constexpr month_day
678 operator/(
int __m,
const day& __d)
noexcept;
680 friend constexpr month_day
681 operator/(
const day& __d,
const month& __m)
noexcept;
683 friend constexpr month_day
684 operator/(
const day& __d,
int __m)
noexcept;
686 friend constexpr year_month_day
687 operator/(
const year_month& __ym,
const day& __d)
noexcept;
701 month(
unsigned __m) noexcept
706 operator++() noexcept
713 operator++(
int)
noexcept
721 operator--() noexcept
728 operator--(
int)
noexcept
736 operator+=(
const months& __m)
noexcept
743 operator-=(
const months& __m)
noexcept
750 operator unsigned() const noexcept
755 {
return 1 <= _M_m && _M_m <= 12; }
757 friend constexpr bool
758 operator==(
const month& __x,
const month& __y)
noexcept
759 {
return unsigned{__x} ==
unsigned{__y}; }
761 friend constexpr strong_ordering
762 operator<=>(
const month& __x,
const month& __y)
noexcept
763 {
return unsigned{__x} <=>
unsigned{__y}; }
765 friend constexpr month
766 operator+(
const month& __x,
const months& __y)
noexcept
770 return month{1 + __detail::__add_modulo<12>(
771 unsigned{__x} + 11, __y.count())};
774 friend constexpr month
775 operator+(
const months& __x,
const month& __y)
noexcept
776 {
return __y + __x; }
778 friend constexpr month
779 operator-(
const month& __x,
const months& __y)
noexcept
783 return month{1 + __detail::__sub_modulo<12>(
784 unsigned{__x} + 11, __y.count())};
788 operator-(
const month& __x,
const month& __y)
noexcept
790 const auto __dm = int(
unsigned(__x)) - int(
unsigned(__y));
791 return months{__dm < 0 ? 12 + __dm : __dm};
794 friend constexpr year_month
795 operator/(
const year& __y,
const month& __m)
noexcept;
797 friend constexpr month_day
798 operator/(
const month& __m,
int __d)
noexcept;
800 friend constexpr month_day_last
801 operator/(
const month& __m, last_spec)
noexcept;
803 friend constexpr month_day_last
804 operator/(last_spec,
const month& __m)
noexcept;
806 friend constexpr month_weekday
807 operator/(
const month& __m,
const weekday_indexed& __wdi)
noexcept;
809 friend constexpr month_weekday
810 operator/(
const weekday_indexed& __wdi,
const month& __m)
noexcept;
812 friend constexpr month_weekday_last
813 operator/(
const month& __m,
const weekday_last& __wdl)
noexcept;
815 friend constexpr month_weekday_last
816 operator/(
const weekday_last& __wdl,
const month& __m)
noexcept;
819 inline constexpr month January{1};
820 inline constexpr month February{2};
821 inline constexpr month March{3};
822 inline constexpr month April{4};
823 inline constexpr month May{5};
824 inline constexpr month June{6};
825 inline constexpr month July{7};
826 inline constexpr month August{8};
827 inline constexpr month September{9};
828 inline constexpr month October{10};
829 inline constexpr month November{11};
830 inline constexpr month December{12};
843 year(
int __y) noexcept
844 : _M_y{
static_cast<short>(__y)}
847 static constexpr year
849 {
return year{-32767}; }
851 static constexpr year
853 {
return year{32767}; }
856 operator++() noexcept
863 operator++(
int)
noexcept
871 operator--() noexcept
878 operator--(
int)
noexcept
886 operator+=(
const years& __y)
noexcept
893 operator-=(
const years& __y)
noexcept
900 operator+() const noexcept
904 operator-() const noexcept
905 {
return year{-_M_y}; }
908 is_leap() const noexcept
916 const auto __y =
static_cast<uint32_t
>(_M_y) + 32800u;
917 return ((__y * 1073750999u) & 3221352463u) <= 126976u;
921 operator int() const noexcept
926 {
return min()._M_y <= _M_y && _M_y <= max()._M_y; }
928 friend constexpr bool
929 operator==(
const year& __x,
const year& __y)
noexcept
930 {
return int{__x} ==
int{__y}; }
932 friend constexpr strong_ordering
933 operator<=>(
const year& __x,
const year& __y)
noexcept
934 {
return int{__x} <=>
int{__y}; }
936 friend constexpr year
937 operator+(
const year& __x,
const years& __y)
noexcept
938 {
return year{
int{__x} +
static_cast<int>(__y.count())}; }
940 friend constexpr year
941 operator+(
const years& __x,
const year& __y)
noexcept
942 {
return __y + __x; }
944 friend constexpr year
945 operator-(
const year& __x,
const years& __y)
noexcept
946 {
return __x + -__y; }
948 friend constexpr years
949 operator-(
const year& __x,
const year& __y)
noexcept
950 {
return years{
int{__x} -
int{__y}}; }
952 friend constexpr year_month
953 operator/(
const year& __y,
int __m)
noexcept;
955 friend constexpr year_month_day
956 operator/(
const year& __y,
const month_day& __md)
noexcept;
958 friend constexpr year_month_day
959 operator/(
const month_day& __md,
const year& __y)
noexcept;
961 friend constexpr year_month_day_last
962 operator/(
const year& __y,
const month_day_last& __mdl)
noexcept;
964 friend constexpr year_month_day_last
965 operator/(
const month_day_last& __mdl,
const year& __y)
noexcept;
967 friend constexpr year_month_weekday
968 operator/(
const year& __y,
const month_weekday& __mwd)
noexcept;
970 friend constexpr year_month_weekday
971 operator/(
const month_weekday& __mwd,
const year& __y)
noexcept;
973 friend constexpr year_month_weekday_last
974 operator/(
const year& __y,
const month_weekday_last& __mwdl)
noexcept;
976 friend constexpr year_month_weekday_last
977 operator/(
const month_weekday_last& __mwdl,
const year& __y)
noexcept;
987 static constexpr weekday
988 _S_from_days(
const days& __d)
990 return weekday{__detail::__add_modulo<7>(4, __d.count())};
997 weekday(
unsigned __wd) noexcept
998 : _M_wd(__wd == 7 ? 0 : __wd)
1002 weekday(
const sys_days& __dp) noexcept
1003 : weekday{_S_from_days(__dp.time_since_epoch())}
1007 weekday(
const local_days& __dp) noexcept
1008 : weekday{sys_days{__dp.time_since_epoch()}}
1012 operator++() noexcept
1019 operator++(
int)
noexcept
1027 operator--() noexcept
1034 operator--(
int)
noexcept
1042 operator+=(
const days& __d)
noexcept
1044 *
this = *
this + __d;
1049 operator-=(
const days& __d)
noexcept
1051 *
this = *
this - __d;
1056 c_encoding() const noexcept
1060 iso_encoding() const noexcept
1061 {
return _M_wd == 0u ? 7u : _M_wd; }
1065 {
return _M_wd <= 6; }
1067 constexpr weekday_indexed
1068 operator[](
unsigned __index)
const noexcept;
1070 constexpr weekday_last
1071 operator[](last_spec)
const noexcept;
1073 friend constexpr bool
1074 operator==(
const weekday& __x,
const weekday& __y)
noexcept
1075 {
return __x._M_wd == __y._M_wd; }
1077 friend constexpr weekday
1078 operator+(
const weekday& __x,
const days& __y)
noexcept
1080 return weekday{__detail::__add_modulo<7>(__x._M_wd, __y.count())};
1083 friend constexpr weekday
1084 operator+(
const days& __x,
const weekday& __y)
noexcept
1085 {
return __y + __x; }
1087 friend constexpr weekday
1088 operator-(
const weekday& __x,
const days& __y)
noexcept
1090 return weekday{__detail::__sub_modulo<7>(__x._M_wd, __y.count())};
1093 friend constexpr days
1094 operator-(
const weekday& __x,
const weekday& __y)
noexcept
1096 const auto __n = __x.c_encoding() - __y.c_encoding();
1097 return static_cast<int>(__n) >= 0 ?
days{__n} :
days{__n + 7};
1101 inline constexpr weekday Sunday{0};
1102 inline constexpr weekday Monday{1};
1103 inline constexpr weekday Tuesday{2};
1104 inline constexpr weekday Wednesday{3};
1105 inline constexpr weekday Thursday{4};
1106 inline constexpr weekday Friday{5};
1107 inline constexpr weekday Saturday{6};
1111 class weekday_indexed
1114 chrono::weekday _M_wd;
1115 unsigned char _M_index;
1118 weekday_indexed() =
default;
1121 weekday_indexed(
const chrono::weekday& __wd,
unsigned __index) noexcept
1122 : _M_wd(__wd), _M_index(__index)
1125 constexpr chrono::weekday
1126 weekday() const noexcept
1130 index() const noexcept
1131 {
return _M_index; };
1135 {
return _M_wd.ok() && 1 <= _M_index && _M_index <= 5; }
1137 friend constexpr bool
1138 operator==(
const weekday_indexed& __x,
const weekday_indexed& __y)
noexcept
1139 {
return __x.weekday() == __y.weekday() && __x.index() == __y.index(); }
1141 friend constexpr month_weekday
1142 operator/(
const month& __m,
const weekday_indexed& __wdi)
noexcept;
1144 friend constexpr month_weekday
1145 operator/(
int __m,
const weekday_indexed& __wdi)
noexcept;
1147 friend constexpr month_weekday
1148 operator/(
const weekday_indexed& __wdi,
const month& __m)
noexcept;
1150 friend constexpr month_weekday
1151 operator/(
const weekday_indexed& __wdi,
int __m)
noexcept;
1153 friend constexpr year_month_weekday
1154 operator/(
const year_month& __ym,
const weekday_indexed& __wdi)
noexcept;
1157 constexpr weekday_indexed
1158 weekday::operator[](
unsigned __index)
const noexcept
1159 {
return {*
this, __index}; }
1166 chrono::weekday _M_wd;
1170 weekday_last(
const chrono::weekday& __wd) noexcept
1174 constexpr chrono::weekday
1175 weekday() const noexcept
1180 {
return _M_wd.ok(); }
1182 friend constexpr bool
1183 operator==(
const weekday_last& __x,
const weekday_last& __y)
noexcept
1184 {
return __x.weekday() == __y.weekday(); }
1186 friend constexpr month_weekday_last
1187 operator/(
int __m,
const weekday_last& __wdl)
noexcept;
1189 friend constexpr month_weekday_last
1190 operator/(
const weekday_last& __wdl,
int __m)
noexcept;
1192 friend constexpr year_month_weekday_last
1193 operator/(
const year_month& __ym,
const weekday_last& __wdl)
noexcept;
1196 constexpr weekday_last
1197 weekday::operator[](last_spec)
const noexcept
1198 {
return weekday_last{*
this}; }
1209 month_day() =
default;
1212 month_day(
const chrono::month& __m,
const chrono::day& __d) noexcept
1213 : _M_m{__m}, _M_d{__d}
1216 constexpr chrono::month
1217 month() const noexcept
1220 constexpr chrono::day
1221 day() const noexcept
1228 && 1u <= unsigned(_M_d)
1229 && unsigned(_M_d) <= __detail::__days_per_month[unsigned(_M_m) - 1];
1232 friend constexpr bool
1233 operator==(
const month_day& __x,
const month_day& __y)
noexcept
1234 {
return __x.month() == __y.month() && __x.day() == __y.day(); }
1236 friend constexpr strong_ordering
1237 operator<=>(
const month_day& __x,
const month_day& __y)
noexcept
1240 friend constexpr month_day
1241 operator/(
const chrono::month& __m,
const chrono::day& __d)
noexcept
1242 {
return {__m, __d}; }
1244 friend constexpr month_day
1245 operator/(
const chrono::month& __m,
int __d)
noexcept
1246 {
return {__m, chrono::day(
unsigned(__d))}; }
1248 friend constexpr month_day
1249 operator/(
int __m,
const chrono::day& __d)
noexcept
1250 {
return {chrono::month(
unsigned(__m)), __d}; }
1252 friend constexpr month_day
1253 operator/(
const chrono::day& __d,
const chrono::month& __m)
noexcept
1254 {
return {__m, __d}; }
1256 friend constexpr month_day
1257 operator/(
const chrono::day& __d,
int __m)
noexcept
1258 {
return {chrono::month(
unsigned(__m)), __d}; }
1260 friend constexpr year_month_day
1261 operator/(
int __y,
const month_day& __md)
noexcept;
1263 friend constexpr year_month_day
1264 operator/(
const month_day& __md,
int __y)
noexcept;
1269 class month_day_last
1276 month_day_last(
const chrono::month& __m) noexcept
1280 constexpr chrono::month
1281 month() const noexcept
1286 {
return _M_m.ok(); }
1288 friend constexpr bool
1289 operator==(
const month_day_last& __x,
const month_day_last& __y)
noexcept
1290 {
return __x.month() == __y.month(); }
1292 friend constexpr strong_ordering
1293 operator<=>(
const month_day_last& __x,
const month_day_last& __y)
noexcept
1296 friend constexpr month_day_last
1297 operator/(
const chrono::month& __m, last_spec)
noexcept
1298 {
return month_day_last{__m}; }
1300 friend constexpr month_day_last
1301 operator/(
int __m, last_spec)
noexcept
1302 {
return chrono::month(
unsigned(__m)) / last; }
1304 friend constexpr month_day_last
1305 operator/(last_spec,
const chrono::month& __m)
noexcept
1306 {
return __m / last; }
1308 friend constexpr month_day_last
1309 operator/(last_spec,
int __m)
noexcept
1310 {
return __m / last; }
1312 friend constexpr year_month_day_last
1313 operator/(
int __y,
const month_day_last& __mdl)
noexcept;
1315 friend constexpr year_month_day_last
1316 operator/(
const month_day_last& __mdl,
int __y)
noexcept;
1325 chrono::weekday_indexed _M_wdi;
1329 month_weekday(
const chrono::month& __m,
1330 const chrono::weekday_indexed& __wdi) noexcept
1331 : _M_m{__m}, _M_wdi{__wdi}
1334 constexpr chrono::month
1335 month() const noexcept
1338 constexpr chrono::weekday_indexed
1339 weekday_indexed() const noexcept
1344 {
return _M_m.ok() && _M_wdi.ok(); }
1346 friend constexpr bool
1347 operator==(
const month_weekday& __x,
const month_weekday& __y)
noexcept
1349 return __x.month() == __y.month()
1350 && __x.weekday_indexed() == __y.weekday_indexed();
1353 friend constexpr month_weekday
1354 operator/(
const chrono::month& __m,
1355 const chrono::weekday_indexed& __wdi)
noexcept
1356 {
return {__m, __wdi}; }
1358 friend constexpr month_weekday
1359 operator/(
int __m,
const chrono::weekday_indexed& __wdi)
noexcept
1360 {
return chrono::month(
unsigned(__m)) / __wdi; }
1362 friend constexpr month_weekday
1363 operator/(
const chrono::weekday_indexed& __wdi,
1364 const chrono::month& __m)
noexcept
1365 {
return __m / __wdi; }
1367 friend constexpr month_weekday
1368 operator/(
const chrono::weekday_indexed& __wdi,
int __m)
noexcept
1369 {
return __m / __wdi; }
1371 friend constexpr year_month_weekday
1372 operator/(
int __y,
const month_weekday& __mwd)
noexcept;
1374 friend constexpr year_month_weekday
1375 operator/(
const month_weekday& __mwd,
int __y)
noexcept;
1380 class month_weekday_last
1384 chrono::weekday_last _M_wdl;
1388 month_weekday_last(
const chrono::month& __m,
1389 const chrono::weekday_last& __wdl) noexcept
1390 :_M_m{__m}, _M_wdl{__wdl}
1393 constexpr chrono::month
1394 month() const noexcept
1397 constexpr chrono::weekday_last
1398 weekday_last() const noexcept
1403 {
return _M_m.ok() && _M_wdl.ok(); }
1405 friend constexpr bool
1406 operator==(
const month_weekday_last& __x,
1407 const month_weekday_last& __y)
noexcept
1409 return __x.month() == __y.month()
1410 && __x.weekday_last() == __y.weekday_last();
1413 friend constexpr month_weekday_last
1414 operator/(
const chrono::month& __m,
1415 const chrono::weekday_last& __wdl)
noexcept
1416 {
return {__m, __wdl}; }
1418 friend constexpr month_weekday_last
1419 operator/(
int __m,
const chrono::weekday_last& __wdl)
noexcept
1420 {
return chrono::month(
unsigned(__m)) / __wdl; }
1422 friend constexpr month_weekday_last
1423 operator/(
const chrono::weekday_last& __wdl,
1424 const chrono::month& __m)
noexcept
1425 {
return __m / __wdl; }
1427 friend constexpr month_weekday_last
1428 operator/(
const chrono::weekday_last& __wdl,
int __m)
noexcept
1429 {
return chrono::month(
unsigned(__m)) / __wdl; }
1431 friend constexpr year_month_weekday_last
1432 operator/(
int __y,
const month_weekday_last& __mwdl)
noexcept;
1434 friend constexpr year_month_weekday_last
1435 operator/(
const month_weekday_last& __mwdl,
int __y)
noexcept;
1455 using __months_years_conversion_disambiguator = void;
1466 year_month() =
default;
1469 year_month(
const chrono::year& __y,
const chrono::month& __m) noexcept
1470 : _M_y{__y}, _M_m{__m}
1473 constexpr chrono::year
1474 year() const noexcept
1477 constexpr chrono::month
1478 month() const noexcept
1481 template<
typename = __detail::__months_years_conversion_disambiguator>
1482 constexpr year_month&
1483 operator+=(
const months& __dm)
noexcept
1485 *
this = *
this + __dm;
1489 template<
typename = __detail::__months_years_conversion_disambiguator>
1490 constexpr year_month&
1491 operator-=(
const months& __dm)
noexcept
1493 *
this = *
this - __dm;
1497 constexpr year_month&
1498 operator+=(
const years& __dy)
noexcept
1500 *
this = *
this + __dy;
1504 constexpr year_month&
1505 operator-=(
const years& __dy)
noexcept
1507 *
this = *
this - __dy;
1513 {
return _M_y.ok() && _M_m.ok(); }
1515 friend constexpr bool
1516 operator==(
const year_month& __x,
const year_month& __y)
noexcept
1517 {
return __x.year() == __y.year() && __x.month() == __y.month(); }
1519 friend constexpr strong_ordering
1520 operator<=>(
const year_month& __x,
const year_month& __y)
noexcept
1523 template<
typename = __detail::__months_years_conversion_disambiguator>
1524 friend constexpr year_month
1525 operator+(
const year_month& __ym,
const months& __dm)
noexcept
1528 auto __m = __ym.month() + __dm;
1529 auto __i = int(
unsigned(__ym.month())) - 1 + __dm.count();
1531 ? __ym.year() +
years{(__i - 11) / 12}
1532 : __ym.year() +
years{__i / 12});
1536 template<
typename = __detail::__months_years_conversion_disambiguator>
1537 friend constexpr year_month
1538 operator+(
const months& __dm,
const year_month& __ym)
noexcept
1539 {
return __ym + __dm; }
1541 template<
typename = __detail::__months_years_conversion_disambiguator>
1542 friend constexpr year_month
1543 operator-(
const year_month& __ym,
const months& __dm)
noexcept
1544 {
return __ym + -__dm; }
1547 operator-(
const year_month& __x,
const year_month& __y)
noexcept
1549 return (__x.year() - __y.year()
1550 +
months{static_cast<int>(unsigned{__x.month()})
1551 -
static_cast<int>(
unsigned{__y.month()})});
1554 friend constexpr year_month
1556 {
return (__ym.year() + __dy) / __ym.month(); }
1558 friend constexpr year_month
1560 {
return __ym + __dy; }
1562 friend constexpr year_month
1564 {
return __ym + -__dy; }
1566 friend constexpr year_month
1567 operator/(
const chrono::year& __y,
const chrono::month& __m)
noexcept
1568 {
return {__y, __m}; }
1570 friend constexpr year_month
1571 operator/(
const chrono::year& __y,
int __m)
noexcept
1572 {
return {__y, chrono::month(
unsigned(__m))}; }
1574 friend constexpr year_month_day
1575 operator/(
const year_month& __ym,
int __d)
noexcept;
1577 friend constexpr year_month_day_last
1578 operator/(
const year_month& __ym, last_spec)
noexcept;
1583 class year_month_day
1590 static constexpr year_month_day _S_from_days(
const days& __dp)
noexcept;
1592 constexpr days _M_days_since_epoch() const noexcept;
1595 year_month_day() = default;
1598 year_month_day(const chrono::year& __y, const chrono::month& __m,
1599 const chrono::day& __d) noexcept
1600 : _M_y{__y}, _M_m{__m}, _M_d{__d}
1604 year_month_day(
const year_month_day_last& __ymdl)
noexcept;
1607 year_month_day(
const sys_days& __dp) noexcept
1608 : year_month_day(_S_from_days(__dp.time_since_epoch()))
1612 year_month_day(
const local_days& __dp) noexcept
1613 : year_month_day(sys_days{__dp.time_since_epoch()})
1616 template<
typename = __detail::__months_years_conversion_disambiguator>
1617 constexpr year_month_day&
1618 operator+=(
const months& __m)
noexcept
1620 *
this = *
this + __m;
1624 template<
typename = __detail::__months_years_conversion_disambiguator>
1625 constexpr year_month_day&
1626 operator-=(
const months& __m)
noexcept
1628 *
this = *
this - __m;
1632 constexpr year_month_day&
1633 operator+=(
const years& __y)
noexcept
1635 *
this = *
this + __y;
1639 constexpr year_month_day&
1640 operator-=(
const years& __y)
noexcept
1642 *
this = *
this - __y;
1646 constexpr chrono::year
1647 year() const noexcept
1650 constexpr chrono::month
1651 month() const noexcept
1654 constexpr chrono::day
1655 day() const noexcept
1659 operator sys_days() const noexcept
1660 {
return sys_days{_M_days_since_epoch()}; }
1663 operator local_days() const noexcept
1664 {
return local_days{sys_days{*
this}.time_since_epoch()}; }
1666 constexpr bool ok() const noexcept;
1668 friend constexpr
bool
1669 operator==(const year_month_day& __x, const year_month_day& __y) noexcept
1671 return __x.year() == __y.year()
1672 && __x.month() == __y.month()
1673 && __x.day() == __y.day();
1676 friend constexpr strong_ordering
1677 operator<=>(
const year_month_day& __x,
const year_month_day& __y)
noexcept
1680 template<
typename = __detail::__months_years_conversion_disambiguator>
1681 friend constexpr year_month_day
1682 operator+(
const year_month_day& __ymd,
const months& __dm)
noexcept
1683 {
return (__ymd.year() / __ymd.month() + __dm) / __ymd.day(); }
1685 template<
typename = __detail::__months_years_conversion_disambiguator>
1686 friend constexpr year_month_day
1687 operator+(
const months& __dm,
const year_month_day& __ymd)
noexcept
1688 {
return __ymd + __dm; }
1690 friend constexpr year_month_day
1691 operator+(
const year_month_day& __ymd,
const years& __dy)
noexcept
1692 {
return (__ymd.year() + __dy) / __ymd.month() / __ymd.day(); }
1694 friend constexpr year_month_day
1695 operator+(
const years& __dy,
const year_month_day& __ymd)
noexcept
1696 {
return __ymd + __dy; }
1698 template<
typename = __detail::__months_years_conversion_disambiguator>
1699 friend constexpr year_month_day
1700 operator-(
const year_month_day& __ymd,
const months& __dm)
noexcept
1701 {
return __ymd + -__dm; }
1703 friend constexpr year_month_day
1704 operator-(
const year_month_day& __ymd,
const years& __dy)
noexcept
1705 {
return __ymd + -__dy; }
1707 friend constexpr year_month_day
1708 operator/(
const year_month& __ym,
const chrono::day& __d)
noexcept
1709 {
return {__ym.year(), __ym.month(), __d}; }
1711 friend constexpr year_month_day
1712 operator/(
const year_month& __ym,
int __d)
noexcept
1713 {
return __ym / chrono::day{unsigned(__d)}; }
1715 friend constexpr year_month_day
1716 operator/(
const chrono::year& __y,
const month_day& __md)
noexcept
1717 {
return __y / __md.month() / __md.day(); }
1719 friend constexpr year_month_day
1720 operator/(
int __y,
const month_day& __md)
noexcept
1721 {
return chrono::year{__y} / __md; }
1723 friend constexpr year_month_day
1724 operator/(
const month_day& __md,
const chrono::year& __y)
noexcept
1725 {
return __y / __md; }
1727 friend constexpr year_month_day
1728 operator/(
const month_day& __md,
int __y)
noexcept
1729 {
return chrono::year(__y) / __md; }
1736 constexpr year_month_day
1737 year_month_day::_S_from_days(
const days& __dp)
noexcept
1739 constexpr auto __z2 =
static_cast<uint32_t
>(-1468000);
1740 constexpr auto __r2_e3 =
static_cast<uint32_t
>(536895458);
1742 const auto __r0 =
static_cast<uint32_t
>(__dp.count()) + __r2_e3;
1744 const auto __n1 = 4 * __r0 + 3;
1745 const auto __q1 = __n1 / 146097;
1746 const auto __r1 = __n1 % 146097 / 4;
1748 constexpr auto __p32 =
static_cast<uint64_t
>(1) << 32;
1749 const auto __n2 = 4 * __r1 + 3;
1750 const auto __u2 =
static_cast<uint64_t
>(2939745) * __n2;
1751 const auto __q2 =
static_cast<uint32_t
>(__u2 / __p32);
1752 const auto __r2 =
static_cast<uint32_t
>(__u2 % __p32) / 2939745 / 4;
1754 constexpr auto __p16 =
static_cast<uint32_t
>(1) << 16;
1755 const auto __n3 = 2141 * __r2 + 197913;
1756 const auto __q3 = __n3 / __p16;
1757 const auto __r3 = __n3 % __p16 / 2141;
1759 const auto __y0 = 100 * __q1 + __q2;
1760 const auto __m0 = __q3;
1761 const auto __d0 = __r3;
1763 const auto __j = __r2 >= 306;
1764 const auto __y1 = __y0 + __j;
1765 const auto __m1 = __j ? __m0 - 12 : __m0;
1766 const auto __d1 = __d0 + 1;
1768 return year_month_day{chrono::year{
static_cast<int>(__y1 + __z2)},
1769 chrono::month{__m1}, chrono::day{__d1}};
1777 year_month_day::_M_days_since_epoch() const noexcept
1779 auto constexpr __z2 =
static_cast<uint32_t
>(-1468000);
1780 auto constexpr __r2_e3 =
static_cast<uint32_t
>(536895458);
1782 const auto __y1 =
static_cast<uint32_t
>(
static_cast<int>(_M_y)) - __z2;
1783 const auto __m1 =
static_cast<uint32_t
>(
static_cast<unsigned>(_M_m));
1784 const auto __d1 =
static_cast<uint32_t
>(
static_cast<unsigned>(_M_d));
1786 const auto __j =
static_cast<uint32_t
>(__m1 < 3);
1787 const auto __y0 = __y1 - __j;
1788 const auto __m0 = __j ? __m1 + 12 : __m1;
1789 const auto __d0 = __d1 - 1;
1791 const auto __q1 = __y0 / 100;
1792 const auto __yc = 1461 * __y0 / 4 - __q1 + __q1 / 4;
1793 const auto __mc = (979 *__m0 - 2919) / 32;
1794 const auto __dc = __d0;
1796 return days{
static_cast<int32_t
>(__yc + __mc + __dc - __r2_e3)};
1801 class year_month_day_last
1805 chrono::month_day_last _M_mdl;
1809 year_month_day_last(
const chrono::year& __y,
1810 const chrono::month_day_last& __mdl) noexcept
1811 : _M_y{__y}, _M_mdl{__mdl}
1814 template<
typename = __detail::__months_years_conversion_disambiguator>
1815 constexpr year_month_day_last&
1816 operator+=(
const months& __m)
noexcept
1818 *
this = *
this + __m;
1822 template<
typename = __detail::__months_years_conversion_disambiguator>
1823 constexpr year_month_day_last&
1824 operator-=(
const months& __m)
noexcept
1826 *
this = *
this - __m;
1830 constexpr year_month_day_last&
1831 operator+=(
const years& __y)
noexcept
1833 *
this = *
this + __y;
1837 constexpr year_month_day_last&
1838 operator-=(
const years& __y)
noexcept
1840 *
this = *
this - __y;
1844 constexpr chrono::year
1845 year() const noexcept
1848 constexpr chrono::month
1849 month() const noexcept
1850 {
return _M_mdl.month(); }
1852 constexpr chrono::month_day_last
1853 month_day_last() const noexcept
1857 constexpr chrono::day
1858 day() const noexcept
1860 const auto __m =
static_cast<unsigned>(month());
1880 return chrono::day{__m != 2 ? (__m ^ (__m >> 3)) | 30
1881 : _M_y.is_leap() ? 29 : 28};
1885 operator sys_days() const noexcept
1886 {
return sys_days{year() / month() / day()}; }
1889 operator local_days() const noexcept
1890 {
return local_days{sys_days{*
this}.time_since_epoch()}; }
1894 {
return _M_y.ok() && _M_mdl.ok(); }
1896 friend constexpr bool
1897 operator==(
const year_month_day_last& __x,
1898 const year_month_day_last& __y)
noexcept
1900 return __x.year() == __y.year()
1901 && __x.month_day_last() == __y.month_day_last();
1904 friend constexpr strong_ordering
1905 operator<=>(
const year_month_day_last& __x,
1906 const year_month_day_last& __y)
noexcept
1909 template<
typename = __detail::__months_years_conversion_disambiguator>
1910 friend constexpr year_month_day_last
1911 operator+(
const year_month_day_last& __ymdl,
1912 const months& __dm)
noexcept
1913 {
return (__ymdl.year() / __ymdl.month() + __dm) / last; }
1915 template<
typename = __detail::__months_years_conversion_disambiguator>
1916 friend constexpr year_month_day_last
1918 const year_month_day_last& __ymdl)
noexcept
1919 {
return __ymdl + __dm; }
1921 template<
typename = __detail::__months_years_conversion_disambiguator>
1922 friend constexpr year_month_day_last
1923 operator-(
const year_month_day_last& __ymdl,
1924 const months& __dm)
noexcept
1925 {
return __ymdl + -__dm; }
1927 friend constexpr year_month_day_last
1928 operator+(
const year_month_day_last& __ymdl,
1929 const years& __dy)
noexcept
1930 {
return {__ymdl.year() + __dy, __ymdl.month_day_last()}; }
1932 friend constexpr year_month_day_last
1934 const year_month_day_last& __ymdl)
noexcept
1935 {
return __ymdl + __dy; }
1937 friend constexpr year_month_day_last
1938 operator-(
const year_month_day_last& __ymdl,
1939 const years& __dy)
noexcept
1940 {
return __ymdl + -__dy; }
1942 friend constexpr year_month_day_last
1943 operator/(
const year_month& __ym, last_spec)
noexcept
1944 {
return {__ym.year(), chrono::month_day_last{__ym.month()}}; }
1946 friend constexpr year_month_day_last
1948 const chrono::month_day_last& __mdl)
noexcept
1949 {
return {__y, __mdl}; }
1951 friend constexpr year_month_day_last
1952 operator/(
int __y,
const chrono::month_day_last& __mdl)
noexcept
1953 {
return chrono::year(__y) / __mdl; }
1955 friend constexpr year_month_day_last
1956 operator/(
const chrono::month_day_last& __mdl,
1957 const chrono::year& __y)
noexcept
1958 {
return __y / __mdl; }
1960 friend constexpr year_month_day_last
1961 operator/(
const chrono::month_day_last& __mdl,
int __y)
noexcept
1962 {
return chrono::year(__y) / __mdl; }
1967 year_month_day::year_month_day(
const year_month_day_last& __ymdl) noexcept
1968 : _M_y{__ymdl.year()}, _M_m{__ymdl.month()}, _M_d{__ymdl.day()}
1972 year_month_day::ok() const noexcept
1974 if (!_M_y.ok() || !_M_m.ok())
1976 return chrono::day{1} <= _M_d && _M_d <= (_M_y / _M_m / last).day();
1981 class year_month_weekday
1986 chrono::weekday_indexed _M_wdi;
1988 static constexpr year_month_weekday
1989 _S_from_sys_days(
const sys_days& __dp)
1991 year_month_day __ymd{__dp};
1992 chrono::weekday __wd{__dp};
1993 auto __index = __wd[(
unsigned{__ymd.day()} - 1) / 7 + 1];
1994 return {__ymd.year(), __ymd.month(), __index};
1998 year_month_weekday() =
default;
2001 year_month_weekday(
const chrono::year& __y,
const chrono::month& __m,
2002 const chrono::weekday_indexed& __wdi) noexcept
2003 : _M_y{__y}, _M_m{__m}, _M_wdi{__wdi}
2007 year_month_weekday(
const sys_days& __dp) noexcept
2008 : year_month_weekday{_S_from_sys_days(__dp)}
2012 year_month_weekday(
const local_days& __dp) noexcept
2013 : year_month_weekday{sys_days{__dp.time_since_epoch()}}
2016 template<
typename = __detail::__months_years_conversion_disambiguator>
2017 constexpr year_month_weekday&
2018 operator+=(
const months& __m)
noexcept
2020 *
this = *
this + __m;
2024 template<
typename = __detail::__months_years_conversion_disambiguator>
2025 constexpr year_month_weekday&
2026 operator-=(
const months& __m)
noexcept
2028 *
this = *
this - __m;
2032 constexpr year_month_weekday&
2033 operator+=(
const years& __y)
noexcept
2035 *
this = *
this + __y;
2039 constexpr year_month_weekday&
2040 operator-=(
const years& __y)
noexcept
2042 *
this = *
this - __y;
2046 constexpr chrono::year
2047 year() const noexcept
2050 constexpr chrono::month
2051 month() const noexcept
2054 constexpr chrono::weekday
2055 weekday() const noexcept
2056 {
return _M_wdi.weekday(); }
2059 index() const noexcept
2060 {
return _M_wdi.index(); }
2062 constexpr chrono::weekday_indexed
2063 weekday_indexed() const noexcept
2067 operator sys_days() const noexcept
2069 auto __d = sys_days{year() / month() / 1};
2070 return __d + (weekday() - chrono::weekday(__d)
2071 +
days{(
static_cast<int>(index())-1)*7});
2075 operator local_days() const noexcept
2076 {
return local_days{sys_days{*
this}.time_since_epoch()}; }
2081 if (!_M_y.ok() || !_M_m.ok() || !_M_wdi.ok())
2083 if (_M_wdi.index() <= 4)
2085 days __d = (_M_wdi.weekday()
2086 - chrono::weekday{sys_days{_M_y / _M_m / 1}}
2087 +
days((_M_wdi.index()-1)*7 + 1));
2088 __glibcxx_assert(__d.count() >= 1);
2089 return (
unsigned)__d.count() <= (unsigned)(_M_y / _M_m / last).day();
2092 friend constexpr bool
2093 operator==(
const year_month_weekday& __x,
2094 const year_month_weekday& __y)
noexcept
2096 return __x.year() == __y.year()
2097 && __x.month() == __y.month()
2098 && __x.weekday_indexed() == __y.weekday_indexed();
2101 template<
typename = __detail::__months_years_conversion_disambiguator>
2102 friend constexpr year_month_weekday
2103 operator+(
const year_month_weekday& __ymwd,
const months& __dm)
noexcept
2105 return ((__ymwd.year() / __ymwd.month() + __dm)
2106 / __ymwd.weekday_indexed());
2109 template<
typename = __detail::__months_years_conversion_disambiguator>
2110 friend constexpr year_month_weekday
2111 operator+(
const months& __dm,
const year_month_weekday& __ymwd)
noexcept
2112 {
return __ymwd + __dm; }
2114 friend constexpr year_month_weekday
2115 operator+(
const year_month_weekday& __ymwd,
const years& __dy)
noexcept
2116 {
return {__ymwd.year() + __dy, __ymwd.month(), __ymwd.weekday_indexed()}; }
2118 friend constexpr year_month_weekday
2119 operator+(
const years& __dy,
const year_month_weekday& __ymwd)
noexcept
2120 {
return __ymwd + __dy; }
2122 template<
typename = __detail::__months_years_conversion_disambiguator>
2123 friend constexpr year_month_weekday
2124 operator-(
const year_month_weekday& __ymwd,
const months& __dm)
noexcept
2125 {
return __ymwd + -__dm; }
2127 friend constexpr year_month_weekday
2128 operator-(
const year_month_weekday& __ymwd,
const years& __dy)
noexcept
2129 {
return __ymwd + -__dy; }
2131 friend constexpr year_month_weekday
2133 const chrono::weekday_indexed& __wdi)
noexcept
2134 {
return {__ym.year(), __ym.month(), __wdi}; }
2136 friend constexpr year_month_weekday
2137 operator/(
const chrono::year& __y,
const month_weekday& __mwd)
noexcept
2138 {
return {__y, __mwd.month(), __mwd.weekday_indexed()}; }
2140 friend constexpr year_month_weekday
2141 operator/(
int __y,
const month_weekday& __mwd)
noexcept
2142 {
return chrono::year(__y) / __mwd; }
2144 friend constexpr year_month_weekday
2145 operator/(
const month_weekday& __mwd,
const chrono::year& __y)
noexcept
2146 {
return __y / __mwd; }
2148 friend constexpr year_month_weekday
2149 operator/(
const month_weekday& __mwd,
int __y)
noexcept
2150 {
return chrono::year(__y) / __mwd; }
2155 class year_month_weekday_last
2160 chrono::weekday_last _M_wdl;
2164 year_month_weekday_last(
const chrono::year& __y,
const chrono::month& __m,
2165 const chrono::weekday_last& __wdl) noexcept
2166 : _M_y{__y}, _M_m{__m}, _M_wdl{__wdl}
2169 template<
typename = __detail::__months_years_conversion_disambiguator>
2170 constexpr year_month_weekday_last&
2171 operator+=(
const months& __m)
noexcept
2173 *
this = *
this + __m;
2177 template<
typename = __detail::__months_years_conversion_disambiguator>
2178 constexpr year_month_weekday_last&
2179 operator-=(
const months& __m)
noexcept
2181 *
this = *
this - __m;
2185 constexpr year_month_weekday_last&
2186 operator+=(
const years& __y)
noexcept
2188 *
this = *
this + __y;
2192 constexpr year_month_weekday_last&
2193 operator-=(
const years& __y)
noexcept
2195 *
this = *
this - __y;
2199 constexpr chrono::year
2200 year() const noexcept
2203 constexpr chrono::month
2204 month() const noexcept
2207 constexpr chrono::weekday
2208 weekday() const noexcept
2209 {
return _M_wdl.weekday(); }
2211 constexpr chrono::weekday_last
2212 weekday_last() const noexcept
2216 operator sys_days() const noexcept
2218 const auto __d = sys_days{_M_y / _M_m / last};
2219 return sys_days{(__d - (chrono::weekday{__d}
2220 - _M_wdl.weekday())).time_since_epoch()};
2224 operator local_days() const noexcept
2225 {
return local_days{sys_days{*
this}.time_since_epoch()}; }
2229 {
return _M_y.ok() && _M_m.ok() && _M_wdl.ok(); }
2231 friend constexpr bool
2232 operator==(
const year_month_weekday_last& __x,
2233 const year_month_weekday_last& __y)
noexcept
2235 return __x.year() == __y.year()
2236 && __x.month() == __y.month()
2237 && __x.weekday_last() == __y.weekday_last();
2240 template<
typename = __detail::__months_years_conversion_disambiguator>
2241 friend constexpr year_month_weekday_last
2242 operator+(
const year_month_weekday_last& __ymwdl,
2243 const months& __dm)
noexcept
2245 return ((__ymwdl.year() / __ymwdl.month() + __dm)
2246 / __ymwdl.weekday_last());
2249 template<
typename = __detail::__months_years_conversion_disambiguator>
2250 friend constexpr year_month_weekday_last
2252 const year_month_weekday_last& __ymwdl)
noexcept
2253 {
return __ymwdl + __dm; }
2255 friend constexpr year_month_weekday_last
2256 operator+(
const year_month_weekday_last& __ymwdl,
2257 const years& __dy)
noexcept
2258 {
return {__ymwdl.year() + __dy, __ymwdl.month(), __ymwdl.weekday_last()}; }
2260 friend constexpr year_month_weekday_last
2262 const year_month_weekday_last& __ymwdl)
noexcept
2263 {
return __ymwdl + __dy; }
2265 template<
typename = __detail::__months_years_conversion_disambiguator>
2266 friend constexpr year_month_weekday_last
2267 operator-(
const year_month_weekday_last& __ymwdl,
2268 const months& __dm)
noexcept
2269 {
return __ymwdl + -__dm; }
2271 friend constexpr year_month_weekday_last
2272 operator-(
const year_month_weekday_last& __ymwdl,
2273 const years& __dy)
noexcept
2274 {
return __ymwdl + -__dy; }
2276 friend constexpr year_month_weekday_last
2278 const chrono::weekday_last& __wdl)
noexcept
2279 {
return {__ym.year(), __ym.month(), __wdl}; }
2281 friend constexpr year_month_weekday_last
2283 const chrono::month_weekday_last& __mwdl)
noexcept
2284 {
return {__y, __mwdl.month(), __mwdl.weekday_last()}; }
2286 friend constexpr year_month_weekday_last
2287 operator/(
int __y,
const chrono::month_weekday_last& __mwdl)
noexcept
2288 {
return chrono::year(__y) / __mwdl; }
2290 friend constexpr year_month_weekday_last
2291 operator/(
const chrono::month_weekday_last& __mwdl,
2292 const chrono::year& __y)
noexcept
2293 {
return __y / __mwdl; }
2295 friend constexpr year_month_weekday_last
2296 operator/(
const chrono::month_weekday_last& __mwdl,
int __y)
noexcept
2297 {
return chrono::year(__y) / __mwdl; }
2306 __pow10(
unsigned __n)
2323 template<
typename _Duration>
2326 static_assert( __is_duration<_Duration>::value );
2329 static consteval int
2330 _S_fractional_width()
2332 auto __den = _Duration::period::den;
2333 const int __multiplicity_2 = std::__countr_zero((uintmax_t)__den);
2334 __den >>= __multiplicity_2;
2335 int __multiplicity_5 = 0;
2336 while ((__den % 5) == 0)
2344 int __width = (__multiplicity_2 > __multiplicity_5
2345 ? __multiplicity_2 : __multiplicity_5);
2352 hh_mm_ss(_Duration __d,
bool __is_neg)
2358 auto __ss = __d - hours() - minutes() - seconds();
2359 if constexpr (treat_as_floating_point_v<typename precision::rep>)
2360 _M_ss._M_r = __ss.count();
2361 else if constexpr (precision::period::den != 1)
2367 static constexpr _Duration
2368 _S_abs(_Duration __d)
2377 static constexpr unsigned fractional_width = {_S_fractional_width()};
2381 chrono::seconds::rep>,
2382 ratio<1, __detail::__pow10(fractional_width)>>;
2384 constexpr hh_mm_ss()
noexcept =
default;
2387 hh_mm_ss(_Duration __d)
2388 : hh_mm_ss(_S_abs(__d), __d < _Duration::zero())
2392 is_negative()
const noexcept
2394 if constexpr (!_S_is_unsigned)
2401 hours()
const noexcept
2405 minutes()
const noexcept
2409 seconds()
const noexcept
2413 subseconds()
const noexcept
2414 {
return static_cast<precision
>(_M_ss); }
2417 operator precision()
const noexcept
2418 {
return to_duration(); }
2421 to_duration()
const noexcept
2423 if constexpr (!_S_is_unsigned)
2425 return -(_M_h + _M_m + _M_s + subseconds());
2426 return _M_h + _M_m + _M_s + subseconds();
2430 static constexpr bool _S_is_unsigned
2431 = __and_v<is_integral<typename _Duration::rep>,
2434 template<
typename _Ratio>
2438 template<
typename _Dur>
2441 typename _Dur::rep _M_r{};
2444 operator _Dur()
const noexcept
2445 {
return _Dur(_M_r); }
2449 template<
typename _Rep>
2450 requires (!treat_as_floating_point_v<_Rep>)
2458 template<
typename _Rep,
typename _Period>
2459 requires (!treat_as_floating_point_v<_Rep>)
2464 unsigned char _M_r{};
2471 template<
typename _Rep,
typename _Period>
2472 requires (!treat_as_floating_point_v<_Rep>)
2477 uint_least32_t _M_r{};
2485 __byte_duration<ratio<60>> _M_m{};
2486 __byte_duration<ratio<1>> _M_s{};
2488 __subseconds<precision> _M_ss{};
2496 {
return 0h <= __h && __h <= 11h; }
2501 {
return 12h <= __h && __h <= 23h; }
2536 template<
class _Tp>
struct zoned_traits { };
2538 enum class choose { earliest, latest };
2540#if __cpp_lib_chrono >= 201803L
2554 static constexpr int unique = 0;
2555 static constexpr int nonexistent = 1;
2556 static constexpr int ambiguous = 2;
2563 class nonexistent_local_time :
public runtime_error
2566 template<
typename _Duration>
2567 nonexistent_local_time(
const local_time<_Duration>& __tp,
2568 const local_info& __i)
2569 : runtime_error(_S_make_what_str(__tp, __i))
2570 { __glibcxx_assert(__i.result == local_info::nonexistent); }
2573 template<
typename _Duration>
2575 _S_make_what_str(
const local_time<_Duration>& __tp,
2576 const local_info& __i)
2579 __os << __tp <<
" is in a gap between\n"
2580 << local_seconds(__i.first.end.time_since_epoch())
2581 + __i.first.offset <<
' ' << __i.first.abbrev <<
" and\n"
2582 << local_seconds(__i.second.begin.time_since_epoch())
2583 + __i.second.offset <<
' ' << __i.second.abbrev
2584 <<
" which are both equivalent to\n"
2585 << __i.first.end <<
" UTC";
2590 class ambiguous_local_time :
public runtime_error
2593 template<
typename _Duration>
2594 ambiguous_local_time(
const local_time<_Duration>& __tp,
2595 const local_info& __i)
2596 : runtime_error(_S_make_what_str(__tp, __i))
2597 { __glibcxx_assert(__i.result == local_info::ambiguous); }
2600 template<
typename _Duration>
2602 _S_make_what_str(
const local_time<_Duration>& __tp,
2603 const local_info& __i)
2606 __os << __tp <<
" is ambiguous. It could be\n"
2607 << __tp <<
' ' << __i.first.abbrev <<
" == "
2608 << __tp - __i.first.offset <<
" UTC or\n"
2609 << __tp <<
' ' << __i.second.abbrev <<
" == "
2610 << __tp - __i.second.offset <<
" UTC";
2616 template<
typename _Duration>
2618 __throw_bad_local_time(
const local_time<_Duration>& __tp,
2619 const local_info& __i)
2622 if (__i.result == local_info::nonexistent)
2623 throw nonexistent_local_time(__tp, __i);
2624 throw ambiguous_local_time(__tp, __i);
2634 time_zone(time_zone&&) =
default;
2635 time_zone& operator=(time_zone&&) =
default;
2640 string_view name() const noexcept {
return _M_name; }
2642 template<
typename _Duration>
2644 get_info(
const sys_time<_Duration>& __st)
const
2645 {
return _M_get_sys_info(chrono::floor<seconds>(__st)); }
2647 template<
typename _Duration>
2649 get_info(
const local_time<_Duration>& __tp)
const
2650 {
return _M_get_local_info(chrono::floor<seconds>(__tp)); }
2652 template<
typename _Duration>
2653 sys_time<common_type_t<_Duration, seconds>>
2654 to_sys(
const local_time<_Duration>& __tp)
const
2656 local_info __info = get_info(__tp);
2658 if (__info.result != local_info::unique)
2659 __throw_bad_local_time(__tp, __info);
2661 return sys_time<_Duration>(__tp.time_since_epoch())
2662 - __info.first.offset;
2665 template<
typename _Duration>
2666 sys_time<common_type_t<_Duration, seconds>>
2667 to_sys(
const local_time<_Duration>& __tp, choose __z)
const
2669 local_info __info = get_info(__tp);
2671 if (__info.result == local_info::nonexistent)
2672 return __info.first.end;
2674 sys_time<_Duration> __st(__tp.time_since_epoch());
2676 if (__info.result == local_info::ambiguous && __z == choose::latest)
2677 return __st - __info.second.offset;
2680 return __st - __info.first.offset;
2683 template<
typename _Duration>
2684 local_time<common_type_t<_Duration, seconds>>
2685 to_local(
const sys_time<_Duration>& __tp)
const
2687 auto __d = (__tp + get_info(__tp).offset).time_since_epoch();
2688 return local_time<common_type_t<_Duration, seconds>>(__d);
2691 [[nodiscard]]
friend bool
2692 operator==(
const time_zone& __x,
const time_zone& __y)
noexcept
2693 {
return __x._M_name == __y._M_name; }
2695 [[nodiscard]]
friend strong_ordering
2696 operator<=>(
const time_zone& __x,
const time_zone& __y)
noexcept
2697 {
return __x._M_name <=> __y._M_name; }
2700 sys_info _M_get_sys_info(sys_seconds)
const;
2701 local_info _M_get_local_info(local_seconds)
const;
2703 friend const tzdb& reload_tzdb();
2705 friend class tzdb_list;
2709 explicit time_zone(unique_ptr<_Impl> __p);
2711 unique_ptr<_Impl> _M_impl;
2714 const time_zone* locate_zone(string_view __tz_name);
2715 const time_zone* current_zone();
2736 tzdb_list(
const tzdb_list&) =
delete;
2737 tzdb_list& operator=(
const tzdb_list&) =
delete;
2746 class const_iterator
2749 using value_type = tzdb;
2750 using reference =
const tzdb&;
2751 using pointer =
const tzdb*;
2752 using difference_type = ptrdiff_t;
2753 using iterator_category = forward_iterator_tag;
2755 constexpr const_iterator() =
default;
2756 const_iterator(
const const_iterator&) =
default;
2757 const_iterator(const_iterator&&) =
default;
2758 const_iterator& operator=(
const const_iterator&) =
default;
2759 const_iterator& operator=(const_iterator&&) =
default;
2762 pointer operator->() const noexcept {
return &**
this; }
2763 const_iterator& operator++();
2764 const_iterator operator++(
int);
2766 bool operator==(
const const_iterator&)
const noexcept =
default;
2769 explicit const_iterator(
const shared_ptr<_Node>&)
noexcept;
2771 friend class tzdb_list;
2773 shared_ptr<_Node> _M_node;
2774 void* _M_reserved =
nullptr;
2784 const tzdb& front() const noexcept;
2800 const_iterator erase_after(const_iterator __p);
2802 const_iterator begin() const noexcept;
2803 const_iterator end() const noexcept {
return {}; }
2804 const_iterator cbegin() const noexcept {
return begin(); }
2805 const_iterator cend() const noexcept {
return end(); }
2808 constexpr explicit tzdb_list(nullptr_t);
2810 friend tzdb_list& get_tzdb_list();
2811 friend const tzdb& get_tzdb();
2812 friend const tzdb& reload_tzdb();
2814 friend class leap_second;
2815 friend struct time_zone::_Impl;
2816 friend class time_zone_link;
2819 __detail::__recent_leap_second_info(leap_second_info&,
unsigned);
2822 class time_zone_link
2825 time_zone_link(time_zone_link&&) =
default;
2826 time_zone_link& operator=(time_zone_link&&) =
default;
2828 string_view name() const noexcept {
return _M_name; }
2829 string_view target() const noexcept {
return _M_target; }
2832 operator==(
const time_zone_link& __x,
const time_zone_link& __y)
noexcept
2833 {
return __x.name() == __y.name(); }
2835 friend strong_ordering
2836 operator<=>(
const time_zone_link& __x,
const time_zone_link& __y)
noexcept
2837 {
return __x.name() <=> __y.name(); }
2840 friend const tzdb& reload_tzdb();
2841 friend struct tzdb_list::_Node;
2843 explicit time_zone_link(nullptr_t) { }
2852 leap_second(
const leap_second&) =
default;
2853 leap_second& operator=(
const leap_second&) =
default;
2856 constexpr sys_seconds
2857 date() const noexcept
2859 if (_M_s >= _M_s.zero()) [[likely]]
2860 return sys_seconds(_M_s);
2861 return sys_seconds(-_M_s);
2866 value() const noexcept
2868 if (_M_s >= _M_s.zero()) [[likely]]
2875 [[nodiscard]]
friend constexpr bool
2876 operator==(
const leap_second&,
const leap_second&)
noexcept =
default;
2878 [[nodiscard]]
friend constexpr strong_ordering
2879 operator<=>(
const leap_second& __x,
const leap_second& __y)
noexcept
2880 {
return __x.date() <=> __y.date(); }
2882 template<
typename _Duration>
2883 [[nodiscard]]
friend constexpr bool
2884 operator==(
const leap_second& __x,
2885 const sys_time<_Duration>& __y)
noexcept
2886 {
return __x.date() == __y; }
2888 template<
typename _Duration>
2889 [[nodiscard]]
friend constexpr bool
2891 const sys_time<_Duration>& __y)
noexcept
2892 {
return __x.date() < __y; }
2894 template<
typename _Duration>
2895 [[nodiscard]]
friend constexpr bool
2896 operator<(
const sys_time<_Duration>& __x,
2897 const leap_second& __y)
noexcept
2898 {
return __x < __y.date(); }
2900 template<
typename _Duration>
2901 [[nodiscard]]
friend constexpr bool
2903 const sys_time<_Duration>& __y)
noexcept
2904 {
return __y < __x.date(); }
2906 template<
typename _Duration>
2907 [[nodiscard]]
friend constexpr bool
2908 operator>(
const sys_time<_Duration>& __x,
2909 const leap_second& __y)
noexcept
2910 {
return __y.date() < __x; }
2912 template<
typename _Duration>
2913 [[nodiscard]]
friend constexpr bool
2915 const sys_time<_Duration>& __y)
noexcept
2916 {
return !(__y < __x.date()); }
2918 template<
typename _Duration>
2919 [[nodiscard]]
friend constexpr bool
2921 const leap_second& __y)
noexcept
2922 {
return !(__y.date() < __x); }
2924 template<
typename _Duration>
2925 [[nodiscard]]
friend constexpr bool
2927 const sys_time<_Duration>& __y)
noexcept
2928 {
return !(__x.date() < __y); }
2930 template<
typename _Duration>
2931 [[nodiscard]]
friend constexpr bool
2933 const leap_second& __y)
noexcept
2934 {
return !(__x < __y.date()); }
2938 template<three_way_comparable_with<seconds> _Duration>
2939 [[nodiscard]]
friend constexpr auto
2940 operator<=>(
const leap_second& __x,
2941 const sys_time<_Duration>& __y)
noexcept
2942 {
return __x.date() <=> __y; }
2945 constexpr explicit leap_second(seconds::rep __s) : _M_s(__s) { }
2947 friend struct tzdb_list::_Node;
2949 friend const tzdb& reload_tzdb();
2955 struct zoned_traits<const time_zone*>
2957 static const time_zone*
2959 {
return std::chrono::locate_zone(
"UTC"); }
2961 static const time_zone*
2962 locate_zone(string_view __name)
2963 {
return std::chrono::locate_zone(__name); }
2969 _GLIBCXX_STD_C::vector<time_zone> zones;
2970 _GLIBCXX_STD_C::vector<time_zone_link> links;
2971 _GLIBCXX_STD_C::vector<leap_second> leap_seconds;
2974 locate_zone(string_view __tz_name)
const;
2977 current_zone()
const;
2980 friend const tzdb& reload_tzdb();
2981 friend class time_zone;
2982 friend struct tzdb_list::_Node;
2985 tzdb_list& get_tzdb_list();
2986 const tzdb& get_tzdb();
2988 const tzdb& reload_tzdb();
2989 string remote_version();
2991 template<
typename _Duration,
typename _TimeZonePtr = const time_zone*>
2995 template<
typename _Duration,
typename _TimeZonePtr>
2998 static_assert(__is_duration_v<_Duration>);
3000 using _Traits = zoned_traits<_TimeZonePtr>;
3004 using string_view = type_identity_t<std::string_view>;
3007 using duration = common_type_t<_Duration, seconds>;
3009 zoned_time()
requires requires { _Traits::default_zone(); }
3012 zoned_time(
const zoned_time&) =
default;
3013 zoned_time& operator=(
const zoned_time&) =
default;
3015 zoned_time(
const sys_time<_Duration>& __st)
3016 requires requires { _Traits::default_zone(); }
3021 zoned_time(_TimeZonePtr __z) : _M_zone(std::move(__z)) { }
3024 zoned_time(string_view __name)
3026 _TimeZonePtr{_Traits::locate_zone(std::string_view{})};
3028 : _M_zone(_Traits::locate_zone(__name))
3031 template<
typename _Duration2>
3032 zoned_time(
const zoned_time<_Duration2, _TimeZonePtr>& __zt)
3033 requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
3034 : _M_zone(__zt._M_zone), _M_tp(__zt._M_tp)
3037 zoned_time(_TimeZonePtr __z,
const sys_time<_Duration>& __st)
3038 : _M_zone(std::move(__z)), _M_tp(__st)
3041 zoned_time(string_view __name,
const sys_time<_Duration>& __st)
3042 : zoned_time(_Traits::locate_zone(__name), __st)
3045 zoned_time(_TimeZonePtr __z,
const local_time<_Duration>& __tp)
3047 { __z->to_sys(__tp) } -> convertible_to<sys_time<_Duration>>;
3049 : _M_zone(
std::move(__z)), _M_tp(_M_zone->to_sys(__tp))
3052 zoned_time(string_view __name,
const local_time<_Duration>& __tp)
3053 requires requires (_TimeZonePtr __z) {
3054 { _Traits::locate_zone(__name) } -> convertible_to<_TimeZonePtr>;
3055 { __z->to_sys(__tp) } -> convertible_to<sys_time<_Duration>>;
3057 : zoned_time(_Traits::locate_zone(__name), __tp)
3060 zoned_time(_TimeZonePtr __z,
const local_time<_Duration>& __tp,
3063 { __z->to_sys(__tp, __c) } -> convertible_to<sys_time<_Duration>>;
3065 : _M_zone(
std::move(__z)), _M_tp(_M_zone->to_sys(__tp, __c))
3068 zoned_time(string_view __name,
const local_time<_Duration>& __tp,
3070 requires requires (_TimeZonePtr __z) {
3071 { _Traits::locate_zone(__name) } -> convertible_to<_TimeZonePtr>;
3072 { __z->to_sys(__tp, __c) } -> convertible_to<sys_time<_Duration>>;
3074 : _M_zone(_Traits::locate_zone(__name)),
3075 _M_tp(_M_zone->to_sys(__tp, __c))
3078 template<
typename _Duration2,
typename _TimeZonePtr2>
3079 zoned_time(_TimeZonePtr __z,
3080 const zoned_time<_Duration2, _TimeZonePtr2>& __zt)
3081 requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
3082 : _M_zone(__z), _M_tp(__zt._M_tp)
3085 template<
typename _Duration2,
typename _TimeZonePtr2>
3086 zoned_time(_TimeZonePtr __z,
3087 const zoned_time<_Duration2, _TimeZonePtr2>& __zt,
3089 requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
3090 : _M_zone(__z), _M_tp(__zt._M_tp)
3093 template<
typename _Duration2,
typename _TimeZonePtr2>
3094 zoned_time(string_view __name,
3095 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)
3103 template<
typename _Duration2,
typename _TimeZonePtr2>
3104 zoned_time(string_view __name,
3105 const zoned_time<_Duration2, _TimeZonePtr2>& __zt,
3107 requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
3109 { _Traits::locate_zone(__name) } -> convertible_to<_TimeZonePtr>;
3111 : _M_zone(_Traits::locate_zone(__name)), _M_tp(__zt._M_tp)
3115 operator=(
const sys_time<_Duration>& __st)
3122 operator=(
const local_time<_Duration>& __lt)
3124 _M_tp = _M_zone->to_sys(__lt);
3129 operator sys_time<duration>()
const {
return _M_tp; }
3132 explicit operator local_time<duration>()
const
3133 {
return get_local_time(); }
3137 get_time_zone()
const
3141 local_time<duration>
3142 get_local_time()
const
3143 {
return _M_zone->to_local(_M_tp); }
3147 get_sys_time()
const
3150#if __cpp_lib_chrono >= 201803L
3154 {
return _M_zone->get_info(_M_tp); }
3157 [[nodiscard]]
friend bool
3158 operator==(
const zoned_time&,
const zoned_time&) =
default;
3161 _TimeZonePtr _M_zone{ _Traits::default_zone() };
3162 sys_time<duration> _M_tp{};
3164 template<
typename _Duration2,
typename _TimeZonePtr2>
3165 friend class zoned_time;
3168#if __cpp_lib_chrono >= 201803L
3169 using zoned_seconds = zoned_time<seconds>;
3171 zoned_time() -> zoned_time<seconds>;
3173 template<
typename _Duration>
3174 zoned_time(sys_time<_Duration>)
3175 -> zoned_time<common_type_t<_Duration, seconds>>;
3179#if __cpp_lib_chrono >= 201803L
3180 template<
typename _TimeZonePtrOrName>
3181 using __time_zone_representation
3182 = __conditional_t<is_convertible_v<_TimeZonePtrOrName, string_view>,
3184 remove_cvref_t<_TimeZonePtrOrName>>;
3186 template<
typename _TimeZonePtrOrName>
3187 struct __time_zone_representation_struct
3189 static_assert(!is_convertible_v<_TimeZonePtrOrName, string_view>,
3190 "std::chrono::time_zone is not defined for freestanding,"
3191 " a custom time zone pointer must be provided");
3192 using type = remove_cvref_t<_TimeZonePtrOrName>;
3195 template<
typename _TimeZonePtrOrName>
3196 using __time_zone_representation
3197 =
typename __time_zone_representation_struct<_TimeZonePtrOrName>::type;
3201 template<
typename _TimeZonePtrOrName>
3202 zoned_time(_TimeZonePtrOrName&&)
3203 -> zoned_time<seconds, __time_zone_representation<_TimeZonePtrOrName>>;
3205 template<
typename _TimeZonePtrOrName,
typename _Duration>
3206 zoned_time(_TimeZonePtrOrName&&, sys_time<_Duration>)
3207 -> zoned_time<common_type_t<_Duration, seconds>,
3208 __time_zone_representation<_TimeZonePtrOrName>>;
3210 template<
typename _TimeZonePtrOrName,
typename _Duration>
3211 zoned_time(_TimeZonePtrOrName&&, local_time<_Duration>,
3212 choose = choose::earliest)
3213 -> zoned_time<common_type_t<_Duration, seconds>,
3214 __time_zone_representation<_TimeZonePtrOrName>>;
3216 template<
typename _Duration,
typename _TimeZonePtrOrName,
3217 typename _TimeZonePtr2>
3218 zoned_time(_TimeZonePtrOrName&&, zoned_time<_Duration, _TimeZonePtr2>,
3219 choose = choose::earliest)
3220 -> zoned_time<common_type_t<_Duration, seconds>,
3221 __time_zone_representation<_TimeZonePtrOrName>>;
3223 template<
typename _Dur1,
typename _TZPtr1,
typename _Dur2,
typename _TZPtr2>
3226 operator==(
const zoned_time<_Dur1, _TZPtr1>& __x,
3227 const zoned_time<_Dur2, _TZPtr2>& __y)
3229 return __x.get_time_zone() == __y.get_time_zone()
3230 && __x.get_sys_time() == __y.get_sys_time();
3238 inline leap_second_info
3239 __get_leap_second_info(sys_seconds __ss,
bool __is_utc)
3241 if (__ss < sys_seconds{}) [[unlikely]]
3244 const seconds::rep __leaps[] {
3275 constexpr leap_second_info __after_last{
3276 .is_leap_second =
false,
3282 constexpr sys_seconds __expires(1814140800s);
3284 if (__ss > __expires)
3286#if __cpp_lib_chrono >= 201803L
3291 leap_second_info __info{ .is_leap_second = __is_utc,
3292 .elapsed = __ss.time_since_epoch() };
3294 if (__detail::__recent_leap_second_info(__info,
std::size(__leaps)))
3297 return __after_last;
3300 seconds::rep __s = __ss.time_since_epoch().count();
3301 const seconds::rep* __first =
std::begin(__leaps);
3302 const seconds::rep* __last =
std::end(__leaps);
3305 if (__s > (__last[-1] + (__last - __first) + 1))
3306 return __after_last;
3308 auto __pos = std::upper_bound(__first, __last, __s);
3309 seconds __elapsed{__pos - __first};
3313 __s -= __elapsed.count();
3315 if (__pos != __first && __s < __pos[-1])
3317 if ((__s + 1) >= __pos[-1])
3318 return {
true, __elapsed};
3322 return {
false, __elapsed};
3326 template<
typename _Duration>
3328 inline leap_second_info
3329 get_leap_second_info(
const utc_time<_Duration>& __ut)
3331 auto __s = chrono::duration_cast<seconds>(__ut.time_since_epoch());
3332 return __detail::__get_leap_second_info(sys_seconds(__s),
true);
3335 template<
typename _Duration>
3337 inline utc_time<common_type_t<_Duration, seconds>>
3338 utc_clock::from_sys(
const sys_time<_Duration>& __t)
3340 using _CDur = common_type_t<_Duration, seconds>;
3341 auto __s = chrono::time_point_cast<seconds>(__t);
3342 const auto __li = __detail::__get_leap_second_info(__s,
false);
3343 return utc_time<_CDur>{__t.time_since_epoch()} + __li.elapsed;
3350#if __glibcxx_chrono_cxx20 >= 202306
3353 template<
typename _Tp>
3354 concept __is_nothrow_copy_hashable =
requires(
const _Tp& __t) {
3361 template<
typename _T1,
typename... _Ts>
3362 [[__gnu__::__always_inline__]]
3364 __pack_ints(_T1 __v1, _Ts... __vs)
3366 using _ResT =
decltype([] {
3367 constexpr size_t __tsize = (
sizeof(_T1) + ... +
sizeof(_Ts));
3368 if constexpr (__tsize <= 1)
3369 return static_cast<unsigned char>(0);
3370 else if constexpr (__tsize <= 2)
3371 return static_cast<__UINT16_TYPE__
>(0);
3372 else if constexpr (__tsize <= 4)
3373 return static_cast<__UINT32_TYPE__
>(0);
3374 else if constexpr (__tsize <= 8)
3375 return static_cast<__UINT64_TYPE__
>(0);
3377 static_assert(__tsize <= 8);
3381 ((__res = (__res << (
sizeof(_Ts) * __CHAR_BIT__) | _ResT(__vs))), ...);
3385 template<
typename _Tp>
3386 [[__gnu__::__always_inline__]]
3390 if constexpr (is_same_v<_Tp, year>)
3391 return static_cast<unsigned short>(
static_cast<int>(__val));
3392 else if constexpr (is_same_v<_Tp, month> || is_same_v<_Tp, day>)
3393 return static_cast<unsigned char>(
static_cast<unsigned>(__val));
3394 else if constexpr (is_same_v<_Tp, weekday>)
3395 return static_cast<unsigned char>(__val.c_encoding());
3396 else if constexpr (is_same_v<_Tp, weekday_indexed>)
3397 return __pack_ints(chrono::__as_int(__val.weekday()),
3398 static_cast<unsigned char>(__val.index()));
3399 else if constexpr (is_same_v<_Tp, weekday_last>)
3400 return chrono::__as_int(__val.weekday());
3402 static_assert(
false);
3405 template<
typename _Arg,
typename... _Args>
3407 __int_hash(_Arg __arg, _Args... __args)
3409 static_assert((is_integral_v<_Arg> && ... && is_integral_v<_Args>));
3412 using _Hasher = _Hash_impl;
3413 size_t __result = _Hasher::hash(__arg);
3414 ((__result = _Hasher::__hash_combine(__args, __result)), ...);
3418 template<
typename... _Tps>
3419 [[__gnu__::__always_inline__]]
3421 __hash(_Tps... __vals)
3423 if constexpr (
sizeof...(_Tps) == 1)
3424 return chrono::__int_hash(chrono::__as_int(__vals)...);
3427 auto __res = chrono::__pack_ints(chrono::__as_int(__vals)...);
3428 return chrono::__int_hash(__res);
3435 template<
typename _Rep,
typename _Period>
3436 requires __is_hash_enabled_for<_Rep>
3440 operator()(
const chrono::duration<_Rep, _Period>& __val)
const
3441 noexcept(__is_nothrow_copy_hashable<_Rep>)
3443 if constexpr (is_integral_v<_Rep>)
3444 return chrono::__int_hash(__val.count());
3446 return hash<_Rep>{}(__val.count());
3450 template<
typename _Rep,
typename _Period>
3456 template<
typename _Clock,
typename _Dur>
3457 requires __is_hash_enabled_for<_Dur>
3458 struct hash<
chrono::time_point<_Clock, _Dur>>
3461 operator()(
const chrono::time_point<_Clock, _Dur>& __val)
const
3462 noexcept(__is_nothrow_copy_hashable<_Dur>)
3463 {
return hash<_Dur>{}(__val.time_since_epoch()); }
3466 template<
typename _Clock,
typename _Dur>
3476 operator()(chrono::day __val)
const noexcept
3477 {
return chrono::__hash(__val); }
3485 operator()(chrono::month __val)
const noexcept
3486 {
return chrono::__hash(__val); }
3494 operator()(chrono::year __val)
const noexcept
3495 {
return chrono::__hash(__val); }
3503 operator()(chrono::weekday __val)
const noexcept
3504 {
return chrono::__hash(__val); }
3512 operator()(chrono::weekday_indexed __val)
const noexcept
3513 {
return chrono::__hash(__val); }
3521 operator()(chrono::weekday_last __val)
const noexcept
3522 {
return chrono::__hash(__val); }
3530 operator()(chrono::month_day __val)
const noexcept
3531 {
return chrono::__hash(__val.month(), __val.day()); }
3538 size_t operator()(chrono::month_day_last __val)
const noexcept
3539 {
return chrono::__hash(__val.month()); }
3547 operator()(chrono::month_weekday __val)
const noexcept
3548 {
return chrono::__hash(__val.month(), __val.weekday_indexed()); }
3556 operator()(chrono::month_weekday_last __val)
const noexcept
3557 {
return chrono::__hash(__val.month(), __val.weekday_last()); }
3565 operator()(chrono::year_month __val)
const noexcept
3566 {
return chrono::__hash(__val.year(), __val.month()); }
3574 operator()(chrono::year_month_day __val)
const noexcept
3575 {
return chrono::__hash(__val.year(), __val.month(), __val.day()); }
3583 operator()(chrono::year_month_day_last __val)
const noexcept
3584 {
return chrono::__hash(__val.year(), __val.month()); }
3592 operator()(chrono::year_month_weekday __val)
const noexcept
3594 return chrono::__hash(__val.year(), __val.month(),
3595 __val.weekday_indexed());
3604 operator()(chrono::year_month_weekday_last __val)
const noexcept
3606 return chrono::__hash(__val.year(), __val.month(),
3607 __val.weekday_last());
3612 template<
typename _Duration,
typename _TimeZonePtr>
3613 requires __is_hash_enabled_for<
3614 typename chrono::zoned_time<_Duration, _TimeZonePtr>::duration>
3615 && __is_hash_enabled_for<_TimeZonePtr>
3616 struct hash<
chrono::zoned_time<_Duration, _TimeZonePtr>>
3619 using _ActualDuration =
3620 typename chrono::zoned_time<_Duration, _TimeZonePtr>::duration;
3624 operator()(
const chrono::zoned_time<_Duration, _TimeZonePtr>& __val)
const
3625 noexcept(__is_nothrow_copy_hashable<_ActualDuration>
3626 && __is_nothrow_copy_hashable<_TimeZonePtr>)
3628 const auto __iduration = [&] {
3629 const _ActualDuration __sd = __val.get_sys_time().time_since_epoch();
3630 if constexpr (is_integral_v<typename _ActualDuration::rep>)
3631 return __sd.count();
3633 return hash<_ActualDuration>{}(__sd);
3636 const auto __izone = [&] {
3637 const _TimeZonePtr __tz = __val.get_time_zone();
3638#if __cpp_lib_chrono >= 201803L
3639 if constexpr (is_same_v<_TimeZonePtr, const chrono::time_zone*>)
3640 return reinterpret_cast<uintptr_t
>(__tz);
3643 return hash<_TimeZonePtr>{}(__tz);
3646 return chrono::__int_hash(__iduration, __izone);
3650 template<
typename _Duration,
typename _TimeZonePtr>
3652 : __and_<__is_fast_hash<hash<
3653 typename chrono::zoned_time<_Duration, _TimeZonePtr>::duration>>,
3654 __is_fast_hash<hash<_TimeZonePtr>>>
3657#if __cpp_lib_chrono >= 201803L
3663 operator()(chrono::leap_second __val)
const noexcept
3665 return chrono::__int_hash(
3666 __val.date().time_since_epoch().count(),
3667 __val.value().count());
3673#ifdef __glibcxx_chrono_cxx20
3680#pragma GCC diagnostic push
3681#pragma GCC diagnostic ignored "-Wliteral-suffix"
3684 constexpr chrono::day
3685 operator""d(
unsigned long long __d)
noexcept
3686 {
return chrono::day{
static_cast<unsigned>(__d)}; }
3690 constexpr chrono::year
3691 operator""y(
unsigned long long __y)
noexcept
3692 {
return chrono::year{
static_cast<int>(__y)}; }
3693#pragma GCC diagnostic pop
3699_GLIBCXX_END_NAMESPACE_VERSION
3702#if defined __glibcxx_chrono_cxx20 && _GLIBCXX_HOSTED
constexpr __enable_if_is_duration< _ToDur > floor(const duration< _Rep, _Period > &__d)
constexpr hours make24(const hours &__h, bool __is_pm) noexcept
Convert a 12-hour time and p.m. flag into a 24-hour time.
constexpr hours make12(const hours &__h) noexcept
Convert a 24-hour time into a 12-hour time.
duration< int64_t, ratio< 2629746 > > months
months
duration< int64_t, ratio< 86400 > > days
days
duration< int64_t, ratio< 31556952 > > years
years
constexpr bool is_pm(const hours &__h) noexcept
True if a chrono::hours value represents a time after midday.
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 bool is_am(const hours &__h) noexcept
True if a chrono::hours value represents a time before midday.
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 times y.
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.
ISO C++ entities toplevel namespace is std.
constexpr auto end(_Container &__cont) noexcept(noexcept(__cont.end())) -> decltype(__cont.end())
Return an iterator pointing to one past the last element of the container.
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
constexpr auto begin(_Container &__cont) noexcept(noexcept(__cont.begin())) -> decltype(__cont.begin())
Return an iterator pointing to the first element of the container.
ISO C++ inline namespace for literal suffixes.
ISO C++ 2011 namespace for date and time utilities.
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
[concept.same], concept same_as