30#ifndef _GLIBCXX_CHRONO_IO_H
31#define _GLIBCXX_CHRONO_IO_H 1
33#pragma GCC system_header
35#if __cplusplus >= 202002L
46_GLIBCXX_BEGIN_NAMESPACE_VERSION
61 template<
typename _CharT>
70#define _GLIBCXX_WIDEN_(C, S) ::std::chrono::__detail::_Widen<C>(S, L##S)
71#define _GLIBCXX_WIDEN(S) _GLIBCXX_WIDEN_(_CharT, S)
73 template<
typename _Period,
typename _CharT>
80#define _GLIBCXX_UNITS_SUFFIX(period, suffix) \
81 if constexpr (is_same_v<_Period, period>) \
82 return _GLIBCXX_WIDEN(suffix); \
90#if _GLIBCXX_USE_ALT_MICROSECONDS_SUFFIX
112#undef _GLIBCXX_UNITS_SUFFIX
116 template<
typename _Period,
typename _CharT,
typename _Out>
120 if (
auto __s = __detail::__units_suffix<_Period, _CharT>();
__s.size())
122 else if constexpr (_Period::den == 1)
124 (uintmax_t)_Period::num);
127 (uintmax_t)_Period::num,
128 (uintmax_t)_Period::den);
137 template<
typename _CharT,
typename _Traits,
138 typename _Rep,
typename _Period>
144 using period =
typename _Period::type;
148 __s.precision(
__os.precision());
150 __detail::__fmt_units_suffix<period, _CharT>(_Out(
__s));
159 template<
typename _Duration>
163 const string* _M_abbrev;
180 template<
typename _Duration>
181 inline __detail::__local_time_fmt<_Duration>
193 [[noreturn,__gnu__::__always_inline__]]
195 __no_timezone_available()
196 { __throw_format_error(
"format error: no timezone available for %Z or %z"); }
198 [[noreturn,__gnu__::__always_inline__]]
200 __not_valid_for_duration()
201 { __throw_format_error(
"format error: chrono-format-spec not valid for "
202 "chrono::duration"); }
204 [[noreturn,__gnu__::__always_inline__]]
206 __invalid_chrono_spec()
207 { __throw_format_error(
"format error: chrono-format-spec not valid for "
210 template<
typename _CharT>
211 struct _ChronoSpec : _Spec<_CharT>
213 basic_string_view<_CharT> _M_chrono_specs;
220 _Year = 1, _Month = 2, _Day = 4, _Weekday = 8, _TimeOfDay = 16,
222 _Date = _Year | _Month | _Day | _Weekday,
223 _DateTime = _Date | _TimeOfDay,
224 _ZonedDateTime = _DateTime | _TimeZone,
228 constexpr _ChronoParts
229 operator|(_ChronoParts __x, _ChronoParts __y)
noexcept
230 {
return static_cast<_ChronoParts
>((int)__x | (
int)__y); }
232 constexpr _ChronoParts&
233 operator|=(_ChronoParts& __x, _ChronoParts __y)
noexcept
234 {
return __x = __x | __y; }
237 template<
typename _CharT>
238 struct __formatter_chrono
240 using __string_view = basic_string_view<_CharT>;
241 using __string = basic_string<_CharT>;
243 template<
typename _ParseContext>
244 constexpr typename _ParseContext::iterator
245 _M_parse(_ParseContext& __pc, _ChronoParts __parts)
247 auto __first = __pc.
begin();
248 auto __last = __pc.end();
250 _ChronoSpec<_CharT> __spec{};
252 auto __finalize = [
this, &__spec] {
256 auto __finished = [&] {
257 if (__first == __last || *__first ==
'}')
268 __first = __spec._M_parse_fill_and_align(__first, __last);
272 __first = __spec._M_parse_width(__first, __last, __pc);
276 if (__parts & _ChronoParts::_Duration)
278 __first = __spec._M_parse_precision(__first, __last, __pc);
283 __first = __spec._M_parse_locale(__first, __last);
290 __string_view __str(__first, __last - __first);
291 auto __end = __str.find(
'}');
292 if (__end != __str.npos)
294 __str.remove_suffix(__str.length() - __end);
295 __last = __first + __end;
297 if (__str.find(
'{') != __str.npos)
298 __throw_format_error(
"chrono format error: '{' in chrono-specs");
305 const auto __chrono_specs = __first++;
306 if (*__chrono_specs !=
'%')
307 __throw_format_error(
"chrono format error: no '%' at start of "
314 while (__first != __last)
316 enum _Mods { _Mod_none, _Mod_E, _Mod_O, _Mod_E_O };
317 _Mods __allowed_mods = _Mod_none;
319 _CharT __c = *__first++;
332 __needed = _DateTime;
333 __allowed_mods = _Mod_E;
337 __allowed_mods = _Mod_E;
342 __allowed_mods = _Mod_O;
354 __needed = _TimeOfDay;
355 __allowed_mods = _Mod_O;
358 if (!(__parts & _Duration))
363 __allowed_mods = _Mod_O;
366 __needed = _TimeOfDay;
367 __allowed_mods = _Mod_O;
373 __needed = _TimeOfDay;
377 __needed = _Duration;
380 __needed = _TimeOfDay;
381 __allowed_mods = _Mod_O;
386 __allowed_mods = _Mod_O;
392 __allowed_mods = _Mod_O;
396 __allowed_mods = _Mod_E;
399 __needed = _TimeOfDay;
400 __allowed_mods = _Mod_E;
404 __allowed_mods = _Mod_E_O;
408 __allowed_mods = _Mod_E;
411 __needed = _TimeZone;
412 __allowed_mods = _Mod_E_O;
415 __needed = _TimeZone;
423 if (__mod) [[unlikely]]
425 __allowed_mods = _Mod_none;
431 __throw_format_error(
"chrono format error: invalid "
432 " specifier in chrono-specs");
435 if ((__mod ==
'E' && !(__allowed_mods & _Mod_E))
436 || (__mod ==
'O' && !(__allowed_mods & _Mod_O)))
437 __throw_format_error(
"chrono format error: invalid "
438 " modifier in chrono-specs");
441 if ((__parts & __needed) != __needed)
442 __throw_format_error(
"chrono format error: format argument "
443 "does not contain the information "
444 "required by the chrono-specs");
447 size_t __pos = __string_view(__first, __last - __first).find(
'%');
452 if (__pos == __string_view::npos)
458 __first += __pos + 1;
463 if (__conv || __mod != _CharT())
464 __throw_format_error(
"chrono format error: unescaped '%' in "
468 _M_spec._M_chrono_specs
469 = __string_view(__chrono_specs, __first - __chrono_specs);
479 template<
typename _Tp,
typename _FormatContext>
480 typename _FormatContext::iterator
481 _M_format(
const _Tp& __t, _FormatContext& __fc,
482 bool __is_neg =
false)
const
484 auto __first = _M_spec._M_chrono_specs.begin();
485 const auto __last = _M_spec._M_chrono_specs.end();
486 if (__first == __last)
487 return _M_format_to_ostream(__t, __fc, __is_neg);
489 _Sink_iter<_CharT> __out;
490 __format::_Str_sink<_CharT> __sink;
491 bool __write_direct =
false;
492 if constexpr (is_same_v<
typename _FormatContext::iterator,
495 if (_M_spec._M_width_kind == __format::_WP_none)
498 __write_direct =
true;
501 __out = __sink.out();
504 __out = __sink.out();
508 if constexpr (__is_specialization_of<_Tp, chrono::hh_mm_ss>)
509 __is_neg = __t.is_negative();
511 auto __print_sign = [&__is_neg, &__out] {
512 if constexpr (chrono::__is_duration_v<_Tp>
513 || __is_specialization_of<_Tp, chrono::hh_mm_ss>)
516 *__out++ = _S_plus_minus[1];
523 constexpr const _CharT* __literals = _GLIBCXX_WIDEN(
"\n\t%");
530 _CharT __c = *__first++;
535 __out = _M_a_A(__t,
std::move(__out), __fc, __c ==
'A');
540 __out = _M_b_B(__t,
std::move(__out), __fc, __c ==
'B');
543 __out = _M_c(__t,
std::move(__out), __fc, __mod ==
'E');
548 __out = _M_C_y_Y(__t,
std::move(__out), __fc, __c, __mod);
552 __out = _M_d_e(__t,
std::move(__out), __fc, __c, __mod ==
'O');
555 __out = _M_D(__t,
std::move(__out), __fc);
558 __out = _M_F(__t,
std::move(__out), __fc);
562 __out = _M_g_G(__t,
std::move(__out), __fc, __c ==
'G');
566 __out = _M_H_I(__t, __print_sign(), __fc, __c, __mod ==
'O');
569 __out = _M_j(__t, __print_sign(), __fc);
572 __out = _M_m(__t,
std::move(__out), __fc, __mod ==
'O');
575 __out = _M_M(__t, __print_sign(), __fc, __mod ==
'O');
578 __out = _M_p(__t,
std::move(__out), __fc);
581 __out = _M_q(__t,
std::move(__out), __fc);
585 if constexpr (chrono::__is_duration_v<_Tp>)
589 __throw_format_error(
"chrono format error: argument is "
593 __out = _M_r(__t, __print_sign(), __fc);
597 __out = _M_R_T(__t, __print_sign(), __fc, __c ==
'T');
600 __out = _M_S(__t, __print_sign(), __fc, __mod ==
'O');
604 __out = _M_u_w(__t,
std::move(__out), __fc, __c, __mod ==
'O');
609 __out = _M_U_V_W(__t,
std::move(__out), __fc, __c,
613 __out = _M_x(__t,
std::move(__out), __fc, __mod ==
'E');
616 __out = _M_X(__t, __print_sign(), __fc, __mod ==
'E');
619 __out = _M_z(__t,
std::move(__out), __fc, (
bool)__mod);
622 __out = _M_Z(__t,
std::move(__out), __fc);
625 *__out++ = __literals[0];
628 *__out++ = __literals[1];
631 *__out++ = __literals[2];
643 __string_view __str(__first, __last - __first);
644 size_t __pos = __str.find(
'%');
649 if (__pos == __str.npos)
653 __str.remove_suffix(__str.length() - __pos);
654 __first += __pos + 1;
656 __out = __format::__write(
std::move(__out), __str);
659 while (__first != __last);
661 if constexpr (is_same_v<
typename _FormatContext::iterator,
667 return __format::__write_padded_as_spec(__str, __str.size(),
671 _ChronoSpec<_CharT> _M_spec;
675 template<
typename _FormatContext>
677 _M_locale(_FormatContext& __fc)
const
679 if (!_M_spec._M_localized)
682 return __fc.locale();
690 template<
typename _Tp,
typename _FormatContext>
691 typename _FormatContext::iterator
692 _M_format_to_ostream(
const _Tp& __t, _FormatContext& __fc,
695 using ::std::chrono::__detail::__utc_leap_second;
696 using ::std::chrono::__detail::__local_time_fmt;
698 if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
699 return _M_format_to_ostream(__t._M_time, __fc,
false);
702 basic_ostringstream<_CharT> __os;
703 __os.imbue(_M_locale(__fc));
705 if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
706 __os << __t._M_date <<
' ' << __t._M_time;
707 else if constexpr (chrono::__is_time_point_v<_Tp>)
714 if constexpr (is_convertible_v<_Tp, chrono::sys_days>)
715 __os << _S_date(__t);
718 auto __days = chrono::floor<chrono::days>(__t);
719 __os << chrono::year_month_day(__days) <<
' '
720 << chrono::hh_mm_ss(__t - __days);
725 if constexpr (chrono::__is_duration_v<_Tp>)
726 if (__is_neg) [[unlikely]]
727 __os << _S_plus_minus[1];
732 return __format::__write_padded_as_spec(__str, __str.size(),
737 static constexpr const _CharT* _S_chars
738 = _GLIBCXX_WIDEN(
"0123456789+-:/ {}");
739 static constexpr const _CharT* _S_plus_minus = _S_chars + 10;
740 static constexpr _CharT _S_colon = _S_chars[12];
741 static constexpr _CharT _S_slash = _S_chars[13];
742 static constexpr _CharT _S_space = _S_chars[14];
743 static constexpr const _CharT* _S_empty_spec = _S_chars + 15;
745 template<
typename _Tp,
typename _FormatContext>
746 typename _FormatContext::iterator
747 _M_a_A(
const _Tp& __t,
typename _FormatContext::iterator __out,
748 _FormatContext& __ctx,
bool __full)
const
752 chrono::weekday __wd = _S_weekday(__t);
754 __throw_format_error(
"format error: invalid weekday");
756 locale __loc = _M_locale(__ctx);
757 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
758 const _CharT* __days[7];
760 __tp._M_days(__days);
762 __tp._M_days_abbreviated(__days);
763 __string_view __str(__days[__wd.c_encoding()]);
764 return __format::__write(
std::move(__out), __str);
767 template<
typename _Tp,
typename _FormatContext>
768 typename _FormatContext::iterator
769 _M_b_B(
const _Tp& __t,
typename _FormatContext::iterator __out,
770 _FormatContext& __ctx,
bool __full)
const
774 chrono::month __m = _S_month(__t);
776 __throw_format_error(
"format error: invalid month");
777 locale __loc = _M_locale(__ctx);
778 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
779 const _CharT* __months[12];
781 __tp._M_months(__months);
783 __tp._M_months_abbreviated(__months);
784 __string_view __str(__months[(
unsigned)__m - 1]);
785 return __format::__write(
std::move(__out), __str);
788 template<
typename _Tp,
typename _FormatContext>
789 typename _FormatContext::iterator
790 _M_c(
const _Tp& __tt,
typename _FormatContext::iterator __out,
791 _FormatContext& __ctx,
bool __mod =
false)
const
796 auto __t = _S_floor_seconds(__tt);
797 locale __loc = _M_locale(__ctx);
798 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
799 const _CharT* __formats[2];
800 __tp._M_date_time_formats(__formats);
801 const _CharT* __rep = __formats[__mod];
803 __rep = _GLIBCXX_WIDEN(
"%a %b %e %H:%M:%S %Y");
804 basic_string<_CharT> __fmt(_S_empty_spec);
805 __fmt.insert(1u, 1u, _S_colon);
806 __fmt.insert(2u, __rep);
811 template<
typename _Tp,
typename _FormatContext>
812 typename _FormatContext::iterator
813 _M_C_y_Y(
const _Tp& __t,
typename _FormatContext::iterator __out,
814 _FormatContext& __ctx, _CharT __conv, _CharT __mod = 0)
const
824 chrono::year __y = _S_year(__t);
826 if (__mod) [[unlikely]]
829 __tm.tm_year = (int)__y - 1900;
830 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
834 basic_string<_CharT> __s;
836 const bool __is_neg = __yi < 0;
837 __yi = __builtin_abs(__yi);
839 if (__conv ==
'Y' || __conv ==
'C')
841 int __ci = __yi / 100;
842 if (__is_neg) [[unlikely]]
844 __s.assign(1, _S_plus_minus[1]);
846 if (__conv ==
'C' && (__ci * 100) != __yi)
849 if (__ci >= 100) [[unlikely]]
851 __s += std::format(_S_empty_spec, __ci / 100);
854 __s += _S_two_digits(__ci);
857 if (__conv ==
'Y' || __conv ==
'y')
858 __s += _S_two_digits(__yi % 100);
860 return __format::__write(
std::move(__out), __string_view(__s));
863 template<
typename _Tp,
typename _FormatContext>
864 typename _FormatContext::iterator
865 _M_D(
const _Tp& __t,
typename _FormatContext::iterator __out,
866 _FormatContext&)
const
868 auto __ymd = _S_date(__t);
869 basic_string<_CharT> __s;
870#if ! _GLIBCXX_USE_CXX11_ABI
873 __s = _S_two_digits((
unsigned)__ymd.month());
875 __s += _S_two_digits((
unsigned)__ymd.day());
877 __s += _S_two_digits(__builtin_abs((
int)__ymd.year()) % 100);
878 return __format::__write(
std::move(__out), __string_view(__s));
881 template<
typename _Tp,
typename _FormatContext>
882 typename _FormatContext::iterator
883 _M_d_e(
const _Tp& __t,
typename _FormatContext::iterator __out,
884 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
891 chrono::day __d = _S_day(__t);
892 unsigned __i = (unsigned)__d;
894 if (__mod) [[unlikely]]
898 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
902 auto __sv = _S_two_digits(__i);
904 if (__conv == _CharT(
'e') && __i < 10)
910 return __format::__write(
std::move(__out), __sv);
913 template<
typename _Tp,
typename _FormatContext>
914 typename _FormatContext::iterator
915 _M_F(
const _Tp& __t,
typename _FormatContext::iterator __out,
916 _FormatContext&)
const
918 auto __ymd = _S_date(__t);
919 auto __s = std::format(_GLIBCXX_WIDEN(
"{:04d}- - "),
921 auto __sv = _S_two_digits((
unsigned)__ymd.month());
922 __s[__s.size() - 5] = __sv[0];
923 __s[__s.size() - 4] = __sv[1];
924 __sv = _S_two_digits((
unsigned)__ymd.day());
925 __s[__s.size() - 2] = __sv[0];
926 __s[__s.size() - 1] = __sv[1];
928 return __format::__write(
std::move(__out), __sv);
931 template<
typename _Tp,
typename _FormatContext>
932 typename _FormatContext::iterator
933 _M_g_G(
const _Tp& __t,
typename _FormatContext::iterator __out,
934 _FormatContext& __ctx,
bool __full)
const
938 using namespace chrono;
939 auto __d = _S_days(__t);
941 __d -= (weekday(__d) - Monday) -
days(3);
943 year __y = year_month_day(__d).year();
944 return _M_C_y_Y(__y,
std::move(__out), __ctx,
"yY"[__full]);
947 template<
typename _Tp,
typename _FormatContext>
948 typename _FormatContext::iterator
949 _M_H_I(
const _Tp& __t,
typename _FormatContext::iterator __out,
950 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
957 const auto __hms = _S_hms(__t);
958 int __i = __hms.hours().count();
960 if (__mod) [[unlikely]]
964 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
968 if (__conv == _CharT(
'I'))
975 return __format::__write(
std::move(__out), _S_two_digits(__i));
978 template<
typename _Tp,
typename _FormatContext>
979 typename _FormatContext::iterator
980 _M_j(
const _Tp& __t,
typename _FormatContext::iterator __out,
981 _FormatContext&)
const
983 if constexpr (chrono::__is_duration_v<_Tp>)
986 unsigned __d = chrono::duration_cast<chrono::days>(__t).count();
992 using namespace chrono;
993 auto __day = _S_days(__t);
994 auto __ymd = _S_date(__t);
998 if constexpr (is_same_v<
typename decltype(__day)::clock, local_t>)
999 __d = __day - local_days(__ymd.year()/January/0);
1001 __d = __day - sys_days(__ymd.year()/January/0);
1007 template<
typename _Tp,
typename _FormatContext>
1008 typename _FormatContext::iterator
1009 _M_m(
const _Tp& __t,
typename _FormatContext::iterator __out,
1010 _FormatContext& __ctx,
bool __mod)
const
1015 auto __m = _S_month(__t);
1016 auto __i = (unsigned)__m;
1018 if (__mod) [[unlikely]]
1021 __tm.tm_mon = __i - 1;
1022 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
1026 return __format::__write(
std::move(__out), _S_two_digits(__i));
1029 template<
typename _Tp,
typename _FormatContext>
1030 typename _FormatContext::iterator
1031 _M_M(
const _Tp& __t,
typename _FormatContext::iterator __out,
1032 _FormatContext& __ctx,
bool __mod)
const
1037 auto __m = _S_hms(__t).minutes();
1038 auto __i = __m.count();
1040 if (__mod) [[unlikely]]
1044 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
1048 return __format::__write(
std::move(__out), _S_two_digits(__i));
1051 template<
typename _Tp,
typename _FormatContext>
1052 typename _FormatContext::iterator
1053 _M_p(
const _Tp& __t,
typename _FormatContext::iterator __out,
1054 _FormatContext& __ctx)
const
1057 auto __hms = _S_hms(__t);
1058 locale __loc = _M_locale(__ctx);
1059 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1060 const _CharT* __ampm[2];
1061 __tp._M_am_pm(__ampm);
1063 __ampm[__hms.hours().count() >= 12]);
1066 template<
typename _Tp,
typename _FormatContext>
1067 typename _FormatContext::iterator
1068 _M_q(
const _Tp&,
typename _FormatContext::iterator __out,
1069 _FormatContext&)
const
1072 if constexpr (!chrono::__is_duration_v<_Tp>)
1073 __throw_format_error(
"format error: argument is not a duration");
1076 namespace __d = chrono::__detail;
1077 using period =
typename _Tp::period;
1078 return __d::__fmt_units_suffix<period, _CharT>(
std::move(__out));
1084 template<
typename _Tp,
typename _FormatContext>
1085 typename _FormatContext::iterator
1086 _M_r(
const _Tp& __tt,
typename _FormatContext::iterator __out,
1087 _FormatContext& __ctx)
const
1090 auto __t = _S_floor_seconds(__tt);
1091 locale __loc = _M_locale(__ctx);
1092 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1093 const _CharT* __ampm_fmt;
1094 __tp._M_am_pm_format(&__ampm_fmt);
1095 basic_string<_CharT> __fmt(_S_empty_spec);
1096 __fmt.insert(1u, 1u, _S_colon);
1097 __fmt.insert(2u, __ampm_fmt);
1102 template<
typename _Tp,
typename _FormatContext>
1103 typename _FormatContext::iterator
1104 _M_R_T(
const _Tp& __t,
typename _FormatContext::iterator __out,
1105 _FormatContext& __ctx,
bool __secs)
const
1109 auto __hms = _S_hms(__t);
1111 auto __s = std::format(_GLIBCXX_WIDEN(
"{:02d}:00"),
1112 __hms.hours().count());
1113 auto __sv = _S_two_digits(__hms.minutes().count());
1114 __s[__s.size() - 2] = __sv[0];
1115 __s[__s.size() - 1] = __sv[1];
1117 __out = __format::__write(
std::move(__out), __sv);
1120 *__out++ = _S_colon;
1121 __out = _M_S(__hms,
std::move(__out), __ctx);
1126 template<
typename _Tp,
typename _FormatContext>
1127 typename _FormatContext::iterator
1128 _M_S(
const _Tp& __t,
typename _FormatContext::iterator __out,
1129 _FormatContext& __ctx,
bool __mod =
false)
const
1133 auto __hms = _S_hms(__t);
1135 if (__mod) [[unlikely]]
1138 __tm.tm_sec = (int)__hms.seconds().count();
1139 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
1143 if constexpr (__hms.fractional_width == 0)
1144 __out = __format::__write(
std::move(__out),
1145 _S_two_digits(__hms.seconds().count()));
1148 locale __loc = _M_locale(__ctx);
1149 auto __s = __hms.seconds();
1150 auto __ss = __hms.subseconds();
1151 using rep =
typename decltype(__ss)::rep;
1152 if constexpr (is_floating_point_v<rep>)
1154 chrono::duration<rep> __fs = __s + __ss;
1156 _GLIBCXX_WIDEN(
"{:#0{}.{}Lf}"),
1158 3 + __hms.fractional_width,
1159 __hms.fractional_width);
1164 = use_facet<numpunct<_CharT>>(__loc);
1165 __out = __format::__write(
std::move(__out),
1166 _S_two_digits(__s.count()));
1167 *__out++ = __np.decimal_point();
1168 if constexpr (is_integral_v<rep>)
1170 _GLIBCXX_WIDEN(
"{:0{}}"),
1172 __hms.fractional_width);
1175 auto __str = std::format(_S_empty_spec, __ss.count());
1178 __hms.fractional_width);
1187 template<
typename _Tp,
typename _FormatContext>
1188 typename _FormatContext::iterator
1189 _M_u_w(
const _Tp& __t,
typename _FormatContext::iterator __out,
1190 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
1197 chrono::weekday __wd = _S_weekday(__t);
1199 if (__mod) [[unlikely]]
1202 __tm.tm_wday = __wd.c_encoding();
1203 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
1207 unsigned __wdi = __conv ==
'u' ? __wd.iso_encoding()
1208 : __wd.c_encoding();
1209 const _CharT __d = _S_digit(__wdi);
1210 return __format::__write(
std::move(__out), __string_view(&__d, 1));
1213 template<
typename _Tp,
typename _FormatContext>
1214 typename _FormatContext::iterator
1215 _M_U_V_W(
const _Tp& __t,
typename _FormatContext::iterator __out,
1216 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
1224 using namespace chrono;
1225 auto __d = _S_days(__t);
1226 using _TDays =
decltype(__d);
1228 if (__mod) [[unlikely]]
1230 const year_month_day __ymd(__d);
1231 const year __y = __ymd.year();
1233 __tm.tm_year = (int)__y - 1900;
1234 __tm.tm_yday = (__d - _TDays(__y/January/1)).count();
1235 __tm.tm_wday = weekday(__d).c_encoding();
1236 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
1244 __d -= (weekday(__d) - Monday) -
days(3);
1247 __first = _TDays(year_month_day(__d).year()/January/1);
1252 if constexpr (
requires { __t.year(); })
1255 __y = year_month_day(__d).year();
1256 const weekday __weekstart = __conv ==
'U' ? Sunday : Monday;
1257 __first = _TDays(__y/January/__weekstart[1]);
1259 auto __weeks = chrono::floor<weeks>(__d - __first);
1260 __string_view __sv = _S_two_digits(__weeks.count() + 1);
1261 return __format::__write(
std::move(__out), __sv);
1264 template<
typename _Tp,
typename _FormatContext>
1265 typename _FormatContext::iterator
1266 _M_x(
const _Tp& __t,
typename _FormatContext::iterator __out,
1267 _FormatContext& __ctx,
bool __mod =
false)
const
1271 locale __loc = _M_locale(__ctx);
1272 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1273 const _CharT* __date_reps[2];
1274 __tp._M_date_formats(__date_reps);
1275 const _CharT* __rep = __date_reps[__mod];
1277 return _M_D(__t,
std::move(__out), __ctx);
1279 basic_string<_CharT> __fmt(_S_empty_spec);
1280 __fmt.insert(1u, 1u, _S_colon);
1281 __fmt.insert(2u, __rep);
1286 template<
typename _Tp,
typename _FormatContext>
1287 typename _FormatContext::iterator
1288 _M_X(
const _Tp& __tt,
typename _FormatContext::iterator __out,
1289 _FormatContext& __ctx,
bool __mod =
false)
const
1293 auto __t = _S_floor_seconds(__tt);
1294 locale __loc = _M_locale(__ctx);
1295 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1296 const _CharT* __time_reps[2];
1297 __tp._M_time_formats(__time_reps);
1298 const _CharT* __rep = __time_reps[__mod];
1300 return _M_R_T(__t,
std::move(__out), __ctx,
true);
1302 basic_string<_CharT> __fmt(_S_empty_spec);
1303 __fmt.insert(1u, 1u, _S_colon);
1304 __fmt.insert(2u, __rep);
1309 template<
typename _Tp,
typename _FormatContext>
1310 typename _FormatContext::iterator
1311 _M_z(
const _Tp& __t,
typename _FormatContext::iterator __out,
1312 _FormatContext&,
bool __mod =
false)
const
1314 using ::std::chrono::__detail::__utc_leap_second;
1315 using ::std::chrono::__detail::__local_time_fmt;
1317 auto __utc = __mod ? __string_view(_GLIBCXX_WIDEN(
"+00:00"), 6)
1318 : __string_view(_GLIBCXX_WIDEN(
"+0000"), 5);
1320 if constexpr (chrono::__is_time_point_v<_Tp>)
1322 if constexpr (is_same_v<
typename _Tp::clock,
1323 chrono::system_clock>)
1324 return __format::__write(
std::move(__out), __utc);
1326 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1328 if (__t._M_offset_sec)
1331 basic_string<_CharT> __s;
1332 if (*__t._M_offset_sec != 0s)
1334 chrono:: hh_mm_ss __hms(*__t._M_offset_sec);
1335 __s = _S_plus_minus[__hms.is_negative()];
1336 __s += _S_two_digits(__hms.hours().count());
1339 __s += _S_two_digits(__hms.minutes().count());
1342 return __format::__write(
std::move(__out), __sv);
1345 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1346 return __format::__write(
std::move(__out), __utc);
1348 __no_timezone_available();
1351 template<
typename _Tp,
typename _FormatContext>
1352 typename _FormatContext::iterator
1353 _M_Z(
const _Tp& __t,
typename _FormatContext::iterator __out,
1354 _FormatContext& __ctx)
const
1356 using ::std::chrono::__detail::__utc_leap_second;
1357 using ::std::chrono::__detail::__local_time_fmt;
1359 __string_view __utc(_GLIBCXX_WIDEN(
"UTC"), 3);
1360 if constexpr (chrono::__is_time_point_v<_Tp>)
1362 if constexpr (is_same_v<
typename _Tp::clock,
1363 chrono::system_clock>)
1364 return __format::__write(
std::move(__out), __utc);
1366 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1370 string_view __sv = *__t._M_abbrev;
1371 if constexpr (is_same_v<_CharT, char>)
1372 return __format::__write(
std::move(__out), __sv);
1376 basic_string<_CharT> __ws(__sv.size(), _CharT());
1377 auto& __ct = use_facet<ctype<_CharT>>(_M_locale(__ctx));
1378 __ct.widen(__sv.begin(), __sv.end(), __ws.data());
1379 __string_view __wsv = __ws;
1380 return __format::__write(
std::move(__out), __wsv);
1384 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1385 return __format::__write(
std::move(__out), __utc);
1387 __no_timezone_available();
1394 _S_digit(
int __n)
noexcept
1397 return _GLIBCXX_WIDEN(
"0123456789999999")[__n & 0xf];
1401 static basic_string_view<_CharT>
1402 _S_two_digits(
int __n)
noexcept
1405 _GLIBCXX_WIDEN(
"0001020304050607080910111213141516171819"
1406 "2021222324252627282930313233343536373839"
1407 "4041424344454647484950515253545556575859"
1408 "6061626364656667686970717273747576777879"
1409 "8081828384858687888990919293949596979899"
1410 "9999999999999999999999999999999999999999"
1411 "9999999999999999") + 2 * (__n & 0x7f),
1419 template<
typename _Tp>
1420 static decltype(
auto)
1421 _S_hms(
const _Tp& __t)
1423 using ::std::chrono::__detail::__utc_leap_second;
1424 using ::std::chrono::__detail::__local_time_fmt;
1426 if constexpr (__is_specialization_of<_Tp, chrono::hh_mm_ss>)
1428 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1430 else if constexpr (chrono::__is_duration_v<_Tp>)
1431 return chrono::hh_mm_ss<_Tp>(__t);
1432 else if constexpr (chrono::__is_time_point_v<_Tp>)
1433 return chrono::hh_mm_ss(__t - chrono::floor<chrono::days>(__t));
1434 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1435 return _S_hms(__t._M_time);
1438 __invalid_chrono_spec();
1439 return chrono::hh_mm_ss<chrono::seconds>();
1444 template<
typename _Tp>
1446 _S_days(
const _Tp& __t)
1448 using namespace chrono;
1449 using ::std::chrono::__detail::__utc_leap_second;
1450 using ::std::chrono::__detail::__local_time_fmt;
1452 if constexpr (__is_time_point_v<_Tp>)
1453 return chrono::floor<days>(__t);
1454 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1456 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1457 return chrono::floor<days>(__t._M_time);
1458 else if constexpr (is_same_v<_Tp, year_month_day>
1459 || is_same_v<_Tp, year_month_day_last>
1460 || is_same_v<_Tp, year_month_weekday>
1461 || is_same_v<_Tp, year_month_weekday_last>)
1462 return sys_days(__t);
1465 if constexpr (__is_duration_v<_Tp>)
1466 __not_valid_for_duration();
1468 __invalid_chrono_spec();
1469 return chrono::sys_days();
1474 template<
typename _Tp>
1475 static chrono::year_month_day
1476 _S_date(
const _Tp& __t)
1478 if constexpr (is_same_v<_Tp, chrono::year_month_day>)
1481 return chrono::year_month_day(_S_days(__t));
1484 template<
typename _Tp>
1486 _S_day(
const _Tp& __t)
1488 using namespace chrono;
1490 if constexpr (is_same_v<_Tp, day>)
1492 else if constexpr (
requires { __t.day(); })
1495 return _S_date(__t).day();
1498 template<
typename _Tp>
1499 static chrono::month
1500 _S_month(
const _Tp& __t)
1502 using namespace chrono;
1504 if constexpr (is_same_v<_Tp, month>)
1506 else if constexpr (
requires { __t.month(); })
1509 return _S_date(__t).month();
1512 template<
typename _Tp>
1514 _S_year(
const _Tp& __t)
1516 using namespace chrono;
1518 if constexpr (is_same_v<_Tp, year>)
1520 else if constexpr (
requires { __t.year(); })
1523 return _S_date(__t).year();
1526 template<
typename _Tp>
1527 static chrono::weekday
1528 _S_weekday(
const _Tp& __t)
1531 using ::std::chrono::__detail::__local_time_fmt;
1533 if constexpr (is_same_v<_Tp, weekday>)
1535 else if constexpr (
requires { __t.weekday(); })
1537 else if constexpr (is_same_v<_Tp, month_weekday>)
1538 return __t.weekday_indexed().weekday();
1539 else if constexpr (is_same_v<_Tp, month_weekday_last>)
1540 return __t.weekday_last().weekday();
1542 return weekday(_S_days(__t));
1546 template<
typename _Tp>
1548 _S_floor_seconds(
const _Tp& __t)
1550 using chrono::__detail::__local_time_fmt;
1551 if constexpr (chrono::__is_time_point_v<_Tp>
1552 || chrono::__is_duration_v<_Tp>)
1554 if constexpr (_Tp::period::den != 1)
1555 return chrono::floor<chrono::seconds>(__t);
1559 else if constexpr (__is_specialization_of<_Tp, chrono::hh_mm_ss>)
1561 if constexpr (_Tp::fractional_width != 0)
1562 return chrono::floor<chrono::seconds>(__t.to_duration());
1566 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1567 return _S_floor_seconds(__t._M_time);
1574 template<
typename _Iter>
1576 _M_locale_fmt(_Iter __out,
const locale& __loc,
const struct tm& __tm,
1577 char __fmt,
char __mod)
const
1579 basic_ostringstream<_CharT> __os;
1580 const auto& __tp = use_facet<time_put<_CharT>>(__loc);
1581 __tp.put(__os, __os, _S_space, &__tm, __fmt, __mod);
1583 __out = __format::__write(
std::move(__out), __os.view());
1591 template<
typename _Rep,
typename _Period,
typename _CharT>
1592 struct formatter<chrono::duration<_Rep, _Period>, _CharT>
1594 constexpr typename basic_format_parse_context<_CharT>::iterator
1595 parse(basic_format_parse_context<_CharT>& __pc)
1597 using namespace __format;
1598 auto __it = _M_f._M_parse(__pc, _Duration|_TimeOfDay);
1599 if constexpr (!is_floating_point_v<_Rep>)
1600 if (_M_f._M_spec._M_prec_kind != __format::_WP_none)
1601 __throw_format_error(
"format error: invalid precision for duration");
1605 template<
typename _Out>
1606 typename basic_format_context<_Out, _CharT>::iterator
1607 format(
const chrono::duration<_Rep, _Period>& __d,
1608 basic_format_context<_Out, _CharT>& __fc)
const
1611 if (__d < __d.zero()) [[unlikely]]
1613 if constexpr (is_integral_v<_Rep>)
1617 using _URep = make_unsigned_t<_Rep>;
1618 auto __ucnt = -
static_cast<_URep
>(__d.count());
1619 auto __ud = chrono::duration<_URep, _Period>(__ucnt);
1620 return _M_f._M_format(__ud, __fc,
true);
1623 return _M_f._M_format(-__d, __fc,
true);
1625 return _M_f._M_format(__d, __fc,
false);
1629 __format::__formatter_chrono<_CharT> _M_f;
1632 template<
typename _CharT>
1633 struct formatter<chrono::day, _CharT>
1635 template<
typename _ParseContext>
1636 constexpr typename _ParseContext::iterator
1637 parse(_ParseContext& __pc)
1638 {
return _M_f._M_parse(__pc, __format::_Day); }
1640 template<
typename _FormatContext>
1641 typename _FormatContext::iterator
1642 format(
const chrono::day& __t, _FormatContext& __fc)
const
1643 {
return _M_f._M_format(__t, __fc); }
1646 __format::__formatter_chrono<_CharT> _M_f;
1649 template<
typename _CharT>
1650 struct formatter<chrono::month, _CharT>
1652 template<
typename _ParseContext>
1653 constexpr typename _ParseContext::iterator
1654 parse(_ParseContext& __pc)
1655 {
return _M_f._M_parse(__pc, __format::_Month); }
1657 template<
typename _FormatContext>
1658 typename _FormatContext::iterator
1659 format(
const chrono::month& __t, _FormatContext& __fc)
const
1660 {
return _M_f._M_format(__t, __fc); }
1663 __format::__formatter_chrono<_CharT> _M_f;
1666 template<
typename _CharT>
1667 struct formatter<chrono::year, _CharT>
1669 template<
typename _ParseContext>
1670 constexpr typename _ParseContext::iterator
1671 parse(_ParseContext& __pc)
1672 {
return _M_f._M_parse(__pc, __format::_Year); }
1674 template<
typename _FormatContext>
1675 typename _FormatContext::iterator
1676 format(
const chrono::year& __t, _FormatContext& __fc)
const
1677 {
return _M_f._M_format(__t, __fc); }
1680 __format::__formatter_chrono<_CharT> _M_f;
1683 template<
typename _CharT>
1684 struct formatter<chrono::weekday, _CharT>
1686 template<
typename _ParseContext>
1687 constexpr typename _ParseContext::iterator
1688 parse(_ParseContext& __pc)
1689 {
return _M_f._M_parse(__pc, __format::_Weekday); }
1691 template<
typename _FormatContext>
1692 typename _FormatContext::iterator
1693 format(
const chrono::weekday& __t, _FormatContext& __fc)
const
1694 {
return _M_f._M_format(__t, __fc); }
1697 __format::__formatter_chrono<_CharT> _M_f;
1700 template<
typename _CharT>
1701 struct formatter<chrono::weekday_indexed, _CharT>
1703 template<
typename _ParseContext>
1704 constexpr typename _ParseContext::iterator
1705 parse(_ParseContext& __pc)
1706 {
return _M_f._M_parse(__pc, __format::_Weekday); }
1708 template<
typename _FormatContext>
1709 typename _FormatContext::iterator
1710 format(
const chrono::weekday_indexed& __t, _FormatContext& __fc)
const
1711 {
return _M_f._M_format(__t, __fc); }
1714 __format::__formatter_chrono<_CharT> _M_f;
1717 template<
typename _CharT>
1718 struct formatter<chrono::weekday_last, _CharT>
1720 template<
typename _ParseContext>
1721 constexpr typename _ParseContext::iterator
1722 parse(_ParseContext& __pc)
1723 {
return _M_f._M_parse(__pc, __format::_Weekday); }
1725 template<
typename _FormatContext>
1726 typename _FormatContext::iterator
1727 format(
const chrono::weekday_last& __t, _FormatContext& __fc)
const
1728 {
return _M_f._M_format(__t, __fc); }
1731 __format::__formatter_chrono<_CharT> _M_f;
1734 template<
typename _CharT>
1735 struct formatter<chrono::month_day, _CharT>
1737 template<
typename _ParseContext>
1738 constexpr typename _ParseContext::iterator
1739 parse(_ParseContext& __pc)
1740 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Day); }
1742 template<
typename _FormatContext>
1743 typename _FormatContext::iterator
1744 format(
const chrono::month_day& __t, _FormatContext& __fc)
const
1745 {
return _M_f._M_format(__t, __fc); }
1748 __format::__formatter_chrono<_CharT> _M_f;
1751 template<
typename _CharT>
1752 struct formatter<chrono::month_day_last, _CharT>
1754 template<
typename _ParseContext>
1755 constexpr typename _ParseContext::iterator
1756 parse(_ParseContext& __pc)
1757 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Day); }
1759 template<
typename _FormatContext>
1760 typename _FormatContext::iterator
1761 format(
const chrono::month_day_last& __t, _FormatContext& __fc)
const
1762 {
return _M_f._M_format(__t, __fc); }
1765 __format::__formatter_chrono<_CharT> _M_f;
1768 template<
typename _CharT>
1769 struct formatter<chrono::month_weekday, _CharT>
1771 template<
typename _ParseContext>
1772 constexpr typename _ParseContext::iterator
1773 parse(_ParseContext& __pc)
1774 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Weekday); }
1776 template<
typename _FormatContext>
1777 typename _FormatContext::iterator
1778 format(
const chrono::month_weekday& __t, _FormatContext& __fc)
const
1779 {
return _M_f._M_format(__t, __fc); }
1782 __format::__formatter_chrono<_CharT> _M_f;
1785 template<
typename _CharT>
1786 struct formatter<chrono::month_weekday_last, _CharT>
1788 template<
typename _ParseContext>
1789 constexpr typename _ParseContext::iterator
1790 parse(_ParseContext& __pc)
1791 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Weekday); }
1793 template<
typename _FormatContext>
1794 typename _FormatContext::iterator
1795 format(
const chrono::month_weekday_last& __t,
1796 _FormatContext& __fc)
const
1797 {
return _M_f._M_format(__t, __fc); }
1800 __format::__formatter_chrono<_CharT> _M_f;
1803 template<
typename _CharT>
1804 struct formatter<chrono::year_month, _CharT>
1806 template<
typename _ParseContext>
1807 constexpr typename _ParseContext::iterator
1808 parse(_ParseContext& __pc)
1809 {
return _M_f._M_parse(__pc, __format::_Year|__format::_Month); }
1811 template<
typename _FormatContext>
1812 typename _FormatContext::iterator
1813 format(
const chrono::year_month& __t, _FormatContext& __fc)
const
1814 {
return _M_f._M_format(__t, __fc); }
1817 __format::__formatter_chrono<_CharT> _M_f;
1820 template<
typename _CharT>
1821 struct formatter<chrono::year_month_day, _CharT>
1823 template<
typename _ParseContext>
1824 constexpr typename _ParseContext::iterator
1825 parse(_ParseContext& __pc)
1826 {
return _M_f._M_parse(__pc, __format::_Date); }
1828 template<
typename _FormatContext>
1829 typename _FormatContext::iterator
1830 format(
const chrono::year_month_day& __t, _FormatContext& __fc)
const
1831 {
return _M_f._M_format(__t, __fc); }
1834 __format::__formatter_chrono<_CharT> _M_f;
1837 template<
typename _CharT>
1838 struct formatter<chrono::year_month_day_last, _CharT>
1840 template<
typename _ParseContext>
1841 constexpr typename _ParseContext::iterator
1842 parse(_ParseContext& __pc)
1843 {
return _M_f._M_parse(__pc, __format::_Date); }
1845 template<
typename _FormatContext>
1846 typename _FormatContext::iterator
1847 format(
const chrono::year_month_day_last& __t,
1848 _FormatContext& __fc)
const
1849 {
return _M_f._M_format(__t, __fc); }
1852 __format::__formatter_chrono<_CharT> _M_f;
1855 template<
typename _CharT>
1856 struct formatter<chrono::year_month_weekday, _CharT>
1858 template<
typename _ParseContext>
1859 constexpr typename _ParseContext::iterator
1860 parse(_ParseContext& __pc)
1861 {
return _M_f._M_parse(__pc, __format::_Date); }
1863 template<
typename _FormatContext>
1864 typename _FormatContext::iterator
1865 format(
const chrono::year_month_weekday& __t,
1866 _FormatContext& __fc)
const
1867 {
return _M_f._M_format(__t, __fc); }
1870 __format::__formatter_chrono<_CharT> _M_f;
1873 template<
typename _CharT>
1874 struct formatter<chrono::year_month_weekday_last, _CharT>
1876 template<
typename _ParseContext>
1877 constexpr typename _ParseContext::iterator
1878 parse(_ParseContext& __pc)
1879 {
return _M_f._M_parse(__pc, __format::_Date); }
1881 template<
typename _FormatContext>
1882 typename _FormatContext::iterator
1883 format(
const chrono::year_month_weekday_last& __t,
1884 _FormatContext& __fc)
const
1885 {
return _M_f._M_format(__t, __fc); }
1888 __format::__formatter_chrono<_CharT> _M_f;
1891 template<
typename _Rep,
typename _Period,
typename _CharT>
1892 struct formatter<chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>, _CharT>
1894 template<
typename _ParseContext>
1895 constexpr typename _ParseContext::iterator
1896 parse(_ParseContext& __pc)
1897 {
return _M_f._M_parse(__pc, __format::_TimeOfDay); }
1899 template<
typename _FormatContext>
1900 typename _FormatContext::iterator
1901 format(
const chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>& __t,
1902 _FormatContext& __fc)
const
1903 {
return _M_f._M_format(__t, __fc); }
1906 __format::__formatter_chrono<_CharT> _M_f;
1909#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
1910 template<
typename _CharT>
1911 struct formatter<chrono::sys_info, _CharT>
1913 template<
typename _ParseContext>
1914 constexpr typename _ParseContext::iterator
1915 parse(_ParseContext& __pc)
1916 {
return _M_f._M_parse(__pc, __format::_ChronoParts{}); }
1918 template<
typename _FormatContext>
1919 typename _FormatContext::iterator
1920 format(
const chrono::sys_info& __i, _FormatContext& __fc)
const
1921 {
return _M_f._M_format(__i, __fc); }
1924 __format::__formatter_chrono<_CharT> _M_f;
1927 template<
typename _CharT>
1928 struct formatter<chrono::local_info, _CharT>
1930 template<
typename _ParseContext>
1931 constexpr typename _ParseContext::iterator
1932 parse(_ParseContext& __pc)
1933 {
return _M_f._M_parse(__pc, __format::_ChronoParts{}); }
1935 template<
typename _FormatContext>
1936 typename _FormatContext::iterator
1937 format(
const chrono::local_info& __i, _FormatContext& __fc)
const
1938 {
return _M_f._M_format(__i, __fc); }
1941 __format::__formatter_chrono<_CharT> _M_f;
1945 template<
typename _Duration,
typename _CharT>
1946 struct formatter<chrono::sys_time<_Duration>, _CharT>
1948 template<
typename _ParseContext>
1949 constexpr typename _ParseContext::iterator
1950 parse(_ParseContext& __pc)
1952 auto __next = _M_f._M_parse(__pc, __format::_ZonedDateTime);
1953 if constexpr (!__stream_insertable)
1954 if (_M_f._M_spec._M_chrono_specs.empty())
1955 __format::__invalid_chrono_spec();
1959 template<
typename _FormatContext>
1960 typename _FormatContext::iterator
1961 format(
const chrono::sys_time<_Duration>& __t,
1962 _FormatContext& __fc)
const
1963 {
return _M_f._M_format(__t, __fc); }
1966 static constexpr bool __stream_insertable
1967 =
requires (basic_ostream<_CharT>& __os,
1968 chrono::sys_time<_Duration> __t) { __os << __t; };
1970 __format::__formatter_chrono<_CharT> _M_f;
1973 template<
typename _Duration,
typename _CharT>
1974 struct formatter<chrono::utc_time<_Duration>, _CharT>
1975 : __format::__formatter_chrono<_CharT>
1977 template<
typename _ParseContext>
1978 constexpr typename _ParseContext::iterator
1979 parse(_ParseContext& __pc)
1980 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
1982 template<
typename _FormatContext>
1983 typename _FormatContext::iterator
1984 format(
const chrono::utc_time<_Duration>& __t,
1985 _FormatContext& __fc)
const
1990 using chrono::__detail::__utc_leap_second;
1992 using chrono::sys_time;
1993 using _CDur = common_type_t<_Duration, seconds>;
1994 const auto __li = chrono::get_leap_second_info(__t);
1995 sys_time<_CDur> __s{__t.time_since_epoch() - __li.elapsed};
1996 if (!__li.is_leap_second) [[likely]]
1997 return _M_f._M_format(__s, __fc);
1999 return _M_f._M_format(__utc_leap_second(__s), __fc);
2003 friend formatter<chrono::__detail::__utc_leap_second<_Duration>, _CharT>;
2005 __format::__formatter_chrono<_CharT> _M_f;
2008 template<
typename _Duration,
typename _CharT>
2009 struct formatter<chrono::tai_time<_Duration>, _CharT>
2010 : __format::__formatter_chrono<_CharT>
2012 template<
typename _ParseContext>
2013 constexpr typename _ParseContext::iterator
2014 parse(_ParseContext& __pc)
2015 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2017 template<
typename _FormatContext>
2018 typename _FormatContext::iterator
2019 format(
const chrono::tai_time<_Duration>& __t,
2020 _FormatContext& __fc)
const
2026 using _CDur = common_type_t<_Duration, chrono::days>;
2027 chrono::local_time<_CDur> __lt(__t.time_since_epoch() - __tai_offset);
2028 const string __abbrev(
"TAI", 3);
2031 return _M_f._M_format(__lf, __fc);
2035 __format::__formatter_chrono<_CharT> _M_f;
2038 template<
typename _Duration,
typename _CharT>
2039 struct formatter<chrono::gps_time<_Duration>, _CharT>
2040 : __format::__formatter_chrono<_CharT>
2042 template<
typename _ParseContext>
2043 constexpr typename _ParseContext::iterator
2044 parse(_ParseContext& __pc)
2045 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2047 template<
typename _FormatContext>
2048 typename _FormatContext::iterator
2049 format(
const chrono::gps_time<_Duration>& __t,
2050 _FormatContext& __fc)
const
2056 using _CDur = common_type_t<_Duration, chrono::days>;
2057 chrono::local_time<_CDur> __lt(__t.time_since_epoch() + __gps_offset);
2058 const string __abbrev(
"GPS", 3);
2061 return _M_f._M_format(__lf, __fc);
2065 __format::__formatter_chrono<_CharT> _M_f;
2068 template<
typename _Duration,
typename _CharT>
2069 struct formatter<chrono::file_time<_Duration>, _CharT>
2071 template<
typename _ParseContext>
2072 constexpr typename _ParseContext::iterator
2073 parse(_ParseContext& __pc)
2074 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2076 template<
typename _FormatContext>
2077 typename _FormatContext::iterator
2078 format(
const chrono::file_time<_Duration>& __t,
2079 _FormatContext& __ctx)
const
2081 using namespace chrono;
2082 return _M_f._M_format(chrono::clock_cast<system_clock>(__t), __ctx);
2086 __format::__formatter_chrono<_CharT> _M_f;
2089 template<
typename _Duration,
typename _CharT>
2090 struct formatter<chrono::local_time<_Duration>, _CharT>
2092 template<
typename _ParseContext>
2093 constexpr typename _ParseContext::iterator
2094 parse(_ParseContext& __pc)
2095 {
return _M_f._M_parse(__pc, __format::_DateTime); }
2097 template<
typename _FormatContext>
2098 typename _FormatContext::iterator
2099 format(
const chrono::local_time<_Duration>& __t,
2100 _FormatContext& __ctx)
const
2101 {
return _M_f._M_format(__t, __ctx); }
2104 __format::__formatter_chrono<_CharT> _M_f;
2107 template<
typename _Duration,
typename _CharT>
2108 struct formatter<chrono::__detail::__local_time_fmt<_Duration>, _CharT>
2110 template<
typename _ParseContext>
2111 constexpr typename _ParseContext::iterator
2112 parse(_ParseContext& __pc)
2113 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2115 template<
typename _FormatContext>
2116 typename _FormatContext::iterator
2117 format(
const chrono::__detail::__local_time_fmt<_Duration>& __t,
2118 _FormatContext& __ctx)
const
2119 {
return _M_f._M_format(__t, __ctx); }
2122 __format::__formatter_chrono<_CharT> _M_f;
2125#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2126 template<
typename _Duration,
typename _TimeZonePtr,
typename _CharT>
2127 struct formatter<chrono::zoned_time<_Duration, _TimeZonePtr>, _CharT>
2128 : formatter<chrono::__detail::__local_time_fmt<_Duration>, _CharT>
2130 template<
typename _FormatContext>
2131 typename _FormatContext::iterator
2132 format(
const chrono::zoned_time<_Duration, _TimeZonePtr>& __tp,
2133 _FormatContext& __ctx)
const
2135 using chrono::__detail::__local_time_fmt;
2136 using _Base = formatter<__local_time_fmt<_Duration>, _CharT>;
2137 const chrono::sys_info __info = __tp.get_info();
2141 return _Base::format(__lf, __ctx);
2147 template<
typename _Duration,
typename _CharT>
2148 struct formatter<chrono::__detail::__utc_leap_second<_Duration>, _CharT>
2149 : formatter<chrono::utc_time<_Duration>, _CharT>
2151 template<
typename _FormatContext>
2152 typename _FormatContext::iterator
2153 format(
const chrono::__detail::__utc_leap_second<_Duration>& __t,
2154 _FormatContext& __fc)
const
2155 {
return this->_M_f._M_format(__t, __fc); }
2166 template<
typename _Duration = seconds>
2169 static_assert(is_same_v<common_type_t<_Duration, seconds>, _Duration>);
2172 _Parser(__format::_ChronoParts __need) : _M_need(__need) { }
2174 _Parser(_Parser&&) =
delete;
2175 void operator=(_Parser&&) =
delete;
2177 _Duration _M_time{};
2178 sys_days _M_sys_days{};
2179 year_month_day _M_ymd{};
2181 __format::_ChronoParts _M_need;
2182 unsigned _M_is_leap_second : 1 {};
2183 unsigned _M_reserved : 15 {};
2185 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2186 basic_istream<_CharT, _Traits>&
2187 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2188 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2189 minutes* __offset =
nullptr);
2194 template<
typename _CharT,
typename _Traits>
2195 static int_least32_t
2196 _S_read_unsigned(basic_istream<_CharT, _Traits>& __is,
2197 ios_base::iostate& __err,
int __n)
2199 int_least32_t __val = _S_try_read_digit(__is, __err);
2200 if (__val == -1) [[unlikely]]
2201 __err |= ios_base::failbit;
2206 for (
int __i = 1; __i < __n1; ++__i)
2207 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
2213 while (__n1++ < __n) [[unlikely]]
2214 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
2216 if (__builtin_mul_overflow(__val, 10, &__val)
2217 || __builtin_add_overflow(__val, __dig, &__val))
2219 __err |= ios_base::failbit;
2229 template<
typename _CharT,
typename _Traits>
2230 static int_least32_t
2231 _S_read_signed(basic_istream<_CharT, _Traits>& __is,
2232 ios_base::iostate& __err,
int __n)
2234 auto __sign = __is.peek();
2235 if (__sign ==
'-' || __sign ==
'+')
2237 int_least32_t __val = _S_read_unsigned(__is, __err, __n);
2238 if (__err & ios_base::failbit)
2240 if (__sign ==
'-') [[unlikely]]
2248 template<
typename _CharT,
typename _Traits>
2249 static int_least32_t
2250 _S_try_read_digit(basic_istream<_CharT, _Traits>& __is,
2251 ios_base::iostate& __err)
2253 int_least32_t __val = -1;
2254 auto __i = __is.peek();
2255 if (!_Traits::eq_int_type(__i, _Traits::eof())) [[likely]]
2257 _CharT __c = _Traits::to_char_type(__i);
2258 if (_CharT(
'0') <= __c && __c <= _CharT(
'9')) [[likely]]
2261 __val = __c - _CharT(
'0');
2265 __err |= ios_base::eofbit;
2271 template<
typename _CharT,
typename _Traits>
2273 _S_read_chr(basic_istream<_CharT, _Traits>& __is,
2274 ios_base::iostate& __err, _CharT __c)
2276 auto __i = __is.peek();
2277 if (_Traits::eq_int_type(__i, _Traits::eof()))
2278 __err |= ios_base::eofbit;
2279 else if (_Traits::to_char_type(__i) == __c) [[likely]]
2284 __err |= ios_base::failbit;
2289 template<
typename _Duration>
2290 using _Parser_t = _Parser<common_type_t<_Duration, seconds>>;
2295 template<
typename _CharT,
typename _Traits,
typename _Rep,
typename _Period,
2296 typename _Alloc = allocator<_CharT>>
2297 inline basic_istream<_CharT, _Traits>&
2298 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2299 duration<_Rep, _Period>& __d,
2300 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2303 auto __need = __format::_ChronoParts::_TimeOfDay;
2304 __detail::_Parser_t<duration<_Rep, _Period>> __p(__need);
2305 if (__p(__is, __fmt, __abbrev, __offset))
2306 __d = chrono::duration_cast<duration<_Rep, _Period>>(__p._M_time);
2310 template<
typename _CharT,
typename _Traits>
2311 inline basic_ostream<_CharT, _Traits>&
2312 operator<<(basic_ostream<_CharT, _Traits>& __os,
const day& __d)
2314 using _Ctx = __format::__format_context<_CharT>;
2315 using _Str = basic_string_view<_CharT>;
2316 _Str __s = _GLIBCXX_WIDEN(
"{:02d} is not a valid day");
2318 __s = __s.substr(0, 6);
2319 auto __u = (unsigned)__d;
2320 __os << std::vformat(__s, make_format_args<_Ctx>(__u));
2324 template<
typename _CharT,
typename _Traits,
2325 typename _Alloc = allocator<_CharT>>
2326 inline basic_istream<_CharT, _Traits>&
2327 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2329 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2332 __detail::_Parser<> __p(__format::_ChronoParts::_Day);
2333 if (__p(__is, __fmt, __abbrev, __offset))
2334 __d = __p._M_ymd.day();
2338 template<
typename _CharT,
typename _Traits>
2339 inline basic_ostream<_CharT, _Traits>&
2340 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month& __m)
2342 using _Ctx = __format::__format_context<_CharT>;
2343 using _Str = basic_string_view<_CharT>;
2344 _Str __s = _GLIBCXX_WIDEN(
"{:L%b}{} is not a valid month");
2347 make_format_args<_Ctx>(__m));
2350 auto __u = (unsigned)__m;
2351 __os <<
std::vformat(__s.substr(6), make_format_args<_Ctx>(__u));
2356 template<
typename _CharT,
typename _Traits,
2357 typename _Alloc = allocator<_CharT>>
2358 inline basic_istream<_CharT, _Traits>&
2359 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2361 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2364 __detail::_Parser<> __p(__format::_ChronoParts::_Month);
2365 if (__p(__is, __fmt, __abbrev, __offset))
2366 __m = __p._M_ymd.month();
2370 template<
typename _CharT,
typename _Traits>
2371 inline basic_ostream<_CharT, _Traits>&
2372 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year& __y)
2374 using _Ctx = __format::__format_context<_CharT>;
2375 using _Str = basic_string_view<_CharT>;
2376 _Str __s = _GLIBCXX_WIDEN(
"-{:04d} is not a valid year");
2378 __s = __s.substr(0, 7);
2380 if (__i >= 0) [[likely]]
2381 __s.remove_prefix(1);
2384 __os << std::vformat(__s, make_format_args<_Ctx>(__i));
2388 template<
typename _CharT,
typename _Traits,
2389 typename _Alloc = allocator<_CharT>>
2390 inline basic_istream<_CharT, _Traits>&
2391 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2393 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2396 __detail::_Parser<> __p(__format::_ChronoParts::_Year);
2397 if (__p(__is, __fmt, __abbrev, __offset))
2398 __y = __p._M_ymd.year();
2402 template<
typename _CharT,
typename _Traits>
2403 inline basic_ostream<_CharT, _Traits>&
2404 operator<<(basic_ostream<_CharT, _Traits>& __os,
const weekday& __wd)
2406 using _Ctx = __format::__format_context<_CharT>;
2407 using _Str = basic_string_view<_CharT>;
2408 _Str __s = _GLIBCXX_WIDEN(
"{:L%a}{} is not a valid weekday");
2411 make_format_args<_Ctx>(__wd));
2414 auto __c = __wd.c_encoding();
2415 __os <<
std::vformat(__s.substr(6), make_format_args<_Ctx>(__c));
2420 template<
typename _CharT,
typename _Traits,
2421 typename _Alloc = allocator<_CharT>>
2422 inline basic_istream<_CharT, _Traits>&
2423 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2425 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2428 __detail::_Parser<> __p(__format::_ChronoParts::_Weekday);
2429 if (__p(__is, __fmt, __abbrev, __offset))
2434 template<
typename _CharT,
typename _Traits>
2435 inline basic_ostream<_CharT, _Traits>&
2436 operator<<(basic_ostream<_CharT, _Traits>& __os,
2437 const weekday_indexed& __wdi)
2442 basic_stringstream<_CharT> __os2;
2443 __os2.imbue(__os.getloc());
2444 __os2 << __wdi.weekday();
2445 const auto __i = __wdi.index();
2446 basic_string_view<_CharT> __s
2447 = _GLIBCXX_WIDEN(
"[ is not a valid index]");
2449 __os2 << std::format(_GLIBCXX_WIDEN(
"{}"), __i);
2450 if (__i >= 1 && __i <= 5)
2451 __os2 << __s.back();
2453 __os2 << __s.substr(1);
2454 __os << __os2.view();
2458 template<
typename _CharT,
typename _Traits>
2459 inline basic_ostream<_CharT, _Traits>&
2460 operator<<(basic_ostream<_CharT, _Traits>& __os,
2461 const weekday_last& __wdl)
2464 basic_stringstream<_CharT> __os2;
2465 __os2.imbue(__os.getloc());
2466 __os2 << __wdl.weekday() << _GLIBCXX_WIDEN(
"[last]");
2467 __os << __os2.view();
2471 template<
typename _CharT,
typename _Traits>
2472 inline basic_ostream<_CharT, _Traits>&
2473 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month_day& __md)
2476 basic_stringstream<_CharT> __os2;
2477 __os2.imbue(__os.getloc());
2478 __os2 << __md.month();
2479 if constexpr (is_same_v<_CharT, char>)
2483 __os2 << __md.day();
2484 __os << __os2.view();
2488 template<
typename _CharT,
typename _Traits,
2489 typename _Alloc = allocator<_CharT>>
2490 inline basic_istream<_CharT, _Traits>&
2491 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2493 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2496 using __format::_ChronoParts;
2497 auto __need = _ChronoParts::_Month | _ChronoParts::_Day;
2498 __detail::_Parser<> __p(__need);
2499 if (__p(__is, __fmt, __abbrev, __offset))
2500 __md = month_day(__p._M_ymd.month(), __p._M_ymd.day());
2504 template<
typename _CharT,
typename _Traits>
2505 inline basic_ostream<_CharT, _Traits>&
2506 operator<<(basic_ostream<_CharT, _Traits>& __os,
2507 const month_day_last& __mdl)
2510 basic_stringstream<_CharT> __os2;
2511 __os2.imbue(__os.getloc());
2512 __os2 << __mdl.month() << _GLIBCXX_WIDEN(
"/last");
2513 __os << __os2.view();
2517 template<
typename _CharT,
typename _Traits>
2518 inline basic_ostream<_CharT, _Traits>&
2519 operator<<(basic_ostream<_CharT, _Traits>& __os,
2520 const month_weekday& __mwd)
2523 basic_stringstream<_CharT> __os2;
2524 __os2.imbue(__os.getloc());
2525 __os2 << __mwd.month();
2526 if constexpr (is_same_v<_CharT, char>)
2530 __os2 << __mwd.weekday_indexed();
2531 __os << __os2.view();
2535 template<
typename _CharT,
typename _Traits>
2536 inline basic_ostream<_CharT, _Traits>&
2537 operator<<(basic_ostream<_CharT, _Traits>& __os,
2538 const month_weekday_last& __mwdl)
2541 basic_stringstream<_CharT> __os2;
2542 __os2.imbue(__os.getloc());
2543 __os2 << __mwdl.month();
2544 if constexpr (is_same_v<_CharT, char>)
2548 __os2 << __mwdl.weekday_last();
2549 __os << __os2.view();
2553 template<
typename _CharT,
typename _Traits>
2554 inline basic_ostream<_CharT, _Traits>&
2555 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year_month& __ym)
2558 basic_stringstream<_CharT> __os2;
2559 __os2.imbue(__os.getloc());
2560 __os2 << __ym.year();
2561 if constexpr (is_same_v<_CharT, char>)
2565 __os2 << __ym.month();
2566 __os << __os2.view();
2570 template<
typename _CharT,
typename _Traits,
2571 typename _Alloc = allocator<_CharT>>
2572 inline basic_istream<_CharT, _Traits>&
2573 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2575 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2578 using __format::_ChronoParts;
2579 auto __need = _ChronoParts::_Year | _ChronoParts::_Month;
2580 __detail::_Parser<> __p(__need);
2581 if (__p(__is, __fmt, __abbrev, __offset))
2582 __ym = year_month(__p._M_ymd.year(), __p._M_ymd.month());
2586 template<
typename _CharT,
typename _Traits>
2587 inline basic_ostream<_CharT, _Traits>&
2588 operator<<(basic_ostream<_CharT, _Traits>& __os,
2589 const year_month_day& __ymd)
2591 using _Ctx = __format::__format_context<_CharT>;
2592 using _Str = basic_string_view<_CharT>;
2593 _Str __s = _GLIBCXX_WIDEN(
"{:%F} is not a valid date");
2594 __os <<
std::vformat(__ymd.ok() ? __s.substr(0, 5) : __s,
2595 make_format_args<_Ctx>(__ymd));
2599 template<
typename _CharT,
typename _Traits,
2600 typename _Alloc = allocator<_CharT>>
2601 inline basic_istream<_CharT, _Traits>&
2603 year_month_day&
__ymd,
2607 using __format::_ChronoParts;
2608 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2609 | _ChronoParts::_Day;
2610 __detail::_Parser<> __p(
__need);
2616 template<
typename _CharT,
typename _Traits>
2619 const year_month_day_last&
__ymdl)
2634 template<
typename _CharT,
typename _Traits>
2635 inline basic_ostream<_CharT, _Traits>&
2636 operator<<(basic_ostream<_CharT, _Traits>& __os,
2637 const year_month_weekday& __ymwd)
2641 basic_stringstream<_CharT> __os2;
2642 __os2.imbue(__os.getloc());
2644 if constexpr (is_same_v<_CharT, char>)
2648 __os2 << __ymwd.year() << __slash << __ymwd.month() << __slash
2649 << __ymwd.weekday_indexed();
2650 __os << __os2.view();
2654 template<
typename _CharT,
typename _Traits>
2655 inline basic_ostream<_CharT, _Traits>&
2656 operator<<(basic_ostream<_CharT, _Traits>& __os,
2657 const year_month_weekday_last& __ymwdl)
2661 basic_stringstream<_CharT> __os2;
2662 __os2.imbue(__os.getloc());
2664 if constexpr (is_same_v<_CharT, char>)
2668 __os2 << __ymwdl.year() << __slash << __ymwdl.month() << __slash
2669 << __ymwdl.weekday_last();
2670 __os << __os2.view();
2674 template<
typename _CharT,
typename _Traits,
typename _Duration>
2675 inline basic_ostream<_CharT, _Traits>&
2676 operator<<(basic_ostream<_CharT, _Traits>& __os,
2677 const hh_mm_ss<_Duration>& __hms)
2679 return __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%T}"), __hms);
2682#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2684 template<
typename _CharT,
typename _Traits>
2685 basic_ostream<_CharT, _Traits>&
2686 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_info& __i)
2688 __os <<
'[' << __i.begin <<
',' << __i.end
2689 <<
',' << hh_mm_ss(__i.offset) <<
',' << __i.save
2690 <<
',' << __i.abbrev <<
']';
2695 template<
typename _CharT,
typename _Traits>
2696 basic_ostream<_CharT, _Traits>&
2697 operator<<(basic_ostream<_CharT, _Traits>& __os,
const local_info& __li)
2700 if (__li.result == local_info::unique)
2704 if (__li.result == local_info::nonexistent)
2705 __os <<
"nonexistent";
2707 __os <<
"ambiguous";
2708 __os <<
" local time between " << __li.first;
2709 __os <<
" and " << __li.second;
2715 template<
typename _CharT,
typename _Traits,
typename _Duration,
2716 typename _TimeZonePtr>
2717 inline basic_ostream<_CharT, _Traits>&
2718 operator<<(basic_ostream<_CharT, _Traits>& __os,
2719 const zoned_time<_Duration, _TimeZonePtr>& __t)
2721 __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T %Z}"), __t);
2726 template<
typename _CharT,
typename _Traits,
typename _Duration>
2727 requires (!treat_as_floating_point_v<typename _Duration::rep>)
2728 && ratio_less_v<typename _Duration::period, days::period>
2729 inline basic_ostream<_CharT, _Traits>&
2730 operator<<(basic_ostream<_CharT, _Traits>& __os,
2731 const sys_time<_Duration>& __tp)
2733 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __tp);
2737 template<
typename _CharT,
typename _Traits>
2738 inline basic_ostream<_CharT, _Traits>&
2739 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_days& __dp)
2741 __os << year_month_day{__dp};
2745 template<
typename _CharT,
typename _Traits,
typename _Duration,
2746 typename _Alloc = allocator<_CharT>>
2747 basic_istream<_CharT, _Traits>&
2748 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2749 sys_time<_Duration>& __tp,
2750 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2756 using __format::_ChronoParts;
2757 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2758 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2759 __detail::_Parser_t<_Duration> __p(__need);
2760 if (__p(__is, __fmt, __abbrev, __offset))
2762 if (__p._M_is_leap_second)
2766 auto __st = __p._M_sys_days + __p._M_time - *__offset;
2767 __tp = chrono::time_point_cast<_Duration>(__st);
2773 template<
typename _CharT,
typename _Traits,
typename _Duration>
2774 inline basic_ostream<_CharT, _Traits>&
2775 operator<<(basic_ostream<_CharT, _Traits>& __os,
2776 const utc_time<_Duration>& __t)
2778 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
2782 template<
typename _CharT,
typename _Traits,
typename _Duration,
2783 typename _Alloc = allocator<_CharT>>
2784 inline basic_istream<_CharT, _Traits>&
2785 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2786 utc_time<_Duration>& __tp,
2787 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2793 using __format::_ChronoParts;
2794 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2795 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2796 __detail::_Parser_t<_Duration> __p(__need);
2797 if (__p(__is, __fmt, __abbrev, __offset))
2801 auto __ut = utc_clock::from_sys(__p._M_sys_days) + __p._M_time
2803 __tp = chrono::time_point_cast<_Duration>(__ut);
2808 template<
typename _CharT,
typename _Traits,
typename _Duration>
2809 inline basic_ostream<_CharT, _Traits>&
2810 operator<<(basic_ostream<_CharT, _Traits>& __os,
2811 const tai_time<_Duration>& __t)
2813 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
2817 template<
typename _CharT,
typename _Traits,
typename _Duration,
2818 typename _Alloc = allocator<_CharT>>
2819 inline basic_istream<_CharT, _Traits>&
2820 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2821 tai_time<_Duration>& __tp,
2822 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2828 using __format::_ChronoParts;
2829 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2830 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2831 __detail::_Parser_t<_Duration> __p(__need);
2832 if (__p(__is, __fmt, __abbrev, __offset))
2834 if (__p._M_is_leap_second)
2838 auto __st = __p._M_sys_days + __p._M_time - *__offset;
2839 auto __tt = tai_clock::from_utc(utc_clock::from_sys(__st));
2840 __tp = chrono::time_point_cast<_Duration>(__tt);
2846 template<
typename _CharT,
typename _Traits,
typename _Duration>
2847 inline basic_ostream<_CharT, _Traits>&
2848 operator<<(basic_ostream<_CharT, _Traits>& __os,
2849 const gps_time<_Duration>& __t)
2851 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
2855 template<
typename _CharT,
typename _Traits,
typename _Duration,
2856 typename _Alloc = allocator<_CharT>>
2857 inline basic_istream<_CharT, _Traits>&
2858 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2859 gps_time<_Duration>& __tp,
2860 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2866 using __format::_ChronoParts;
2867 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2868 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2869 __detail::_Parser_t<_Duration> __p(__need);
2870 if (__p(__is, __fmt, __abbrev, __offset))
2872 if (__p._M_is_leap_second)
2876 auto __st = __p._M_sys_days + __p._M_time - *__offset;
2877 auto __tt = gps_clock::from_utc(utc_clock::from_sys(__st));
2878 __tp = chrono::time_point_cast<_Duration>(__tt);
2884 template<
typename _CharT,
typename _Traits,
typename _Duration>
2885 inline basic_ostream<_CharT, _Traits>&
2886 operator<<(basic_ostream<_CharT, _Traits>& __os,
2887 const file_time<_Duration>& __t)
2889 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
2893 template<
typename _CharT,
typename _Traits,
typename _Duration,
2894 typename _Alloc = allocator<_CharT>>
2895 inline basic_istream<_CharT, _Traits>&
2896 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2897 file_time<_Duration>& __tp,
2898 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2901 sys_time<_Duration> __st;
2902 if (chrono::from_stream(__is, __fmt, __st, __abbrev, __offset))
2903 __tp = chrono::time_point_cast<_Duration>(file_clock::from_sys(__st));
2907 template<
typename _CharT,
typename _Traits,
typename _Duration>
2908 inline basic_ostream<_CharT, _Traits>&
2909 operator<<(basic_ostream<_CharT, _Traits>& __os,
2910 const local_time<_Duration>& __lt)
2912 __os << sys_time<_Duration>{__lt.time_since_epoch()};
2916 template<
typename _CharT,
typename _Traits,
typename _Duration,
2917 typename _Alloc = allocator<_CharT>>
2918 basic_istream<_CharT, _Traits>&
2919 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2920 local_time<_Duration>& __tp,
2921 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2924 using __format::_ChronoParts;
2925 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2926 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2927 __detail::_Parser_t<_Duration> __p(__need);
2928 if (__p(__is, __fmt, __abbrev, __offset))
2930 days __d = __p._M_sys_days.time_since_epoch();
2931 auto __t = local_days(__d) + __p._M_time;
2932 __tp = chrono::time_point_cast<_Duration>(__t);
2941 template<
typename _Parsable,
typename _CharT,
2943 typename... _OptArgs>
2944 concept __parsable =
requires (basic_istream<_CharT, _Traits>& __is,
2945 const _CharT* __fmt, _Parsable& __tp,
2946 _OptArgs*... __args)
2947 { from_stream(__is, __fmt, __tp, __args...); };
2949 template<
typename _Parsable,
typename _CharT,
2950 typename _Traits = char_traits<_CharT>,
2951 typename _Alloc = allocator<_CharT>>
2955 using __string_type = basic_string<_CharT, _Traits, _Alloc>;
2958 _Parse(
const _CharT* __fmt, _Parsable& __tp,
2959 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2962 _M_abbrev(__abbrev), _M_offset(__offset)
2965 _Parse(_Parse&&) =
delete;
2966 _Parse& operator=(_Parse&&) =
delete;
2969 using __stream_type = basic_istream<_CharT, _Traits>;
2971 const _CharT*
const _M_fmt;
2972 _Parsable*
const _M_tp;
2973 __string_type*
const _M_abbrev;
2976 friend __stream_type&
2977 operator>>(__stream_type& __is, _Parse&& __p)
2980 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev,
2982 else if (__p._M_abbrev)
2983 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev);
2985 from_stream(__is, __p._M_fmt, *__p._M_tp);
2989 friend void operator>>(__stream_type&, _Parse&) =
delete;
2990 friend void operator>>(__stream_type&,
const _Parse&) =
delete;
2994 template<
typename _CharT, __detail::__parsable<_CharT> _Parsable>
2995 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
2997 parse(
const _CharT* __fmt, _Parsable& __tp)
2998 {
return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp); }
3000 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3001 __detail::__parsable<_CharT, _Traits> _Parsable>
3004 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp)
3006 return __detail::_Parse<_Parsable, _CharT, _Traits>(__fmt.c_str(), __tp);
3009 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3010 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
3011 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
3012 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
3014 parse(
const _CharT* __fmt, _Parsable& __tp,
3015 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
3018 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
3022 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3023 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
3024 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
3027 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
3028 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
3031 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
3035 template<
typename _CharT,
typename _Traits =
char_traits<_CharT>,
3036 typename _StrT = basic_
string<_CharT, _Traits>,
3037 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
3038 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
3040 parse(
const _CharT* __fmt, _Parsable& __tp,
minutes& __offset)
3042 return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp,
nullptr,
3046 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3047 typename _StrT = basic_string<_CharT, _Traits>,
3048 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
3051 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
3054 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
3059 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3060 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
3061 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
3062 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
3064 parse(
const _CharT* __fmt, _Parsable& __tp,
3065 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
3068 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
3073 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3074 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
3075 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
3078 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
3079 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
3082 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
3088 template<
typename _Duration>
3089 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3090 basic_istream<_CharT, _Traits>&
3091 __detail::_Parser<_Duration>::
3092 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3093 basic_string<_CharT, _Traits, _Alloc>* __abbrev,
3096 using sentry =
typename basic_istream<_CharT, _Traits>::sentry;
3098 if (sentry __cerb(__is,
true); __cerb)
3100 locale __loc = __is.getloc();
3105 struct _Stream_state
3108 _Stream_state(basic_istream<_CharT, _Traits>& __i)
3110 _M_flags(__i.flags(ios_base::
skipws | ios_base::
dec)),
3116 _M_is.flags(_M_flags);
3120 _Stream_state(_Stream_state&&) =
delete;
3122 basic_istream<_CharT, _Traits>& _M_is;
3123 ios_base::fmtflags _M_flags;
3133 auto __read_unsigned = [&] (
int __n) {
3134 return _S_read_unsigned(__is, __err, __n);
3139 auto __read_signed = [&] (
int __n) {
3140 return _S_read_signed(__is, __err, __n);
3144 auto __read_chr = [&__is, &__err] (_CharT __c) {
3145 return _S_read_chr(__is, __err, __c);
3148 using __format::_ChronoParts;
3149 _ChronoParts __parts{};
3151 const year __bad_y = --year::min();
3152 const month __bad_mon(255);
3153 const day __bad_day(255);
3154 const weekday __bad_wday(255);
3155 const hours __bad_h(-1);
3156 const minutes __bad_min(-9999);
3159 year __y = __bad_y, __yy = __bad_y;
3160 year __iso_y = __bad_y, __iso_yy = __bad_y;
3161 month __m = __bad_mon;
3162 day __d = __bad_day;
3163 weekday __wday = __bad_wday;
3164 hours __h = __bad_h, __h12 = __bad_h;
3166 _Duration __s = __bad_sec;
3168 int __iso_wk = -1, __sunday_wk = -1, __monday_wk = -1;
3170 int __dayofyear = -1;
3172 minutes __tz_offset = __bad_min;
3173 basic_string<_CharT, _Traits> __tz_abbr;
3175 if ((_M_need & _ChronoParts::_TimeOfDay)
3176 && (_M_need & _ChronoParts::_Year))
3182 __parts = _ChronoParts::_TimeOfDay;
3189 bool __is_flag =
false;
3191 constexpr bool __is_floating
3192 = treat_as_floating_point_v<typename _Duration::rep>;
3211 _CharT __c = *__fmt++;
3218 else if (!__read_chr(__c)) [[unlikely]]
3229 if (__mod || __num) [[unlikely]]
3234 __tmget.get(__is, {}, __is, __err, &__tm,
3236 if (!__is_failed(__err))
3237 __wday = weekday(__tm.tm_wday);
3239 __parts |= _ChronoParts::_Weekday;
3245 if (__mod || __num) [[unlikely]]
3253 __tmget.get(__is, {}, __is, __err, &__tm,
3255 if (!__is_failed(__err))
3256 __m = month(__tm.tm_mon + 1);
3258 __parts |= _ChronoParts::_Month;
3262 if (__mod ==
'O' || __num) [[unlikely]]
3267 __tmget.get(__is, {}, __is, __err, &__tm,
3268 __fmt - 2 - (__mod ==
'E'), __fmt);
3269 if (!__is_failed(__err))
3271 __y = year(__tm.tm_year + 1900);
3272 __m = month(__tm.tm_mon + 1);
3273 __d = day(__tm.tm_mday);
3274 __h =
hours(__tm.tm_hour);
3279 __parts |= _ChronoParts::_DateTime;
3283 if (!__mod) [[likely]]
3285 auto __v = __read_signed(__num ? __num : 2);
3286 if (!__is_failed(__err))
3288 int __cmin = (int)year::min() / 100;
3289 int __cmax = (int)year::max() / 100;
3290 if (__cmin <= __v && __v <= __cmax)
3291 __century = __v * 100;
3296 else if (__mod ==
'E')
3299 __tmget.get(__is, {}, __is, __err, &__tm,
3301 if (!__is_failed(__err))
3302 __century = __tm.tm_year;
3311 if (!__mod) [[likely]]
3313 auto __v = __read_unsigned(__num ? __num : 2);
3314 if (!__is_failed(__err))
3317 else if (__mod ==
'O')
3320 __tmget.get(__is, {}, __is, __err, &__tm,
3322 if (!__is_failed(__err))
3323 __d = day(__tm.tm_mday);
3327 __parts |= _ChronoParts::_Day;
3331 if (__mod || __num) [[unlikely]]
3335 auto __month = __read_unsigned(2);
3337 auto __day = __read_unsigned(2);
3339 auto __year = __read_unsigned(2);
3340 if (__is_failed(__err))
3342 __y = year(__year + 1900 + 100 *
int(__year < 69));
3343 __m = month(__month);
3345 if (!year_month_day(__y, __m, __d).ok())
3347 __y = __yy = __iso_y = __iso_yy = __bad_y;
3353 __parts |= _ChronoParts::_Date;
3357 if (__mod) [[unlikely]]
3361 auto __year = __read_signed(__num ? __num : 4);
3363 auto __month = __read_unsigned(2);
3365 auto __day = __read_unsigned(2);
3366 if (__is_failed(__err))
3369 __m = month(__month);
3371 if (!year_month_day(__y, __m, __d).ok())
3373 __y = __yy = __iso_y = __iso_yy = __bad_y;
3379 __parts |= _ChronoParts::_Date;
3383 if (__mod) [[unlikely]]
3387 auto __val = __read_unsigned(__num ? __num : 2);
3388 if (__val >= 0 && __val <= 99)
3390 __iso_yy = year(__val);
3391 if (__century == -1)
3395 __iso_yy = __iso_y = __y = __yy = __bad_y;
3397 __parts |= _ChronoParts::_Year;
3401 if (__mod) [[unlikely]]
3404 __iso_y = year(__read_unsigned(__num ? __num : 4));
3405 __parts |= _ChronoParts::_Year;
3410 if (__mod ==
'E') [[unlikely]]
3412 else if (__mod ==
'O')
3417 __tmget.get(__is, {}, __is, __err, &__tm,
3419 if (!__is_failed(__err))
3423 __h12 =
hours(__tm.tm_hour);
3427 __h =
hours(__tm.tm_hour);
3436 auto __val = __read_unsigned(__num ? __num : 2);
3437 if (__c ==
'I' && __val >= 1 && __val <= 12)
3439 __h12 =
hours(__val);
3442 else if (__c ==
'H' && __val >= 0 && __val <= 23)
3449 if (_M_need & _ChronoParts::_TimeOfDay)
3454 __parts |= _ChronoParts::_TimeOfDay;
3458 if (__mod) [[unlikely]]
3460 else if (_M_need == _ChronoParts::_TimeOfDay)
3462 auto __val = __read_signed(__num ? __num : 3);
3463 if (!__is_failed(__err))
3466 __parts |= _ChronoParts::_TimeOfDay;
3471 __dayofyear = __read_unsigned(__num ? __num : 3);
3478 if (__mod ==
'E') [[unlikely]]
3480 else if (__mod ==
'O')
3483 __tmget.get(__is, {}, __is, __err, &__tm,
3485 if (!__is_failed(__err))
3486 __m = month(__tm.tm_mon + 1);
3490 auto __val = __read_unsigned(__num ? __num : 2);
3491 if (__val >= 1 && __val <= 12)
3496 __parts |= _ChronoParts::_Month;
3500 if (__mod ==
'E') [[unlikely]]
3502 else if (__mod ==
'O')
3505 __tmget.get(__is, {}, __is, __err, &__tm,
3507 if (!__is_failed(__err))
3512 auto __val = __read_unsigned(__num ? __num : 2);
3513 if (0 <= __val && __val < 60)
3517 if (_M_need & _ChronoParts::_TimeOfDay)
3522 __parts |= _ChronoParts::_TimeOfDay;
3532 const _CharT* __ampms[2];
3533 __tmpunct._M_am_pm(__ampms);
3534 int __n = 0, __which = 3;
3535 while (__which != 0)
3537 auto __i = __is.peek();
3538 if (_Traits::eq_int_type(__i, _Traits::eof()))
3548 else if (__ampms[0][__n + 1] == _CharT())
3559 else if (__ampms[1][__n + 1] == _CharT())
3570 if (__which == 0 || __which == 3)
3583 __tmget.get(__is, {}, __is, __err, &__tm,
3585 if (!__is_failed(__err))
3587 __h =
hours(__tm.tm_hour);
3592 __parts |= _ChronoParts::_TimeOfDay;
3597 if (__mod || __num) [[unlikely]]
3604 auto __val = __read_unsigned(2);
3605 if (__val == -1 || __val > 23) [[unlikely]]
3607 if (_M_need & _ChronoParts::_TimeOfDay)
3611 if (!__read_chr(
':')) [[unlikely]]
3615 __val = __read_unsigned(2);
3616 if (__val == -1 || __val > 60) [[unlikely]]
3618 if (_M_need & _ChronoParts::_TimeOfDay)
3626 __parts |= _ChronoParts::_TimeOfDay;
3629 else if (!__read_chr(
':')) [[unlikely]]
3635 if (__mod ==
'E') [[unlikely]]
3637 else if (__mod ==
'O')
3640 __tmget.get(__is, {}, __is, __err, &__tm,
3642 if (!__is_failed(__err))
3645 else if constexpr (_Duration::period::den == 1
3648 auto __val = __read_unsigned(__num ? __num : 2);
3649 if (0 <= __val && __val <= 59) [[likely]]
3653 if (_M_need & _ChronoParts::_TimeOfDay)
3660 basic_stringstream<_CharT> __buf;
3661 auto __digit = _S_try_read_digit(__is, __err);
3664 __buf.put(_CharT(
'0') + __digit);
3665 __digit = _S_try_read_digit(__is, __err);
3667 __buf.put(_CharT(
'0') + __digit);
3670 auto __i = __is.peek();
3671 if (_Traits::eq_int_type(__i, _Traits::eof()))
3678 auto& __np = use_facet<numpunct<_CharT>>(__loc);
3679 __dp = __np.decimal_point();
3681 _CharT __c = _Traits::to_char_type(__i);
3687 = hh_mm_ss<_Duration>::fractional_width;
3690 __digit = _S_try_read_digit(__is, __err);
3692 __buf.put(_CharT(
'0') + __digit);
3700 if (!__is_failed(__err)) [[likely]]
3702 long double __val{};
3703#if __cpp_lib_to_chars
3705 auto __first = __str.data();
3706 auto __last = __first + __str.size();
3710 if ((
bool)ec || ptr != __last) [[unlikely]]
3717 duration<long double> __fs(__val);
3718 if constexpr (__is_floating)
3721 __s = chrono::round<_Duration>(__fs);
3725 __parts |= _ChronoParts::_TimeOfDay;
3730 if (__mod ==
'E') [[unlikely]]
3732 else if (__mod ==
'O')
3737 __tmget.get(__is, {}, __is, __err, &__tm,
3739 if (!__is_failed(__err))
3740 __wday = weekday(__tm.tm_wday);
3747 const int __lo = __c ==
'u' ? 1 : 0;
3748 const int __hi = __lo + 6;
3749 auto __val = __read_unsigned(__num ? __num : 1);
3750 if (__lo <= __val && __val <= __hi)
3751 __wday = weekday(__val);
3754 __wday = __bad_wday;
3758 __parts |= _ChronoParts::_Weekday;
3764 if (__mod ==
'E') [[unlikely]]
3766 else if (__mod ==
'O')
3768 if (__c ==
'V') [[unlikely]]
3778 const int __lo = __c ==
'V' ? 1 : 0;
3779 const int __hi = 53;
3780 auto __val = __read_unsigned(__num ? __num : 2);
3781 if (__lo <= __val && __val <= __hi)
3786 __sunday_wk = __val;
3792 __monday_wk = __val;
3797 __iso_wk = __sunday_wk = __monday_wk = -1;
3803 if (__mod ==
'O' || __num) [[unlikely]]
3808 __tmget.get(__is, {}, __is, __err, &__tm,
3809 __fmt - 2 - (__mod ==
'E'), __fmt);
3810 if (!__is_failed(__err))
3812 __y = year(__tm.tm_year + 1900);
3813 __m = month(__tm.tm_mon + 1);
3814 __d = day(__tm.tm_mday);
3817 __parts |= _ChronoParts::_Date;
3821 if (__mod ==
'O' || __num) [[unlikely]]
3826 __tmget.get(__is, {}, __is, __err, &__tm,
3827 __fmt - 2 - (__mod ==
'E'), __fmt);
3828 if (!__is_failed(__err))
3830 __h =
hours(__tm.tm_hour);
3835 __parts |= _ChronoParts::_TimeOfDay;
3839 if (__mod) [[unlikely]]
3842 __tmget.get(__is, {}, __is, __err, &__tm,
3844 if (!__is_failed(__err))
3846 int __cent = __tm.tm_year < 2000 ? 1900 : 2000;
3847 __yy = year(__tm.tm_year - __cent);
3848 if (__century == -1)
3854 auto __val = __read_unsigned(__num ? __num : 2);
3855 if (__val >= 0 && __val <= 99)
3858 if (__century == -1)
3859 __century = __val < 69 ? 2000 : 1900;
3862 __y = __yy = __iso_yy = __iso_y = __bad_y;
3864 __parts |= _ChronoParts::_Year;
3868 if (__mod ==
'O') [[unlikely]]
3870 else if (__mod ==
'E')
3873 __tmget.get(__is, {}, __is, __err, &__tm,
3875 if (!__is_failed(__err))
3876 __y = year(__tm.tm_year);
3880 auto __val = __read_unsigned(__num ? __num : 4);
3881 if (!__is_failed(__err))
3884 __parts |= _ChronoParts::_Year;
3888 if (__num) [[unlikely]]
3895 auto __i = __is.peek();
3896 if (_Traits::eq_int_type(__i, _Traits::eof()))
3901 _CharT __ic = _Traits::to_char_type(__i);
3902 const bool __neg = __ic == _CharT(
'-');
3903 if (__ic == _CharT(
'-') || __ic == _CharT(
'+'))
3910 __hh = __read_unsigned(2);
3915 __hh = 10 * _S_try_read_digit(__is, __err);
3916 __hh += _S_try_read_digit(__is, __err);
3919 if (__is_failed(__err))
3923 if (_Traits::eq_int_type(__i, _Traits::eof()))
3926 __tz_offset =
minutes(__hh * (__neg ? -60 : 60));
3929 __ic = _Traits::to_char_type(__i);
3931 bool __read_mm =
false;
3934 if (__ic == _GLIBCXX_WIDEN(
":")[0])
3941 else if (_CharT(
'0') <= __ic && __ic <= _CharT(
'9'))
3947 int_least32_t __mm = 0;
3950 __mm = 10 * _S_try_read_digit(__is, __err);
3951 __mm += _S_try_read_digit(__is, __err);
3954 if (!__is_failed(__err))
3956 auto __z = __hh * 60 + __mm;
3957 __tz_offset =
minutes(__neg ? -__z : __z);
3963 if (__mod || __num) [[unlikely]]
3967 basic_string_view<_CharT> __x = _GLIBCXX_WIDEN(
"_/-+");
3971 auto __i = __is.peek();
3972 if (!_Traits::eq_int_type(__i, _Traits::eof()))
3974 _CharT __a = _Traits::to_char_type(__i);
3976 || __x.find(__a) != __x.npos)
3978 __tz_abbr.push_back(__a);
3987 if (__tz_abbr.empty())
3993 if (__mod || __num) [[unlikely]]
3997 _CharT __i = __is.peek();
3998 if (_Traits::eq_int_type(__i, _Traits::eof()))
4000 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
4008 if (__mod || __num) [[unlikely]]
4012 _CharT __i = __is.peek();
4013 if (_Traits::eq_int_type(__i, _Traits::eof()))
4015 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
4021 if (__mod || __num) [[unlikely]]
4029 if (__mod || __num) [[unlikely]]
4038 if (_CharT(
'1') <= __c && __c <= _CharT(
'9'))
4040 if (!__mod) [[likely]]
4043 auto __end = __fmt + _Traits::length(__fmt);
4045 = __format::__parse_integer(__fmt - 1, __end);
4046 if (__ptr) [[likely]]
4057 if (__is_failed(__err)) [[unlikely]]
4067 if (__yy != __bad_y && __y == __bad_y)
4068 __y =
years(__century) + __yy;
4069 if (__iso_yy != __bad_y && __iso_y == __bad_y)
4070 __iso_y =
years(__century) + __iso_yy;
4073 bool __can_use_doy =
false;
4074 bool __can_use_iso_wk =
false;
4075 bool __can_use_sun_wk =
false;
4076 bool __can_use_mon_wk =
false;
4079 if (__y != __bad_y && __dayofyear >= 0)
4081 __can_use_doy =
true;
4082 __parts |= _ChronoParts::_Date;
4084 else if (__y != __bad_y && __wday != __bad_wday && __sunday_wk >= 0)
4086 __can_use_sun_wk =
true;
4087 __parts |= _ChronoParts::_Date;
4089 else if (__y != __bad_y && __wday != __bad_wday && __monday_wk >= 0)
4091 __can_use_mon_wk =
true;
4092 __parts |= _ChronoParts::_Date;
4094 else if (__iso_y != __bad_y && __wday != __bad_wday && __iso_wk > 0)
4097 __can_use_iso_wk =
true;
4098 __parts |= _ChronoParts::_Date;
4101 if (__is_failed(__err)) [[unlikely]]
4103 else if (__is_flag) [[unlikely]]
4105 else if ((_M_need & __parts) == _M_need) [[likely]]
4127 const bool __need_wday = _M_need & _ChronoParts::_Weekday;
4131 const bool __need_time = _M_need & _ChronoParts::_TimeOfDay;
4133 if (__need_wday && __wday != __bad_wday)
4135 else if (_M_need & _ChronoParts::_Date)
4139 const bool __need_ymd = !__need_wday && !__need_time;
4141 if ((_M_need & _ChronoParts::_Year && __y == __bad_y)
4142 || (_M_need & _ChronoParts::_Month && __m == __bad_mon)
4143 || (_M_need & _ChronoParts::_Day && __d == __bad_day))
4150 if ((0 < __dayofyear && __dayofyear <= 365)
4151 || (__dayofyear == 366 && __y.is_leap()))
4154 _M_sys_days = sys_days(__y/January/1)
4155 +
days(__dayofyear - 1);
4157 _M_ymd = year_month_day(_M_sys_days);
4162 else if (__can_use_iso_wk)
4170 const sys_days __jan4(__iso_y/January/4);
4171 weekday __wd1(__jan4 -
days(3));
4172 if (__wd1 != Thursday)
4173 if (__wd1 != Wednesday || !__iso_y.is_leap())
4177 if (!__is_failed(__err)) [[likely]]
4180 sys_days __w(Thursday[1]/January/__iso_y);
4182 __w -= Thursday - Monday;
4184 __w += __wday - Monday;
4188 _M_ymd = year_month_day(_M_sys_days);
4191 else if (__can_use_sun_wk)
4194 sys_days __wk1(__y/January/Sunday[1]);
4195 _M_sys_days = __wk1 +
weeks(__sunday_wk - 1)
4196 +
days(__wday.c_encoding());
4197 _M_ymd = year_month_day(_M_sys_days);
4198 if (_M_ymd.year() != __y) [[unlikely]]
4201 else if (__can_use_mon_wk)
4204 sys_days __wk1(__y/January/Monday[1]);
4205 _M_sys_days = __wk1 +
weeks(__monday_wk - 1)
4206 +
days(__wday.c_encoding() - 1);
4207 _M_ymd = year_month_day(_M_sys_days);
4208 if (_M_ymd.year() != __y) [[unlikely]]
4220 if (_M_need & _ChronoParts::_Year)
4222 if (!__y.ok()) [[unlikely]]
4225 else if (__y == __bad_y)
4228 if (_M_need & _ChronoParts::_Month)
4230 if (!__m.ok()) [[unlikely]]
4233 else if (__m == __bad_mon)
4236 if (_M_need & _ChronoParts::_Day)
4238 if (__d < day(1) || __d > (__y/__m/last).day())
4241 else if (__d == __bad_day)
4244 if (year_month_day __ymd(__y, __m, __d); __ymd.ok())
4247 if (__need_wday || __need_time)
4248 _M_sys_days = sys_days(_M_ymd);
4255 _M_wd = weekday(_M_sys_days);
4261 if (__h == __bad_h && __h12 != __bad_h)
4265 else if (__ampm == 2)
4266 __h = __h12 ==
hours(12) ? __h12 : __h12 +
hours(12);
4271 auto __t = _M_time.zero();
4280 if (__min != __bad_min)
4286 if (__s != __bad_sec)
4290 _M_is_leap_second = __s >=
seconds(60);
4299 if (!__is_failed(__err)) [[likely]]
4301 if (__offset && __tz_offset != __bad_min)
4302 *__offset = __tz_offset;
4303 if (__abbrev && !__tz_abbr.empty())
4311 __is.setstate(__err);
4315#undef _GLIBCXX_WIDEN
4320_GLIBCXX_END_NAMESPACE_VERSION
__detail::__local_time_fmt< _Duration > local_time_format(local_time< _Duration > __time, const string *__abbrev=nullptr, const seconds *__offset_sec=nullptr)
duration< int64_t > seconds
seconds
duration< int64_t, ratio< 604800 > > weeks
weeks
duration< int64_t, ratio< 3600 > > hours
hours
duration< int64_t, ratio< 86400 > > days
days
basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const duration< _Rep, _Period > &__d)
duration< int64_t, ratio< 60 > > minutes
minutes
duration< int64_t, ratio< 31556952 > > years
years
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
ISO C++ entities toplevel namespace is std.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
chars_format
floating-point format for primitive numerical conversion
bool isspace(_CharT __c, const locale &__loc)
Convenience interface to ctype.is(ctype_base::space, __c).
_CharT toupper(_CharT __c, const locale &__loc)
Convenience interface to ctype.toupper(__c).
bool isalnum(_CharT __c, const locale &__loc)
Convenience interface to ctype.is(ctype_base::alnum, __c).
ios_base & dec(ios_base &__base)
Calls base.setf(ios_base::dec, ios_base::basefield).
ios_base & skipws(ios_base &__base)
Calls base.setf(ios_base::skipws).
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
constexpr bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
basic_istream< _CharT, _Traits > & ws(basic_istream< _CharT, _Traits > &__is)
Quick and easy way to eat whitespace.
constexpr from_chars_result from_chars(const char *__first, const char *__last, _Tp &__value, int __base=10)
std::from_chars for integral types.
ISO C++ 2011 namespace for date and time utilities.
static constexpr bool is_signed
_Ios_Iostate iostate
This is a bitmask type.
static const iostate eofbit
Indicates that an input operation reached the end of an input sequence.
static const iostate goodbit
Indicates all is well.
static const iostate failbit
Indicates that an input operation failed to read the expected characters, or that an output operation...
Container class for localization functionality.
static const locale & classic()
Return reference to the C locale.