30#ifndef _GLIBCXX_CHRONO_IO_H
31#define _GLIBCXX_CHRONO_IO_H 1
33#pragma GCC system_header
35#if __cplusplus >= 202002L
44namespace std _GLIBCXX_VISIBILITY(default)
46_GLIBCXX_BEGIN_NAMESPACE_VERSION
61 template<
typename _CharT>
63 _Widen(
const char* __narrow,
const wchar_t* __wide)
65 if constexpr (is_same_v<_CharT, wchar_t>)
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>
75 __units_suffix()
noexcept
80#define _GLIBCXX_UNITS_SUFFIX(period, suffix) \
81 if constexpr (is_same_v<_Period, period>) \
82 return _GLIBCXX_WIDEN(suffix); \
85 _GLIBCXX_UNITS_SUFFIX(atto,
"as")
86 _GLIBCXX_UNITS_SUFFIX(femto,
"fs")
87 _GLIBCXX_UNITS_SUFFIX(pico,
"ps")
88 _GLIBCXX_UNITS_SUFFIX(nano,
"ns")
89 _GLIBCXX_UNITS_SUFFIX(milli,
"ms")
90#if _GLIBCXX_USE_ALT_MICROSECONDS_SUFFIX
93 _GLIBCXX_UNITS_SUFFIX(micro,
"\u00b5s")
95 _GLIBCXX_UNITS_SUFFIX(micro,
"us")
97 _GLIBCXX_UNITS_SUFFIX(centi,
"cs")
98 _GLIBCXX_UNITS_SUFFIX(deci,
"ds")
100 _GLIBCXX_UNITS_SUFFIX(deca,
"das")
101 _GLIBCXX_UNITS_SUFFIX(hecto,
"hs")
102 _GLIBCXX_UNITS_SUFFIX(kilo,
"ks")
103 _GLIBCXX_UNITS_SUFFIX(mega,
"Ms")
104 _GLIBCXX_UNITS_SUFFIX(giga,
"Gs")
105 _GLIBCXX_UNITS_SUFFIX(tera,
"Ts")
106 _GLIBCXX_UNITS_SUFFIX(tera,
"Ts")
107 _GLIBCXX_UNITS_SUFFIX(peta,
"Ps")
108 _GLIBCXX_UNITS_SUFFIX(exa,
"Es")
112#undef _GLIBCXX_UNITS_SUFFIX
116 template<
typename _Period,
typename _CharT,
typename _Out>
118 __fmt_units_suffix(_Out __out)
noexcept
120 if (
auto __s = __detail::__units_suffix<_Period, _CharT>(); __s.size())
121 return __format::__write(
std::move(__out), __s);
122 else if constexpr (_Period::den == 1)
123 return std::format_to(
std::move(__out), _GLIBCXX_WIDEN(
"[{}]s"),
124 (uintmax_t)_Period::num);
126 return std::format_to(
std::move(__out), _GLIBCXX_WIDEN(
"[{}/{}]s"),
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;
150 __detail::__fmt_units_suffix<period, _CharT>(_Out(__s));
159 template<
typename _Duration>
160 struct __local_time_fmt
163 const string* _M_abbrev;
167 struct __local_fmt_t;
180 template<
typename _Duration>
181 inline __detail::__local_time_fmt<_Duration>
183 const string* __abbrev =
nullptr,
184 const seconds* __offset_sec =
nullptr)
185 {
return {__time, __abbrev, __offset_sec}; }
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>)
586 __out = std::format_to(__print_sign(), _S_empty_spec,
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);
807 return std::vformat_to(
std::move(__out), __loc, __fmt,
808 std::make_format_args<_FormatContext>(__t));
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();
987 return std::format_to(
std::move(__out), _S_empty_spec, __d);
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);
1002 return std::format_to(
std::move(__out), _GLIBCXX_WIDEN(
"{:03d}"),
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);
1062 return std::format_to(
std::move(__out), _S_empty_spec,
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);
1098 return std::vformat_to(
std::move(__out), __fmt,
1099 std::make_format_args<_FormatContext>(__t));
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;
1155 __out = std::format_to(
std::move(__out), __loc,
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>)
1169 __out = std::format_to(
std::move(__out),
1170 _GLIBCXX_WIDEN(
"{:0{}}"),
1172 __hms.fractional_width);
1175 auto __str = std::format(_S_empty_spec, __ss.count());
1176 __out = std::format_to(_GLIBCXX_WIDEN(
"{:0>{}s}"),
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);
1282 return std::vformat_to(
std::move(__out), __fmt,
1283 std::make_format_args<_FormatContext>(__t));
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);
1305 return std::vformat_to(
std::move(__out), __fmt,
1306 std::make_format_args<_FormatContext>(__t));
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
1610 return _M_f._M_format(chrono::abs(__d), __fc, __d < __d.zero());
1614 __format::__formatter_chrono<_CharT> _M_f;
1617 template<
typename _CharT>
1618 struct formatter<chrono::day, _CharT>
1620 template<
typename _ParseContext>
1621 constexpr typename _ParseContext::iterator
1622 parse(_ParseContext& __pc)
1623 {
return _M_f._M_parse(__pc, __format::_Day); }
1625 template<
typename _FormatContext>
1626 typename _FormatContext::iterator
1627 format(
const chrono::day& __t, _FormatContext& __fc)
const
1628 {
return _M_f._M_format(__t, __fc); }
1631 __format::__formatter_chrono<_CharT> _M_f;
1634 template<
typename _CharT>
1635 struct formatter<chrono::month, _CharT>
1637 template<
typename _ParseContext>
1638 constexpr typename _ParseContext::iterator
1639 parse(_ParseContext& __pc)
1640 {
return _M_f._M_parse(__pc, __format::_Month); }
1642 template<
typename _FormatContext>
1643 typename _FormatContext::iterator
1644 format(
const chrono::month& __t, _FormatContext& __fc)
const
1645 {
return _M_f._M_format(__t, __fc); }
1648 __format::__formatter_chrono<_CharT> _M_f;
1651 template<
typename _CharT>
1652 struct formatter<chrono::year, _CharT>
1654 template<
typename _ParseContext>
1655 constexpr typename _ParseContext::iterator
1656 parse(_ParseContext& __pc)
1657 {
return _M_f._M_parse(__pc, __format::_Year); }
1659 template<
typename _FormatContext>
1660 typename _FormatContext::iterator
1661 format(
const chrono::year& __t, _FormatContext& __fc)
const
1662 {
return _M_f._M_format(__t, __fc); }
1665 __format::__formatter_chrono<_CharT> _M_f;
1668 template<
typename _CharT>
1669 struct formatter<chrono::weekday, _CharT>
1671 template<
typename _ParseContext>
1672 constexpr typename _ParseContext::iterator
1673 parse(_ParseContext& __pc)
1674 {
return _M_f._M_parse(__pc, __format::_Weekday); }
1676 template<
typename _FormatContext>
1677 typename _FormatContext::iterator
1678 format(
const chrono::weekday& __t, _FormatContext& __fc)
const
1679 {
return _M_f._M_format(__t, __fc); }
1682 __format::__formatter_chrono<_CharT> _M_f;
1685 template<
typename _CharT>
1686 struct formatter<chrono::weekday_indexed, _CharT>
1688 template<
typename _ParseContext>
1689 constexpr typename _ParseContext::iterator
1690 parse(_ParseContext& __pc)
1691 {
return _M_f._M_parse(__pc, __format::_Weekday); }
1693 template<
typename _FormatContext>
1694 typename _FormatContext::iterator
1695 format(
const chrono::weekday_indexed& __t, _FormatContext& __fc)
const
1696 {
return _M_f._M_format(__t, __fc); }
1699 __format::__formatter_chrono<_CharT> _M_f;
1702 template<
typename _CharT>
1703 struct formatter<chrono::weekday_last, _CharT>
1705 template<
typename _ParseContext>
1706 constexpr typename _ParseContext::iterator
1707 parse(_ParseContext& __pc)
1708 {
return _M_f._M_parse(__pc, __format::_Weekday); }
1710 template<
typename _FormatContext>
1711 typename _FormatContext::iterator
1712 format(
const chrono::weekday_last& __t, _FormatContext& __fc)
const
1713 {
return _M_f._M_format(__t, __fc); }
1716 __format::__formatter_chrono<_CharT> _M_f;
1719 template<
typename _CharT>
1720 struct formatter<chrono::month_day, _CharT>
1722 template<
typename _ParseContext>
1723 constexpr typename _ParseContext::iterator
1724 parse(_ParseContext& __pc)
1725 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Day); }
1727 template<
typename _FormatContext>
1728 typename _FormatContext::iterator
1729 format(
const chrono::month_day& __t, _FormatContext& __fc)
const
1730 {
return _M_f._M_format(__t, __fc); }
1733 __format::__formatter_chrono<_CharT> _M_f;
1736 template<
typename _CharT>
1737 struct formatter<chrono::month_day_last, _CharT>
1739 template<
typename _ParseContext>
1740 constexpr typename _ParseContext::iterator
1741 parse(_ParseContext& __pc)
1742 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Day); }
1744 template<
typename _FormatContext>
1745 typename _FormatContext::iterator
1746 format(
const chrono::month_day_last& __t, _FormatContext& __fc)
const
1747 {
return _M_f._M_format(__t, __fc); }
1750 __format::__formatter_chrono<_CharT> _M_f;
1753 template<
typename _CharT>
1754 struct formatter<chrono::month_weekday, _CharT>
1756 template<
typename _ParseContext>
1757 constexpr typename _ParseContext::iterator
1758 parse(_ParseContext& __pc)
1759 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Weekday); }
1761 template<
typename _FormatContext>
1762 typename _FormatContext::iterator
1763 format(
const chrono::month_weekday& __t, _FormatContext& __fc)
const
1764 {
return _M_f._M_format(__t, __fc); }
1767 __format::__formatter_chrono<_CharT> _M_f;
1770 template<
typename _CharT>
1771 struct formatter<chrono::month_weekday_last, _CharT>
1773 template<
typename _ParseContext>
1774 constexpr typename _ParseContext::iterator
1775 parse(_ParseContext& __pc)
1776 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Weekday); }
1778 template<
typename _FormatContext>
1779 typename _FormatContext::iterator
1780 format(
const chrono::month_weekday_last& __t,
1781 _FormatContext& __fc)
const
1782 {
return _M_f._M_format(__t, __fc); }
1785 __format::__formatter_chrono<_CharT> _M_f;
1788 template<
typename _CharT>
1789 struct formatter<chrono::year_month, _CharT>
1791 template<
typename _ParseContext>
1792 constexpr typename _ParseContext::iterator
1793 parse(_ParseContext& __pc)
1794 {
return _M_f._M_parse(__pc, __format::_Year|__format::_Month); }
1796 template<
typename _FormatContext>
1797 typename _FormatContext::iterator
1798 format(
const chrono::year_month& __t, _FormatContext& __fc)
const
1799 {
return _M_f._M_format(__t, __fc); }
1802 __format::__formatter_chrono<_CharT> _M_f;
1805 template<
typename _CharT>
1806 struct formatter<chrono::year_month_day, _CharT>
1808 template<
typename _ParseContext>
1809 constexpr typename _ParseContext::iterator
1810 parse(_ParseContext& __pc)
1811 {
return _M_f._M_parse(__pc, __format::_Date); }
1813 template<
typename _FormatContext>
1814 typename _FormatContext::iterator
1815 format(
const chrono::year_month_day& __t, _FormatContext& __fc)
const
1816 {
return _M_f._M_format(__t, __fc); }
1819 __format::__formatter_chrono<_CharT> _M_f;
1822 template<
typename _CharT>
1823 struct formatter<chrono::year_month_day_last, _CharT>
1825 template<
typename _ParseContext>
1826 constexpr typename _ParseContext::iterator
1827 parse(_ParseContext& __pc)
1828 {
return _M_f._M_parse(__pc, __format::_Date); }
1830 template<
typename _FormatContext>
1831 typename _FormatContext::iterator
1832 format(
const chrono::year_month_day_last& __t,
1833 _FormatContext& __fc)
const
1834 {
return _M_f._M_format(__t, __fc); }
1837 __format::__formatter_chrono<_CharT> _M_f;
1840 template<
typename _CharT>
1841 struct formatter<chrono::year_month_weekday, _CharT>
1843 template<
typename _ParseContext>
1844 constexpr typename _ParseContext::iterator
1845 parse(_ParseContext& __pc)
1846 {
return _M_f._M_parse(__pc, __format::_Date); }
1848 template<
typename _FormatContext>
1849 typename _FormatContext::iterator
1850 format(
const chrono::year_month_weekday& __t,
1851 _FormatContext& __fc)
const
1852 {
return _M_f._M_format(__t, __fc); }
1855 __format::__formatter_chrono<_CharT> _M_f;
1858 template<
typename _CharT>
1859 struct formatter<chrono::year_month_weekday_last, _CharT>
1861 template<
typename _ParseContext>
1862 constexpr typename _ParseContext::iterator
1863 parse(_ParseContext& __pc)
1864 {
return _M_f._M_parse(__pc, __format::_Date); }
1866 template<
typename _FormatContext>
1867 typename _FormatContext::iterator
1868 format(
const chrono::year_month_weekday_last& __t,
1869 _FormatContext& __fc)
const
1870 {
return _M_f._M_format(__t, __fc); }
1873 __format::__formatter_chrono<_CharT> _M_f;
1876 template<
typename _Rep,
typename _Period,
typename _CharT>
1877 struct formatter<chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>, _CharT>
1879 template<
typename _ParseContext>
1880 constexpr typename _ParseContext::iterator
1881 parse(_ParseContext& __pc)
1882 {
return _M_f._M_parse(__pc, __format::_TimeOfDay); }
1884 template<
typename _FormatContext>
1885 typename _FormatContext::iterator
1886 format(
const chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>& __t,
1887 _FormatContext& __fc)
const
1888 {
return _M_f._M_format(__t, __fc); }
1891 __format::__formatter_chrono<_CharT> _M_f;
1894#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
1895 template<
typename _CharT>
1896 struct formatter<chrono::sys_info, _CharT>
1898 template<
typename _ParseContext>
1899 constexpr typename _ParseContext::iterator
1900 parse(_ParseContext& __pc)
1901 {
return _M_f._M_parse(__pc, __format::_ChronoParts{}); }
1903 template<
typename _FormatContext>
1904 typename _FormatContext::iterator
1905 format(
const chrono::sys_info& __i, _FormatContext& __fc)
const
1906 {
return _M_f._M_format(__i, __fc); }
1909 __format::__formatter_chrono<_CharT> _M_f;
1912 template<
typename _CharT>
1913 struct formatter<chrono::local_info, _CharT>
1915 template<
typename _ParseContext>
1916 constexpr typename _ParseContext::iterator
1917 parse(_ParseContext& __pc)
1918 {
return _M_f._M_parse(__pc, __format::_ChronoParts{}); }
1920 template<
typename _FormatContext>
1921 typename _FormatContext::iterator
1922 format(
const chrono::local_info& __i, _FormatContext& __fc)
const
1923 {
return _M_f._M_format(__i, __fc); }
1926 __format::__formatter_chrono<_CharT> _M_f;
1930 template<
typename _Duration,
typename _CharT>
1931 struct formatter<chrono::sys_time<_Duration>, _CharT>
1933 template<
typename _ParseContext>
1934 constexpr typename _ParseContext::iterator
1935 parse(_ParseContext& __pc)
1937 auto __next = _M_f._M_parse(__pc, __format::_ZonedDateTime);
1938 if constexpr (!__stream_insertable)
1939 if (_M_f._M_spec._M_chrono_specs.empty())
1940 __format::__invalid_chrono_spec();
1944 template<
typename _FormatContext>
1945 typename _FormatContext::iterator
1946 format(
const chrono::sys_time<_Duration>& __t,
1947 _FormatContext& __fc)
const
1948 {
return _M_f._M_format(__t, __fc); }
1951 static constexpr bool __stream_insertable
1952 =
requires (basic_ostream<_CharT>& __os,
1953 chrono::sys_time<_Duration> __t) { __os << __t; };
1955 __format::__formatter_chrono<_CharT> _M_f;
1958 template<
typename _Duration,
typename _CharT>
1959 struct formatter<chrono::utc_time<_Duration>, _CharT>
1960 : __format::__formatter_chrono<_CharT>
1962 template<
typename _ParseContext>
1963 constexpr typename _ParseContext::iterator
1964 parse(_ParseContext& __pc)
1965 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
1967 template<
typename _FormatContext>
1968 typename _FormatContext::iterator
1969 format(
const chrono::utc_time<_Duration>& __t,
1970 _FormatContext& __fc)
const
1975 using chrono::__detail::__utc_leap_second;
1976 using chrono::seconds;
1977 using chrono::sys_time;
1978 using _CDur = common_type_t<_Duration, seconds>;
1979 const auto __li = chrono::get_leap_second_info(__t);
1980 sys_time<_CDur> __s{__t.time_since_epoch() - __li.elapsed};
1981 if (!__li.is_leap_second) [[likely]]
1982 return _M_f._M_format(__s, __fc);
1984 return _M_f._M_format(__utc_leap_second(__s), __fc);
1988 friend formatter<chrono::__detail::__utc_leap_second<_Duration>, _CharT>;
1990 __format::__formatter_chrono<_CharT> _M_f;
1993 template<
typename _Duration,
typename _CharT>
1994 struct formatter<chrono::tai_time<_Duration>, _CharT>
1995 : __format::__formatter_chrono<_CharT>
1997 template<
typename _ParseContext>
1998 constexpr typename _ParseContext::iterator
1999 parse(_ParseContext& __pc)
2000 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2002 template<
typename _FormatContext>
2003 typename _FormatContext::iterator
2004 format(
const chrono::tai_time<_Duration>& __t,
2005 _FormatContext& __fc)
const
2010 constexpr chrono::days __tai_offset = chrono::days(4383);
2011 using _CDur = common_type_t<_Duration, chrono::days>;
2012 chrono::local_time<_CDur> __lt(__t.time_since_epoch() - __tai_offset);
2013 const string __abbrev(
"TAI", 3);
2014 const chrono::seconds __off = 0s;
2015 const auto __lf = chrono::local_time_format(__lt, &__abbrev, &__off);
2016 return _M_f._M_format(__lf, __fc);
2020 __format::__formatter_chrono<_CharT> _M_f;
2023 template<
typename _Duration,
typename _CharT>
2024 struct formatter<chrono::gps_time<_Duration>, _CharT>
2025 : __format::__formatter_chrono<_CharT>
2027 template<
typename _ParseContext>
2028 constexpr typename _ParseContext::iterator
2029 parse(_ParseContext& __pc)
2030 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2032 template<
typename _FormatContext>
2033 typename _FormatContext::iterator
2034 format(
const chrono::gps_time<_Duration>& __t,
2035 _FormatContext& __fc)
const
2040 constexpr chrono::days __gps_offset = chrono::days(3657);
2041 using _CDur = common_type_t<_Duration, chrono::days>;
2042 chrono::local_time<_CDur> __lt(__t.time_since_epoch() + __gps_offset);
2043 const string __abbrev(
"GPS", 3);
2044 const chrono::seconds __off = 0s;
2045 const auto __lf = chrono::local_time_format(__lt, &__abbrev, &__off);
2046 return _M_f._M_format(__lf, __fc);
2050 __format::__formatter_chrono<_CharT> _M_f;
2053 template<
typename _Duration,
typename _CharT>
2054 struct formatter<chrono::file_time<_Duration>, _CharT>
2056 template<
typename _ParseContext>
2057 constexpr typename _ParseContext::iterator
2058 parse(_ParseContext& __pc)
2059 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2061 template<
typename _FormatContext>
2062 typename _FormatContext::iterator
2063 format(
const chrono::file_time<_Duration>& __t,
2064 _FormatContext& __ctx)
const
2066 using namespace chrono;
2067 return _M_f._M_format(chrono::clock_cast<system_clock>(__t), __ctx);
2071 __format::__formatter_chrono<_CharT> _M_f;
2074 template<
typename _Duration,
typename _CharT>
2075 struct formatter<chrono::local_time<_Duration>, _CharT>
2077 template<
typename _ParseContext>
2078 constexpr typename _ParseContext::iterator
2079 parse(_ParseContext& __pc)
2080 {
return _M_f._M_parse(__pc, __format::_DateTime); }
2082 template<
typename _FormatContext>
2083 typename _FormatContext::iterator
2084 format(
const chrono::local_time<_Duration>& __t,
2085 _FormatContext& __ctx)
const
2086 {
return _M_f._M_format(__t, __ctx); }
2089 __format::__formatter_chrono<_CharT> _M_f;
2092 template<
typename _Duration,
typename _CharT>
2093 struct formatter<chrono::__detail::__local_time_fmt<_Duration>, _CharT>
2095 template<
typename _ParseContext>
2096 constexpr typename _ParseContext::iterator
2097 parse(_ParseContext& __pc)
2098 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2100 template<
typename _FormatContext>
2101 typename _FormatContext::iterator
2102 format(
const chrono::__detail::__local_time_fmt<_Duration>& __t,
2103 _FormatContext& __ctx)
const
2104 {
return _M_f._M_format(__t, __ctx); }
2107 __format::__formatter_chrono<_CharT> _M_f;
2110#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2111 template<
typename _Duration,
typename _TimeZonePtr,
typename _CharT>
2112 struct formatter<chrono::zoned_time<_Duration, _TimeZonePtr>, _CharT>
2113 : formatter<chrono::__detail::__local_time_fmt<_Duration>, _CharT>
2115 template<
typename _FormatContext>
2116 typename _FormatContext::iterator
2117 format(
const chrono::zoned_time<_Duration, _TimeZonePtr>& __tp,
2118 _FormatContext& __ctx)
const
2120 using chrono::__detail::__local_time_fmt;
2121 using _Base = formatter<__local_time_fmt<_Duration>, _CharT>;
2122 const chrono::sys_info __info = __tp.get_info();
2123 const auto __lf = chrono::local_time_format(__tp.get_local_time(),
2126 return _Base::format(__lf, __ctx);
2132 template<
typename _Duration,
typename _CharT>
2133 struct formatter<chrono::__detail::__utc_leap_second<_Duration>, _CharT>
2134 : formatter<chrono::utc_time<_Duration>, _CharT>
2136 template<
typename _FormatContext>
2137 typename _FormatContext::iterator
2138 format(
const chrono::__detail::__utc_leap_second<_Duration>& __t,
2139 _FormatContext& __fc)
const
2140 {
return this->_M_f._M_format(__t, __fc); }
2151 template<
typename _Duration = seconds>
2154 static_assert(is_same_v<common_type_t<_Duration, seconds>, _Duration>);
2157 _Parser(__format::_ChronoParts __need) : _M_need(__need) { }
2159 _Parser(_Parser&&) =
delete;
2160 void operator=(_Parser&&) =
delete;
2162 _Duration _M_time{};
2163 sys_days _M_sys_days{};
2164 year_month_day _M_ymd{};
2166 __format::_ChronoParts _M_need;
2167 unsigned _M_is_leap_second : 1 {};
2168 unsigned _M_reserved : 15 {};
2170 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2171 basic_istream<_CharT, _Traits>&
2172 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2173 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2174 minutes* __offset =
nullptr);
2179 template<
typename _CharT,
typename _Traits>
2180 static int_least32_t
2181 _S_read_unsigned(basic_istream<_CharT, _Traits>& __is,
2182 ios_base::iostate& __err,
int __n)
2184 int_least32_t __val = _S_try_read_digit(__is, __err);
2185 if (__val == -1) [[unlikely]]
2186 __err |= ios_base::failbit;
2191 for (
int __i = 1; __i < __n1; ++__i)
2192 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
2198 while (__n1++ < __n) [[unlikely]]
2199 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
2201 if (__builtin_mul_overflow(__val, 10, &__val)
2202 || __builtin_add_overflow(__val, __dig, &__val))
2204 __err |= ios_base::failbit;
2214 template<
typename _CharT,
typename _Traits>
2215 static int_least32_t
2216 _S_read_signed(basic_istream<_CharT, _Traits>& __is,
2217 ios_base::iostate& __err,
int __n)
2219 auto __sign = __is.peek();
2220 if (__sign ==
'-' || __sign ==
'+')
2222 int_least32_t __val = _S_read_unsigned(__is, __err, __n);
2223 if (__err & ios_base::failbit)
2225 if (__sign ==
'-') [[unlikely]]
2233 template<
typename _CharT,
typename _Traits>
2234 static int_least32_t
2235 _S_try_read_digit(basic_istream<_CharT, _Traits>& __is,
2236 ios_base::iostate& __err)
2238 int_least32_t __val = -1;
2239 auto __i = __is.peek();
2240 if (!_Traits::eq_int_type(__i, _Traits::eof())) [[likely]]
2242 _CharT __c = _Traits::to_char_type(__i);
2243 if (_CharT(
'0') <= __c && __c <= _CharT(
'9')) [[likely]]
2246 __val = __c - _CharT(
'0');
2250 __err |= ios_base::eofbit;
2256 template<
typename _CharT,
typename _Traits>
2258 _S_read_chr(basic_istream<_CharT, _Traits>& __is,
2259 ios_base::iostate& __err, _CharT __c)
2261 auto __i = __is.peek();
2262 if (_Traits::eq_int_type(__i, _Traits::eof()))
2263 __err |= ios_base::eofbit;
2264 else if (_Traits::to_char_type(__i) == __c) [[likely]]
2269 __err |= ios_base::failbit;
2274 template<
typename _Duration>
2275 using _Parser_t = _Parser<common_type_t<_Duration, seconds>>;
2280 template<
typename _CharT,
typename _Traits,
typename _Rep,
typename _Period,
2281 typename _Alloc = allocator<_CharT>>
2282 inline basic_istream<_CharT, _Traits>&
2283 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2284 duration<_Rep, _Period>& __d,
2285 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2288 auto __need = __format::_ChronoParts::_TimeOfDay;
2289 __detail::_Parser_t<duration<_Rep, _Period>> __p(__need);
2290 if (__p(__is, __fmt, __abbrev, __offset))
2291 __d = chrono::duration_cast<duration<_Rep, _Period>>(__p._M_time);
2295 template<
typename _CharT,
typename _Traits>
2296 inline basic_ostream<_CharT, _Traits>&
2297 operator<<(basic_ostream<_CharT, _Traits>& __os,
const day& __d)
2299 using _Ctx = __format::__format_context<_CharT>;
2300 using _Str = basic_string_view<_CharT>;
2301 _Str __s = _GLIBCXX_WIDEN(
"{:02d} is not a valid day");
2303 __s = __s.substr(0, 6);
2304 auto __u = (unsigned)__d;
2305 __os << std::vformat(__s, make_format_args<_Ctx>(__u));
2309 template<
typename _CharT,
typename _Traits,
2310 typename _Alloc = allocator<_CharT>>
2311 inline basic_istream<_CharT, _Traits>&
2312 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2314 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2317 __detail::_Parser<> __p(__format::_ChronoParts::_Day);
2318 if (__p(__is, __fmt, __abbrev, __offset))
2319 __d = __p._M_ymd.day();
2323 template<
typename _CharT,
typename _Traits>
2324 inline basic_ostream<_CharT, _Traits>&
2325 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month& __m)
2327 using _Ctx = __format::__format_context<_CharT>;
2328 using _Str = basic_string_view<_CharT>;
2329 _Str __s = _GLIBCXX_WIDEN(
"{:L%b}{} is not a valid month");
2331 __os << std::vformat(__os.getloc(), __s.substr(0, 6),
2332 make_format_args<_Ctx>(__m));
2335 auto __u = (unsigned)__m;
2336 __os << std::vformat(__s.substr(6), make_format_args<_Ctx>(__u));
2341 template<
typename _CharT,
typename _Traits,
2342 typename _Alloc = allocator<_CharT>>
2343 inline basic_istream<_CharT, _Traits>&
2344 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2346 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2349 __detail::_Parser<> __p(__format::_ChronoParts::_Month);
2350 if (__p(__is, __fmt, __abbrev, __offset))
2351 __m = __p._M_ymd.month();
2355 template<
typename _CharT,
typename _Traits>
2356 inline basic_ostream<_CharT, _Traits>&
2357 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year& __y)
2359 using _Ctx = __format::__format_context<_CharT>;
2360 using _Str = basic_string_view<_CharT>;
2361 _Str __s = _GLIBCXX_WIDEN(
"-{:04d} is not a valid year");
2363 __s = __s.substr(0, 7);
2365 if (__i >= 0) [[likely]]
2366 __s.remove_prefix(1);
2369 __os << std::vformat(__s, make_format_args<_Ctx>(__i));
2373 template<
typename _CharT,
typename _Traits,
2374 typename _Alloc = allocator<_CharT>>
2375 inline basic_istream<_CharT, _Traits>&
2376 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2378 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2381 __detail::_Parser<> __p(__format::_ChronoParts::_Year);
2382 if (__p(__is, __fmt, __abbrev, __offset))
2383 __y = __p._M_ymd.year();
2387 template<
typename _CharT,
typename _Traits>
2388 inline basic_ostream<_CharT, _Traits>&
2389 operator<<(basic_ostream<_CharT, _Traits>& __os,
const weekday& __wd)
2391 using _Ctx = __format::__format_context<_CharT>;
2392 using _Str = basic_string_view<_CharT>;
2393 _Str __s = _GLIBCXX_WIDEN(
"{:L%a}{} is not a valid weekday");
2395 __os << std::vformat(__os.getloc(), __s.substr(0, 6),
2396 make_format_args<_Ctx>(__wd));
2399 auto __c = __wd.c_encoding();
2400 __os << std::vformat(__s.substr(6), make_format_args<_Ctx>(__c));
2405 template<
typename _CharT,
typename _Traits,
2406 typename _Alloc = allocator<_CharT>>
2407 inline basic_istream<_CharT, _Traits>&
2408 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2410 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2413 __detail::_Parser<> __p(__format::_ChronoParts::_Weekday);
2414 if (__p(__is, __fmt, __abbrev, __offset))
2419 template<
typename _CharT,
typename _Traits>
2420 inline basic_ostream<_CharT, _Traits>&
2421 operator<<(basic_ostream<_CharT, _Traits>& __os,
2422 const weekday_indexed& __wdi)
2427 basic_stringstream<_CharT> __os2;
2428 __os2.imbue(__os.getloc());
2429 __os2 << __wdi.weekday();
2430 const auto __i = __wdi.index();
2431 basic_string_view<_CharT> __s
2432 = _GLIBCXX_WIDEN(
"[ is not a valid index]");
2434 __os2 << std::format(_GLIBCXX_WIDEN(
"{}"), __i);
2435 if (__i >= 1 && __i <= 5)
2436 __os2 << __s.back();
2438 __os2 << __s.substr(1);
2439 __os << __os2.view();
2443 template<
typename _CharT,
typename _Traits>
2444 inline basic_ostream<_CharT, _Traits>&
2445 operator<<(basic_ostream<_CharT, _Traits>& __os,
2446 const weekday_last& __wdl)
2449 basic_stringstream<_CharT> __os2;
2450 __os2.imbue(__os.getloc());
2451 __os2 << __wdl.weekday() << _GLIBCXX_WIDEN(
"[last]");
2452 __os << __os2.view();
2456 template<
typename _CharT,
typename _Traits>
2457 inline basic_ostream<_CharT, _Traits>&
2458 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month_day& __md)
2461 basic_stringstream<_CharT> __os2;
2462 __os2.imbue(__os.getloc());
2463 __os2 << __md.month();
2464 if constexpr (is_same_v<_CharT, char>)
2468 __os2 << __md.day();
2469 __os << __os2.view();
2473 template<
typename _CharT,
typename _Traits,
2474 typename _Alloc = allocator<_CharT>>
2475 inline basic_istream<_CharT, _Traits>&
2476 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2478 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2481 using __format::_ChronoParts;
2482 auto __need = _ChronoParts::_Month | _ChronoParts::_Day;
2483 __detail::_Parser<> __p(__need);
2484 if (__p(__is, __fmt, __abbrev, __offset))
2485 __md = month_day(__p._M_ymd.month(), __p._M_ymd.day());
2489 template<
typename _CharT,
typename _Traits>
2490 inline basic_ostream<_CharT, _Traits>&
2491 operator<<(basic_ostream<_CharT, _Traits>& __os,
2492 const month_day_last& __mdl)
2495 basic_stringstream<_CharT> __os2;
2496 __os2.imbue(__os.getloc());
2497 __os2 << __mdl.month() << _GLIBCXX_WIDEN(
"/last");
2498 __os << __os2.view();
2502 template<
typename _CharT,
typename _Traits>
2503 inline basic_ostream<_CharT, _Traits>&
2504 operator<<(basic_ostream<_CharT, _Traits>& __os,
2505 const month_weekday& __mwd)
2508 basic_stringstream<_CharT> __os2;
2509 __os2.imbue(__os.getloc());
2510 __os2 << __mwd.month();
2511 if constexpr (is_same_v<_CharT, char>)
2515 __os2 << __mwd.weekday_indexed();
2516 __os << __os2.view();
2520 template<
typename _CharT,
typename _Traits>
2521 inline basic_ostream<_CharT, _Traits>&
2522 operator<<(basic_ostream<_CharT, _Traits>& __os,
2523 const month_weekday_last& __mwdl)
2526 basic_stringstream<_CharT> __os2;
2527 __os2.imbue(__os.getloc());
2528 __os2 << __mwdl.month();
2529 if constexpr (is_same_v<_CharT, char>)
2533 __os2 << __mwdl.weekday_last();
2534 __os << __os2.view();
2538 template<
typename _CharT,
typename _Traits>
2539 inline basic_ostream<_CharT, _Traits>&
2540 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year_month& __ym)
2543 basic_stringstream<_CharT> __os2;
2544 __os2.imbue(__os.getloc());
2545 __os2 << __ym.year();
2546 if constexpr (is_same_v<_CharT, char>)
2550 __os2 << __ym.month();
2551 __os << __os2.view();
2555 template<
typename _CharT,
typename _Traits,
2556 typename _Alloc = allocator<_CharT>>
2557 inline basic_istream<_CharT, _Traits>&
2558 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2560 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2563 using __format::_ChronoParts;
2564 auto __need = _ChronoParts::_Year | _ChronoParts::_Month;
2565 __detail::_Parser<> __p(__need);
2566 if (__p(__is, __fmt, __abbrev, __offset))
2567 __ym = year_month(__p._M_ymd.year(), __p._M_ymd.month());
2571 template<
typename _CharT,
typename _Traits>
2572 inline basic_ostream<_CharT, _Traits>&
2573 operator<<(basic_ostream<_CharT, _Traits>& __os,
2574 const year_month_day& __ymd)
2576 using _Ctx = __format::__format_context<_CharT>;
2577 using _Str = basic_string_view<_CharT>;
2578 _Str __s = _GLIBCXX_WIDEN(
"{:%F} is not a valid date");
2579 __os << std::vformat(__ymd.ok() ? __s.substr(0, 5) : __s,
2580 make_format_args<_Ctx>(__ymd));
2584 template<
typename _CharT,
typename _Traits,
2585 typename _Alloc = allocator<_CharT>>
2586 inline basic_istream<_CharT, _Traits>&
2588 year_month_day& __ymd,
2592 using __format::_ChronoParts;
2593 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2594 | _ChronoParts::_Day;
2595 __detail::_Parser<> __p(__need);
2596 if (__p(__is, __fmt, __abbrev, __offset))
2601 template<
typename _CharT,
typename _Traits>
2604 const year_month_day_last& __ymdl)
2609 __os2 << __ymdl.year();
2610 if constexpr (is_same_v<_CharT, char>)
2614 __os2 << __ymdl.month_day_last();
2615 __os << __os2.view();
2619 template<
typename _CharT,
typename _Traits>
2620 inline basic_ostream<_CharT, _Traits>&
2621 operator<<(basic_ostream<_CharT, _Traits>& __os,
2622 const year_month_weekday& __ymwd)
2626 basic_stringstream<_CharT> __os2;
2627 __os2.
imbue(__os.getloc());
2629 if constexpr (is_same_v<_CharT, char>)
2633 __os2 << __ymwd.year() << __slash << __ymwd.month() << __slash
2634 << __ymwd.weekday_indexed();
2635 __os << __os2.view();
2639 template<
typename _CharT,
typename _Traits>
2640 inline basic_ostream<_CharT, _Traits>&
2641 operator<<(basic_ostream<_CharT, _Traits>& __os,
2642 const year_month_weekday_last& __ymwdl)
2646 basic_stringstream<_CharT> __os2;
2647 __os2.imbue(__os.getloc());
2649 if constexpr (is_same_v<_CharT, char>)
2653 __os2 << __ymwdl.year() << __slash << __ymwdl.month() << __slash
2654 << __ymwdl.weekday_last();
2655 __os << __os2.view();
2659 template<
typename _CharT,
typename _Traits,
typename _Duration>
2660 inline basic_ostream<_CharT, _Traits>&
2661 operator<<(basic_ostream<_CharT, _Traits>& __os,
2662 const hh_mm_ss<_Duration>& __hms)
2664 return __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%T}"), __hms);
2667#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2669 template<
typename _CharT,
typename _Traits>
2670 basic_ostream<_CharT, _Traits>&
2671 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_info& __i)
2673 __os <<
'[' << __i.begin <<
',' << __i.end
2674 <<
',' << hh_mm_ss(__i.offset) <<
',' << __i.save
2675 <<
',' << __i.abbrev <<
']';
2680 template<
typename _CharT,
typename _Traits>
2681 basic_ostream<_CharT, _Traits>&
2682 operator<<(basic_ostream<_CharT, _Traits>& __os,
const local_info& __li)
2685 if (__li.result == local_info::unique)
2689 if (__li.result == local_info::nonexistent)
2690 __os <<
"nonexistent";
2692 __os <<
"ambiguous";
2693 __os <<
" local time between " << __li.first;
2694 __os <<
" and " << __li.second;
2700 template<
typename _CharT,
typename _Traits,
typename _Duration,
2701 typename _TimeZonePtr>
2702 inline basic_ostream<_CharT, _Traits>&
2703 operator<<(basic_ostream<_CharT, _Traits>& __os,
2704 const zoned_time<_Duration, _TimeZonePtr>& __t)
2706 __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T %Z}"), __t);
2711 template<
typename _CharT,
typename _Traits,
typename _Duration>
2712 requires (!treat_as_floating_point_v<typename _Duration::rep>)
2713 && ratio_less_v<typename _Duration::period, days::period>
2714 inline basic_ostream<_CharT, _Traits>&
2715 operator<<(basic_ostream<_CharT, _Traits>& __os,
2716 const sys_time<_Duration>& __tp)
2718 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __tp);
2722 template<
typename _CharT,
typename _Traits>
2723 inline basic_ostream<_CharT, _Traits>&
2724 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_days& __dp)
2726 __os << year_month_day{__dp};
2730 template<
typename _CharT,
typename _Traits,
typename _Duration,
2731 typename _Alloc = allocator<_CharT>>
2732 basic_istream<_CharT, _Traits>&
2733 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2734 sys_time<_Duration>& __tp,
2735 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2741 using __format::_ChronoParts;
2742 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2743 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2744 __detail::_Parser_t<_Duration> __p(__need);
2745 if (__p(__is, __fmt, __abbrev, __offset))
2747 if (__p._M_is_leap_second)
2751 auto __st = __p._M_sys_days + __p._M_time - *__offset;
2752 __tp = chrono::time_point_cast<_Duration>(__st);
2758 template<
typename _CharT,
typename _Traits,
typename _Duration>
2759 inline basic_ostream<_CharT, _Traits>&
2760 operator<<(basic_ostream<_CharT, _Traits>& __os,
2761 const utc_time<_Duration>& __t)
2763 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
2767 template<
typename _CharT,
typename _Traits,
typename _Duration,
2768 typename _Alloc = allocator<_CharT>>
2769 inline basic_istream<_CharT, _Traits>&
2770 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2771 utc_time<_Duration>& __tp,
2772 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2778 using __format::_ChronoParts;
2779 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2780 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2781 __detail::_Parser_t<_Duration> __p(__need);
2782 if (__p(__is, __fmt, __abbrev, __offset))
2786 auto __ut = utc_clock::from_sys(__p._M_sys_days) + __p._M_time
2788 __tp = chrono::time_point_cast<_Duration>(__ut);
2793 template<
typename _CharT,
typename _Traits,
typename _Duration>
2794 inline basic_ostream<_CharT, _Traits>&
2795 operator<<(basic_ostream<_CharT, _Traits>& __os,
2796 const tai_time<_Duration>& __t)
2798 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
2802 template<
typename _CharT,
typename _Traits,
typename _Duration,
2803 typename _Alloc = allocator<_CharT>>
2804 inline basic_istream<_CharT, _Traits>&
2805 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2806 tai_time<_Duration>& __tp,
2807 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2813 using __format::_ChronoParts;
2814 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2815 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2816 __detail::_Parser_t<_Duration> __p(__need);
2817 if (__p(__is, __fmt, __abbrev, __offset))
2819 if (__p._M_is_leap_second)
2823 auto __st = __p._M_sys_days + __p._M_time - *__offset;
2824 auto __tt = tai_clock::from_utc(utc_clock::from_sys(__st));
2825 __tp = chrono::time_point_cast<_Duration>(__tt);
2831 template<
typename _CharT,
typename _Traits,
typename _Duration>
2832 inline basic_ostream<_CharT, _Traits>&
2833 operator<<(basic_ostream<_CharT, _Traits>& __os,
2834 const gps_time<_Duration>& __t)
2836 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
2840 template<
typename _CharT,
typename _Traits,
typename _Duration,
2841 typename _Alloc = allocator<_CharT>>
2842 inline basic_istream<_CharT, _Traits>&
2843 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2844 gps_time<_Duration>& __tp,
2845 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2851 using __format::_ChronoParts;
2852 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2853 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2854 __detail::_Parser_t<_Duration> __p(__need);
2855 if (__p(__is, __fmt, __abbrev, __offset))
2857 if (__p._M_is_leap_second)
2861 auto __st = __p._M_sys_days + __p._M_time - *__offset;
2862 auto __tt = gps_clock::from_utc(utc_clock::from_sys(__st));
2863 __tp = chrono::time_point_cast<_Duration>(__tt);
2869 template<
typename _CharT,
typename _Traits,
typename _Duration>
2870 inline basic_ostream<_CharT, _Traits>&
2871 operator<<(basic_ostream<_CharT, _Traits>& __os,
2872 const file_time<_Duration>& __t)
2874 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
2878 template<
typename _CharT,
typename _Traits,
typename _Duration,
2879 typename _Alloc = allocator<_CharT>>
2880 inline basic_istream<_CharT, _Traits>&
2881 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2882 file_time<_Duration>& __tp,
2883 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2886 sys_time<_Duration> __st;
2887 if (chrono::from_stream(__is, __fmt, __st, __abbrev, __offset))
2888 __tp = chrono::time_point_cast<_Duration>(file_clock::from_sys(__st));
2892 template<
typename _CharT,
typename _Traits,
typename _Duration>
2893 inline basic_ostream<_CharT, _Traits>&
2894 operator<<(basic_ostream<_CharT, _Traits>& __os,
2895 const local_time<_Duration>& __lt)
2897 __os << sys_time<_Duration>{__lt.time_since_epoch()};
2901 template<
typename _CharT,
typename _Traits,
typename _Duration,
2902 typename _Alloc = allocator<_CharT>>
2903 basic_istream<_CharT, _Traits>&
2904 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2905 local_time<_Duration>& __tp,
2906 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2909 using __format::_ChronoParts;
2910 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2911 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2912 __detail::_Parser_t<_Duration> __p(__need);
2913 if (__p(__is, __fmt, __abbrev, __offset))
2915 days __d = __p._M_sys_days.time_since_epoch();
2916 auto __t = local_days(__d) + __p._M_time;
2917 __tp = chrono::time_point_cast<_Duration>(__t);
2926 template<
typename _Parsable,
typename _CharT,
2928 typename... _OptArgs>
2929 concept __parsable =
requires (basic_istream<_CharT, _Traits>& __is,
2930 const _CharT* __fmt, _Parsable& __tp,
2931 _OptArgs*... __args)
2932 { from_stream(__is, __fmt, __tp, __args...); };
2934 template<
typename _Parsable,
typename _CharT,
2935 typename _Traits = char_traits<_CharT>,
2936 typename _Alloc = allocator<_CharT>>
2940 using __string_type = basic_string<_CharT, _Traits, _Alloc>;
2943 _Parse(
const _CharT* __fmt, _Parsable& __tp,
2944 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2947 _M_abbrev(__abbrev), _M_offset(__offset)
2950 _Parse(_Parse&&) =
delete;
2951 _Parse& operator=(_Parse&&) =
delete;
2954 using __stream_type = basic_istream<_CharT, _Traits>;
2956 const _CharT*
const _M_fmt;
2957 _Parsable*
const _M_tp;
2958 __string_type*
const _M_abbrev;
2961 friend __stream_type&
2962 operator>>(__stream_type& __is, _Parse&& __p)
2965 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev,
2967 else if (__p._M_abbrev)
2968 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev);
2970 from_stream(__is, __p._M_fmt, *__p._M_tp);
2974 friend void operator>>(__stream_type&, _Parse&) =
delete;
2975 friend void operator>>(__stream_type&,
const _Parse&) =
delete;
2979 template<
typename _CharT, __detail::__parsable<_CharT> _Parsable>
2980 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
2982 parse(
const _CharT* __fmt, _Parsable& __tp)
2983 {
return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp); }
2985 template<
typename _CharT,
typename _Traits,
typename _Alloc,
2986 __detail::__parsable<_CharT, _Traits> _Parsable>
2989 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp)
2991 return __detail::_Parse<_Parsable, _CharT, _Traits>(__fmt.c_str(), __tp);
2994 template<
typename _CharT,
typename _Traits,
typename _Alloc,
2995 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
2996 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
2997 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
2999 parse(
const _CharT* __fmt, _Parsable& __tp,
3000 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
3003 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
3007 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3008 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
3009 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
3012 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
3013 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
3016 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
3020 template<
typename _CharT,
typename _Traits =
char_traits<_CharT>,
3021 typename _StrT = basic_
string<_CharT, _Traits>,
3022 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
3023 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
3025 parse(
const _CharT* __fmt, _Parsable& __tp,
minutes& __offset)
3027 return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp,
nullptr,
3031 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3032 typename _StrT = basic_string<_CharT, _Traits>,
3033 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
3036 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
3039 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
3044 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3045 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
3046 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
3047 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
3049 parse(
const _CharT* __fmt, _Parsable& __tp,
3050 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
3053 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
3058 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3059 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
3060 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
3063 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
3064 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
3067 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
3073 template<
typename _Duration>
3074 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3075 basic_istream<_CharT, _Traits>&
3076 __detail::_Parser<_Duration>::
3077 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3078 basic_string<_CharT, _Traits, _Alloc>* __abbrev,
3081 using sentry =
typename basic_istream<_CharT, _Traits>::sentry;
3083 if (sentry __cerb(__is,
true); __cerb)
3085 locale __loc = __is.getloc();
3086 auto& __tmget = std::use_facet<std::time_get<_CharT>>(__loc);
3087 auto& __tmpunct = std::use_facet<std::__timepunct<_CharT>>(__loc);
3090 struct _Stream_state
3093 _Stream_state(basic_istream<_CharT, _Traits>& __i)
3095 _M_flags(__i.flags(ios_base::
skipws | ios_base::
dec)),
3101 _M_is.flags(_M_flags);
3105 _Stream_state(_Stream_state&&) =
delete;
3107 basic_istream<_CharT, _Traits>& _M_is;
3108 ios_base::fmtflags _M_flags;
3118 auto __read_unsigned = [&] (
int __n) {
3119 return _S_read_unsigned(__is, __err, __n);
3124 auto __read_signed = [&] (
int __n) {
3125 return _S_read_signed(__is, __err, __n);
3129 auto __read_chr = [&__is, &__err] (_CharT __c) {
3130 return _S_read_chr(__is, __err, __c);
3133 using __format::_ChronoParts;
3134 _ChronoParts __parts{};
3136 const year __bad_y = --year::min();
3137 const month __bad_mon(255);
3138 const day __bad_day(255);
3139 const weekday __bad_wday(255);
3140 const hours __bad_h(-1);
3141 const minutes __bad_min(-9999);
3144 year __y = __bad_y, __yy = __bad_y;
3145 year __iso_y = __bad_y, __iso_yy = __bad_y;
3146 month __m = __bad_mon;
3147 day __d = __bad_day;
3148 weekday __wday = __bad_wday;
3149 hours __h = __bad_h, __h12 = __bad_h;
3151 _Duration __s = __bad_sec;
3153 int __iso_wk = -1, __sunday_wk = -1, __monday_wk = -1;
3155 int __dayofyear = -1;
3157 minutes __tz_offset = __bad_min;
3158 basic_string<_CharT, _Traits> __tz_abbr;
3160 if ((_M_need & _ChronoParts::_TimeOfDay)
3161 && (_M_need & _ChronoParts::_Year))
3167 __parts = _ChronoParts::_TimeOfDay;
3174 bool __is_flag =
false;
3176 constexpr bool __is_floating
3177 = treat_as_floating_point_v<typename _Duration::rep>;
3196 _CharT __c = *__fmt++;
3203 else if (!__read_chr(__c)) [[unlikely]]
3214 if (__mod || __num) [[unlikely]]
3219 __tmget.get(__is, {}, __is, __err, &__tm,
3221 if (!__is_failed(__err))
3222 __wday = weekday(__tm.tm_wday);
3224 __parts |= _ChronoParts::_Weekday;
3230 if (__mod || __num) [[unlikely]]
3238 __tmget.get(__is, {}, __is, __err, &__tm,
3240 if (!__is_failed(__err))
3241 __m = month(__tm.tm_mon + 1);
3243 __parts |= _ChronoParts::_Month;
3247 if (__mod ==
'O' || __num) [[unlikely]]
3252 __tmget.get(__is, {}, __is, __err, &__tm,
3253 __fmt - 2 - (__mod ==
'E'), __fmt);
3254 if (!__is_failed(__err))
3256 __y = year(__tm.tm_year + 1900);
3257 __m = month(__tm.tm_mon + 1);
3258 __d = day(__tm.tm_mday);
3259 __h =
hours(__tm.tm_hour);
3264 __parts |= _ChronoParts::_DateTime;
3268 if (!__mod) [[likely]]
3270 auto __v = __read_signed(__num ? __num : 2);
3271 if (!__is_failed(__err))
3273 int __cmin = (int)year::min() / 100;
3274 int __cmax = (int)year::max() / 100;
3275 if (__cmin <= __v && __v <= __cmax)
3276 __century = __v * 100;
3281 else if (__mod ==
'E')
3284 __tmget.get(__is, {}, __is, __err, &__tm,
3286 if (!__is_failed(__err))
3287 __century = __tm.tm_year;
3296 if (!__mod) [[likely]]
3298 auto __v = __read_unsigned(__num ? __num : 2);
3299 if (!__is_failed(__err))
3302 else if (__mod ==
'O')
3305 __tmget.get(__is, {}, __is, __err, &__tm,
3307 if (!__is_failed(__err))
3308 __d = day(__tm.tm_mday);
3312 __parts |= _ChronoParts::_Day;
3316 if (__mod || __num) [[unlikely]]
3320 auto __month = __read_unsigned(2);
3322 auto __day = __read_unsigned(2);
3324 auto __year = __read_unsigned(2);
3325 if (__is_failed(__err))
3327 __y = year(__year + 1900 + 100 *
int(__year < 69));
3328 __m = month(__month);
3330 if (!year_month_day(__y, __m, __d).ok())
3332 __y = __yy = __iso_y = __iso_yy = __bad_y;
3338 __parts |= _ChronoParts::_Date;
3342 if (__mod) [[unlikely]]
3346 auto __year = __read_signed(__num ? __num : 4);
3348 auto __month = __read_unsigned(2);
3350 auto __day = __read_unsigned(2);
3351 if (__is_failed(__err))
3354 __m = month(__month);
3356 if (!year_month_day(__y, __m, __d).ok())
3358 __y = __yy = __iso_y = __iso_yy = __bad_y;
3364 __parts |= _ChronoParts::_Date;
3368 if (__mod) [[unlikely]]
3372 auto __val = __read_unsigned(__num ? __num : 2);
3373 if (__val >= 0 && __val <= 99)
3375 __iso_yy = year(__val);
3376 if (__century == -1)
3380 __iso_yy = __iso_y = __y = __yy = __bad_y;
3382 __parts |= _ChronoParts::_Year;
3386 if (__mod) [[unlikely]]
3389 __iso_y = year(__read_unsigned(__num ? __num : 4));
3390 __parts |= _ChronoParts::_Year;
3395 if (__mod ==
'E') [[unlikely]]
3397 else if (__mod ==
'O')
3402 __tmget.get(__is, {}, __is, __err, &__tm,
3404 if (!__is_failed(__err))
3408 __h12 =
hours(__tm.tm_hour);
3412 __h =
hours(__tm.tm_hour);
3421 auto __val = __read_unsigned(__num ? __num : 2);
3422 if (__c ==
'I' && __val >= 1 && __val <= 12)
3424 __h12 =
hours(__val);
3427 else if (__c ==
'H' && __val >= 0 && __val <= 23)
3434 if (_M_need & _ChronoParts::_TimeOfDay)
3439 __parts |= _ChronoParts::_TimeOfDay;
3443 if (__mod) [[unlikely]]
3445 else if (_M_need == _ChronoParts::_TimeOfDay)
3447 auto __val = __read_signed(__num ? __num : 3);
3448 if (!__is_failed(__err))
3451 __parts |= _ChronoParts::_TimeOfDay;
3456 __dayofyear = __read_unsigned(__num ? __num : 3);
3463 if (__mod ==
'E') [[unlikely]]
3465 else if (__mod ==
'O')
3468 __tmget.get(__is, {}, __is, __err, &__tm,
3470 if (!__is_failed(__err))
3471 __m = month(__tm.tm_mon + 1);
3475 auto __val = __read_unsigned(__num ? __num : 2);
3476 if (__val >= 1 && __val <= 12)
3481 __parts |= _ChronoParts::_Month;
3485 if (__mod ==
'E') [[unlikely]]
3487 else if (__mod ==
'O')
3490 __tmget.get(__is, {}, __is, __err, &__tm,
3492 if (!__is_failed(__err))
3497 auto __val = __read_unsigned(__num ? __num : 2);
3498 if (0 <= __val && __val < 60)
3502 if (_M_need & _ChronoParts::_TimeOfDay)
3507 __parts |= _ChronoParts::_TimeOfDay;
3517 const _CharT* __ampms[2];
3518 __tmpunct._M_am_pm(__ampms);
3519 int __n = 0, __which = 3;
3520 while (__which != 0)
3522 auto __i = __is.peek();
3523 if (_Traits::eq_int_type(__i, _Traits::eof()))
3533 else if (__ampms[0][__n + 1] == _CharT())
3544 else if (__ampms[1][__n + 1] == _CharT())
3555 if (__which == 0 || __which == 3)
3568 __tmget.get(__is, {}, __is, __err, &__tm,
3570 if (!__is_failed(__err))
3572 __h =
hours(__tm.tm_hour);
3577 __parts |= _ChronoParts::_TimeOfDay;
3582 if (__mod || __num) [[unlikely]]
3589 auto __val = __read_unsigned(2);
3590 if (__val == -1 || __val > 23) [[unlikely]]
3592 if (_M_need & _ChronoParts::_TimeOfDay)
3596 if (!__read_chr(
':')) [[unlikely]]
3600 __val = __read_unsigned(2);
3601 if (__val == -1 || __val > 60) [[unlikely]]
3603 if (_M_need & _ChronoParts::_TimeOfDay)
3611 __parts |= _ChronoParts::_TimeOfDay;
3614 else if (!__read_chr(
':')) [[unlikely]]
3620 if (__mod ==
'E') [[unlikely]]
3622 else if (__mod ==
'O')
3625 __tmget.get(__is, {}, __is, __err, &__tm,
3627 if (!__is_failed(__err))
3630 else if constexpr (_Duration::period::den == 1
3633 auto __val = __read_unsigned(__num ? __num : 2);
3634 if (0 <= __val && __val <= 59) [[likely]]
3638 if (_M_need & _ChronoParts::_TimeOfDay)
3645 basic_stringstream<_CharT> __buf;
3646 auto __digit = _S_try_read_digit(__is, __err);
3649 __buf.put(_CharT(
'0') + __digit);
3650 __digit = _S_try_read_digit(__is, __err);
3652 __buf.put(_CharT(
'0') + __digit);
3655 auto __i = __is.peek();
3656 if (_Traits::eq_int_type(__i, _Traits::eof()))
3663 auto& __np = use_facet<numpunct<_CharT>>(__loc);
3664 __dp = __np.decimal_point();
3666 _CharT __c = _Traits::to_char_type(__i);
3672 = hh_mm_ss<_Duration>::fractional_width;
3675 __digit = _S_try_read_digit(__is, __err);
3677 __buf.put(_CharT(
'0') + __digit);
3685 if (!__is_failed(__err)) [[likely]]
3687 long double __val{};
3688#if __cpp_lib_to_chars
3690 auto __first = __str.data();
3691 auto __last = __first + __str.size();
3695 if ((
bool)ec || ptr != __last) [[unlikely]]
3702 duration<long double> __fs(__val);
3703 if constexpr (__is_floating)
3706 __s = chrono::round<_Duration>(__fs);
3710 __parts |= _ChronoParts::_TimeOfDay;
3715 if (__mod ==
'E') [[unlikely]]
3717 else if (__mod ==
'O')
3722 __tmget.get(__is, {}, __is, __err, &__tm,
3724 if (!__is_failed(__err))
3725 __wday = weekday(__tm.tm_wday);
3732 const int __lo = __c ==
'u' ? 1 : 0;
3733 const int __hi = __lo + 6;
3734 auto __val = __read_unsigned(__num ? __num : 1);
3735 if (__lo <= __val && __val <= __hi)
3736 __wday = weekday(__val);
3739 __wday = __bad_wday;
3743 __parts |= _ChronoParts::_Weekday;
3749 if (__mod ==
'E') [[unlikely]]
3751 else if (__mod ==
'O')
3753 if (__c ==
'V') [[unlikely]]
3763 const int __lo = __c ==
'V' ? 1 : 0;
3764 const int __hi = 53;
3765 auto __val = __read_unsigned(__num ? __num : 2);
3766 if (__lo <= __val && __val <= __hi)
3771 __sunday_wk = __val;
3777 __monday_wk = __val;
3782 __iso_wk = __sunday_wk = __monday_wk = -1;
3788 if (__mod ==
'O' || __num) [[unlikely]]
3793 __tmget.get(__is, {}, __is, __err, &__tm,
3794 __fmt - 2 - (__mod ==
'E'), __fmt);
3795 if (!__is_failed(__err))
3797 __y = year(__tm.tm_year + 1900);
3798 __m = month(__tm.tm_mon + 1);
3799 __d = day(__tm.tm_mday);
3802 __parts |= _ChronoParts::_Date;
3806 if (__mod ==
'O' || __num) [[unlikely]]
3811 __tmget.get(__is, {}, __is, __err, &__tm,
3812 __fmt - 2 - (__mod ==
'E'), __fmt);
3813 if (!__is_failed(__err))
3815 __h =
hours(__tm.tm_hour);
3820 __parts |= _ChronoParts::_TimeOfDay;
3824 if (__mod) [[unlikely]]
3827 __tmget.get(__is, {}, __is, __err, &__tm,
3829 if (!__is_failed(__err))
3831 int __cent = __tm.tm_year < 2000 ? 1900 : 2000;
3832 __yy = year(__tm.tm_year - __cent);
3833 if (__century == -1)
3839 auto __val = __read_unsigned(__num ? __num : 2);
3840 if (__val >= 0 && __val <= 99)
3843 if (__century == -1)
3844 __century = __val < 69 ? 2000 : 1900;
3847 __y = __yy = __iso_yy = __iso_y = __bad_y;
3849 __parts |= _ChronoParts::_Year;
3853 if (__mod ==
'O') [[unlikely]]
3855 else if (__mod ==
'E')
3858 __tmget.get(__is, {}, __is, __err, &__tm,
3860 if (!__is_failed(__err))
3861 __y = year(__tm.tm_year);
3865 auto __val = __read_unsigned(__num ? __num : 4);
3866 if (!__is_failed(__err))
3869 __parts |= _ChronoParts::_Year;
3873 if (__num) [[unlikely]]
3880 auto __i = __is.peek();
3881 if (_Traits::eq_int_type(__i, _Traits::eof()))
3886 _CharT __ic = _Traits::to_char_type(__i);
3887 const bool __neg = __ic == _CharT(
'-');
3888 if (__ic == _CharT(
'-') || __ic == _CharT(
'+'))
3895 __hh = __read_unsigned(2);
3900 __hh = 10 * _S_try_read_digit(__is, __err);
3901 __hh += _S_try_read_digit(__is, __err);
3904 if (__is_failed(__err))
3908 if (_Traits::eq_int_type(__i, _Traits::eof()))
3911 __tz_offset =
minutes(__hh * (__neg ? -60 : 60));
3914 __ic = _Traits::to_char_type(__i);
3916 bool __read_mm =
false;
3919 if (__ic == _GLIBCXX_WIDEN(
":")[0])
3926 else if (_CharT(
'0') <= __ic && __ic <= _CharT(
'9'))
3932 int_least32_t __mm = 0;
3935 __mm = 10 * _S_try_read_digit(__is, __err);
3936 __mm += _S_try_read_digit(__is, __err);
3939 if (!__is_failed(__err))
3941 auto __z = __hh * 60 + __mm;
3942 __tz_offset =
minutes(__neg ? -__z : __z);
3948 if (__mod || __num) [[unlikely]]
3952 basic_string_view<_CharT> __x = _GLIBCXX_WIDEN(
"_/-+");
3956 auto __i = __is.peek();
3957 if (!_Traits::eq_int_type(__i, _Traits::eof()))
3959 _CharT __a = _Traits::to_char_type(__i);
3961 || __x.find(__a) != __x.npos)
3963 __tz_abbr.push_back(__a);
3972 if (__tz_abbr.empty())
3978 if (__mod || __num) [[unlikely]]
3982 _CharT __i = __is.peek();
3983 if (_Traits::eq_int_type(__i, _Traits::eof()))
3985 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
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))
4006 if (__mod || __num) [[unlikely]]
4014 if (__mod || __num) [[unlikely]]
4023 if (_CharT(
'1') <= __c && __c <= _CharT(
'9'))
4025 if (!__mod) [[likely]]
4028 auto __end = __fmt + _Traits::length(__fmt);
4030 = __format::__parse_integer(__fmt - 1, __end);
4031 if (__ptr) [[likely]]
4042 if (__is_failed(__err)) [[unlikely]]
4052 if (__yy != __bad_y && __y == __bad_y)
4053 __y =
years(__century) + __yy;
4054 if (__iso_yy != __bad_y && __iso_y == __bad_y)
4055 __iso_y =
years(__century) + __iso_yy;
4058 bool __can_use_doy =
false;
4059 bool __can_use_iso_wk =
false;
4060 bool __can_use_sun_wk =
false;
4061 bool __can_use_mon_wk =
false;
4064 if (__y != __bad_y && __dayofyear >= 0)
4066 __can_use_doy =
true;
4067 __parts |= _ChronoParts::_Date;
4069 else if (__y != __bad_y && __wday != __bad_wday && __sunday_wk >= 0)
4071 __can_use_sun_wk =
true;
4072 __parts |= _ChronoParts::_Date;
4074 else if (__y != __bad_y && __wday != __bad_wday && __monday_wk >= 0)
4076 __can_use_mon_wk =
true;
4077 __parts |= _ChronoParts::_Date;
4079 else if (__iso_y != __bad_y && __wday != __bad_wday && __iso_wk > 0)
4082 __can_use_iso_wk =
true;
4083 __parts |= _ChronoParts::_Date;
4086 if (__is_failed(__err)) [[unlikely]]
4088 else if (__is_flag) [[unlikely]]
4090 else if ((_M_need & __parts) == _M_need) [[likely]]
4112 const bool __need_wday = _M_need & _ChronoParts::_Weekday;
4116 const bool __need_time = _M_need & _ChronoParts::_TimeOfDay;
4118 if (__need_wday && __wday != __bad_wday)
4120 else if (_M_need & _ChronoParts::_Date)
4124 const bool __need_ymd = !__need_wday && !__need_time;
4126 if ((_M_need & _ChronoParts::_Year && __y == __bad_y)
4127 || (_M_need & _ChronoParts::_Month && __m == __bad_mon)
4128 || (_M_need & _ChronoParts::_Day && __d == __bad_day))
4135 if ((0 < __dayofyear && __dayofyear <= 365)
4136 || (__dayofyear == 366 && __y.is_leap()))
4139 _M_sys_days = sys_days(__y/January/1)
4140 +
days(__dayofyear - 1);
4142 _M_ymd = year_month_day(_M_sys_days);
4147 else if (__can_use_iso_wk)
4155 const sys_days __jan4(__iso_y/January/4);
4156 weekday __wd1(__jan4 -
days(3));
4157 if (__wd1 != Thursday)
4158 if (__wd1 != Wednesday || !__iso_y.is_leap())
4162 if (!__is_failed(__err)) [[likely]]
4165 sys_days __w(Thursday[1]/January/__iso_y);
4167 __w -= Thursday - Monday;
4169 __w += __wday - Monday;
4173 _M_ymd = year_month_day(_M_sys_days);
4176 else if (__can_use_sun_wk)
4179 sys_days __wk1(__y/January/Sunday[1]);
4180 _M_sys_days = __wk1 +
weeks(__sunday_wk - 1)
4181 +
days(__wday.c_encoding());
4182 _M_ymd = year_month_day(_M_sys_days);
4183 if (_M_ymd.year() != __y) [[unlikely]]
4186 else if (__can_use_mon_wk)
4189 sys_days __wk1(__y/January/Monday[1]);
4190 _M_sys_days = __wk1 +
weeks(__monday_wk - 1)
4191 +
days(__wday.c_encoding() - 1);
4192 _M_ymd = year_month_day(_M_sys_days);
4193 if (_M_ymd.year() != __y) [[unlikely]]
4205 if (_M_need & _ChronoParts::_Year)
4207 if (!__y.ok()) [[unlikely]]
4210 else if (__y == __bad_y)
4213 if (_M_need & _ChronoParts::_Month)
4215 if (!__m.ok()) [[unlikely]]
4218 else if (__m == __bad_mon)
4221 if (_M_need & _ChronoParts::_Day)
4223 if (__d < day(1) || __d > (__y/__m/last).day())
4226 else if (__d == __bad_day)
4229 if (year_month_day __ymd(__y, __m, __d); __ymd.ok())
4232 if (__need_wday || __need_time)
4233 _M_sys_days = sys_days(_M_ymd);
4240 _M_wd = weekday(_M_sys_days);
4246 if (__h == __bad_h && __h12 != __bad_h)
4250 else if (__ampm == 2)
4251 __h = __h12 ==
hours(12) ? __h12 : __h12 +
hours(12);
4256 auto __t = _M_time.zero();
4265 if (__min != __bad_min)
4271 if (__s != __bad_sec)
4275 _M_is_leap_second = __s >=
seconds(60);
4284 if (!__is_failed(__err)) [[likely]]
4286 if (__offset && __tz_offset != __bad_min)
4287 *__offset = __tz_offset;
4288 if (__abbrev && !__tz_abbr.empty())
4296 __is.setstate(__err);
4300#undef _GLIBCXX_WIDEN
4305_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.
locale imbue(const locale &__loc)
Moves to a new locale.
Template class basic_istream.
Template class basic_ostream.
Controlling output for std::string.
Controlling input and output for std::string.
Provides output iterator semantics for streambufs.
Provides compile-time rational arithmetic.
A non-owning reference to a string.
Basis for explicit traits specializations.
chrono::duration represents a distance between two points in time
chrono::time_point represents a point in time as measured by a clock
Managing sequences of characters and character-like objects.
_Ios_Iostate iostate
This is a bitmask type.
streamsize precision() const
Flags access.
fmtflags flags() const
Access to format flags.
static const iostate eofbit
Indicates that an input operation reached the end of an input sequence.
static const iostate goodbit
Indicates all is well.
locale getloc() const
Locale access.
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.