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
68namespace std _GLIBCXX_VISIBILITY(default)
70_GLIBCXX_BEGIN_NAMESPACE_VERSION
87#ifdef __glibcxx_chrono_cxx20
91 template<
typename _Duration>
93 using local_seconds = local_time<seconds>;
94 using local_days = local_time<days>;
101 template<
typename _Duration>
103 using utc_seconds = utc_time<seconds>;
105 template<
typename _Duration>
107 using tai_seconds = tai_time<seconds>;
109 template<
typename _Duration>
111 using gps_seconds = gps_time<seconds>;
117 template<>
inline constexpr bool is_clock_v<utc_clock> =
true;
118 template<>
inline constexpr bool is_clock_v<tai_clock> =
true;
119 template<>
inline constexpr bool is_clock_v<gps_clock> =
true;
121 struct leap_second_info
127 template<
typename _Duration>
129 get_leap_second_info(
const utc_time<_Duration>& __ut);
140 using rep = system_clock::rep;
141 using period = system_clock::period;
144 static constexpr bool is_steady =
false;
149 {
return from_sys(system_clock::now()); }
151 template<
typename _Duration>
153 static sys_time<common_type_t<_Duration, seconds>>
154 to_sys(
const utc_time<_Duration>& __t)
157 const auto __li = chrono::get_leap_second_info(__t);
158 sys_time<_CDur> __s{__t.time_since_epoch() - __li.elapsed};
159 if (__li.is_leap_second)
164 template<
typename _Duration>
166 static utc_time<common_type_t<_Duration, seconds>>
167 from_sys(
const sys_time<_Duration>& __t);
179 using rep = system_clock::rep;
180 using period = system_clock::period;
183 static constexpr bool is_steady =
false;
189 template<
typename _Duration>
191 static utc_time<common_type_t<_Duration, seconds>>
192 to_utc(
const tai_time<_Duration>& __t)
195 return utc_time<_CDur>{__t.time_since_epoch()} - 378691210s;
198 template<
typename _Duration>
200 static tai_time<common_type_t<_Duration, seconds>>
201 from_utc(
const utc_time<_Duration>& __t)
204 return tai_time<_CDur>{__t.time_since_epoch()} + 378691210s;
217 using rep = system_clock::rep;
218 using period = system_clock::period;
221 static constexpr bool is_steady =
false;
227 template<
typename _Duration>
229 static utc_time<common_type_t<_Duration, seconds>>
230 to_utc(
const gps_time<_Duration>& __t)
233 return utc_time<_CDur>{__t.time_since_epoch()} + 315964809s;
236 template<
typename _Duration>
238 static gps_time<common_type_t<_Duration, seconds>>
239 from_utc(
const utc_time<_Duration>& __t)
242 return gps_time<_CDur>{__t.time_since_epoch()} - 315964809s;
247 template<
typename _DestClock,
typename _SourceClock>
248 struct clock_time_conversion
253 template<
typename _Clock>
254 struct clock_time_conversion<_Clock, _Clock>
256 template<
typename _Duration>
257 time_point<_Clock, _Duration>
258 operator()(
const time_point<_Clock, _Duration>& __t)
const
266 template<
typename _Duration>
268 operator()(
const sys_time<_Duration>& __t)
const
275 template<
typename _Duration>
277 operator()(
const utc_time<_Duration>& __t)
const
286 template<
typename _Duration>
287 utc_time<common_type_t<_Duration, seconds>>
288 operator()(
const sys_time<_Duration>& __t)
const
289 {
return utc_clock::from_sys(__t); }
295 template<
typename _Duration>
296 sys_time<common_type_t<_Duration, seconds>>
297 operator()(
const utc_time<_Duration>& __t)
const
298 {
return utc_clock::to_sys(__t); }
301 template<
typename _Tp,
typename _Clock>
302 inline constexpr bool __is_time_point_for_v =
false;
304 template<
typename _Clock,
typename _Duration>
305 inline constexpr bool
306 __is_time_point_for_v<time_point<_Clock, _Duration>, _Clock> =
true;
310 template<
typename _SourceClock>
311 struct clock_time_conversion<
system_clock, _SourceClock>
313 template<
typename _Duration,
typename _Src = _SourceClock>
315 operator()(
const time_point<_SourceClock, _Duration>& __t)
const
316 ->
decltype(_Src::to_sys(__t))
318 using _Ret =
decltype(_SourceClock::to_sys(__t));
319 static_assert(__is_time_point_for_v<_Ret, system_clock>);
320 return _SourceClock::to_sys(__t);
324 template<
typename _DestClock>
327 template<
typename _Duration,
typename _Dest = _DestClock>
329 operator()(
const sys_time<_Duration>& __t)
const
330 ->
decltype(_Dest::from_sys(__t))
332 using _Ret =
decltype(_DestClock::from_sys(__t));
333 static_assert(__is_time_point_for_v<_Ret, _DestClock>);
334 return _DestClock::from_sys(__t);
340 template<
typename _SourceClock>
341 struct clock_time_conversion<
utc_clock, _SourceClock>
343 template<
typename _Duration,
typename _Src = _SourceClock>
345 operator()(
const time_point<_SourceClock, _Duration>& __t)
const
346 ->
decltype(_Src::to_utc(__t))
348 using _Ret =
decltype(_SourceClock::to_utc(__t));
349 static_assert(__is_time_point_for_v<_Ret, utc_clock>);
350 return _SourceClock::to_utc(__t);
354 template<
typename _DestClock>
355 struct clock_time_conversion<_DestClock,
utc_clock>
357 template<
typename _Duration,
typename _Dest = _DestClock>
359 operator()(
const utc_time<_Duration>& __t)
const
360 ->
decltype(_Dest::from_utc(__t))
362 using _Ret =
decltype(_DestClock::from_utc(__t));
363 static_assert(__is_time_point_for_v<_Ret, _DestClock>);
364 return _DestClock::from_utc(__t);
372 template<
typename _DestClock,
typename _SourceClock,
typename _Duration>
373 concept __clock_convs
374 =
requires (
const time_point<_SourceClock, _Duration>& __t) {
375 clock_time_conversion<_DestClock, _SourceClock>{}(__t);
379 template<
typename _DestClock,
typename _SourceClock,
typename _Duration>
380 concept __clock_convs_sys
381 =
requires (
const time_point<_SourceClock, _Duration>& __t) {
382 clock_time_conversion<_DestClock, system_clock>{}(
383 clock_time_conversion<system_clock, _SourceClock>{}(__t));
386 template<
typename _DestClock,
typename _SourceClock,
typename _Duration>
387 concept __clock_convs_utc
388 =
requires (
const time_point<_SourceClock, _Duration>& __t) {
389 clock_time_conversion<_DestClock, utc_clock>{}(
390 clock_time_conversion<utc_clock, _SourceClock>{}(__t));
393 template<
typename _DestClock,
typename _SourceClock,
typename _Duration>
394 concept __clock_convs_sys_utc
395 =
requires (
const time_point<_SourceClock, _Duration>& __t) {
396 clock_time_conversion<_DestClock, utc_clock>{}(
397 clock_time_conversion<utc_clock, system_clock>{}(
398 clock_time_conversion<system_clock, _SourceClock>{}(__t)));
401 template<
typename _DestClock,
typename _SourceClock,
typename _Duration>
402 concept __clock_convs_utc_sys
403 =
requires (
const time_point<_SourceClock, _Duration>& __t) {
404 clock_time_conversion<_DestClock, system_clock>{}(
405 clock_time_conversion<system_clock, utc_clock>{}(
406 clock_time_conversion<utc_clock, _SourceClock>{}(__t)));
413 template<
typename _DestClock,
typename _SourceClock,
typename _Duration>
417 requires __detail::__clock_convs<_DestClock, _SourceClock, _Duration>
419 || __detail::__clock_convs_sys<_DestClock, _SourceClock, _Duration>
420 || __detail::__clock_convs_utc<_DestClock, _SourceClock, _Duration>
421 || __detail::__clock_convs_sys_utc<_DestClock, _SourceClock, _Duration>
422 || __detail::__clock_convs_utc_sys<_DestClock, _SourceClock, _Duration>
425 constexpr bool __direct
426 = __detail::__clock_convs<_DestClock, _SourceClock, _Duration>;
427 if constexpr (__direct)
429 return clock_time_conversion<_DestClock, _SourceClock>{}(__t);
434 constexpr bool __convert_via_sys_clock
435 = __detail::__clock_convs_sys<_DestClock, _SourceClock, _Duration>;
436 constexpr bool __convert_via_utc_clock
437 = __detail::__clock_convs_utc<_DestClock, _SourceClock, _Duration>;
438 if constexpr (__convert_via_sys_clock)
440 static_assert(!__convert_via_utc_clock,
441 "clock_cast requires a unique best conversion, but "
442 "conversion is possible via system_clock and also via"
444 return clock_time_conversion<_DestClock, system_clock>{}(
445 clock_time_conversion<system_clock, _SourceClock>{}(__t));
447 else if constexpr (__convert_via_utc_clock)
449 return clock_time_conversion<_DestClock, utc_clock>{}(
450 clock_time_conversion<utc_clock, _SourceClock>{}(__t));
454 constexpr bool __convert_via_sys_and_utc_clocks
455 = __detail::__clock_convs_sys_utc<_DestClock,
459 if constexpr (__convert_via_sys_and_utc_clocks)
461 constexpr bool __convert_via_utc_and_sys_clocks
462 = __detail::__clock_convs_utc_sys<_DestClock,
465 static_assert(!__convert_via_utc_and_sys_clocks,
466 "clock_cast requires a unique best conversion, but "
467 "conversion is possible via system_clock followed by "
468 "utc_clock, and also via utc_clock followed by "
470 return clock_time_conversion<_DestClock, utc_clock>{}(
471 clock_time_conversion<utc_clock, system_clock>{}(
472 clock_time_conversion<system_clock, _SourceClock>{}(__t)));
476 return clock_time_conversion<_DestClock, system_clock>{}(
477 clock_time_conversion<system_clock, utc_clock>{}(
478 clock_time_conversion<utc_clock, _SourceClock>{}(__t)));
492 class weekday_indexed;
495 class month_day_last;
497 class month_weekday_last;
499 class year_month_day;
500 class year_month_day_last;
501 class year_month_weekday;
502 class year_month_weekday_last;
506 explicit last_spec() =
default;
508 friend constexpr month_day_last
511 friend constexpr month_day_last
515 inline constexpr last_spec last{};
520 template <
unsigned __d,
typename _Tp>
525 auto constexpr __a = _Up(-1) - _Up(255 + __d - 2);
526 auto constexpr __b = _Up(__d * (__a / __d) - 1);
528 return _Up(-1) - __b;
534 template <
unsigned __d,
typename _Tp>
536 __add_modulo(
unsigned __x, _Tp __y)
548 auto const __offset = __y >= 0 ? _Up(0) : __modulo_offset<__d, _Tp>();
549 return (__x + _Up(__y) - __offset) % __d;
553 template <
unsigned __d,
typename _Tp>
555 __sub_modulo(
unsigned __x, _Tp __y)
558 auto const __offset = __y <= 0 ? _Up(0) : __modulo_offset<__d, _Tp>();
559 return (__x - _Up(__y) - __offset) % __d;
562 inline constexpr unsigned __days_per_month[12]
563 = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
577 day(
unsigned __d) noexcept
582 operator++() noexcept
589 operator++(
int)
noexcept
597 operator--() noexcept
604 operator--(
int)
noexcept
612 operator+=(
const days& __d)
noexcept
619 operator-=(
const days& __d)
noexcept
626 operator unsigned() const noexcept
631 {
return 1 <= _M_d && _M_d <= 31; }
633 friend constexpr bool
634 operator==(
const day& __x,
const day& __y)
noexcept
635 {
return unsigned{__x} ==
unsigned{__y}; }
637 friend constexpr strong_ordering
638 operator<=>(
const day& __x,
const day& __y)
noexcept
639 {
return unsigned{__x} <=>
unsigned{__y}; }
642 operator+(
const day& __x,
const days& __y)
noexcept
643 {
return day(
unsigned{__x} + __y.count()); }
646 operator+(
const days& __x,
const day& __y)
noexcept
647 {
return __y + __x; }
650 operator-(
const day& __x,
const days& __y)
noexcept
651 {
return __x + -__y; }
653 friend constexpr days
654 operator-(
const day& __x,
const day& __y)
noexcept
655 {
return days{int(
unsigned{__x}) -
int(
unsigned{__y})}; }
657 friend constexpr month_day
658 operator/(
const month& __m,
const day& __d)
noexcept;
660 friend constexpr month_day
661 operator/(
int __m,
const day& __d)
noexcept;
663 friend constexpr month_day
664 operator/(
const day& __d,
const month& __m)
noexcept;
666 friend constexpr month_day
667 operator/(
const day& __d,
int __m)
noexcept;
669 friend constexpr year_month_day
670 operator/(
const year_month& __ym,
const day& __d)
noexcept;
684 month(
unsigned __m) noexcept
689 operator++() noexcept
696 operator++(
int)
noexcept
704 operator--() noexcept
711 operator--(
int)
noexcept
719 operator+=(
const months& __m)
noexcept
726 operator-=(
const months& __m)
noexcept
733 operator unsigned() const noexcept
738 {
return 1 <= _M_m && _M_m <= 12; }
740 friend constexpr bool
741 operator==(
const month& __x,
const month& __y)
noexcept
742 {
return unsigned{__x} ==
unsigned{__y}; }
744 friend constexpr strong_ordering
745 operator<=>(
const month& __x,
const month& __y)
noexcept
746 {
return unsigned{__x} <=>
unsigned{__y}; }
748 friend constexpr month
749 operator+(
const month& __x,
const months& __y)
noexcept
753 return month{1 + __detail::__add_modulo<12>(
754 unsigned{__x} + 11, __y.count())};
757 friend constexpr month
758 operator+(
const months& __x,
const month& __y)
noexcept
759 {
return __y + __x; }
761 friend constexpr month
762 operator-(
const month& __x,
const months& __y)
noexcept
766 return month{1 + __detail::__sub_modulo<12>(
767 unsigned{__x} + 11, __y.count())};
771 operator-(
const month& __x,
const month& __y)
noexcept
773 const auto __dm = int(
unsigned(__x)) - int(
unsigned(__y));
774 return months{__dm < 0 ? 12 + __dm : __dm};
777 friend constexpr year_month
778 operator/(
const year& __y,
const month& __m)
noexcept;
780 friend constexpr month_day
781 operator/(
const month& __m,
int __d)
noexcept;
783 friend constexpr month_day_last
784 operator/(
const month& __m, last_spec)
noexcept;
786 friend constexpr month_day_last
787 operator/(last_spec,
const month& __m)
noexcept;
789 friend constexpr month_weekday
790 operator/(
const month& __m,
const weekday_indexed& __wdi)
noexcept;
792 friend constexpr month_weekday
793 operator/(
const weekday_indexed& __wdi,
const month& __m)
noexcept;
795 friend constexpr month_weekday_last
796 operator/(
const month& __m,
const weekday_last& __wdl)
noexcept;
798 friend constexpr month_weekday_last
799 operator/(
const weekday_last& __wdl,
const month& __m)
noexcept;
802 inline constexpr month January{1};
803 inline constexpr month February{2};
804 inline constexpr month March{3};
805 inline constexpr month April{4};
806 inline constexpr month May{5};
807 inline constexpr month June{6};
808 inline constexpr month July{7};
809 inline constexpr month August{8};
810 inline constexpr month September{9};
811 inline constexpr month October{10};
812 inline constexpr month November{11};
813 inline constexpr month December{12};
826 year(
int __y) noexcept
827 : _M_y{
static_cast<short>(__y)}
830 static constexpr year
832 {
return year{-32767}; }
834 static constexpr year
836 {
return year{32767}; }
839 operator++() noexcept
846 operator++(
int)
noexcept
854 operator--() noexcept
861 operator--(
int)
noexcept
869 operator+=(
const years& __y)
noexcept
876 operator-=(
const years& __y)
noexcept
883 operator+() const noexcept
887 operator-() const noexcept
888 {
return year{-_M_y}; }
891 is_leap() const noexcept
915 return (_M_y & (_M_y % 25 == 0 ? 15 : 3)) == 0;
919 operator int() const noexcept
924 {
return min()._M_y <= _M_y && _M_y <= max()._M_y; }
926 friend constexpr bool
927 operator==(
const year& __x,
const year& __y)
noexcept
928 {
return int{__x} ==
int{__y}; }
930 friend constexpr strong_ordering
931 operator<=>(
const year& __x,
const year& __y)
noexcept
932 {
return int{__x} <=>
int{__y}; }
934 friend constexpr year
935 operator+(
const year& __x,
const years& __y)
noexcept
936 {
return year{
int{__x} +
static_cast<int>(__y.count())}; }
938 friend constexpr year
939 operator+(
const years& __x,
const year& __y)
noexcept
940 {
return __y + __x; }
942 friend constexpr year
943 operator-(
const year& __x,
const years& __y)
noexcept
944 {
return __x + -__y; }
946 friend constexpr years
947 operator-(
const year& __x,
const year& __y)
noexcept
948 {
return years{
int{__x} -
int{__y}}; }
950 friend constexpr year_month
951 operator/(
const year& __y,
int __m)
noexcept;
953 friend constexpr year_month_day
954 operator/(
const year& __y,
const month_day& __md)
noexcept;
956 friend constexpr year_month_day
957 operator/(
const month_day& __md,
const year& __y)
noexcept;
959 friend constexpr year_month_day_last
960 operator/(
const year& __y,
const month_day_last& __mdl)
noexcept;
962 friend constexpr year_month_day_last
963 operator/(
const month_day_last& __mdl,
const year& __y)
noexcept;
965 friend constexpr year_month_weekday
966 operator/(
const year& __y,
const month_weekday& __mwd)
noexcept;
968 friend constexpr year_month_weekday
969 operator/(
const month_weekday& __mwd,
const year& __y)
noexcept;
971 friend constexpr year_month_weekday_last
972 operator/(
const year& __y,
const month_weekday_last& __mwdl)
noexcept;
974 friend constexpr year_month_weekday_last
975 operator/(
const month_weekday_last& __mwdl,
const year& __y)
noexcept;
985 static constexpr weekday
986 _S_from_days(
const days& __d)
988 return weekday{__detail::__add_modulo<7>(4, __d.count())};
995 weekday(
unsigned __wd) noexcept
996 : _M_wd(__wd == 7 ? 0 : __wd)
1000 weekday(
const sys_days& __dp) noexcept
1001 : weekday{_S_from_days(__dp.time_since_epoch())}
1005 weekday(
const local_days& __dp) noexcept
1006 : weekday{sys_days{__dp.time_since_epoch()}}
1010 operator++() noexcept
1017 operator++(
int)
noexcept
1025 operator--() noexcept
1032 operator--(
int)
noexcept
1040 operator+=(
const days& __d)
noexcept
1042 *
this = *
this + __d;
1047 operator-=(
const days& __d)
noexcept
1049 *
this = *
this - __d;
1054 c_encoding() const noexcept
1058 iso_encoding() const noexcept
1059 {
return _M_wd == 0u ? 7u : _M_wd; }
1063 {
return _M_wd <= 6; }
1065 constexpr weekday_indexed
1066 operator[](
unsigned __index)
const noexcept;
1068 constexpr weekday_last
1069 operator[](last_spec)
const noexcept;
1071 friend constexpr bool
1072 operator==(
const weekday& __x,
const weekday& __y)
noexcept
1073 {
return __x._M_wd == __y._M_wd; }
1075 friend constexpr weekday
1076 operator+(
const weekday& __x,
const days& __y)
noexcept
1078 return weekday{__detail::__add_modulo<7>(__x._M_wd, __y.count())};
1081 friend constexpr weekday
1082 operator+(
const days& __x,
const weekday& __y)
noexcept
1083 {
return __y + __x; }
1085 friend constexpr weekday
1086 operator-(
const weekday& __x,
const days& __y)
noexcept
1088 return weekday{__detail::__sub_modulo<7>(__x._M_wd, __y.count())};
1091 friend constexpr days
1092 operator-(
const weekday& __x,
const weekday& __y)
noexcept
1094 const auto __n = __x.c_encoding() - __y.c_encoding();
1095 return static_cast<int>(__n) >= 0 ?
days{__n} :
days{__n + 7};
1099 inline constexpr weekday Sunday{0};
1100 inline constexpr weekday Monday{1};
1101 inline constexpr weekday Tuesday{2};
1102 inline constexpr weekday Wednesday{3};
1103 inline constexpr weekday Thursday{4};
1104 inline constexpr weekday Friday{5};
1105 inline constexpr weekday Saturday{6};
1109 class weekday_indexed
1112 chrono::weekday _M_wd;
1113 unsigned char _M_index;
1116 weekday_indexed() =
default;
1119 weekday_indexed(
const chrono::weekday& __wd,
unsigned __index) noexcept
1120 : _M_wd(__wd), _M_index(__index)
1123 constexpr chrono::weekday
1124 weekday() const noexcept
1128 index() const noexcept
1129 {
return _M_index; };
1133 {
return _M_wd.ok() && 1 <= _M_index && _M_index <= 5; }
1135 friend constexpr bool
1136 operator==(
const weekday_indexed& __x,
const weekday_indexed& __y)
noexcept
1137 {
return __x.weekday() == __y.weekday() && __x.index() == __y.index(); }
1139 friend constexpr month_weekday
1140 operator/(
const month& __m,
const weekday_indexed& __wdi)
noexcept;
1142 friend constexpr month_weekday
1143 operator/(
int __m,
const weekday_indexed& __wdi)
noexcept;
1145 friend constexpr month_weekday
1146 operator/(
const weekday_indexed& __wdi,
const month& __m)
noexcept;
1148 friend constexpr month_weekday
1149 operator/(
const weekday_indexed& __wdi,
int __m)
noexcept;
1151 friend constexpr year_month_weekday
1152 operator/(
const year_month& __ym,
const weekday_indexed& __wdi)
noexcept;
1155 constexpr weekday_indexed
1156 weekday::operator[](
unsigned __index)
const noexcept
1157 {
return {*
this, __index}; }
1164 chrono::weekday _M_wd;
1168 weekday_last(
const chrono::weekday& __wd) noexcept
1172 constexpr chrono::weekday
1173 weekday() const noexcept
1178 {
return _M_wd.ok(); }
1180 friend constexpr bool
1181 operator==(
const weekday_last& __x,
const weekday_last& __y)
noexcept
1182 {
return __x.weekday() == __y.weekday(); }
1184 friend constexpr month_weekday_last
1185 operator/(
int __m,
const weekday_last& __wdl)
noexcept;
1187 friend constexpr month_weekday_last
1188 operator/(
const weekday_last& __wdl,
int __m)
noexcept;
1190 friend constexpr year_month_weekday_last
1191 operator/(
const year_month& __ym,
const weekday_last& __wdl)
noexcept;
1194 constexpr weekday_last
1195 weekday::operator[](last_spec)
const noexcept
1196 {
return weekday_last{*
this}; }
1207 month_day() =
default;
1210 month_day(
const chrono::month& __m,
const chrono::day& __d) noexcept
1211 : _M_m{__m}, _M_d{__d}
1214 constexpr chrono::month
1215 month() const noexcept
1218 constexpr chrono::day
1219 day() const noexcept
1226 && 1u <= unsigned(_M_d)
1227 && unsigned(_M_d) <= __detail::__days_per_month[unsigned(_M_m) - 1];
1230 friend constexpr bool
1231 operator==(
const month_day& __x,
const month_day& __y)
noexcept
1232 {
return __x.month() == __y.month() && __x.day() == __y.day(); }
1234 friend constexpr strong_ordering
1235 operator<=>(
const month_day& __x,
const month_day& __y)
noexcept
1238 friend constexpr month_day
1239 operator/(
const chrono::month& __m,
const chrono::day& __d)
noexcept
1240 {
return {__m, __d}; }
1242 friend constexpr month_day
1243 operator/(
const chrono::month& __m,
int __d)
noexcept
1244 {
return {__m, chrono::day(
unsigned(__d))}; }
1246 friend constexpr month_day
1247 operator/(
int __m,
const chrono::day& __d)
noexcept
1248 {
return {chrono::month(
unsigned(__m)), __d}; }
1250 friend constexpr month_day
1251 operator/(
const chrono::day& __d,
const chrono::month& __m)
noexcept
1252 {
return {__m, __d}; }
1254 friend constexpr month_day
1255 operator/(
const chrono::day& __d,
int __m)
noexcept
1256 {
return {chrono::month(
unsigned(__m)), __d}; }
1258 friend constexpr year_month_day
1259 operator/(
int __y,
const month_day& __md)
noexcept;
1261 friend constexpr year_month_day
1262 operator/(
const month_day& __md,
int __y)
noexcept;
1267 class month_day_last
1274 month_day_last(
const chrono::month& __m) noexcept
1278 constexpr chrono::month
1279 month() const noexcept
1284 {
return _M_m.ok(); }
1286 friend constexpr bool
1287 operator==(
const month_day_last& __x,
const month_day_last& __y)
noexcept
1288 {
return __x.month() == __y.month(); }
1290 friend constexpr strong_ordering
1291 operator<=>(
const month_day_last& __x,
const month_day_last& __y)
noexcept
1294 friend constexpr month_day_last
1295 operator/(
const chrono::month& __m, last_spec)
noexcept
1296 {
return month_day_last{__m}; }
1298 friend constexpr month_day_last
1299 operator/(
int __m, last_spec)
noexcept
1300 {
return chrono::month(
unsigned(__m)) / last; }
1302 friend constexpr month_day_last
1303 operator/(last_spec,
const chrono::month& __m)
noexcept
1304 {
return __m / last; }
1306 friend constexpr month_day_last
1307 operator/(last_spec,
int __m)
noexcept
1308 {
return __m / last; }
1310 friend constexpr year_month_day_last
1311 operator/(
int __y,
const month_day_last& __mdl)
noexcept;
1313 friend constexpr year_month_day_last
1314 operator/(
const month_day_last& __mdl,
int __y)
noexcept;
1323 chrono::weekday_indexed _M_wdi;
1327 month_weekday(
const chrono::month& __m,
1328 const chrono::weekday_indexed& __wdi) noexcept
1329 : _M_m{__m}, _M_wdi{__wdi}
1332 constexpr chrono::month
1333 month() const noexcept
1336 constexpr chrono::weekday_indexed
1337 weekday_indexed() const noexcept
1342 {
return _M_m.ok() && _M_wdi.ok(); }
1344 friend constexpr bool
1345 operator==(
const month_weekday& __x,
const month_weekday& __y)
noexcept
1347 return __x.month() == __y.month()
1348 && __x.weekday_indexed() == __y.weekday_indexed();
1351 friend constexpr month_weekday
1352 operator/(
const chrono::month& __m,
1353 const chrono::weekday_indexed& __wdi)
noexcept
1354 {
return {__m, __wdi}; }
1356 friend constexpr month_weekday
1357 operator/(
int __m,
const chrono::weekday_indexed& __wdi)
noexcept
1358 {
return chrono::month(
unsigned(__m)) / __wdi; }
1360 friend constexpr month_weekday
1361 operator/(
const chrono::weekday_indexed& __wdi,
1362 const chrono::month& __m)
noexcept
1363 {
return __m / __wdi; }
1365 friend constexpr month_weekday
1366 operator/(
const chrono::weekday_indexed& __wdi,
int __m)
noexcept
1367 {
return __m / __wdi; }
1369 friend constexpr year_month_weekday
1370 operator/(
int __y,
const month_weekday& __mwd)
noexcept;
1372 friend constexpr year_month_weekday
1373 operator/(
const month_weekday& __mwd,
int __y)
noexcept;
1378 class month_weekday_last
1382 chrono::weekday_last _M_wdl;
1386 month_weekday_last(
const chrono::month& __m,
1387 const chrono::weekday_last& __wdl) noexcept
1388 :_M_m{__m}, _M_wdl{__wdl}
1391 constexpr chrono::month
1392 month() const noexcept
1395 constexpr chrono::weekday_last
1396 weekday_last() const noexcept
1401 {
return _M_m.ok() && _M_wdl.ok(); }
1403 friend constexpr bool
1404 operator==(
const month_weekday_last& __x,
1405 const month_weekday_last& __y)
noexcept
1407 return __x.month() == __y.month()
1408 && __x.weekday_last() == __y.weekday_last();
1411 friend constexpr month_weekday_last
1412 operator/(
const chrono::month& __m,
1413 const chrono::weekday_last& __wdl)
noexcept
1414 {
return {__m, __wdl}; }
1416 friend constexpr month_weekday_last
1417 operator/(
int __m,
const chrono::weekday_last& __wdl)
noexcept
1418 {
return chrono::month(
unsigned(__m)) / __wdl; }
1420 friend constexpr month_weekday_last
1421 operator/(
const chrono::weekday_last& __wdl,
1422 const chrono::month& __m)
noexcept
1423 {
return __m / __wdl; }
1425 friend constexpr month_weekday_last
1426 operator/(
const chrono::weekday_last& __wdl,
int __m)
noexcept
1427 {
return chrono::month(
unsigned(__m)) / __wdl; }
1429 friend constexpr year_month_weekday_last
1430 operator/(
int __y,
const month_weekday_last& __mwdl)
noexcept;
1432 friend constexpr year_month_weekday_last
1433 operator/(
const month_weekday_last& __mwdl,
int __y)
noexcept;
1452 using __months_years_conversion_disambiguator = void;
1462 year_month() =
default;
1465 year_month(
const chrono::year& __y,
const chrono::month& __m) noexcept
1466 : _M_y{__y}, _M_m{__m}
1469 constexpr chrono::year
1470 year() const noexcept
1473 constexpr chrono::month
1474 month() const noexcept
1477 template<
typename = __detail::__months_years_conversion_disambiguator>
1478 constexpr year_month&
1479 operator+=(
const months& __dm)
noexcept
1481 *
this = *
this + __dm;
1485 template<
typename = __detail::__months_years_conversion_disambiguator>
1486 constexpr year_month&
1487 operator-=(
const months& __dm)
noexcept
1489 *
this = *
this - __dm;
1493 constexpr year_month&
1494 operator+=(
const years& __dy)
noexcept
1496 *
this = *
this + __dy;
1500 constexpr year_month&
1501 operator-=(
const years& __dy)
noexcept
1503 *
this = *
this - __dy;
1509 {
return _M_y.ok() && _M_m.ok(); }
1511 friend constexpr bool
1512 operator==(
const year_month& __x,
const year_month& __y)
noexcept
1513 {
return __x.year() == __y.year() && __x.month() == __y.month(); }
1515 friend constexpr strong_ordering
1516 operator<=>(
const year_month& __x,
const year_month& __y)
noexcept
1519 template<
typename = __detail::__months_years_conversion_disambiguator>
1520 friend constexpr year_month
1521 operator+(
const year_month& __ym,
const months& __dm)
noexcept
1524 auto __m = __ym.month() + __dm;
1525 auto __i = int(
unsigned(__ym.month())) - 1 + __dm.count();
1527 ? __ym.year() +
years{(__i - 11) / 12}
1528 : __ym.year() +
years{__i / 12});
1532 template<
typename = __detail::__months_years_conversion_disambiguator>
1533 friend constexpr year_month
1534 operator+(
const months& __dm,
const year_month& __ym)
noexcept
1535 {
return __ym + __dm; }
1537 template<
typename = __detail::__months_years_conversion_disambiguator>
1538 friend constexpr year_month
1539 operator-(
const year_month& __ym,
const months& __dm)
noexcept
1540 {
return __ym + -__dm; }
1543 operator-(
const year_month& __x,
const year_month& __y)
noexcept
1545 return (__x.year() - __y.year()
1546 +
months{static_cast<int>(unsigned{__x.month()})
1547 -
static_cast<int>(
unsigned{__y.month()})});
1550 friend constexpr year_month
1552 {
return (__ym.year() + __dy) / __ym.month(); }
1554 friend constexpr year_month
1556 {
return __ym + __dy; }
1558 friend constexpr year_month
1560 {
return __ym + -__dy; }
1562 friend constexpr year_month
1563 operator/(
const chrono::year& __y,
const chrono::month& __m)
noexcept
1564 {
return {__y, __m}; }
1566 friend constexpr year_month
1567 operator/(
const chrono::year& __y,
int __m)
noexcept
1568 {
return {__y, chrono::month(
unsigned(__m))}; }
1570 friend constexpr year_month_day
1571 operator/(
const year_month& __ym,
int __d)
noexcept;
1573 friend constexpr year_month_day_last
1574 operator/(
const year_month& __ym, last_spec)
noexcept;
1579 class year_month_day
1586 static constexpr year_month_day _S_from_days(
const days& __dp)
noexcept;
1588 constexpr days _M_days_since_epoch() const noexcept;
1591 year_month_day() = default;
1594 year_month_day(const chrono::year& __y, const chrono::month& __m,
1595 const chrono::day& __d) noexcept
1596 : _M_y{__y}, _M_m{__m}, _M_d{__d}
1600 year_month_day(
const year_month_day_last& __ymdl)
noexcept;
1603 year_month_day(
const sys_days& __dp) noexcept
1604 : year_month_day(_S_from_days(__dp.time_since_epoch()))
1608 year_month_day(
const local_days& __dp) noexcept
1609 : year_month_day(sys_days{__dp.time_since_epoch()})
1612 template<
typename = __detail::__months_years_conversion_disambiguator>
1613 constexpr year_month_day&
1614 operator+=(
const months& __m)
noexcept
1616 *
this = *
this + __m;
1620 template<
typename = __detail::__months_years_conversion_disambiguator>
1621 constexpr year_month_day&
1622 operator-=(
const months& __m)
noexcept
1624 *
this = *
this - __m;
1628 constexpr year_month_day&
1629 operator+=(
const years& __y)
noexcept
1631 *
this = *
this + __y;
1635 constexpr year_month_day&
1636 operator-=(
const years& __y)
noexcept
1638 *
this = *
this - __y;
1642 constexpr chrono::year
1643 year() const noexcept
1646 constexpr chrono::month
1647 month() const noexcept
1650 constexpr chrono::day
1651 day() const noexcept
1655 operator sys_days() const noexcept
1656 {
return sys_days{_M_days_since_epoch()}; }
1659 operator local_days() const noexcept
1660 {
return local_days{sys_days{*
this}.time_since_epoch()}; }
1662 constexpr bool ok() const noexcept;
1664 friend constexpr
bool
1665 operator==(const year_month_day& __x, const year_month_day& __y) noexcept
1667 return __x.year() == __y.year()
1668 && __x.month() == __y.month()
1669 && __x.day() == __y.day();
1672 friend constexpr strong_ordering
1673 operator<=>(
const year_month_day& __x,
const year_month_day& __y)
noexcept
1676 template<
typename = __detail::__months_years_conversion_disambiguator>
1677 friend constexpr year_month_day
1678 operator+(
const year_month_day& __ymd,
const months& __dm)
noexcept
1679 {
return (__ymd.year() / __ymd.month() + __dm) / __ymd.day(); }
1681 template<
typename = __detail::__months_years_conversion_disambiguator>
1682 friend constexpr year_month_day
1683 operator+(
const months& __dm,
const year_month_day& __ymd)
noexcept
1684 {
return __ymd + __dm; }
1686 friend constexpr year_month_day
1687 operator+(
const year_month_day& __ymd,
const years& __dy)
noexcept
1688 {
return (__ymd.year() + __dy) / __ymd.month() / __ymd.day(); }
1690 friend constexpr year_month_day
1691 operator+(
const years& __dy,
const year_month_day& __ymd)
noexcept
1692 {
return __ymd + __dy; }
1694 template<
typename = __detail::__months_years_conversion_disambiguator>
1695 friend constexpr year_month_day
1696 operator-(
const year_month_day& __ymd,
const months& __dm)
noexcept
1697 {
return __ymd + -__dm; }
1699 friend constexpr year_month_day
1700 operator-(
const year_month_day& __ymd,
const years& __dy)
noexcept
1701 {
return __ymd + -__dy; }
1703 friend constexpr year_month_day
1704 operator/(
const year_month& __ym,
const chrono::day& __d)
noexcept
1705 {
return {__ym.year(), __ym.month(), __d}; }
1707 friend constexpr year_month_day
1708 operator/(
const year_month& __ym,
int __d)
noexcept
1709 {
return __ym / chrono::day{unsigned(__d)}; }
1711 friend constexpr year_month_day
1712 operator/(
const chrono::year& __y,
const month_day& __md)
noexcept
1713 {
return __y / __md.month() / __md.day(); }
1715 friend constexpr year_month_day
1716 operator/(
int __y,
const month_day& __md)
noexcept
1717 {
return chrono::year{__y} / __md; }
1719 friend constexpr year_month_day
1720 operator/(
const month_day& __md,
const chrono::year& __y)
noexcept
1721 {
return __y / __md; }
1723 friend constexpr year_month_day
1724 operator/(
const month_day& __md,
int __y)
noexcept
1725 {
return chrono::year(__y) / __md; }
1732 constexpr year_month_day
1733 year_month_day::_S_from_days(
const days& __dp)
noexcept
1735 constexpr auto __z2 =
static_cast<uint32_t
>(-1468000);
1736 constexpr auto __r2_e3 =
static_cast<uint32_t
>(536895458);
1738 const auto __r0 =
static_cast<uint32_t
>(__dp.count()) + __r2_e3;
1740 const auto __n1 = 4 * __r0 + 3;
1741 const auto __q1 = __n1 / 146097;
1742 const auto __r1 = __n1 % 146097 / 4;
1744 constexpr auto __p32 =
static_cast<uint64_t
>(1) << 32;
1745 const auto __n2 = 4 * __r1 + 3;
1746 const auto __u2 =
static_cast<uint64_t
>(2939745) * __n2;
1747 const auto __q2 =
static_cast<uint32_t
>(__u2 / __p32);
1748 const auto __r2 =
static_cast<uint32_t
>(__u2 % __p32) / 2939745 / 4;
1750 constexpr auto __p16 =
static_cast<uint32_t
>(1) << 16;
1751 const auto __n3 = 2141 * __r2 + 197913;
1752 const auto __q3 = __n3 / __p16;
1753 const auto __r3 = __n3 % __p16 / 2141;
1755 const auto __y0 = 100 * __q1 + __q2;
1756 const auto __m0 = __q3;
1757 const auto __d0 = __r3;
1759 const auto __j = __r2 >= 306;
1760 const auto __y1 = __y0 + __j;
1761 const auto __m1 = __j ? __m0 - 12 : __m0;
1762 const auto __d1 = __d0 + 1;
1764 return year_month_day{chrono::year{
static_cast<int>(__y1 + __z2)},
1765 chrono::month{__m1}, chrono::day{__d1}};
1773 year_month_day::_M_days_since_epoch() const noexcept
1775 auto constexpr __z2 =
static_cast<uint32_t
>(-1468000);
1776 auto constexpr __r2_e3 =
static_cast<uint32_t
>(536895458);
1778 const auto __y1 =
static_cast<uint32_t
>(
static_cast<int>(_M_y)) - __z2;
1779 const auto __m1 =
static_cast<uint32_t
>(
static_cast<unsigned>(_M_m));
1780 const auto __d1 =
static_cast<uint32_t
>(
static_cast<unsigned>(_M_d));
1782 const auto __j =
static_cast<uint32_t
>(__m1 < 3);
1783 const auto __y0 = __y1 - __j;
1784 const auto __m0 = __j ? __m1 + 12 : __m1;
1785 const auto __d0 = __d1 - 1;
1787 const auto __q1 = __y0 / 100;
1788 const auto __yc = 1461 * __y0 / 4 - __q1 + __q1 / 4;
1789 const auto __mc = (979 *__m0 - 2919) / 32;
1790 const auto __dc = __d0;
1792 return days{
static_cast<int32_t
>(__yc + __mc + __dc - __r2_e3)};
1797 class year_month_day_last
1801 chrono::month_day_last _M_mdl;
1805 year_month_day_last(
const chrono::year& __y,
1806 const chrono::month_day_last& __mdl) noexcept
1807 : _M_y{__y}, _M_mdl{__mdl}
1810 template<
typename = __detail::__months_years_conversion_disambiguator>
1811 constexpr year_month_day_last&
1812 operator+=(
const months& __m)
noexcept
1814 *
this = *
this + __m;
1818 template<
typename = __detail::__months_years_conversion_disambiguator>
1819 constexpr year_month_day_last&
1820 operator-=(
const months& __m)
noexcept
1822 *
this = *
this - __m;
1826 constexpr year_month_day_last&
1827 operator+=(
const years& __y)
noexcept
1829 *
this = *
this + __y;
1833 constexpr year_month_day_last&
1834 operator-=(
const years& __y)
noexcept
1836 *
this = *
this - __y;
1840 constexpr chrono::year
1841 year() const noexcept
1844 constexpr chrono::month
1845 month() const noexcept
1846 {
return _M_mdl.month(); }
1848 constexpr chrono::month_day_last
1849 month_day_last() const noexcept
1853 constexpr chrono::day
1854 day() const noexcept
1856 const auto __m =
static_cast<unsigned>(month());
1876 return chrono::day{__m != 2 ? (__m ^ (__m >> 3)) | 30
1877 : _M_y.is_leap() ? 29 : 28};
1881 operator sys_days() const noexcept
1882 {
return sys_days{year() / month() / day()}; }
1885 operator local_days() const noexcept
1886 {
return local_days{sys_days{*
this}.time_since_epoch()}; }
1890 {
return _M_y.ok() && _M_mdl.ok(); }
1892 friend constexpr bool
1893 operator==(
const year_month_day_last& __x,
1894 const year_month_day_last& __y)
noexcept
1896 return __x.year() == __y.year()
1897 && __x.month_day_last() == __y.month_day_last();
1900 friend constexpr strong_ordering
1901 operator<=>(
const year_month_day_last& __x,
1902 const year_month_day_last& __y)
noexcept
1905 template<
typename = __detail::__months_years_conversion_disambiguator>
1906 friend constexpr year_month_day_last
1907 operator+(
const year_month_day_last& __ymdl,
1908 const months& __dm)
noexcept
1909 {
return (__ymdl.year() / __ymdl.month() + __dm) / last; }
1911 template<
typename = __detail::__months_years_conversion_disambiguator>
1912 friend constexpr year_month_day_last
1914 const year_month_day_last& __ymdl)
noexcept
1915 {
return __ymdl + __dm; }
1917 template<
typename = __detail::__months_years_conversion_disambiguator>
1918 friend constexpr year_month_day_last
1919 operator-(
const year_month_day_last& __ymdl,
1920 const months& __dm)
noexcept
1921 {
return __ymdl + -__dm; }
1923 friend constexpr year_month_day_last
1924 operator+(
const year_month_day_last& __ymdl,
1925 const years& __dy)
noexcept
1926 {
return {__ymdl.year() + __dy, __ymdl.month_day_last()}; }
1928 friend constexpr year_month_day_last
1930 const year_month_day_last& __ymdl)
noexcept
1931 {
return __ymdl + __dy; }
1933 friend constexpr year_month_day_last
1934 operator-(
const year_month_day_last& __ymdl,
1935 const years& __dy)
noexcept
1936 {
return __ymdl + -__dy; }
1938 friend constexpr year_month_day_last
1939 operator/(
const year_month& __ym, last_spec)
noexcept
1940 {
return {__ym.year(), chrono::month_day_last{__ym.month()}}; }
1942 friend constexpr year_month_day_last
1944 const chrono::month_day_last& __mdl)
noexcept
1945 {
return {__y, __mdl}; }
1947 friend constexpr year_month_day_last
1948 operator/(
int __y,
const chrono::month_day_last& __mdl)
noexcept
1949 {
return chrono::year(__y) / __mdl; }
1951 friend constexpr year_month_day_last
1952 operator/(
const chrono::month_day_last& __mdl,
1953 const chrono::year& __y)
noexcept
1954 {
return __y / __mdl; }
1956 friend constexpr year_month_day_last
1957 operator/(
const chrono::month_day_last& __mdl,
int __y)
noexcept
1958 {
return chrono::year(__y) / __mdl; }
1963 year_month_day::year_month_day(
const year_month_day_last& __ymdl) noexcept
1964 : _M_y{__ymdl.year()}, _M_m{__ymdl.month()}, _M_d{__ymdl.day()}
1968 year_month_day::ok() const noexcept
1970 if (!_M_y.ok() || !_M_m.ok())
1972 return chrono::day{1} <= _M_d && _M_d <= (_M_y / _M_m / last).day();
1977 class year_month_weekday
1982 chrono::weekday_indexed _M_wdi;
1984 static constexpr year_month_weekday
1985 _S_from_sys_days(
const sys_days& __dp)
1987 year_month_day __ymd{__dp};
1988 chrono::weekday __wd{__dp};
1989 auto __index = __wd[(
unsigned{__ymd.day()} - 1) / 7 + 1];
1990 return {__ymd.year(), __ymd.month(), __index};
1994 year_month_weekday() =
default;
1997 year_month_weekday(
const chrono::year& __y,
const chrono::month& __m,
1998 const chrono::weekday_indexed& __wdi) noexcept
1999 : _M_y{__y}, _M_m{__m}, _M_wdi{__wdi}
2003 year_month_weekday(
const sys_days& __dp) noexcept
2004 : year_month_weekday{_S_from_sys_days(__dp)}
2008 year_month_weekday(
const local_days& __dp) noexcept
2009 : year_month_weekday{sys_days{__dp.time_since_epoch()}}
2012 template<
typename = __detail::__months_years_conversion_disambiguator>
2013 constexpr year_month_weekday&
2014 operator+=(
const months& __m)
noexcept
2016 *
this = *
this + __m;
2020 template<
typename = __detail::__months_years_conversion_disambiguator>
2021 constexpr year_month_weekday&
2022 operator-=(
const months& __m)
noexcept
2024 *
this = *
this - __m;
2028 constexpr year_month_weekday&
2029 operator+=(
const years& __y)
noexcept
2031 *
this = *
this + __y;
2035 constexpr year_month_weekday&
2036 operator-=(
const years& __y)
noexcept
2038 *
this = *
this - __y;
2042 constexpr chrono::year
2043 year() const noexcept
2046 constexpr chrono::month
2047 month() const noexcept
2050 constexpr chrono::weekday
2051 weekday() const noexcept
2052 {
return _M_wdi.weekday(); }
2055 index() const noexcept
2056 {
return _M_wdi.index(); }
2058 constexpr chrono::weekday_indexed
2059 weekday_indexed() const noexcept
2063 operator sys_days() const noexcept
2065 auto __d = sys_days{year() / month() / 1};
2066 return __d + (weekday() - chrono::weekday(__d)
2067 +
days{(
static_cast<int>(index())-1)*7});
2071 operator local_days() const noexcept
2072 {
return local_days{sys_days{*
this}.time_since_epoch()}; }
2077 if (!_M_y.ok() || !_M_m.ok() || !_M_wdi.ok())
2079 if (_M_wdi.index() <= 4)
2081 days __d = (_M_wdi.weekday()
2082 - chrono::weekday{sys_days{_M_y / _M_m / 1}}
2083 +
days((_M_wdi.index()-1)*7 + 1));
2084 __glibcxx_assert(__d.count() >= 1);
2085 return (
unsigned)__d.count() <= (unsigned)(_M_y / _M_m / last).day();
2088 friend constexpr bool
2089 operator==(
const year_month_weekday& __x,
2090 const year_month_weekday& __y)
noexcept
2092 return __x.year() == __y.year()
2093 && __x.month() == __y.month()
2094 && __x.weekday_indexed() == __y.weekday_indexed();
2097 template<
typename = __detail::__months_years_conversion_disambiguator>
2098 friend constexpr year_month_weekday
2099 operator+(
const year_month_weekday& __ymwd,
const months& __dm)
noexcept
2101 return ((__ymwd.year() / __ymwd.month() + __dm)
2102 / __ymwd.weekday_indexed());
2105 template<
typename = __detail::__months_years_conversion_disambiguator>
2106 friend constexpr year_month_weekday
2107 operator+(
const months& __dm,
const year_month_weekday& __ymwd)
noexcept
2108 {
return __ymwd + __dm; }
2110 friend constexpr year_month_weekday
2111 operator+(
const year_month_weekday& __ymwd,
const years& __dy)
noexcept
2112 {
return {__ymwd.year() + __dy, __ymwd.month(), __ymwd.weekday_indexed()}; }
2114 friend constexpr year_month_weekday
2115 operator+(
const years& __dy,
const year_month_weekday& __ymwd)
noexcept
2116 {
return __ymwd + __dy; }
2118 template<
typename = __detail::__months_years_conversion_disambiguator>
2119 friend constexpr year_month_weekday
2120 operator-(
const year_month_weekday& __ymwd,
const months& __dm)
noexcept
2121 {
return __ymwd + -__dm; }
2123 friend constexpr year_month_weekday
2124 operator-(
const year_month_weekday& __ymwd,
const years& __dy)
noexcept
2125 {
return __ymwd + -__dy; }
2127 friend constexpr year_month_weekday
2129 const chrono::weekday_indexed& __wdi)
noexcept
2130 {
return {__ym.year(), __ym.month(), __wdi}; }
2132 friend constexpr year_month_weekday
2133 operator/(
const chrono::year& __y,
const month_weekday& __mwd)
noexcept
2134 {
return {__y, __mwd.month(), __mwd.weekday_indexed()}; }
2136 friend constexpr year_month_weekday
2137 operator/(
int __y,
const month_weekday& __mwd)
noexcept
2138 {
return chrono::year(__y) / __mwd; }
2140 friend constexpr year_month_weekday
2141 operator/(
const month_weekday& __mwd,
const chrono::year& __y)
noexcept
2142 {
return __y / __mwd; }
2144 friend constexpr year_month_weekday
2145 operator/(
const month_weekday& __mwd,
int __y)
noexcept
2146 {
return chrono::year(__y) / __mwd; }
2151 class year_month_weekday_last
2156 chrono::weekday_last _M_wdl;
2160 year_month_weekday_last(
const chrono::year& __y,
const chrono::month& __m,
2161 const chrono::weekday_last& __wdl) noexcept
2162 : _M_y{__y}, _M_m{__m}, _M_wdl{__wdl}
2165 template<
typename = __detail::__months_years_conversion_disambiguator>
2166 constexpr year_month_weekday_last&
2167 operator+=(
const months& __m)
noexcept
2169 *
this = *
this + __m;
2173 template<
typename = __detail::__months_years_conversion_disambiguator>
2174 constexpr year_month_weekday_last&
2175 operator-=(
const months& __m)
noexcept
2177 *
this = *
this - __m;
2181 constexpr year_month_weekday_last&
2182 operator+=(
const years& __y)
noexcept
2184 *
this = *
this + __y;
2188 constexpr year_month_weekday_last&
2189 operator-=(
const years& __y)
noexcept
2191 *
this = *
this - __y;
2195 constexpr chrono::year
2196 year() const noexcept
2199 constexpr chrono::month
2200 month() const noexcept
2203 constexpr chrono::weekday
2204 weekday() const noexcept
2205 {
return _M_wdl.weekday(); }
2207 constexpr chrono::weekday_last
2208 weekday_last() const noexcept
2212 operator sys_days() const noexcept
2214 const auto __d = sys_days{_M_y / _M_m / last};
2215 return sys_days{(__d - (chrono::weekday{__d}
2216 - _M_wdl.weekday())).time_since_epoch()};
2220 operator local_days() const noexcept
2221 {
return local_days{sys_days{*
this}.time_since_epoch()}; }
2225 {
return _M_y.ok() && _M_m.ok() && _M_wdl.ok(); }
2227 friend constexpr bool
2228 operator==(
const year_month_weekday_last& __x,
2229 const year_month_weekday_last& __y)
noexcept
2231 return __x.year() == __y.year()
2232 && __x.month() == __y.month()
2233 && __x.weekday_last() == __y.weekday_last();
2236 template<
typename = __detail::__months_years_conversion_disambiguator>
2237 friend constexpr year_month_weekday_last
2238 operator+(
const year_month_weekday_last& __ymwdl,
2239 const months& __dm)
noexcept
2241 return ((__ymwdl.year() / __ymwdl.month() + __dm)
2242 / __ymwdl.weekday_last());
2245 template<
typename = __detail::__months_years_conversion_disambiguator>
2246 friend constexpr year_month_weekday_last
2248 const year_month_weekday_last& __ymwdl)
noexcept
2249 {
return __ymwdl + __dm; }
2251 friend constexpr year_month_weekday_last
2252 operator+(
const year_month_weekday_last& __ymwdl,
2253 const years& __dy)
noexcept
2254 {
return {__ymwdl.year() + __dy, __ymwdl.month(), __ymwdl.weekday_last()}; }
2256 friend constexpr year_month_weekday_last
2258 const year_month_weekday_last& __ymwdl)
noexcept
2259 {
return __ymwdl + __dy; }
2261 template<
typename = __detail::__months_years_conversion_disambiguator>
2262 friend constexpr year_month_weekday_last
2263 operator-(
const year_month_weekday_last& __ymwdl,
2264 const months& __dm)
noexcept
2265 {
return __ymwdl + -__dm; }
2267 friend constexpr year_month_weekday_last
2268 operator-(
const year_month_weekday_last& __ymwdl,
2269 const years& __dy)
noexcept
2270 {
return __ymwdl + -__dy; }
2272 friend constexpr year_month_weekday_last
2274 const chrono::weekday_last& __wdl)
noexcept
2275 {
return {__ym.year(), __ym.month(), __wdl}; }
2277 friend constexpr year_month_weekday_last
2279 const chrono::month_weekday_last& __mwdl)
noexcept
2280 {
return {__y, __mwdl.month(), __mwdl.weekday_last()}; }
2282 friend constexpr year_month_weekday_last
2283 operator/(
int __y,
const chrono::month_weekday_last& __mwdl)
noexcept
2284 {
return chrono::year(__y) / __mwdl; }
2286 friend constexpr year_month_weekday_last
2287 operator/(
const chrono::month_weekday_last& __mwdl,
2288 const chrono::year& __y)
noexcept
2289 {
return __y / __mwdl; }
2291 friend constexpr year_month_weekday_last
2292 operator/(
const chrono::month_weekday_last& __mwdl,
int __y)
noexcept
2293 {
return chrono::year(__y) / __mwdl; }
2302 __pow10(
unsigned __n)
2319 template<
typename _Duration>
2322 static_assert( __is_duration<_Duration>::value );
2325 static consteval int
2326 _S_fractional_width()
2328 auto __den = _Duration::period::den;
2329 const int __multiplicity_2 = std::__countr_zero((uintmax_t)__den);
2330 __den >>= __multiplicity_2;
2331 int __multiplicity_5 = 0;
2332 while ((__den % 5) == 0)
2340 int __width = (__multiplicity_2 > __multiplicity_5
2341 ? __multiplicity_2 : __multiplicity_5);
2348 hh_mm_ss(_Duration __d,
bool __is_neg)
2354 auto __ss = __d - hours() - minutes() - seconds();
2355 if constexpr (treat_as_floating_point_v<typename precision::rep>)
2356 _M_ss._M_r = __ss.count();
2357 else if constexpr (precision::period::den != 1)
2361 static constexpr _Duration
2362 _S_abs(_Duration __d)
2371 static constexpr unsigned fractional_width = {_S_fractional_width()};
2375 chrono::seconds::rep>,
2376 ratio<1, __detail::__pow10(fractional_width)>>;
2378 constexpr hh_mm_ss()
noexcept =
default;
2381 hh_mm_ss(_Duration __d)
2382 : hh_mm_ss(_S_abs(__d), __d < _Duration::zero())
2386 is_negative()
const noexcept
2388 if constexpr (!_S_is_unsigned)
2395 hours()
const noexcept
2399 minutes()
const noexcept
2403 seconds()
const noexcept
2407 subseconds()
const noexcept
2408 {
return static_cast<precision
>(_M_ss); }
2411 operator precision()
const noexcept
2412 {
return to_duration(); }
2415 to_duration()
const noexcept
2417 if constexpr (!_S_is_unsigned)
2419 return -(_M_h + _M_m + _M_s + subseconds());
2420 return _M_h + _M_m + _M_s + subseconds();
2424 static constexpr bool _S_is_unsigned
2425 = __and_v<is_integral<typename _Duration::rep>,
2428 template<
typename _Ratio>
2432 template<
typename _Dur>
2435 typename _Dur::rep _M_r{};
2438 operator _Dur()
const noexcept
2439 {
return _Dur(_M_r); }
2443 template<
typename _Rep>
2444 requires (!treat_as_floating_point_v<_Rep>)
2452 template<
typename _Rep,
typename _Period>
2453 requires (!treat_as_floating_point_v<_Rep>)
2458 unsigned char _M_r{};
2465 template<
typename _Rep,
typename _Period>
2466 requires (!treat_as_floating_point_v<_Rep>)
2471 uint_least32_t _M_r{};
2479 __byte_duration<ratio<60>> _M_m{};
2480 __byte_duration<ratio<1>> _M_s{};
2482 __subseconds<precision> _M_ss{};
2488 is_am(
const hours& __h)
noexcept
2489 {
return 0h <= __h && __h <= 11h; }
2492 is_pm(
const hours& __h)
noexcept
2493 {
return 12h <= __h && __h <= 23h; }
2496 make12(
const hours& __h)
noexcept
2506 make24(
const hours& __h,
bool __is_pm)
noexcept
2525#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2541 static constexpr int unique = 0;
2542 static constexpr int nonexistent = 1;
2543 static constexpr int ambiguous = 2;
2550 class nonexistent_local_time :
public runtime_error
2553 template<
typename _Duration>
2554 nonexistent_local_time(
const local_time<_Duration>& __tp,
2555 const local_info& __i)
2556 : runtime_error(_S_make_what_str(__tp, __i))
2557 { __glibcxx_assert(__i.result == local_info::nonexistent); }
2560 template<
typename _Duration>
2562 _S_make_what_str(
const local_time<_Duration>& __tp,
2563 const local_info& __i)
2566 __os << __tp <<
" is in a gap between\n"
2567 << local_seconds(__i.first.end.time_since_epoch())
2568 + __i.first.offset <<
' ' << __i.first.abbrev <<
" and\n"
2569 << local_seconds(__i.second.begin.time_since_epoch())
2570 + __i.second.offset <<
' ' << __i.second.abbrev
2571 <<
" which are both equivalent to\n"
2572 << __i.first.end <<
" UTC";
2577 class ambiguous_local_time :
public runtime_error
2580 template<
typename _Duration>
2581 ambiguous_local_time(
const local_time<_Duration>& __tp,
2582 const local_info& __i)
2583 : runtime_error(_S_make_what_str(__tp, __i))
2584 { __glibcxx_assert(__i.result == local_info::ambiguous); }
2587 template<
typename _Duration>
2589 _S_make_what_str(
const local_time<_Duration>& __tp,
2590 const local_info& __i)
2593 __os << __tp <<
" is ambiguous. It could be\n"
2594 << __tp <<
' ' << __i.first.abbrev <<
" == "
2595 << __tp - __i.first.offset <<
" UTC or\n"
2596 << __tp <<
' ' << __i.second.abbrev <<
" == "
2597 << __tp - __i.second.offset <<
" UTC";
2602 template<
typename _Duration>
2604 __throw_bad_local_time(
const local_time<_Duration>& __tp,
2605 const local_info& __i)
2608 if (__i.result == local_info::nonexistent)
2609 throw nonexistent_local_time(__tp, __i);
2610 throw ambiguous_local_time(__tp, __i);
2616 enum class choose { earliest, latest };
2621 time_zone(time_zone&&) =
default;
2622 time_zone& operator=(time_zone&&) =
default;
2627 string_view name() const noexcept {
return _M_name; }
2629 template<
typename _Duration>
2631 get_info(
const sys_time<_Duration>& __st)
const
2632 {
return _M_get_sys_info(chrono::floor<seconds>(__st)); }
2634 template<
typename _Duration>
2636 get_info(
const local_time<_Duration>& __tp)
const
2637 {
return _M_get_local_info(chrono::floor<seconds>(__tp)); }
2639 template<
typename _Duration>
2640 sys_time<common_type_t<_Duration, seconds>>
2641 to_sys(
const local_time<_Duration>& __tp)
const
2643 local_info __info = get_info(__tp);
2645 if (__info.result != local_info::unique)
2646 __throw_bad_local_time(__tp, __info);
2648 return sys_time<_Duration>(__tp.time_since_epoch())
2649 - __info.first.offset;
2652 template<
typename _Duration>
2653 sys_time<common_type_t<_Duration, seconds>>
2654 to_sys(
const local_time<_Duration>& __tp, choose __z)
const
2656 local_info __info = get_info(__tp);
2658 if (__info.result == local_info::nonexistent)
2659 return __info.first.end;
2661 sys_time<_Duration> __st(__tp.time_since_epoch());
2663 if (__info.result == local_info::ambiguous && __z == choose::latest)
2664 return __st - __info.second.offset;
2667 return __st - __info.first.offset;
2670 template<
typename _Duration>
2671 local_time<common_type_t<_Duration, seconds>>
2672 to_local(
const sys_time<_Duration>& __tp)
const
2674 auto __d = (__tp + get_info(__tp).offset).time_since_epoch();
2675 return local_time<common_type_t<_Duration, seconds>>(__d);
2678 [[nodiscard]]
friend bool
2679 operator==(
const time_zone& __x,
const time_zone& __y)
noexcept
2680 {
return __x._M_name == __y._M_name; }
2682 [[nodiscard]]
friend strong_ordering
2683 operator<=>(
const time_zone& __x,
const time_zone& __y)
noexcept
2684 {
return __x._M_name <=> __y._M_name; }
2687 sys_info _M_get_sys_info(sys_seconds)
const;
2688 local_info _M_get_local_info(local_seconds)
const;
2690 friend const tzdb& reload_tzdb();
2692 friend class tzdb_list;
2696 explicit time_zone(unique_ptr<_Impl> __p);
2698 unique_ptr<_Impl> _M_impl;
2701 const time_zone* locate_zone(string_view __tz_name);
2702 const time_zone* current_zone();
2723 tzdb_list(
const tzdb_list&) =
delete;
2724 tzdb_list& operator=(
const tzdb_list&) =
delete;
2733 class const_iterator
2736 using value_type = tzdb;
2737 using reference =
const tzdb&;
2738 using pointer =
const tzdb*;
2739 using difference_type = ptrdiff_t;
2742 constexpr const_iterator() =
default;
2743 const_iterator(
const const_iterator&) =
default;
2744 const_iterator(const_iterator&&) =
default;
2745 const_iterator& operator=(
const const_iterator&) =
default;
2746 const_iterator& operator=(const_iterator&&) =
default;
2748 reference operator*()
const noexcept;
2749 pointer operator->()
const noexcept {
return &**
this; }
2750 const_iterator& operator++();
2751 const_iterator operator++(
int);
2753 bool operator==(
const const_iterator&)
const noexcept =
default;
2758 friend class tzdb_list;
2761 void* _M_reserved =
nullptr;
2791 const_iterator
cbegin() const noexcept {
return begin(); }
2792 const_iterator
cend() const noexcept {
return end(); }
2795 constexpr explicit tzdb_list(nullptr_t);
2797 friend tzdb_list& get_tzdb_list();
2798 friend const tzdb& get_tzdb();
2799 friend const tzdb& reload_tzdb();
2801 friend class leap_second;
2802 friend struct time_zone::_Impl;
2803 friend class time_zone_link;
2806 class time_zone_link
2809 time_zone_link(time_zone_link&&) =
default;
2810 time_zone_link& operator=(time_zone_link&&) =
default;
2812 string_view name() const noexcept {
return _M_name; }
2813 string_view target() const noexcept {
return _M_target; }
2816 operator==(
const time_zone_link& __x,
const time_zone_link& __y)
noexcept
2817 {
return __x.name() == __y.name(); }
2819 friend strong_ordering
2820 operator<=>(
const time_zone_link& __x,
const time_zone_link& __y)
noexcept
2821 {
return __x.name() <=> __y.name(); }
2824 friend const tzdb& reload_tzdb();
2825 friend struct tzdb_list::_Node;
2827 explicit time_zone_link(nullptr_t) { }
2836 leap_second(
const leap_second&) =
default;
2837 leap_second& operator=(
const leap_second&) =
default;
2840 constexpr sys_seconds
2841 date() const noexcept
2843 if (_M_s >= _M_s.zero()) [[likely]]
2844 return sys_seconds(_M_s);
2845 return sys_seconds(-_M_s);
2850 value() const noexcept
2852 if (_M_s >= _M_s.zero()) [[likely]]
2859 [[nodiscard]]
friend constexpr bool
2860 operator==(
const leap_second&,
const leap_second&)
noexcept =
default;
2862 [[nodiscard]]
friend constexpr strong_ordering
2863 operator<=>(
const leap_second& __x,
const leap_second& __y)
noexcept
2864 {
return __x.date() <=> __y.date(); }
2866 template<
typename _Duration>
2867 [[nodiscard]]
friend constexpr bool
2868 operator==(
const leap_second& __x,
2869 const sys_time<_Duration>& __y)
noexcept
2870 {
return __x.date() == __y; }
2872 template<
typename _Duration>
2873 [[nodiscard]]
friend constexpr bool
2875 const sys_time<_Duration>& __y)
noexcept
2876 {
return __x.date() < __y; }
2878 template<
typename _Duration>
2879 [[nodiscard]]
friend constexpr bool
2880 operator<(
const sys_time<_Duration>& __x,
2881 const leap_second& __y)
noexcept
2882 {
return __x < __y.date(); }
2884 template<
typename _Duration>
2885 [[nodiscard]]
friend constexpr bool
2887 const sys_time<_Duration>& __y)
noexcept
2888 {
return __y < __x.date(); }
2890 template<
typename _Duration>
2891 [[nodiscard]]
friend constexpr bool
2892 operator>(
const sys_time<_Duration>& __x,
2893 const leap_second& __y)
noexcept
2894 {
return __y.date() < __x; }
2896 template<
typename _Duration>
2897 [[nodiscard]]
friend constexpr bool
2899 const sys_time<_Duration>& __y)
noexcept
2900 {
return !(__y < __x.date()); }
2902 template<
typename _Duration>
2903 [[nodiscard]]
friend constexpr bool
2905 const leap_second& __y)
noexcept
2906 {
return !(__y.date() < __x); }
2908 template<
typename _Duration>
2909 [[nodiscard]]
friend constexpr bool
2911 const sys_time<_Duration>& __y)
noexcept
2912 {
return !(__x.date() < __y); }
2914 template<
typename _Duration>
2915 [[nodiscard]]
friend constexpr bool
2917 const leap_second& __y)
noexcept
2918 {
return !(__x < __y.date()); }
2922 template<three_way_comparable_with<seconds> _Duration>
2923 [[nodiscard]]
friend constexpr auto
2924 operator<=>(
const leap_second& __x,
2925 const sys_time<_Duration>& __y)
noexcept
2926 {
return __x.date() <=> __y; }
2929 explicit leap_second(seconds::rep __s) : _M_s(__s) { }
2931 friend struct tzdb_list::_Node;
2933 friend const tzdb& reload_tzdb();
2935 template<
typename _Duration>
2936 friend leap_second_info
2937 get_leap_second_info(
const utc_time<_Duration>&);
2942 template<
class _Tp>
struct zoned_traits { };
2945 struct zoned_traits<const time_zone*>
2947 static const time_zone*
2949 {
return std::chrono::locate_zone(
"UTC"); }
2951 static const time_zone*
2952 locate_zone(string_view __name)
2953 {
return std::chrono::locate_zone(__name); }
2959 _GLIBCXX_STD_C::vector<time_zone> zones;
2960 _GLIBCXX_STD_C::vector<time_zone_link> links;
2961 _GLIBCXX_STD_C::vector<leap_second> leap_seconds;
2964 locate_zone(string_view __tz_name)
const;
2967 current_zone()
const;
2970 friend const tzdb& reload_tzdb();
2971 friend class time_zone;
2972 friend struct tzdb_list::_Node;
2975 tzdb_list& get_tzdb_list();
2976 const tzdb& get_tzdb();
2978 const tzdb& reload_tzdb();
2979 string remote_version();
2981 template<
typename _Duration,
typename _TimeZonePtr = const time_zone*>
2984 static_assert(__is_duration_v<_Duration>);
2986 using _Traits = zoned_traits<_TimeZonePtr>;
2990 using string_view = type_identity_t<std::string_view>;
2993 using duration = common_type_t<_Duration, seconds>;
2995 zoned_time()
requires requires { _Traits::default_zone(); }
2998 zoned_time(
const zoned_time&) =
default;
2999 zoned_time& operator=(
const zoned_time&) =
default;
3001 zoned_time(
const sys_time<_Duration>& __st)
3002 requires requires { _Traits::default_zone(); }
3007 zoned_time(_TimeZonePtr __z) : _M_zone(std::
move(__z)) { }
3010 zoned_time(string_view __name)
3012 _TimeZonePtr{_Traits::locate_zone(std::string_view{})};
3014 : _M_zone(_Traits::locate_zone(__name))
3017 template<
typename _Duration2>
3018 zoned_time(
const zoned_time<_Duration2, _TimeZonePtr>& __zt)
3019 requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
3020 : _M_zone(__zt._M_zone), _M_tp(__zt._M_tp)
3023 zoned_time(_TimeZonePtr __z,
const sys_time<_Duration>& __st)
3024 : _M_zone(std::
move(__z)), _M_tp(__st)
3027 zoned_time(string_view __name,
const sys_time<_Duration>& __st)
3028 : zoned_time(_Traits::locate_zone(__name), __st)
3031 zoned_time(_TimeZonePtr __z,
const local_time<_Duration>& __tp)
3033 { __z->to_sys(__tp) } -> convertible_to<sys_time<_Duration>>;
3035 : _M_zone(
std::move(__z)), _M_tp(_M_zone->to_sys(__tp))
3038 zoned_time(string_view __name,
const local_time<_Duration>& __tp)
3039 requires requires (_TimeZonePtr __z) {
3040 { _Traits::locate_zone(__name) } -> convertible_to<_TimeZonePtr>;
3041 { __z->to_sys(__tp) } -> convertible_to<sys_time<_Duration>>;
3043 : zoned_time(_Traits::locate_zone(__name), __tp)
3046 zoned_time(_TimeZonePtr __z,
const local_time<_Duration>& __tp,
3049 { __z->to_sys(__tp, __c) } -> convertible_to<sys_time<_Duration>>;
3051 : _M_zone(
std::move(__z)), _M_tp(_M_zone->to_sys(__tp, __c))
3054 zoned_time(string_view __name,
const local_time<_Duration>& __tp,
3056 requires requires (_TimeZonePtr __z) {
3057 { _Traits::locate_zone(__name) } -> convertible_to<_TimeZonePtr>;
3058 { __z->to_sys(__tp, __c) } -> convertible_to<sys_time<_Duration>>;
3060 : _M_zone(_Traits::locate_zone(__name)),
3061 _M_tp(_M_zone->to_sys(__tp, __c))
3064 template<
typename _Duration2,
typename _TimeZonePtr2>
3065 zoned_time(_TimeZonePtr __z,
3066 const zoned_time<_Duration2, _TimeZonePtr2>& __zt)
3067 requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
3068 : _M_zone(__z), _M_tp(__zt._M_tp)
3071 template<
typename _Duration2,
typename _TimeZonePtr2>
3072 zoned_time(_TimeZonePtr __z,
3073 const zoned_time<_Duration2, _TimeZonePtr2>& __zt,
3075 requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
3076 : _M_zone(__z), _M_tp(__zt._M_tp)
3079 template<
typename _Duration2,
typename _TimeZonePtr2>
3080 zoned_time(string_view __name,
3081 const zoned_time<_Duration2, _TimeZonePtr2>& __zt)
3082 requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
3084 { _Traits::locate_zone(__name) } -> convertible_to<_TimeZonePtr>;
3086 : _M_zone(_Traits::locate_zone(__name)), _M_tp(__zt._M_tp)
3089 template<
typename _Duration2,
typename _TimeZonePtr2>
3090 zoned_time(string_view __name,
3091 const zoned_time<_Duration2, _TimeZonePtr2>& __zt,
3093 requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
3095 { _Traits::locate_zone(__name) } -> convertible_to<_TimeZonePtr>;
3097 : _M_zone(_Traits::locate_zone(__name)), _M_tp(__zt._M_tp)
3101 operator=(
const sys_time<_Duration>& __st)
3108 operator=(
const local_time<_Duration>& __lt)
3110 _M_tp = _M_zone->to_sys(__lt);
3115 operator sys_time<duration>()
const {
return _M_tp; }
3118 explicit operator local_time<duration>()
const
3119 {
return get_local_time(); }
3123 get_time_zone()
const
3127 local_time<duration>
3128 get_local_time()
const
3129 {
return _M_zone->to_local(_M_tp); }
3133 get_sys_time()
const
3139 {
return _M_zone->get_info(_M_tp); }
3141 [[nodiscard]]
friend bool
3142 operator==(
const zoned_time&,
const zoned_time&) =
default;
3145 _TimeZonePtr _M_zone{ _Traits::default_zone() };
3146 sys_time<duration> _M_tp{};
3148 template<
typename _Duration2,
typename _TimeZonePtr2>
3149 friend class zoned_time;
3152 zoned_time() -> zoned_time<seconds>;
3154 template<
typename _Duration>
3155 zoned_time(sys_time<_Duration>)
3156 -> zoned_time<common_type_t<_Duration, seconds>>;
3159 template<
typename _TimeZonePtrOrName>
3160 using __time_zone_representation
3161 = __conditional_t<is_convertible_v<_TimeZonePtrOrName, string_view>,
3163 remove_cvref_t<_TimeZonePtrOrName>>;
3166 template<
typename _TimeZonePtrOrName>
3167 zoned_time(_TimeZonePtrOrName&&)
3168 -> zoned_time<seconds, __time_zone_representation<_TimeZonePtrOrName>>;
3170 template<
typename _TimeZonePtrOrName,
typename _Duration>
3171 zoned_time(_TimeZonePtrOrName&&, sys_time<_Duration>)
3172 -> zoned_time<common_type_t<_Duration, seconds>,
3173 __time_zone_representation<_TimeZonePtrOrName>>;
3175 template<
typename _TimeZonePtrOrName,
typename _Duration>
3176 zoned_time(_TimeZonePtrOrName&&, local_time<_Duration>,
3177 choose = choose::earliest)
3178 -> zoned_time<common_type_t<_Duration, seconds>,
3179 __time_zone_representation<_TimeZonePtrOrName>>;
3181 template<
typename _Duration,
typename _TimeZonePtrOrName,
3182 typename _TimeZonePtr2>
3183 zoned_time(_TimeZonePtrOrName&&, zoned_time<_Duration, _TimeZonePtr2>,
3184 choose = choose::earliest)
3185 -> zoned_time<common_type_t<_Duration, seconds>,
3186 __time_zone_representation<_TimeZonePtrOrName>>;
3188 template<
typename _Dur1,
typename _TZPtr1,
typename _Dur2,
typename _TZPtr2>
3191 operator==(
const zoned_time<_Dur1, _TZPtr1>& __x,
3192 const zoned_time<_Dur2, _TZPtr2>& __y)
3194 return __x.get_time_zone() == __y.get_time_zone()
3195 && __x.get_sys_time() == __y.get_sys_time();
3198 using zoned_seconds = zoned_time<seconds>;
3203 inline leap_second_info
3204 __get_leap_second_info(sys_seconds __ss,
bool __is_utc)
3206 if (__ss < sys_seconds{}) [[unlikely]]
3209 const seconds::rep __leaps[] {
3240 const sys_seconds __expires(1766880000s);
3242#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
3243 if (__ss > __expires)
3248 auto __db = get_tzdb_list().begin();
3249 auto __first = __db->leap_seconds.
begin() + __n;
3250 auto __last = __db->leap_seconds.end();
3251 auto __pos = std::upper_bound(__first, __last, __ss);
3253 for (
auto __i = __first; __i != __pos; ++__i)
3254 __elapsed += __i->value();
3261 if (__pos != __first && __ss < __pos[-1])
3263 if ((__ss + 1s) >= __pos[-1])
3264 return {
true, __elapsed};
3265 __elapsed -= __pos[-1].value();
3268 return {
false, __elapsed};
3273 seconds::rep __s = __ss.time_since_epoch().count();
3274 const seconds::rep* __first =
std::begin(__leaps);
3275 const seconds::rep* __last =
std::end(__leaps);
3278 if (__s > (__last[-1] + (__last - __first) + 1))
3279 return {
false,
seconds(__last - __first) };
3281 auto __pos = std::upper_bound(__first, __last, __s);
3282 seconds __elapsed{__pos - __first};
3286 __s -= __elapsed.count();
3288 if (__pos != __first && __s < __pos[-1])
3290 if ((__s + 1) >= __pos[-1])
3291 return {
true, __elapsed};
3295 return {
false, __elapsed};
3300 template<
typename _Duration>
3302 inline leap_second_info
3303 get_leap_second_info(
const utc_time<_Duration>& __ut)
3305 auto __s = chrono::duration_cast<seconds>(__ut.time_since_epoch());
3306 return __detail::__get_leap_second_info(sys_seconds(__s),
true);
3309 template<
typename _Duration>
3311 inline utc_time<common_type_t<_Duration, seconds>>
3312 utc_clock::from_sys(
const sys_time<_Duration>& __t)
3314 using _CDur = common_type_t<_Duration, seconds>;
3315 auto __s = chrono::time_point_cast<seconds>(__t);
3316 const auto __li = __detail::__get_leap_second_info(__s,
false);
3317 return utc_time<_CDur>{__t.time_since_epoch()} + __li.elapsed;
3325#ifdef __glibcxx_chrono_cxx20
3332#pragma GCC diagnostic push
3333#pragma GCC diagnostic ignored "-Wliteral-suffix"
3336 constexpr chrono::day
3337 operator""d(
unsigned long long __d)
noexcept
3338 {
return chrono::day{
static_cast<unsigned>(__d)}; }
3342 constexpr chrono::year
3343 operator""y(
unsigned long long __y)
noexcept
3344 {
return chrono::year{
static_cast<int>(__y)}; }
3345#pragma GCC diagnostic pop
3351_GLIBCXX_END_NAMESPACE_VERSION
3354#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.
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