30#ifndef _GLIBCXX_CHRONO
31#define _GLIBCXX_CHRONO 1
33#pragma GCC system_header
37#if __cplusplus < 201103L
43#if __cplusplus >= 202002L
49# include <bits/shared_ptr.h>
53#if __cplusplus >= 202002L
59namespace std _GLIBCXX_VISIBILITY(default)
61_GLIBCXX_BEGIN_NAMESPACE_VERSION
78#if __cplusplus >= 202002L
82 template<
typename _Duration>
91 template<
typename _Duration>
95 template<
typename _Duration>
99 template<
typename _Duration>
107 template<>
inline constexpr bool is_clock_v<utc_clock> =
true;
108 template<>
inline constexpr bool is_clock_v<tai_clock> =
true;
109 template<>
inline constexpr bool is_clock_v<gps_clock> =
true;
111 struct leap_second_info
117 template<
typename _Duration>
130 using rep = system_clock::rep;
131 using period = system_clock::period;
134 static constexpr bool is_steady =
false;
139 {
return from_sys(system_clock::now()); }
141 template<
typename _Duration>
147 const auto __li = chrono::get_leap_second_info(__t);
149 if (__li.is_leap_second)
150 __s = chrono::floor<seconds>(__s) +
seconds{1} - _CDur{1};
154 template<
typename _Duration>
169 using rep = system_clock::rep;
170 using period = system_clock::period;
173 static constexpr bool is_steady =
false;
179 {
return from_utc(utc_clock::now()); }
181 template<
typename _Duration>
190 template<
typename _Duration>
209 using rep = system_clock::rep;
210 using period = system_clock::period;
213 static constexpr bool is_steady =
false;
219 {
return from_utc(utc_clock::now()); }
221 template<
typename _Duration>
230 template<
typename _Duration>
241 template<
typename _DestClock,
typename _SourceClock>
242 struct clock_time_conversion
247 template<
typename _Clock>
248 struct clock_time_conversion<_Clock, _Clock>
250 template<
typename _Duration>
251 time_point<_Clock, _Duration>
252 operator()(
const time_point<_Clock, _Duration>& __t)
const
257 struct clock_time_conversion<system_clock, system_clock>
259 template<
typename _Duration>
261 operator()(
const sys_time<_Duration>& __t)
const
266 struct clock_time_conversion<utc_clock, utc_clock>
268 template<
typename _Duration>
270 operator()(
const utc_time<_Duration>& __t)
const
277 struct clock_time_conversion<utc_clock, system_clock>
279 template<
typename _Duration>
280 utc_time<common_type_t<_Duration, seconds>>
281 operator()(
const sys_time<_Duration>& __t)
const
282 {
return utc_clock::from_sys(__t); }
286 struct clock_time_conversion<system_clock, utc_clock>
288 template<
typename _Duration>
289 sys_time<common_type_t<_Duration, seconds>>
290 operator()(
const utc_time<_Duration>& __t)
const
291 {
return utc_clock::to_sys(__t); }
294 template<
typename _Tp,
typename _Clock>
295 inline constexpr bool __is_time_point_for_v =
false;
297 template<
typename _Clock,
typename _Duration>
298 inline constexpr bool
299 __is_time_point_for_v<time_point<_Clock, _Duration>, _Clock> =
true;
303 template<
typename _SourceClock>
304 struct clock_time_conversion<system_clock, _SourceClock>
306 template<
typename _Duration,
typename _Src = _SourceClock>
308 operator()(
const time_point<_SourceClock, _Duration>& __t)
const
309 ->
decltype(_Src::to_sys(__t))
311 using _Ret =
decltype(_SourceClock::to_sys(__t));
312 static_assert(__is_time_point_for_v<_Ret, system_clock>);
313 return _SourceClock::to_sys(__t);
317 template<
typename _DestClock>
318 struct clock_time_conversion<_DestClock, system_clock>
320 template<
typename _Duration,
typename _Dest = _DestClock>
322 operator()(
const sys_time<_Duration>& __t)
const
323 ->
decltype(_Dest::from_sys(__t))
325 using _Ret =
decltype(_DestClock::from_sys(__t));
326 static_assert(__is_time_point_for_v<_Ret, _DestClock>);
327 return _DestClock::from_sys(__t);
333 template<
typename _SourceClock>
334 struct clock_time_conversion<utc_clock, _SourceClock>
336 template<
typename _Duration,
typename _Src = _SourceClock>
338 operator()(
const time_point<_SourceClock, _Duration>& __t)
const
339 ->
decltype(_Src::to_utc(__t))
341 using _Ret =
decltype(_SourceClock::to_utc(__t));
342 static_assert(__is_time_point_for_v<_Ret, utc_clock>);
343 return _SourceClock::to_utc(__t);
347 template<
typename _DestClock>
348 struct clock_time_conversion<_DestClock, utc_clock>
350 template<
typename _Duration,
typename _Dest = _DestClock>
352 operator()(
const utc_time<_Duration>& __t)
const
353 ->
decltype(_Dest::from_utc(__t))
355 using _Ret =
decltype(_DestClock::from_utc(__t));
356 static_assert(__is_time_point_for_v<_Ret, _DestClock>);
357 return _DestClock::from_utc(__t);
364 template<
typename _DestClock,
typename _SourceClock,
typename _Duration>
365 concept __clock_convs
366 =
requires (
const time_point<_SourceClock, _Duration>& __t) {
367 clock_time_conversion<_DestClock, _SourceClock>{}(__t);
370 template<
typename _DestClock,
typename _SourceClock,
typename _Duration>
371 concept __clock_convs_sys
372 =
requires (
const time_point<_SourceClock, _Duration>& __t) {
373 clock_time_conversion<_DestClock, system_clock>{}(
374 clock_time_conversion<system_clock, _SourceClock>{}(__t));
377 template<
typename _DestClock,
typename _SourceClock,
typename _Duration>
378 concept __clock_convs_utc
379 =
requires (
const time_point<_SourceClock, _Duration>& __t) {
380 clock_time_conversion<_DestClock, utc_clock>{}(
381 clock_time_conversion<utc_clock, _SourceClock>{}(__t));
384 template<
typename _DestClock,
typename _SourceClock,
typename _Duration>
385 concept __clock_convs_sys_utc
386 =
requires (
const time_point<_SourceClock, _Duration>& __t) {
387 clock_time_conversion<_DestClock, utc_clock>{}(
388 clock_time_conversion<utc_clock, system_clock>{}(
389 clock_time_conversion<system_clock, _SourceClock>{}(__t)));
392 template<
typename _DestClock,
typename _SourceClock,
typename _Duration>
393 concept __clock_convs_utc_sys
394 =
requires (
const time_point<_SourceClock, _Duration>& __t) {
395 clock_time_conversion<_DestClock, system_clock>{}(
396 clock_time_conversion<system_clock, utc_clock>{}(
397 clock_time_conversion<utc_clock, _SourceClock>{}(__t)));
404 template<
typename _DestClock,
typename _SourceClock,
typename _Duration>
408 requires __detail::__clock_convs<_DestClock, _SourceClock, _Duration>
409 || __detail::__clock_convs_sys<_DestClock, _SourceClock, _Duration>
410 || __detail::__clock_convs_utc<_DestClock, _SourceClock, _Duration>
411 || __detail::__clock_convs_sys_utc<_DestClock, _SourceClock, _Duration>
412 || __detail::__clock_convs_utc_sys<_DestClock, _SourceClock, _Duration>
414 constexpr bool __direct
415 = __detail::__clock_convs<_DestClock, _SourceClock, _Duration>;
416 if constexpr (__direct)
418 return clock_time_conversion<_DestClock, _SourceClock>{}(__t);
422 constexpr bool __convert_via_sys_clock
423 = __detail::__clock_convs_sys<_DestClock, _SourceClock, _Duration>;
424 constexpr bool __convert_via_utc_clock
425 = __detail::__clock_convs_utc<_DestClock, _SourceClock, _Duration>;
426 if constexpr (__convert_via_sys_clock)
428 static_assert(!__convert_via_utc_clock,
429 "clock_cast requires a unique best conversion, but "
430 "conversion is possible via system_clock and also via"
432 return clock_time_conversion<_DestClock, system_clock>{}(
433 clock_time_conversion<system_clock, _SourceClock>{}(__t));
435 else if constexpr (__convert_via_utc_clock)
437 return clock_time_conversion<_DestClock, utc_clock>{}(
438 clock_time_conversion<utc_clock, _SourceClock>{}(__t));
442 constexpr bool __convert_via_sys_and_utc_clocks
443 = __detail::__clock_convs_sys_utc<_DestClock,
447 if constexpr (__convert_via_sys_and_utc_clocks)
449 constexpr bool __convert_via_utc_and_sys_clocks
450 = __detail::__clock_convs_utc_sys<_DestClock,
453 static_assert(!__convert_via_utc_and_sys_clocks,
454 "clock_cast requires a unique best conversion, but "
455 "conversion is possible via system_clock followed by "
456 "utc_clock, and also via utc_clock followed by "
458 return clock_time_conversion<_DestClock, utc_clock>{}(
459 clock_time_conversion<utc_clock, system_clock>{}(
460 clock_time_conversion<system_clock, _SourceClock>{}(__t)));
464 return clock_time_conversion<_DestClock, system_clock>{}(
465 clock_time_conversion<system_clock, utc_clock>{}(
466 clock_time_conversion<utc_clock, _SourceClock>{}(__t)));
479 class weekday_indexed;
482 class month_day_last;
484 class month_weekday_last;
486 class year_month_day;
487 class year_month_day_last;
488 class year_month_weekday;
489 class year_month_weekday_last;
493 explicit last_spec() =
default;
495 friend constexpr month_day_last
498 friend constexpr month_day_last
502 inline constexpr last_spec last{};
507 template <
unsigned __d,
typename _Tp>
511 using _Up = make_unsigned_t<_Tp>;
512 auto constexpr __a = _Up(-1) - _Up(255 + __d - 2);
513 auto constexpr __b = _Up(__d * (__a / __d) - 1);
515 return _Up(-1) - __b;
521 template <
unsigned __d,
typename _Tp>
523 __add_modulo(
unsigned __x, _Tp __y)
525 using _Up = make_unsigned_t<_Tp>;
535 auto const __offset = __y >= 0 ? _Up(0) : __modulo_offset<__d, _Tp>();
536 return (__x + _Up(__y) - __offset) % __d;
540 template <
unsigned __d,
typename _Tp>
542 __sub_modulo(
unsigned __x, _Tp __y)
544 using _Up = make_unsigned_t<_Tp>;
545 auto const __offset = __y <= 0 ? _Up(0) : __modulo_offset<__d, _Tp>();
546 return (__x - _Up(__y) - __offset) % __d;
549 inline constexpr unsigned __days_per_month[12]
550 = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
564 day(
unsigned __d) noexcept
569 operator++() noexcept
576 operator++(
int)
noexcept
584 operator--() noexcept
591 operator--(
int)
noexcept
599 operator+=(
const days& __d)
noexcept
606 operator-=(
const days& __d)
noexcept
613 operator unsigned() const noexcept
618 {
return 1 <= _M_d && _M_d <= 31; }
620 friend constexpr bool
621 operator==(
const day& __x,
const day& __y)
noexcept
622 {
return unsigned{__x} ==
unsigned{__y}; }
624 friend constexpr strong_ordering
625 operator<=>(
const day& __x,
const day& __y)
noexcept
626 {
return unsigned{__x} <=>
unsigned{__y}; }
630 {
return day(
unsigned{__x} + __y.count()); }
634 {
return __y + __x; }
638 {
return __x + -__y; }
640 friend constexpr days
641 operator-(
const day& __x,
const day& __y)
noexcept
642 {
return days{int(
unsigned{__x}) -
int(
unsigned{__y})}; }
644 friend constexpr month_day
645 operator/(
const month& __m,
const day& __d)
noexcept;
647 friend constexpr month_day
648 operator/(
int __m,
const day& __d)
noexcept;
650 friend constexpr month_day
651 operator/(
const day& __d,
const month& __m)
noexcept;
653 friend constexpr month_day
654 operator/(
const day& __d,
int __m)
noexcept;
656 friend constexpr year_month_day
657 operator/(
const year_month& __ym,
const day& __d)
noexcept;
671 month(
unsigned __m) noexcept
676 operator++() noexcept
683 operator++(
int)
noexcept
691 operator--() noexcept
698 operator--(
int)
noexcept
706 operator+=(
const months& __m)
noexcept
713 operator-=(
const months& __m)
noexcept
720 operator unsigned() const noexcept
725 {
return 1 <= _M_m && _M_m <= 12; }
727 friend constexpr bool
728 operator==(
const month& __x,
const month& __y)
noexcept
729 {
return unsigned{__x} ==
unsigned{__y}; }
731 friend constexpr strong_ordering
732 operator<=>(
const month& __x,
const month& __y)
noexcept
733 {
return unsigned{__x} <=>
unsigned{__y}; }
735 friend constexpr month
740 return month{1 + __detail::__add_modulo<12>(
741 unsigned{__x} + 11, __y.count())};
744 friend constexpr month
746 {
return __y + __x; }
748 friend constexpr month
753 return month{1 + __detail::__sub_modulo<12>(
754 unsigned{__x} + 11, __y.count())};
758 operator-(
const month& __x,
const month& __y)
noexcept
760 const auto __dm = int(
unsigned(__x)) - int(
unsigned(__y));
761 return months{__dm < 0 ? 12 + __dm : __dm};
764 friend constexpr year_month
765 operator/(
const year& __y,
const month& __m)
noexcept;
767 friend constexpr month_day
768 operator/(
const month& __m,
int __d)
noexcept;
770 friend constexpr month_day_last
771 operator/(
const month& __m, last_spec)
noexcept;
773 friend constexpr month_day_last
774 operator/(last_spec,
const month& __m)
noexcept;
776 friend constexpr month_weekday
777 operator/(
const month& __m,
const weekday_indexed& __wdi)
noexcept;
779 friend constexpr month_weekday
780 operator/(
const weekday_indexed& __wdi,
const month& __m)
noexcept;
782 friend constexpr month_weekday_last
783 operator/(
const month& __m,
const weekday_last& __wdl)
noexcept;
785 friend constexpr month_weekday_last
786 operator/(
const weekday_last& __wdl,
const month& __m)
noexcept;
789 inline constexpr month January{1};
790 inline constexpr month February{2};
791 inline constexpr month March{3};
792 inline constexpr month April{4};
793 inline constexpr month May{5};
794 inline constexpr month June{6};
795 inline constexpr month July{7};
796 inline constexpr month August{8};
797 inline constexpr month September{9};
798 inline constexpr month October{10};
799 inline constexpr month November{11};
800 inline constexpr month December{12};
813 year(
int __y) noexcept
814 : _M_y{
static_cast<short>(__y)}
817 static constexpr year
819 {
return year{-32767}; }
821 static constexpr year
823 {
return year{32767}; }
826 operator++() noexcept
833 operator++(
int)
noexcept
841 operator--() noexcept
848 operator--(
int)
noexcept
856 operator+=(
const years& __y)
noexcept
863 operator-=(
const years& __y)
noexcept
875 {
return year{-_M_y}; }
878 is_leap() const noexcept
902 return (_M_y & (_M_y % 25 == 0 ? 15 : 3)) == 0;
906 operator int() const noexcept
911 {
return min()._M_y <= _M_y && _M_y <= max()._M_y; }
913 friend constexpr bool
914 operator==(
const year& __x,
const year& __y)
noexcept
915 {
return int{__x} ==
int{__y}; }
917 friend constexpr strong_ordering
918 operator<=>(
const year& __x,
const year& __y)
noexcept
919 {
return int{__x} <=>
int{__y}; }
921 friend constexpr year
923 {
return year{
int{__x} +
static_cast<int>(__y.count())}; }
925 friend constexpr year
927 {
return __y + __x; }
929 friend constexpr year
931 {
return __x + -__y; }
933 friend constexpr years
934 operator-(
const year& __x,
const year& __y)
noexcept
935 {
return years{
int{__x} -
int{__y}}; }
937 friend constexpr year_month
938 operator/(
const year& __y,
int __m)
noexcept;
940 friend constexpr year_month_day
941 operator/(
const year& __y,
const month_day& __md)
noexcept;
943 friend constexpr year_month_day
944 operator/(
const month_day& __md,
const year& __y)
noexcept;
946 friend constexpr year_month_day_last
947 operator/(
const year& __y,
const month_day_last& __mdl)
noexcept;
949 friend constexpr year_month_day_last
950 operator/(
const month_day_last& __mdl,
const year& __y)
noexcept;
952 friend constexpr year_month_weekday
953 operator/(
const year& __y,
const month_weekday& __mwd)
noexcept;
955 friend constexpr year_month_weekday
956 operator/(
const month_weekday& __mwd,
const year& __y)
noexcept;
958 friend constexpr year_month_weekday_last
959 operator/(
const year& __y,
const month_weekday_last& __mwdl)
noexcept;
961 friend constexpr year_month_weekday_last
962 operator/(
const month_weekday_last& __mwdl,
const year& __y)
noexcept;
972 static constexpr weekday
973 _S_from_days(
const days& __d)
975 return weekday{__detail::__add_modulo<7>(4, __d.count())};
982 weekday(
unsigned __wd) noexcept
983 : _M_wd(__wd == 7 ? 0 : __wd)
987 weekday(
const sys_days& __dp) noexcept
988 : weekday{_S_from_days(__dp.time_since_epoch())}
992 weekday(
const local_days& __dp) noexcept
993 : weekday{sys_days{__dp.time_since_epoch()}}
997 operator++() noexcept
1004 operator++(
int)
noexcept
1012 operator--() noexcept
1019 operator--(
int)
noexcept
1027 operator+=(
const days& __d)
noexcept
1029 *
this = *
this + __d;
1034 operator-=(
const days& __d)
noexcept
1036 *
this = *
this - __d;
1041 c_encoding() const noexcept
1045 iso_encoding() const noexcept
1046 {
return _M_wd == 0u ? 7u : _M_wd; }
1050 {
return _M_wd <= 6; }
1052 constexpr weekday_indexed
1053 operator[](
unsigned __index)
const noexcept;
1055 constexpr weekday_last
1056 operator[](last_spec)
const noexcept;
1058 friend constexpr bool
1059 operator==(
const weekday& __x,
const weekday& __y)
noexcept
1060 {
return __x._M_wd == __y._M_wd; }
1062 friend constexpr weekday
1065 return weekday{__detail::__add_modulo<7>(__x._M_wd, __y.count())};
1068 friend constexpr weekday
1070 {
return __y + __x; }
1072 friend constexpr weekday
1075 return weekday{__detail::__sub_modulo<7>(__x._M_wd, __y.count())};
1078 friend constexpr days
1079 operator-(
const weekday& __x,
const weekday& __y)
noexcept
1081 const auto __n = __x.c_encoding() - __y.c_encoding();
1082 return static_cast<int>(__n) >= 0 ?
days{__n} :
days{__n + 7};
1086 inline constexpr weekday Sunday{0};
1087 inline constexpr weekday Monday{1};
1088 inline constexpr weekday Tuesday{2};
1089 inline constexpr weekday Wednesday{3};
1090 inline constexpr weekday Thursday{4};
1091 inline constexpr weekday Friday{5};
1092 inline constexpr weekday Saturday{6};
1096 class weekday_indexed
1099 chrono::weekday _M_wd;
1100 unsigned char _M_index;
1103 weekday_indexed() =
default;
1106 weekday_indexed(
const chrono::weekday& __wd,
unsigned __index) noexcept
1107 : _M_wd(__wd), _M_index(__index)
1110 constexpr chrono::weekday
1111 weekday() const noexcept
1115 index() const noexcept
1116 {
return _M_index; };
1120 {
return _M_wd.ok() && 1 <= _M_index && _M_index <= 5; }
1122 friend constexpr bool
1123 operator==(
const weekday_indexed& __x,
const weekday_indexed& __y)
noexcept
1124 {
return __x.weekday() == __y.weekday() && __x.index() == __y.index(); }
1126 friend constexpr month_weekday
1127 operator/(
const month& __m,
const weekday_indexed& __wdi)
noexcept;
1129 friend constexpr month_weekday
1130 operator/(
int __m,
const weekday_indexed& __wdi)
noexcept;
1132 friend constexpr month_weekday
1133 operator/(
const weekday_indexed& __wdi,
const month& __m)
noexcept;
1135 friend constexpr month_weekday
1136 operator/(
const weekday_indexed& __wdi,
int __m)
noexcept;
1138 friend constexpr year_month_weekday
1139 operator/(
const year_month& __ym,
const weekday_indexed& __wdi)
noexcept;
1142 constexpr weekday_indexed
1143 weekday::operator[](
unsigned __index)
const noexcept
1144 {
return {*
this, __index}; }
1151 chrono::weekday _M_wd;
1155 weekday_last(
const chrono::weekday& __wd) noexcept
1159 constexpr chrono::weekday
1160 weekday() const noexcept
1165 {
return _M_wd.ok(); }
1167 friend constexpr bool
1168 operator==(
const weekday_last& __x,
const weekday_last& __y)
noexcept
1169 {
return __x.weekday() == __y.weekday(); }
1171 friend constexpr month_weekday_last
1172 operator/(
int __m,
const weekday_last& __wdl)
noexcept;
1174 friend constexpr month_weekday_last
1175 operator/(
const weekday_last& __wdl,
int __m)
noexcept;
1177 friend constexpr year_month_weekday_last
1178 operator/(
const year_month& __ym,
const weekday_last& __wdl)
noexcept;
1181 constexpr weekday_last
1182 weekday::operator[](last_spec)
const noexcept
1183 {
return weekday_last{*
this}; }
1194 month_day() =
default;
1197 month_day(
const chrono::month& __m,
const chrono::day& __d) noexcept
1198 : _M_m{__m}, _M_d{__d}
1201 constexpr chrono::month
1202 month() const noexcept
1205 constexpr chrono::day
1206 day() const noexcept
1213 && 1u <= unsigned(_M_d)
1214 && unsigned(_M_d) <= __detail::__days_per_month[unsigned(_M_m) - 1];
1217 friend constexpr bool
1218 operator==(
const month_day& __x,
const month_day& __y)
noexcept
1219 {
return __x.month() == __y.month() && __x.day() == __y.day(); }
1221 friend constexpr strong_ordering
1222 operator<=>(
const month_day& __x,
const month_day& __y)
noexcept
1225 friend constexpr month_day
1226 operator/(
const chrono::month& __m,
const chrono::day& __d)
noexcept
1227 {
return {__m, __d}; }
1229 friend constexpr month_day
1230 operator/(
const chrono::month& __m,
int __d)
noexcept
1231 {
return {__m, chrono::day(
unsigned(__d))}; }
1233 friend constexpr month_day
1234 operator/(
int __m,
const chrono::day& __d)
noexcept
1235 {
return {chrono::month(
unsigned(__m)), __d}; }
1237 friend constexpr month_day
1238 operator/(
const chrono::day& __d,
const chrono::month& __m)
noexcept
1239 {
return {__m, __d}; }
1241 friend constexpr month_day
1242 operator/(
const chrono::day& __d,
int __m)
noexcept
1243 {
return {chrono::month(
unsigned(__m)), __d}; }
1245 friend constexpr year_month_day
1246 operator/(
int __y,
const month_day& __md)
noexcept;
1248 friend constexpr year_month_day
1249 operator/(
const month_day& __md,
int __y)
noexcept;
1254 class month_day_last
1261 month_day_last(
const chrono::month& __m) noexcept
1265 constexpr chrono::month
1266 month() const noexcept
1271 {
return _M_m.ok(); }
1273 friend constexpr bool
1274 operator==(
const month_day_last& __x,
const month_day_last& __y)
noexcept
1275 {
return __x.month() == __y.month(); }
1277 friend constexpr strong_ordering
1278 operator<=>(
const month_day_last& __x,
const month_day_last& __y)
noexcept
1281 friend constexpr month_day_last
1282 operator/(
const chrono::month& __m, last_spec)
noexcept
1283 {
return month_day_last{__m}; }
1285 friend constexpr month_day_last
1287 {
return chrono::month(
unsigned(__m)) / last; }
1289 friend constexpr month_day_last
1290 operator/(last_spec,
const chrono::month& __m)
noexcept
1291 {
return __m / last; }
1293 friend constexpr month_day_last
1295 {
return __m / last; }
1297 friend constexpr year_month_day_last
1298 operator/(
int __y,
const month_day_last& __mdl)
noexcept;
1300 friend constexpr year_month_day_last
1301 operator/(
const month_day_last& __mdl,
int __y)
noexcept;
1310 chrono::weekday_indexed _M_wdi;
1314 month_weekday(
const chrono::month& __m,
1315 const chrono::weekday_indexed& __wdi) noexcept
1316 : _M_m{__m}, _M_wdi{__wdi}
1319 constexpr chrono::month
1320 month() const noexcept
1323 constexpr chrono::weekday_indexed
1324 weekday_indexed() const noexcept
1329 {
return _M_m.ok() && _M_wdi.ok(); }
1331 friend constexpr bool
1332 operator==(
const month_weekday& __x,
const month_weekday& __y)
noexcept
1334 return __x.month() == __y.month()
1335 && __x.weekday_indexed() == __y.weekday_indexed();
1338 friend constexpr month_weekday
1340 const chrono::weekday_indexed& __wdi)
noexcept
1341 {
return {__m, __wdi}; }
1343 friend constexpr month_weekday
1344 operator/(
int __m,
const chrono::weekday_indexed& __wdi)
noexcept
1345 {
return chrono::month(
unsigned(__m)) / __wdi; }
1347 friend constexpr month_weekday
1348 operator/(
const chrono::weekday_indexed& __wdi,
1349 const chrono::month& __m)
noexcept
1350 {
return __m / __wdi; }
1352 friend constexpr month_weekday
1353 operator/(
const chrono::weekday_indexed& __wdi,
int __m)
noexcept
1354 {
return __m / __wdi; }
1356 friend constexpr year_month_weekday
1357 operator/(
int __y,
const month_weekday& __mwd)
noexcept;
1359 friend constexpr year_month_weekday
1360 operator/(
const month_weekday& __mwd,
int __y)
noexcept;
1365 class month_weekday_last
1369 chrono::weekday_last _M_wdl;
1373 month_weekday_last(
const chrono::month& __m,
1374 const chrono::weekday_last& __wdl) noexcept
1375 :_M_m{__m}, _M_wdl{__wdl}
1378 constexpr chrono::month
1379 month() const noexcept
1382 constexpr chrono::weekday_last
1383 weekday_last() const noexcept
1388 {
return _M_m.ok() && _M_wdl.ok(); }
1390 friend constexpr bool
1391 operator==(
const month_weekday_last& __x,
1392 const month_weekday_last& __y)
noexcept
1394 return __x.month() == __y.month()
1395 && __x.weekday_last() == __y.weekday_last();
1398 friend constexpr month_weekday_last
1400 const chrono::weekday_last& __wdl)
noexcept
1401 {
return {__m, __wdl}; }
1403 friend constexpr month_weekday_last
1404 operator/(
int __m,
const chrono::weekday_last& __wdl)
noexcept
1405 {
return chrono::month(
unsigned(__m)) / __wdl; }
1407 friend constexpr month_weekday_last
1408 operator/(
const chrono::weekday_last& __wdl,
1409 const chrono::month& __m)
noexcept
1410 {
return __m / __wdl; }
1412 friend constexpr month_weekday_last
1413 operator/(
const chrono::weekday_last& __wdl,
int __m)
noexcept
1414 {
return chrono::month(
unsigned(__m)) / __wdl; }
1416 friend constexpr year_month_weekday_last
1417 operator/(
int __y,
const month_weekday_last& __mwdl)
noexcept;
1419 friend constexpr year_month_weekday_last
1420 operator/(
const month_weekday_last& __mwdl,
int __y)
noexcept;
1439 using __months_years_conversion_disambiguator = void;
1449 year_month() =
default;
1452 year_month(
const chrono::year& __y,
const chrono::month& __m) noexcept
1453 : _M_y{__y}, _M_m{__m}
1456 constexpr chrono::year
1457 year() const noexcept
1460 constexpr chrono::month
1461 month() const noexcept
1464 template<
typename = __detail::__months_years_conversion_disambiguator>
1465 constexpr year_month&
1466 operator+=(
const months& __dm)
noexcept
1468 *
this = *
this + __dm;
1472 template<
typename = __detail::__months_years_conversion_disambiguator>
1473 constexpr year_month&
1474 operator-=(
const months& __dm)
noexcept
1476 *
this = *
this - __dm;
1480 constexpr year_month&
1481 operator+=(
const years& __dy)
noexcept
1483 *
this = *
this + __dy;
1487 constexpr year_month&
1488 operator-=(
const years& __dy)
noexcept
1490 *
this = *
this - __dy;
1496 {
return _M_y.ok() && _M_m.ok(); }
1498 friend constexpr bool
1499 operator==(
const year_month& __x,
const year_month& __y)
noexcept
1500 {
return __x.year() == __y.year() && __x.month() == __y.month(); }
1502 friend constexpr strong_ordering
1503 operator<=>(
const year_month& __x,
const year_month& __y)
noexcept
1506 template<
typename = __detail::__months_years_conversion_disambiguator>
1507 friend constexpr year_month
1511 auto __m = __ym.month() + __dm;
1512 auto __i = int(
unsigned(__ym.month())) - 1 + __dm.count();
1514 ? __ym.year() +
years{(__i - 11) / 12}
1515 : __ym.year() +
years{__i / 12});
1519 template<
typename = __detail::__months_years_conversion_disambiguator>
1520 friend constexpr year_month
1522 {
return __ym + __dm; }
1524 template<
typename = __detail::__months_years_conversion_disambiguator>
1525 friend constexpr year_month
1527 {
return __ym + -__dm; }
1530 operator-(
const year_month& __x,
const year_month& __y)
noexcept
1532 return (__x.year() - __y.year()
1533 +
months{static_cast<int>(unsigned{__x.month()})
1534 -
static_cast<int>(
unsigned{__y.month()})});
1537 friend constexpr year_month
1539 {
return (__ym.year() + __dy) / __ym.month(); }
1541 friend constexpr year_month
1543 {
return __ym + __dy; }
1545 friend constexpr year_month
1547 {
return __ym + -__dy; }
1549 friend constexpr year_month
1550 operator/(
const chrono::year& __y,
const chrono::month& __m)
noexcept
1551 {
return {__y, __m}; }
1553 friend constexpr year_month
1554 operator/(
const chrono::year& __y,
int __m)
noexcept
1555 {
return {__y, chrono::month(
unsigned(__m))}; }
1557 friend constexpr year_month_day
1558 operator/(
const year_month& __ym,
int __d)
noexcept;
1560 friend constexpr year_month_day_last
1561 operator/(
const year_month& __ym, last_spec)
noexcept;
1566 class year_month_day
1573 static constexpr year_month_day _S_from_days(
const days& __dp)
noexcept;
1575 constexpr days _M_days_since_epoch() const noexcept;
1578 year_month_day() = default;
1581 year_month_day(const chrono::year& __y, const chrono::month& __m,
1582 const chrono::day& __d) noexcept
1583 : _M_y{__y}, _M_m{__m}, _M_d{__d}
1587 year_month_day(
const year_month_day_last& __ymdl)
noexcept;
1590 year_month_day(
const sys_days& __dp) noexcept
1591 : year_month_day(_S_from_days(__dp.time_since_epoch()))
1595 year_month_day(
const local_days& __dp) noexcept
1596 : year_month_day(sys_days{__dp.time_since_epoch()})
1599 template<
typename = __detail::__months_years_conversion_disambiguator>
1600 constexpr year_month_day&
1601 operator+=(
const months& __m)
noexcept
1603 *
this = *
this + __m;
1607 template<
typename = __detail::__months_years_conversion_disambiguator>
1608 constexpr year_month_day&
1609 operator-=(
const months& __m)
noexcept
1611 *
this = *
this - __m;
1615 constexpr year_month_day&
1616 operator+=(
const years& __y)
noexcept
1618 *
this = *
this + __y;
1622 constexpr year_month_day&
1623 operator-=(
const years& __y)
noexcept
1625 *
this = *
this - __y;
1629 constexpr chrono::year
1630 year() const noexcept
1633 constexpr chrono::month
1634 month() const noexcept
1637 constexpr chrono::day
1638 day() const noexcept
1642 operator sys_days() const noexcept
1643 {
return sys_days{_M_days_since_epoch()}; }
1646 operator local_days() const noexcept
1647 {
return local_days{sys_days{*
this}.time_since_epoch()}; }
1649 constexpr bool ok() const noexcept;
1651 friend constexpr
bool
1652 operator==(const year_month_day& __x, const year_month_day& __y) noexcept
1654 return __x.year() == __y.year()
1655 && __x.month() == __y.month()
1656 && __x.day() == __y.day();
1659 friend constexpr strong_ordering
1660 operator<=>(
const year_month_day& __x,
const year_month_day& __y)
noexcept
1663 template<
typename = __detail::__months_years_conversion_disambiguator>
1664 friend constexpr year_month_day
1665 operator+(
const year_month_day& __ymd,
const months& __dm)
noexcept
1666 {
return (__ymd.year() / __ymd.month() + __dm) / __ymd.day(); }
1668 template<
typename = __detail::__months_years_conversion_disambiguator>
1669 friend constexpr year_month_day
1670 operator+(
const months& __dm,
const year_month_day& __ymd)
noexcept
1671 {
return __ymd + __dm; }
1673 friend constexpr year_month_day
1674 operator+(
const year_month_day& __ymd,
const years& __dy)
noexcept
1675 {
return (__ymd.year() + __dy) / __ymd.month() / __ymd.day(); }
1677 friend constexpr year_month_day
1678 operator+(
const years& __dy,
const year_month_day& __ymd)
noexcept
1679 {
return __ymd + __dy; }
1681 template<
typename = __detail::__months_years_conversion_disambiguator>
1682 friend constexpr year_month_day
1683 operator-(
const year_month_day& __ymd,
const months& __dm)
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 + -__dy; }
1690 friend constexpr year_month_day
1691 operator/(
const year_month& __ym,
const chrono::day& __d)
noexcept
1692 {
return {__ym.year(), __ym.month(), __d}; }
1694 friend constexpr year_month_day
1695 operator/(
const year_month& __ym,
int __d)
noexcept
1696 {
return __ym / chrono::day{unsigned(__d)}; }
1698 friend constexpr year_month_day
1699 operator/(
const chrono::year& __y,
const month_day& __md)
noexcept
1700 {
return __y / __md.month() / __md.day(); }
1702 friend constexpr year_month_day
1703 operator/(
int __y,
const month_day& __md)
noexcept
1704 {
return chrono::year{__y} / __md; }
1706 friend constexpr year_month_day
1707 operator/(
const month_day& __md,
const chrono::year& __y)
noexcept
1708 {
return __y / __md; }
1710 friend constexpr year_month_day
1711 operator/(
const month_day& __md,
int __y)
noexcept
1712 {
return chrono::year(__y) / __md; }
1719 constexpr year_month_day
1720 year_month_day::_S_from_days(
const days& __dp)
noexcept
1722 constexpr auto __z2 =
static_cast<uint32_t
>(-1468000);
1723 constexpr auto __r2_e3 =
static_cast<uint32_t
>(536895458);
1725 const auto __r0 =
static_cast<uint32_t
>(__dp.count()) + __r2_e3;
1727 const auto __n1 = 4 * __r0 + 3;
1728 const auto __q1 = __n1 / 146097;
1729 const auto __r1 = __n1 % 146097 / 4;
1731 constexpr auto __p32 =
static_cast<uint64_t
>(1) << 32;
1732 const auto __n2 = 4 * __r1 + 3;
1733 const auto __u2 =
static_cast<uint64_t
>(2939745) * __n2;
1734 const auto __q2 =
static_cast<uint32_t
>(__u2 / __p32);
1735 const auto __r2 =
static_cast<uint32_t
>(__u2 % __p32) / 2939745 / 4;
1737 constexpr auto __p16 =
static_cast<uint32_t
>(1) << 16;
1738 const auto __n3 = 2141 * __r2 + 197913;
1739 const auto __q3 = __n3 / __p16;
1740 const auto __r3 = __n3 % __p16 / 2141;
1742 const auto __y0 = 100 * __q1 + __q2;
1743 const auto __m0 = __q3;
1744 const auto __d0 = __r3;
1746 const auto __j = __r2 >= 306;
1747 const auto __y1 = __y0 + __j;
1748 const auto __m1 = __j ? __m0 - 12 : __m0;
1749 const auto __d1 = __d0 + 1;
1751 return year_month_day{chrono::year{
static_cast<int>(__y1 + __z2)},
1752 chrono::month{__m1}, chrono::day{__d1}};
1760 year_month_day::_M_days_since_epoch() const noexcept
1762 auto constexpr __z2 =
static_cast<uint32_t
>(-1468000);
1763 auto constexpr __r2_e3 =
static_cast<uint32_t
>(536895458);
1765 const auto __y1 =
static_cast<uint32_t
>(
static_cast<int>(_M_y)) - __z2;
1766 const auto __m1 =
static_cast<uint32_t
>(
static_cast<unsigned>(_M_m));
1767 const auto __d1 =
static_cast<uint32_t
>(
static_cast<unsigned>(_M_d));
1769 const auto __j =
static_cast<uint32_t
>(__m1 < 3);
1770 const auto __y0 = __y1 - __j;
1771 const auto __m0 = __j ? __m1 + 12 : __m1;
1772 const auto __d0 = __d1 - 1;
1774 const auto __q1 = __y0 / 100;
1775 const auto __yc = 1461 * __y0 / 4 - __q1 + __q1 / 4;
1776 const auto __mc = (979 *__m0 - 2919) / 32;
1777 const auto __dc = __d0;
1779 return days{
static_cast<int32_t
>(__yc + __mc + __dc - __r2_e3)};
1784 class year_month_day_last
1788 chrono::month_day_last _M_mdl;
1792 year_month_day_last(
const chrono::year& __y,
1793 const chrono::month_day_last& __mdl) noexcept
1794 : _M_y{__y}, _M_mdl{__mdl}
1797 template<
typename = __detail::__months_years_conversion_disambiguator>
1798 constexpr year_month_day_last&
1799 operator+=(
const months& __m)
noexcept
1801 *
this = *
this + __m;
1805 template<
typename = __detail::__months_years_conversion_disambiguator>
1806 constexpr year_month_day_last&
1807 operator-=(
const months& __m)
noexcept
1809 *
this = *
this - __m;
1813 constexpr year_month_day_last&
1814 operator+=(
const years& __y)
noexcept
1816 *
this = *
this + __y;
1820 constexpr year_month_day_last&
1821 operator-=(
const years& __y)
noexcept
1823 *
this = *
this - __y;
1827 constexpr chrono::year
1828 year() const noexcept
1831 constexpr chrono::month
1832 month() const noexcept
1833 {
return _M_mdl.month(); }
1835 constexpr chrono::month_day_last
1836 month_day_last() const noexcept
1840 constexpr chrono::day
1841 day() const noexcept
1843 const auto __m =
static_cast<unsigned>(month());
1863 return chrono::day{__m != 2 ? (__m ^ (__m >> 3)) | 30
1864 : _M_y.is_leap() ? 29 : 28};
1868 operator sys_days() const noexcept
1869 {
return sys_days{year() / month() / day()}; }
1872 operator local_days() const noexcept
1873 {
return local_days{sys_days{*
this}.time_since_epoch()}; }
1877 {
return _M_y.ok() && _M_mdl.ok(); }
1879 friend constexpr bool
1880 operator==(
const year_month_day_last& __x,
1881 const year_month_day_last& __y)
noexcept
1883 return __x.year() == __y.year()
1884 && __x.month_day_last() == __y.month_day_last();
1887 friend constexpr strong_ordering
1888 operator<=>(
const year_month_day_last& __x,
1889 const year_month_day_last& __y)
noexcept
1892 template<
typename = __detail::__months_years_conversion_disambiguator>
1893 friend constexpr year_month_day_last
1894 operator+(
const year_month_day_last& __ymdl,
1895 const months& __dm)
noexcept
1896 {
return (__ymdl.year() / __ymdl.month() + __dm) / last; }
1898 template<
typename = __detail::__months_years_conversion_disambiguator>
1899 friend constexpr year_month_day_last
1901 const year_month_day_last& __ymdl)
noexcept
1902 {
return __ymdl + __dm; }
1904 template<
typename = __detail::__months_years_conversion_disambiguator>
1905 friend constexpr year_month_day_last
1906 operator-(
const year_month_day_last& __ymdl,
1907 const months& __dm)
noexcept
1908 {
return __ymdl + -__dm; }
1910 friend constexpr year_month_day_last
1911 operator+(
const year_month_day_last& __ymdl,
1912 const years& __dy)
noexcept
1913 {
return {__ymdl.year() + __dy, __ymdl.month_day_last()}; }
1915 friend constexpr year_month_day_last
1917 const year_month_day_last& __ymdl)
noexcept
1918 {
return __ymdl + __dy; }
1920 friend constexpr year_month_day_last
1921 operator-(
const year_month_day_last& __ymdl,
1922 const years& __dy)
noexcept
1923 {
return __ymdl + -__dy; }
1925 friend constexpr year_month_day_last
1926 operator/(
const year_month& __ym, last_spec)
noexcept
1927 {
return {__ym.year(), chrono::month_day_last{__ym.month()}}; }
1929 friend constexpr year_month_day_last
1931 const chrono::month_day_last& __mdl)
noexcept
1932 {
return {__y, __mdl}; }
1934 friend constexpr year_month_day_last
1935 operator/(
int __y,
const chrono::month_day_last& __mdl)
noexcept
1936 {
return chrono::year(__y) / __mdl; }
1938 friend constexpr year_month_day_last
1939 operator/(
const chrono::month_day_last& __mdl,
1940 const chrono::year& __y)
noexcept
1941 {
return __y / __mdl; }
1943 friend constexpr year_month_day_last
1944 operator/(
const chrono::month_day_last& __mdl,
int __y)
noexcept
1945 {
return chrono::year(__y) / __mdl; }
1950 year_month_day::year_month_day(
const year_month_day_last& __ymdl) noexcept
1951 : _M_y{__ymdl.year()}, _M_m{__ymdl.month()}, _M_d{__ymdl.day()}
1955 year_month_day::ok() const noexcept
1957 if (!_M_y.ok() || !_M_m.ok())
1959 return chrono::day{1} <= _M_d && _M_d <= (_M_y / _M_m / last).day();
1964 class year_month_weekday
1969 chrono::weekday_indexed _M_wdi;
1971 static constexpr year_month_weekday
1972 _S_from_sys_days(
const sys_days& __dp)
1974 year_month_day __ymd{__dp};
1975 chrono::weekday __wd{__dp};
1976 auto __index = __wd[(
unsigned{__ymd.day()} - 1) / 7 + 1];
1977 return {__ymd.year(), __ymd.month(), __index};
1981 year_month_weekday() =
default;
1984 year_month_weekday(
const chrono::year& __y,
const chrono::month& __m,
1985 const chrono::weekday_indexed& __wdi) noexcept
1986 : _M_y{__y}, _M_m{__m}, _M_wdi{__wdi}
1990 year_month_weekday(
const sys_days& __dp) noexcept
1991 : year_month_weekday{_S_from_sys_days(__dp)}
1995 year_month_weekday(
const local_days& __dp) noexcept
1996 : year_month_weekday{sys_days{__dp.time_since_epoch()}}
1999 template<
typename = __detail::__months_years_conversion_disambiguator>
2000 constexpr year_month_weekday&
2001 operator+=(
const months& __m)
noexcept
2003 *
this = *
this + __m;
2007 template<
typename = __detail::__months_years_conversion_disambiguator>
2008 constexpr year_month_weekday&
2009 operator-=(
const months& __m)
noexcept
2011 *
this = *
this - __m;
2015 constexpr year_month_weekday&
2016 operator+=(
const years& __y)
noexcept
2018 *
this = *
this + __y;
2022 constexpr year_month_weekday&
2023 operator-=(
const years& __y)
noexcept
2025 *
this = *
this - __y;
2029 constexpr chrono::year
2030 year() const noexcept
2033 constexpr chrono::month
2034 month() const noexcept
2037 constexpr chrono::weekday
2038 weekday() const noexcept
2039 {
return _M_wdi.weekday(); }
2042 index() const noexcept
2043 {
return _M_wdi.index(); }
2045 constexpr chrono::weekday_indexed
2046 weekday_indexed() const noexcept
2050 operator sys_days() const noexcept
2052 auto __d = sys_days{year() / month() / 1};
2053 return __d + (weekday() - chrono::weekday(__d)
2054 +
days{(
static_cast<int>(index())-1)*7});
2058 operator local_days() const noexcept
2059 {
return local_days{sys_days{*
this}.time_since_epoch()}; }
2064 if (!_M_y.ok() || !_M_m.ok() || !_M_wdi.ok())
2066 if (_M_wdi.index() <= 4)
2068 days __d = (_M_wdi.weekday()
2069 - chrono::weekday{sys_days{_M_y / _M_m / 1}}
2070 +
days((_M_wdi.index()-1)*7 + 1));
2071 __glibcxx_assert(__d.count() >= 1);
2072 return (
unsigned)__d.count() <= (unsigned)(_M_y / _M_m / last).day();
2075 friend constexpr bool
2076 operator==(
const year_month_weekday& __x,
2077 const year_month_weekday& __y)
noexcept
2079 return __x.year() == __y.year()
2080 && __x.month() == __y.month()
2081 && __x.weekday_indexed() == __y.weekday_indexed();
2084 template<
typename = __detail::__months_years_conversion_disambiguator>
2085 friend constexpr year_month_weekday
2086 operator+(
const year_month_weekday& __ymwd,
const months& __dm)
noexcept
2088 return ((__ymwd.year() / __ymwd.month() + __dm)
2089 / __ymwd.weekday_indexed());
2092 template<
typename = __detail::__months_years_conversion_disambiguator>
2093 friend constexpr year_month_weekday
2094 operator+(
const months& __dm,
const year_month_weekday& __ymwd)
noexcept
2095 {
return __ymwd + __dm; }
2097 friend constexpr year_month_weekday
2098 operator+(
const year_month_weekday& __ymwd,
const years& __dy)
noexcept
2099 {
return {__ymwd.year() + __dy, __ymwd.month(), __ymwd.weekday_indexed()}; }
2101 friend constexpr year_month_weekday
2102 operator+(
const years& __dy,
const year_month_weekday& __ymwd)
noexcept
2103 {
return __ymwd + __dy; }
2105 template<
typename = __detail::__months_years_conversion_disambiguator>
2106 friend constexpr year_month_weekday
2107 operator-(
const year_month_weekday& __ymwd,
const months& __dm)
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 + -__dy; }
2114 friend constexpr year_month_weekday
2116 const chrono::weekday_indexed& __wdi)
noexcept
2117 {
return {__ym.year(), __ym.month(), __wdi}; }
2119 friend constexpr year_month_weekday
2120 operator/(
const chrono::year& __y,
const month_weekday& __mwd)
noexcept
2121 {
return {__y, __mwd.month(), __mwd.weekday_indexed()}; }
2123 friend constexpr year_month_weekday
2124 operator/(
int __y,
const month_weekday& __mwd)
noexcept
2125 {
return chrono::year(__y) / __mwd; }
2127 friend constexpr year_month_weekday
2128 operator/(
const month_weekday& __mwd,
const chrono::year& __y)
noexcept
2129 {
return __y / __mwd; }
2131 friend constexpr year_month_weekday
2132 operator/(
const month_weekday& __mwd,
int __y)
noexcept
2133 {
return chrono::year(__y) / __mwd; }
2138 class year_month_weekday_last
2143 chrono::weekday_last _M_wdl;
2147 year_month_weekday_last(
const chrono::year& __y,
const chrono::month& __m,
2148 const chrono::weekday_last& __wdl) noexcept
2149 : _M_y{__y}, _M_m{__m}, _M_wdl{__wdl}
2152 template<
typename = __detail::__months_years_conversion_disambiguator>
2153 constexpr year_month_weekday_last&
2154 operator+=(
const months& __m)
noexcept
2156 *
this = *
this + __m;
2160 template<
typename = __detail::__months_years_conversion_disambiguator>
2161 constexpr year_month_weekday_last&
2162 operator-=(
const months& __m)
noexcept
2164 *
this = *
this - __m;
2168 constexpr year_month_weekday_last&
2169 operator+=(
const years& __y)
noexcept
2171 *
this = *
this + __y;
2175 constexpr year_month_weekday_last&
2176 operator-=(
const years& __y)
noexcept
2178 *
this = *
this - __y;
2182 constexpr chrono::year
2183 year() const noexcept
2186 constexpr chrono::month
2187 month() const noexcept
2190 constexpr chrono::weekday
2191 weekday() const noexcept
2192 {
return _M_wdl.weekday(); }
2194 constexpr chrono::weekday_last
2195 weekday_last() const noexcept
2199 operator sys_days() const noexcept
2201 const auto __d = sys_days{_M_y / _M_m / last};
2202 return sys_days{(__d - (chrono::weekday{__d}
2203 - _M_wdl.weekday())).time_since_epoch()};
2207 operator local_days() const noexcept
2208 {
return local_days{sys_days{*
this}.time_since_epoch()}; }
2212 {
return _M_y.ok() && _M_m.ok() && _M_wdl.ok(); }
2214 friend constexpr bool
2215 operator==(
const year_month_weekday_last& __x,
2216 const year_month_weekday_last& __y)
noexcept
2218 return __x.year() == __y.year()
2219 && __x.month() == __y.month()
2220 && __x.weekday_last() == __y.weekday_last();
2223 template<
typename = __detail::__months_years_conversion_disambiguator>
2224 friend constexpr year_month_weekday_last
2225 operator+(
const year_month_weekday_last& __ymwdl,
2226 const months& __dm)
noexcept
2228 return ((__ymwdl.year() / __ymwdl.month() + __dm)
2229 / __ymwdl.weekday_last());
2232 template<
typename = __detail::__months_years_conversion_disambiguator>
2233 friend constexpr year_month_weekday_last
2235 const year_month_weekday_last& __ymwdl)
noexcept
2236 {
return __ymwdl + __dm; }
2238 friend constexpr year_month_weekday_last
2239 operator+(
const year_month_weekday_last& __ymwdl,
2240 const years& __dy)
noexcept
2241 {
return {__ymwdl.year() + __dy, __ymwdl.month(), __ymwdl.weekday_last()}; }
2243 friend constexpr year_month_weekday_last
2245 const year_month_weekday_last& __ymwdl)
noexcept
2246 {
return __ymwdl + __dy; }
2248 template<
typename = __detail::__months_years_conversion_disambiguator>
2249 friend constexpr year_month_weekday_last
2250 operator-(
const year_month_weekday_last& __ymwdl,
2251 const months& __dm)
noexcept
2252 {
return __ymwdl + -__dm; }
2254 friend constexpr year_month_weekday_last
2255 operator-(
const year_month_weekday_last& __ymwdl,
2256 const years& __dy)
noexcept
2257 {
return __ymwdl + -__dy; }
2259 friend constexpr year_month_weekday_last
2261 const chrono::weekday_last& __wdl)
noexcept
2262 {
return {__ym.year(), __ym.month(), __wdl}; }
2264 friend constexpr year_month_weekday_last
2266 const chrono::month_weekday_last& __mwdl)
noexcept
2267 {
return {__y, __mwdl.month(), __mwdl.weekday_last()}; }
2269 friend constexpr year_month_weekday_last
2270 operator/(
int __y,
const chrono::month_weekday_last& __mwdl)
noexcept
2271 {
return chrono::year(__y) / __mwdl; }
2273 friend constexpr year_month_weekday_last
2274 operator/(
const chrono::month_weekday_last& __mwdl,
2275 const chrono::year& __y)
noexcept
2276 {
return __y / __mwdl; }
2278 friend constexpr year_month_weekday_last
2279 operator/(
const chrono::month_weekday_last& __mwdl,
int __y)
noexcept
2280 {
return chrono::year(__y) / __mwdl; }
2289 __pow10(
unsigned __n)
2297 template<
typename _Duration>
struct __utc_leap_second;
2308 template<
typename _Duration>
2311 static_assert( __is_duration<_Duration>::value );
2314 static consteval int
2315 _S_fractional_width()
2317 auto __den = _Duration::period::den;
2318 const int __multiplicity_2 = std::__countr_zero((uintmax_t)__den);
2319 __den >>= __multiplicity_2;
2320 int __multiplicity_5 = 0;
2321 while ((__den % 5) == 0)
2329 int __width = (__multiplicity_2 > __multiplicity_5
2330 ? __multiplicity_2 : __multiplicity_5);
2337 hh_mm_ss(_Duration __d,
bool __is_neg)
2338 : _M_h (duration_cast<chrono::hours>(__d)),
2339 _M_m (duration_cast<chrono::minutes>(__d -
hours())),
2340 _M_s (duration_cast<chrono::seconds>(__d -
hours() -
minutes())),
2344 if constexpr (treat_as_floating_point_v<typename precision::rep>)
2345 _M_ss._M_r = __ss.count();
2346 else if constexpr (precision::period::den != 1)
2347 _M_ss._M_r = duration_cast<precision>(__ss).count();
2350 static constexpr _Duration
2351 _S_abs(_Duration __d)
2354 return chrono::abs(__d);
2360 static constexpr unsigned fractional_width = {_S_fractional_width()};
2364 chrono::seconds::rep>,
2365 ratio<1, __detail::__pow10(fractional_width)>>;
2367 constexpr hh_mm_ss()
noexcept =
default;
2371 :
hh_mm_ss(_S_abs(__d), __d < _Duration::zero())
2375 is_negative()
const noexcept
2377 if constexpr (!_S_is_unsigned)
2384 hours()
const noexcept
2396 subseconds()
const noexcept
2397 {
return static_cast<precision
>(_M_ss); }
2400 operator precision()
const noexcept
2401 {
return to_duration(); }
2404 to_duration()
const noexcept
2406 if constexpr (!_S_is_unsigned)
2408 return -(_M_h + _M_m + _M_s + subseconds());
2409 return _M_h + _M_m + _M_s + subseconds();
2413 static constexpr bool _S_is_unsigned
2414 = __and_v<is_integral<typename _Duration::rep>,
2417 template<
typename _Ratio>
2421 template<
typename _Dur>
2424 typename _Dur::rep _M_r{};
2427 operator _Dur()
const noexcept
2428 {
return _Dur(_M_r); }
2432 template<
typename _Rep>
2433 requires (!treat_as_floating_point_v<_Rep>)
2442 template<
typename _Tp>
2443 static constexpr bool __fits
2447 template<
typename _Rep,
typename _Period>
2448 requires (!treat_as_floating_point_v<_Rep>)
2451 || __fits<unsigned char>)
2452 struct __subseconds<
duration<_Rep, _Period>>
2454 unsigned char _M_r{};
2461 template<
typename _Rep,
typename _Period>
2462 requires (!treat_as_floating_point_v<_Rep>)
2465 || __fits<uint_least32_t>)
2466 struct __subseconds<
duration<_Rep, _Period>>
2468 uint_least32_t _M_r{};
2476 __byte_duration<ratio<60>> _M_m{};
2477 __byte_duration<ratio<1>> _M_s{};
2479 __subseconds<precision> _M_ss{};
2481 template<
typename>
friend struct __detail::__utc_leap_second;
2488 template<
typename _Duration>
2489 struct __utc_leap_second
2493 : _M_date(chrono::floor<
days>(__s)), _M_time(__s - _M_date)
2499 hh_mm_ss<common_type_t<_Duration, days>> _M_time;
2507 is_am(
const hours& __h)
noexcept
2508 {
return 0h <= __h && __h <= 11h; }
2511 is_pm(
const hours& __h)
noexcept
2512 {
return 12h <= __h && __h <= 23h; }
2515 make12(
const hours& __h)
noexcept
2525 make24(
const hours& __h,
bool __is_pm)
noexcept
2543#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2559 static constexpr int unique = 0;
2560 static constexpr int nonexistent = 1;
2561 static constexpr int ambiguous = 2;
2568 class nonexistent_local_time :
public runtime_error
2571 template<
typename _Duration>
2572 nonexistent_local_time(
const local_time<_Duration>& __tp,
2573 const local_info& __i)
2574 : runtime_error(_S_make_what_str(__tp, __i))
2575 { __glibcxx_assert(__i.result == local_info::nonexistent); }
2578 template<
typename _Duration>
2580 _S_make_what_str(
const local_time<_Duration>& __tp,
2581 const local_info& __i)
2584 __os << __tp <<
" is in a gap between\n"
2585 << local_seconds(__i.first.end.time_since_epoch())
2586 + __i.first.offset <<
' ' << __i.first.abbrev <<
" and\n"
2587 << local_seconds(__i.second.begin.time_since_epoch())
2588 + __i.second.offset <<
' ' << __i.second.abbrev
2589 <<
" which are both equivalent to\n"
2590 << __i.first.end <<
" UTC";
2595 class ambiguous_local_time :
public runtime_error
2598 template<
typename _Duration>
2599 ambiguous_local_time(
const local_time<_Duration>& __tp,
2600 const local_info& __i)
2601 : runtime_error(_S_make_what_str(__tp, __i))
2602 { __glibcxx_assert(__i.result == local_info::ambiguous); }
2605 template<
typename _Duration>
2607 _S_make_what_str(
const local_time<_Duration>& __tp,
2608 const local_info& __i)
2611 __os << __tp <<
" is ambiguous. It could be\n"
2612 << __tp <<
' ' << __i.first.abbrev <<
" == "
2613 << __tp - __i.first.offset <<
" UTC or\n"
2614 << __tp <<
' ' << __i.second.abbrev <<
" == "
2615 << __tp - __i.second.offset <<
" UTC";
2620 template<
typename _Duration>
2622 __throw_bad_local_time(
const local_time<_Duration>& __tp,
2623 const local_info& __i)
2626 if (__i.result == local_info::nonexistent)
2627 throw nonexistent_local_time(__tp, __i);
2628 throw ambiguous_local_time(__tp, __i);
2634 enum class choose { earliest, latest };
2639 time_zone(time_zone&&) =
default;
2640 time_zone& operator=(time_zone&&) =
default;
2645 string_view name() const noexcept {
return _M_name; }
2647 template<
typename _Duration>
2649 get_info(
const sys_time<_Duration>& __st)
const
2650 {
return _M_get_sys_info(chrono::floor<seconds>(__st)); }
2652 template<
typename _Duration>
2654 get_info(
const local_time<_Duration>& __tp)
const
2655 {
return _M_get_local_info(chrono::floor<seconds>(__tp)); }
2657 template<
typename _Duration>
2658 sys_time<common_type_t<_Duration, seconds>>
2659 to_sys(
const local_time<_Duration>& __tp)
const
2661 local_info __info = get_info(__tp);
2663 if (__info.result != local_info::unique)
2664 __throw_bad_local_time(__tp, __info);
2666 return sys_time<_Duration>(__tp.time_since_epoch())
2667 - __info.first.offset;
2670 template<
typename _Duration>
2671 sys_time<common_type_t<_Duration, seconds>>
2672 to_sys(
const local_time<_Duration>& __tp, choose __z)
const
2674 local_info __info = get_info(__tp);
2676 if (__info.result == local_info::nonexistent)
2677 return __info.first.end;
2679 sys_time<_Duration> __st(__tp.time_since_epoch());
2681 if (__info.result == local_info::ambiguous && __z == choose::latest)
2682 return __st - __info.second.offset;
2685 return __st - __info.first.offset;
2688 template<
typename _Duration>
2689 local_time<common_type_t<_Duration, seconds>>
2690 to_local(
const sys_time<_Duration>& __tp)
const
2692 auto __d = (__tp + get_info(__tp).offset).time_since_epoch();
2693 return local_time<common_type_t<_Duration, seconds>>(__d);
2696 [[nodiscard]]
friend bool
2697 operator==(
const time_zone& __x,
const time_zone& __y)
noexcept
2698 {
return __x._M_name == __y._M_name; }
2700 [[nodiscard]]
friend strong_ordering
2701 operator<=>(
const time_zone& __x,
const time_zone& __y)
noexcept
2702 {
return __x._M_name <=> __y._M_name; }
2705 sys_info _M_get_sys_info(sys_seconds)
const;
2706 local_info _M_get_local_info(local_seconds)
const;
2708 friend const tzdb& reload_tzdb();
2710 friend class tzdb_list;
2714 explicit time_zone(unique_ptr<_Impl> __p);
2716 unique_ptr<_Impl> _M_impl;
2719 const time_zone* locate_zone(string_view __tz_name);
2720 const time_zone* current_zone();
2754 using value_type = tzdb;
2755 using reference =
const tzdb&;
2756 using pointer =
const tzdb*;
2757 using difference_type = ptrdiff_t;
2767 pointer operator->()
const noexcept {
return &**
this; }
2779 void* _M_reserved =
nullptr;
2809 const_iterator cbegin() const noexcept {
return begin(); }
2810 const_iterator cend() const noexcept {
return end(); }
2813 constexpr explicit tzdb_list(nullptr_t);
2815 friend tzdb_list& get_tzdb_list();
2816 friend const tzdb& get_tzdb();
2817 friend const tzdb& reload_tzdb();
2819 friend class leap_second;
2820 friend struct time_zone::_Impl;
2821 friend class time_zone_link;
2824 class time_zone_link
2827 time_zone_link(time_zone_link&&) =
default;
2828 time_zone_link& operator=(time_zone_link&&) =
default;
2830 string_view name() const noexcept {
return _M_name; }
2831 string_view target() const noexcept {
return _M_target; }
2834 operator==(
const time_zone_link& __x,
const time_zone_link& __y)
noexcept
2835 {
return __x.name() == __y.name(); }
2837 friend strong_ordering
2838 operator<=>(
const time_zone_link& __x,
const time_zone_link& __y)
noexcept
2839 {
return __x.name() <=> __y.name(); }
2842 friend const tzdb& reload_tzdb();
2843 friend struct tzdb_list::_Node;
2845 explicit time_zone_link(nullptr_t) { }
2854 leap_second(
const leap_second&) =
default;
2855 leap_second& operator=(
const leap_second&) =
default;
2858 constexpr sys_seconds
2859 date() const noexcept
2861 if (_M_s >= _M_s.zero()) [[likely]]
2862 return sys_seconds(_M_s);
2863 return sys_seconds(-_M_s);
2868 value() const noexcept
2870 if (_M_s >= _M_s.zero()) [[likely]]
2877 [[nodiscard]]
friend constexpr bool
2878 operator==(
const leap_second&,
const leap_second&)
noexcept =
default;
2880 [[nodiscard]]
friend constexpr strong_ordering
2881 operator<=>(
const leap_second& __x,
const leap_second& __y)
noexcept
2882 {
return __x.date() <=> __y.date(); }
2884 template<
typename _Duration>
2885 [[nodiscard]]
friend constexpr bool
2886 operator==(
const leap_second& __x,
2887 const sys_time<_Duration>& __y)
noexcept
2888 {
return __x.date() == __y; }
2890 template<
typename _Duration>
2891 [[nodiscard]]
friend constexpr bool
2892 operator<(
const leap_second& __x,
2893 const sys_time<_Duration>& __y)
noexcept
2894 {
return __x.date() < __y; }
2896 template<
typename _Duration>
2897 [[nodiscard]]
friend constexpr bool
2898 operator<(
const sys_time<_Duration>& __x,
2899 const leap_second& __y)
noexcept
2900 {
return __x < __y.date(); }
2902 template<
typename _Duration>
2903 [[nodiscard]]
friend constexpr bool
2904 operator>(
const leap_second& __x,
2905 const sys_time<_Duration>& __y)
noexcept
2906 {
return __y < __x.date(); }
2908 template<
typename _Duration>
2909 [[nodiscard]]
friend constexpr bool
2910 operator>(
const sys_time<_Duration>& __x,
2911 const leap_second& __y)
noexcept
2912 {
return __y.date() < __x; }
2914 template<
typename _Duration>
2915 [[nodiscard]]
friend constexpr bool
2916 operator<=(
const leap_second& __x,
2917 const sys_time<_Duration>& __y)
noexcept
2918 {
return !(__y < __x.date()); }
2920 template<
typename _Duration>
2921 [[nodiscard]]
friend constexpr bool
2922 operator<=(
const sys_time<_Duration>& __x,
2923 const leap_second& __y)
noexcept
2924 {
return !(__y.date() < __x); }
2926 template<
typename _Duration>
2927 [[nodiscard]]
friend constexpr bool
2928 operator>=(
const leap_second& __x,
2929 const sys_time<_Duration>& __y)
noexcept
2930 {
return !(__x.date() < __y); }
2932 template<
typename _Duration>
2933 [[nodiscard]]
friend constexpr bool
2934 operator>=(
const sys_time<_Duration>& __x,
2935 const leap_second& __y)
noexcept
2936 {
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 explicit leap_second(seconds::rep __s) : _M_s(__s) { }
2947 friend struct tzdb_list::_Node;
2949 friend const tzdb& reload_tzdb();
2951 template<
typename _Duration>
2952 friend leap_second_info
2953 get_leap_second_info(
const utc_time<_Duration>&);
2958 template<
class _Tp>
struct zoned_traits { };
2961 struct zoned_traits<const time_zone*>
2963 static const time_zone*
2965 {
return std::chrono::locate_zone(
"UTC"); }
2967 static const time_zone*
2968 locate_zone(string_view __name)
2969 {
return std::chrono::locate_zone(__name); }
2975 _GLIBCXX_STD_C::vector<time_zone> zones;
2976 _GLIBCXX_STD_C::vector<time_zone_link> links;
2977 _GLIBCXX_STD_C::vector<leap_second> leap_seconds;
2980 locate_zone(string_view __tz_name)
const;
2983 current_zone()
const;
2986 friend const tzdb& reload_tzdb();
2987 friend class time_zone;
2988 friend struct tzdb_list::_Node;
2991 tzdb_list& get_tzdb_list();
2992 const tzdb& get_tzdb();
2994 const tzdb& reload_tzdb();
2995 string remote_version();
2997 template<
typename _Duration,
typename _TimeZonePtr = const time_zone*>
3000 static_assert(__is_duration_v<_Duration>);
3002 using _Traits = zoned_traits<_TimeZonePtr>;
3006 using string_view = type_identity_t<std::string_view>;
3009 using duration = common_type_t<_Duration, seconds>;
3011 zoned_time()
requires requires { _Traits::default_zone(); }
3014 zoned_time(
const zoned_time&) =
default;
3015 zoned_time& operator=(
const zoned_time&) =
default;
3017 zoned_time(
const sys_time<_Duration>& __st)
3018 requires requires { _Traits::default_zone(); }
3023 zoned_time(_TimeZonePtr __z) : _M_zone(
std::move(__z)) { }
3026 zoned_time(string_view __name)
3028 _TimeZonePtr{_Traits::locate_zone(std::string_view{})};
3030 : _M_zone(_Traits::locate_zone(__name))
3033 template<
typename _Duration2>
3034 zoned_time(
const zoned_time<_Duration2, _TimeZonePtr>& __zt)
3035 requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
3036 : _M_zone(__zt._M_zone), _M_tp(__zt._M_tp)
3039 zoned_time(_TimeZonePtr __z,
const sys_time<_Duration>& __st)
3040 : _M_zone(
std::move(__z)), _M_tp(__st)
3043 zoned_time(string_view __name,
const sys_time<_Duration>& __st)
3044 : zoned_time(_Traits::locate_zone(__name), __st)
3047 zoned_time(_TimeZonePtr __z,
const local_time<_Duration>& __tp)
3049 { __z->to_sys(__tp) } -> convertible_to<sys_time<_Duration>>;
3051 : _M_zone(
std::move(__z)), _M_tp(_M_zone->to_sys(__tp))
3054 zoned_time(string_view __name,
const local_time<_Duration>& __tp)
3055 requires requires (_TimeZonePtr __z) {
3056 { _Traits::locate_zone(__name) } -> convertible_to<_TimeZonePtr>;
3057 { __z->to_sys(__tp) } -> convertible_to<sys_time<_Duration>>;
3059 : zoned_time(_Traits::locate_zone(__name), __tp)
3062 zoned_time(_TimeZonePtr __z,
const local_time<_Duration>& __tp,
3065 { __z->to_sys(__tp, __c) } -> convertible_to<sys_time<_Duration>>;
3067 : _M_zone(
std::move(__z)), _M_tp(_M_zone->to_sys(__tp, __c))
3070 zoned_time(string_view __name,
const local_time<_Duration>& __tp,
3072 requires requires (_TimeZonePtr __z) {
3073 { _Traits::locate_zone(__name) } -> convertible_to<_TimeZonePtr>;
3074 { __z->to_sys(__tp, __c) } -> convertible_to<sys_time<_Duration>>;
3076 : _M_zone(_Traits::locate_zone(__name)),
3077 _M_tp(_M_zone->to_sys(__tp, __c))
3080 template<
typename _Duration2,
typename _TimeZonePtr2>
3081 zoned_time(_TimeZonePtr __z,
3082 const zoned_time<_Duration2, _TimeZonePtr2>& __zt)
3083 requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
3084 : _M_zone(__z), _M_tp(__zt._M_tp)
3087 template<
typename _Duration2,
typename _TimeZonePtr2>
3088 zoned_time(_TimeZonePtr __z,
3089 const zoned_time<_Duration2, _TimeZonePtr2>& __zt,
3091 requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
3092 : _M_zone(__z), _M_tp(__zt._M_tp)
3095 template<
typename _Duration2,
typename _TimeZonePtr2>
3096 zoned_time(string_view __name,
3097 const zoned_time<_Duration2, _TimeZonePtr2>& __zt)
3098 requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
3100 { _Traits::locate_zone(__name) } -> convertible_to<_TimeZonePtr>;
3102 : _M_zone(_Traits::locate_zone(__name)), _M_tp(__zt._M_tp)
3105 template<
typename _Duration2,
typename _TimeZonePtr2>
3106 zoned_time(string_view __name,
3107 const zoned_time<_Duration2, _TimeZonePtr2>& __zt,
3109 requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
3111 { _Traits::locate_zone(__name) } -> convertible_to<_TimeZonePtr>;
3113 : _M_zone(_Traits::locate_zone(__name)), _M_tp(__zt._M_tp)
3117 operator=(
const sys_time<_Duration>& __st)
3124 operator=(
const local_time<_Duration>& __lt)
3126 _M_tp = _M_zone->to_sys(__lt);
3131 operator sys_time<duration>()
const {
return _M_tp; }
3134 explicit operator local_time<duration>()
const
3135 {
return get_local_time(); }
3139 get_time_zone()
const
3143 local_time<duration>
3144 get_local_time()
const
3145 {
return _M_zone->to_local(_M_tp); }
3149 get_sys_time()
const
3155 {
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 zoned_time() -> zoned_time<seconds>;
3170 template<
typename _Duration>
3171 zoned_time(sys_time<_Duration>)
3172 -> zoned_time<common_type_t<_Duration, seconds>>;
3175 template<
typename _TimeZonePtrOrName>
3176 using __time_zone_representation
3177 = __conditional_t<is_convertible_v<_TimeZonePtrOrName, string_view>,
3179 remove_cvref_t<_TimeZonePtrOrName>>;
3182 template<
typename _TimeZonePtrOrName>
3183 zoned_time(_TimeZonePtrOrName&&)
3184 -> zoned_time<seconds, __time_zone_representation<_TimeZonePtrOrName>>;
3186 template<
typename _TimeZonePtrOrName,
typename _Duration>
3187 zoned_time(_TimeZonePtrOrName&&, sys_time<_Duration>)
3188 -> zoned_time<common_type_t<_Duration, seconds>,
3189 __time_zone_representation<_TimeZonePtrOrName>>;
3191 template<
typename _TimeZonePtrOrName,
typename _Duration>
3192 zoned_time(_TimeZonePtrOrName&&, local_time<_Duration>,
3193 choose = choose::earliest)
3194 -> zoned_time<common_type_t<_Duration, seconds>,
3195 __time_zone_representation<_TimeZonePtrOrName>>;
3197 template<
typename _Duration,
typename _TimeZonePtrOrName,
3198 typename _TimeZonePtr2>
3199 zoned_time(_TimeZonePtrOrName&&, zoned_time<_Duration, _TimeZonePtr2>,
3200 choose = choose::earliest)
3201 -> zoned_time<common_type_t<_Duration, seconds>,
3202 __time_zone_representation<_TimeZonePtrOrName>>;
3204 template<
typename _Dur1,
typename _TZPtr1,
typename _Dur2,
typename _TZPtr2>
3207 operator==(
const zoned_time<_Dur1, _TZPtr1>& __x,
3208 const zoned_time<_Dur2, _TZPtr2>& __y)
3210 return __x.get_time_zone() == __y.get_time_zone()
3211 && __x.get_sys_time() == __y.get_sys_time();
3214 using zoned_seconds = zoned_time<seconds>;
3219 inline leap_second_info
3220 __get_leap_second_info(sys_seconds __ss,
bool __is_utc)
3222 if (__ss < sys_seconds{}) [[unlikely]]
3225 const seconds::rep __leaps[] {
3256 const sys_seconds __expires(1735344000s);
3258#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
3259 if (__ss > __expires)
3264 auto __db = get_tzdb_list().begin();
3265 auto __first = __db->leap_seconds.begin() + __n;
3266 auto __last = __db->leap_seconds.end();
3267 auto __pos = std::upper_bound(__first, __last, __ss);
3269 for (
auto __i = __first; __i != __pos; ++__i)
3270 __elapsed += __i->value();
3277 if (__pos != __first && __ss < __pos[-1])
3279 if ((__ss + 1s) >= __pos[-1])
3280 return {
true, __elapsed};
3281 __elapsed -= __pos[-1].value();
3284 return {
false, __elapsed};
3289 seconds::rep __s = __ss.time_since_epoch().count();
3290 const seconds::rep* __first =
std::begin(__leaps);
3291 const seconds::rep* __last =
std::end(__leaps);
3294 if (__s > (__last[-1] + (__last - __first) + 1))
3295 return {
false,
seconds(__last - __first) };
3297 auto __pos = std::upper_bound(__first, __last, __s);
3298 seconds __elapsed{__pos - __first};
3302 __s -= __elapsed.count();
3304 if (__pos != __first && __s < __pos[-1])
3306 if ((__s + 1) >= __pos[-1])
3307 return {
true, __elapsed};
3311 return {
false, __elapsed};
3316 template<
typename _Duration>
3318 inline leap_second_info
3319 get_leap_second_info(
const utc_time<_Duration>& __ut)
3321 auto __s = chrono::duration_cast<seconds>(__ut.time_since_epoch());
3322 return __detail::__get_leap_second_info(sys_seconds(__s),
true);
3325 template<
typename _Duration>
3327 inline utc_time<common_type_t<_Duration, seconds>>
3328 utc_clock::from_sys(
const sys_time<_Duration>& __t)
3330 using _CDur = common_type_t<_Duration, seconds>;
3331 auto __s = chrono::time_point_cast<seconds>(__t);
3332 const auto __li = __detail::__get_leap_second_info(__s,
false);
3333 return utc_time<_CDur>{__t.time_since_epoch()} + __li.elapsed;
3340#if __cplusplus >= 202002L
3341 inline namespace literals
3343 inline namespace chrono_literals
3347#pragma GCC diagnostic push
3348#pragma GCC diagnostic ignored "-Wliteral-suffix"
3351 constexpr chrono::day
3352 operator""d(
unsigned long long __d)
noexcept
3353 {
return chrono::day{
static_cast<unsigned>(__d)}; }
3357 constexpr chrono::year
3358 operator""y(
unsigned long long __y)
noexcept
3359 {
return chrono::year{
static_cast<int>(__y)}; }
3360#pragma GCC diagnostic pop
3366_GLIBCXX_END_NAMESPACE_VERSION
3369#if __cplusplus >= 202002L
duration< int64_t > seconds
seconds
duration< int64_t, ratio< 3600 > > hours
hours
auto clock_cast(const time_point< _SourceClock, _Duration > &__t)
Convert a time point to a different clock.
duration< int64_t, ratio< 86400 > > days
days
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 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)
duration< int64_t, ratio< 2629746 > > months
months
duration< int64_t, ratio< 31556952 > > years
years
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.
typename common_type< _Tp... >::type common_type_t
Alias template for common_type.
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 size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
const tzdb & front() const noexcept
Properties of fundamental types.
Provides compile-time rational arithmetic.
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.