30#ifndef _GLIBCXX_CHRONO_IO_H
31#define _GLIBCXX_CHRONO_IO_H 1
33#pragma GCC system_header
35#if __cplusplus >= 202002L
43namespace std _GLIBCXX_VISIBILITY(default)
45_GLIBCXX_BEGIN_NAMESPACE_VERSION
60 template<
typename _CharT>
62 _Widen(
const char* __narrow,
const wchar_t* __wide)
64 if constexpr (is_same_v<_CharT, wchar_t>)
69#define _GLIBCXX_WIDEN_(C, S) ::std::chrono::__detail::_Widen<C>(S, L##S)
70#define _GLIBCXX_WIDEN(S) _GLIBCXX_WIDEN_(_CharT, S)
72 template<
typename _Period,
typename _CharT>
74 __units_suffix()
noexcept
79#define _GLIBCXX_UNITS_SUFFIX(period, suffix) \
80 if constexpr (is_same_v<_Period, period>) \
81 return _GLIBCXX_WIDEN(suffix); \
84 _GLIBCXX_UNITS_SUFFIX(atto,
"as")
85 _GLIBCXX_UNITS_SUFFIX(femto,
"fs")
86 _GLIBCXX_UNITS_SUFFIX(pico,
"ps")
87 _GLIBCXX_UNITS_SUFFIX(nano,
"ns")
88 _GLIBCXX_UNITS_SUFFIX(milli,
"ms")
89#if _GLIBCXX_USE_ALT_MICROSECONDS_SUFFIX
92 _GLIBCXX_UNITS_SUFFIX(micro,
"\u00b5s")
94 _GLIBCXX_UNITS_SUFFIX(micro,
"us")
96 _GLIBCXX_UNITS_SUFFIX(centi,
"cs")
97 _GLIBCXX_UNITS_SUFFIX(deci,
"ds")
99 _GLIBCXX_UNITS_SUFFIX(deca,
"das")
100 _GLIBCXX_UNITS_SUFFIX(hecto,
"hs")
101 _GLIBCXX_UNITS_SUFFIX(kilo,
"ks")
102 _GLIBCXX_UNITS_SUFFIX(mega,
"Ms")
103 _GLIBCXX_UNITS_SUFFIX(giga,
"Gs")
104 _GLIBCXX_UNITS_SUFFIX(tera,
"Ts")
105 _GLIBCXX_UNITS_SUFFIX(tera,
"Ts")
106 _GLIBCXX_UNITS_SUFFIX(peta,
"Ps")
107 _GLIBCXX_UNITS_SUFFIX(exa,
"Es")
111#undef _GLIBCXX_UNITS_SUFFIX
115 template<
typename _Period,
typename _CharT,
typename _Out>
117 __fmt_units_suffix(_Out __out)
noexcept
119 if (
auto __s = __detail::__units_suffix<_Period, _CharT>(); __s.size())
120 return __format::__write(
std::move(__out), __s);
121 else if constexpr (_Period::den == 1)
122 return std::format_to(
std::move(__out), _GLIBCXX_WIDEN(
"[{}]s"),
123 (uintmax_t)_Period::num);
125 return std::format_to(
std::move(__out), _GLIBCXX_WIDEN(
"[{}/{}]s"),
126 (uintmax_t)_Period::num,
127 (uintmax_t)_Period::den);
136 template<
typename _CharT,
typename _Traits,
137 typename _Rep,
typename _Period>
143 using period =
typename _Period::type;
149 __detail::__fmt_units_suffix<period, _CharT>(_Out(__s));
158 template<
typename _Duration>
159 struct __local_time_fmt
162 const string* _M_abbrev;
166 struct __local_fmt_t;
179 template<
typename _Duration>
180 inline __detail::__local_time_fmt<_Duration>
182 const string* __abbrev =
nullptr,
183 const seconds* __offset_sec =
nullptr)
184 {
return {__time, __abbrev, __offset_sec}; }
192 [[noreturn,__gnu__::__always_inline__]]
194 __no_timezone_available()
195 { __throw_format_error(
"format error: no timezone available for %Z or %z"); }
197 [[noreturn,__gnu__::__always_inline__]]
199 __not_valid_for_duration()
200 { __throw_format_error(
"format error: chrono-format-spec not valid for "
201 "chrono::duration"); }
203 [[noreturn,__gnu__::__always_inline__]]
205 __invalid_chrono_spec()
206 { __throw_format_error(
"format error: chrono-format-spec not valid for "
209 template<
typename _CharT>
210 struct _ChronoSpec : _Spec<_CharT>
212 basic_string_view<_CharT> _M_chrono_specs;
219 _Year = 1, _Month = 2, _Day = 4, _Weekday = 8, _TimeOfDay = 16,
221 _Date = _Year | _Month | _Day | _Weekday,
222 _DateTime = _Date | _TimeOfDay,
223 _ZonedDateTime = _DateTime | _TimeZone,
227 constexpr _ChronoParts
228 operator|(_ChronoParts __x, _ChronoParts __y)
noexcept
229 {
return static_cast<_ChronoParts
>((int)__x | (
int)__y); }
231 constexpr _ChronoParts&
232 operator|=(_ChronoParts& __x, _ChronoParts __y)
noexcept
233 {
return __x = __x | __y; }
236 template<
typename _CharT>
237 struct __formatter_chrono
239 using __string_view = basic_string_view<_CharT>;
240 using __string = basic_string<_CharT>;
242 template<
typename _ParseContext>
243 constexpr typename _ParseContext::iterator
244 _M_parse(_ParseContext& __pc, _ChronoParts __parts)
246 auto __first = __pc.
begin();
247 auto __last = __pc.end();
249 _ChronoSpec<_CharT> __spec{};
251 auto __finalize = [
this, &__spec] {
255 auto __finished = [&] {
256 if (__first == __last || *__first ==
'}')
267 __first = __spec._M_parse_fill_and_align(__first, __last);
271 __first = __spec._M_parse_width(__first, __last, __pc);
275 if (__parts & _ChronoParts::_Duration)
277 __first = __spec._M_parse_precision(__first, __last, __pc);
282 __first = __spec._M_parse_locale(__first, __last);
289 __string_view __str(__first, __last - __first);
290 auto __end = __str.find(
'}');
291 if (__end != __str.npos)
293 __str.remove_suffix(__str.length() - __end);
294 __last = __first + __end;
296 if (__str.find(
'{') != __str.npos)
297 __throw_format_error(
"chrono format error: '{' in chrono-specs");
304 const auto __chrono_specs = __first++;
305 if (*__chrono_specs !=
'%')
306 __throw_format_error(
"chrono format error: no '%' at start of "
313 while (__first != __last)
315 enum _Mods { _Mod_none, _Mod_E, _Mod_O, _Mod_E_O };
316 _Mods __allowed_mods = _Mod_none;
318 _CharT __c = *__first++;
331 __needed = _DateTime;
332 __allowed_mods = _Mod_E;
336 __allowed_mods = _Mod_E;
341 __allowed_mods = _Mod_O;
353 __needed = _TimeOfDay;
354 __allowed_mods = _Mod_O;
357 if (!(__parts & _Duration))
362 __allowed_mods = _Mod_O;
365 __needed = _TimeOfDay;
366 __allowed_mods = _Mod_O;
372 __needed = _TimeOfDay;
376 __needed = _Duration;
379 __needed = _TimeOfDay;
380 __allowed_mods = _Mod_O;
385 __allowed_mods = _Mod_O;
391 __allowed_mods = _Mod_O;
395 __allowed_mods = _Mod_E;
398 __needed = _TimeOfDay;
399 __allowed_mods = _Mod_E;
403 __allowed_mods = _Mod_E_O;
407 __allowed_mods = _Mod_E;
410 __needed = _TimeZone;
411 __allowed_mods = _Mod_E_O;
414 __needed = _TimeZone;
422 if (__mod) [[unlikely]]
424 __allowed_mods = _Mod_none;
430 __throw_format_error(
"chrono format error: invalid "
431 " specifier in chrono-specs");
434 if ((__mod ==
'E' && !(__allowed_mods & _Mod_E))
435 || (__mod ==
'O' && !(__allowed_mods & _Mod_O)))
436 __throw_format_error(
"chrono format error: invalid "
437 " modifier in chrono-specs");
440 if ((__parts & __needed) != __needed)
441 __throw_format_error(
"chrono format error: format argument "
442 "does not contain the information "
443 "required by the chrono-specs");
446 size_t __pos = __string_view(__first, __last - __first).find(
'%');
451 if (__pos == __string_view::npos)
457 __first += __pos + 1;
462 if (__conv || __mod != _CharT())
463 __throw_format_error(
"chrono format error: unescaped '%' in "
467 _M_spec._M_chrono_specs
468 = __string_view(__chrono_specs, __first - __chrono_specs);
478 template<
typename _Tp,
typename _FormatContext>
479 typename _FormatContext::iterator
480 _M_format(
const _Tp& __t, _FormatContext& __fc,
481 bool __is_neg =
false)
const
483 auto __first = _M_spec._M_chrono_specs.begin();
484 const auto __last = _M_spec._M_chrono_specs.end();
485 if (__first == __last)
486 return _M_format_to_ostream(__t, __fc, __is_neg);
488 _Sink_iter<_CharT> __out;
489 __format::_Str_sink<_CharT> __sink;
490 bool __write_direct =
false;
491 if constexpr (is_same_v<
typename _FormatContext::iterator,
494 if (_M_spec._M_width_kind == __format::_WP_none)
497 __write_direct =
true;
500 __out = __sink.out();
503 __out = __sink.out();
507 if constexpr (__is_specialization_of<_Tp, chrono::hh_mm_ss>)
508 __is_neg = __t.is_negative();
510 auto __print_sign = [&__is_neg, &__out] {
511 if constexpr (chrono::__is_duration_v<_Tp>
512 || __is_specialization_of<_Tp, chrono::hh_mm_ss>)
515 *__out++ = _S_plus_minus[1];
522 constexpr const _CharT* __literals = _GLIBCXX_WIDEN(
"\n\t%");
529 _CharT __c = *__first++;
534 __out = _M_a_A(__t,
std::move(__out), __fc, __c ==
'A');
539 __out = _M_b_B(__t,
std::move(__out), __fc, __c ==
'B');
542 __out = _M_c(__t,
std::move(__out), __fc, __mod ==
'E');
547 __out = _M_C_y_Y(__t,
std::move(__out), __fc, __c, __mod);
551 __out = _M_d_e(__t,
std::move(__out), __fc, __c, __mod ==
'O');
554 __out = _M_D(__t,
std::move(__out), __fc);
557 __out = _M_F(__t,
std::move(__out), __fc);
561 __out = _M_g_G(__t,
std::move(__out), __fc, __c ==
'G');
565 __out = _M_H_I(__t, __print_sign(), __fc, __c, __mod ==
'O');
568 __out = _M_j(__t, __print_sign(), __fc);
571 __out = _M_m(__t,
std::move(__out), __fc, __mod ==
'O');
574 __out = _M_M(__t, __print_sign(), __fc, __mod ==
'O');
577 __out = _M_p(__t,
std::move(__out), __fc);
580 __out = _M_q(__t,
std::move(__out), __fc);
584 if constexpr (chrono::__is_duration_v<_Tp>)
585 __out = std::format_to(__print_sign(), _S_empty_spec,
588 __throw_format_error(
"chrono format error: argument is "
592 __out = _M_r(__t, __print_sign(), __fc);
596 __out = _M_R_T(__t, __print_sign(), __fc, __c ==
'T');
599 __out = _M_S(__t, __print_sign(), __fc, __mod ==
'O');
603 __out = _M_u_w(__t,
std::move(__out), __fc, __c, __mod ==
'O');
608 __out = _M_U_V_W(__t,
std::move(__out), __fc, __c,
612 __out = _M_x(__t,
std::move(__out), __fc, __mod ==
'E');
615 __out = _M_X(__t, __print_sign(), __fc, __mod ==
'E');
618 __out = _M_z(__t,
std::move(__out), __fc, (
bool)__mod);
621 __out = _M_Z(__t,
std::move(__out), __fc);
624 *__out++ = __literals[0];
627 *__out++ = __literals[1];
630 *__out++ = __literals[2];
642 __string_view __str(__first, __last - __first);
643 size_t __pos = __str.find(
'%');
648 if (__pos == __str.npos)
652 __str.remove_suffix(__str.length() - __pos);
653 __first += __pos + 1;
655 __out = __format::__write(
std::move(__out), __str);
658 while (__first != __last);
660 if constexpr (is_same_v<
typename _FormatContext::iterator,
666 return __format::__write_padded_as_spec(__str, __str.size(),
670 _ChronoSpec<_CharT> _M_spec;
674 template<
typename _FormatContext>
676 _M_locale(_FormatContext& __fc)
const
678 if (!_M_spec._M_localized)
681 return __fc.locale();
689 template<
typename _Tp,
typename _FormatContext>
690 typename _FormatContext::iterator
691 _M_format_to_ostream(
const _Tp& __t, _FormatContext& __fc,
694 using ::std::chrono::__detail::__utc_leap_second;
695 using ::std::chrono::__detail::__local_time_fmt;
697 if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
698 return _M_format_to_ostream(__t._M_time, __fc,
false);
701 basic_ostringstream<_CharT> __os;
702 __os.imbue(_M_locale(__fc));
704 if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
705 __os << __t._M_date <<
' ' << __t._M_time;
706 else if constexpr (chrono::__is_time_point_v<_Tp>)
713 if constexpr (is_convertible_v<_Tp, chrono::sys_days>)
714 __os << _S_date(__t);
717 auto __days = chrono::floor<chrono::days>(__t);
718 __os << chrono::year_month_day(__days) <<
' '
719 << chrono::hh_mm_ss(__t - __days);
724 if constexpr (chrono::__is_duration_v<_Tp>)
725 if (__is_neg) [[unlikely]]
726 __os << _S_plus_minus[1];
731 return __format::__write_padded_as_spec(__str, __str.size(),
736 static constexpr const _CharT* _S_chars
737 = _GLIBCXX_WIDEN(
"0123456789+-:/ {}");
738 static constexpr const _CharT* _S_plus_minus = _S_chars + 10;
739 static constexpr _CharT _S_colon = _S_chars[12];
740 static constexpr _CharT _S_slash = _S_chars[13];
741 static constexpr _CharT _S_space = _S_chars[14];
742 static constexpr const _CharT* _S_empty_spec = _S_chars + 15;
744 template<
typename _Tp,
typename _FormatContext>
745 typename _FormatContext::iterator
746 _M_a_A(
const _Tp& __t,
typename _FormatContext::iterator __out,
747 _FormatContext& __ctx,
bool __full)
const
751 chrono::weekday __wd = _S_weekday(__t);
753 __throw_format_error(
"format error: invalid weekday");
755 locale __loc = _M_locale(__ctx);
756 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
757 const _CharT* __days[7];
759 __tp._M_days(__days);
761 __tp._M_days_abbreviated(__days);
762 __string_view __str(__days[__wd.c_encoding()]);
763 return __format::__write(
std::move(__out), __str);
766 template<
typename _Tp,
typename _FormatContext>
767 typename _FormatContext::iterator
768 _M_b_B(
const _Tp& __t,
typename _FormatContext::iterator __out,
769 _FormatContext& __ctx,
bool __full)
const
773 chrono::month __m = _S_month(__t);
775 __throw_format_error(
"format error: invalid month");
776 locale __loc = _M_locale(__ctx);
777 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
778 const _CharT* __months[12];
780 __tp._M_months(__months);
782 __tp._M_months_abbreviated(__months);
783 __string_view __str(__months[(
unsigned)__m - 1]);
784 return __format::__write(
std::move(__out), __str);
787 template<
typename _Tp,
typename _FormatContext>
788 typename _FormatContext::iterator
789 _M_c(
const _Tp& __tt,
typename _FormatContext::iterator __out,
790 _FormatContext& __ctx,
bool __mod =
false)
const
795 auto __t = _S_floor_seconds(__tt);
796 locale __loc = _M_locale(__ctx);
797 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
798 const _CharT* __formats[2];
799 __tp._M_date_time_formats(__formats);
800 const _CharT* __rep = __formats[__mod];
802 __rep = _GLIBCXX_WIDEN(
"%a %b %e %H:%M:%S %Y");
803 basic_string<_CharT> __fmt(_S_empty_spec);
804 __fmt.insert(1u, 1u, _S_colon);
805 __fmt.insert(2u, __rep);
806 return std::vformat_to(
std::move(__out), __loc, __fmt,
807 std::make_format_args<_FormatContext>(__t));
810 template<
typename _Tp,
typename _FormatContext>
811 typename _FormatContext::iterator
812 _M_C_y_Y(
const _Tp& __t,
typename _FormatContext::iterator __out,
813 _FormatContext& __ctx, _CharT __conv, _CharT __mod = 0)
const
823 chrono::year __y = _S_year(__t);
825 if (__mod) [[unlikely]]
828 __tm.tm_year = (int)__y - 1900;
829 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
833 basic_string<_CharT> __s;
835 const bool __is_neg = __yi < 0;
836 __yi = __builtin_abs(__yi);
838 if (__conv ==
'Y' || __conv ==
'C')
840 int __ci = __yi / 100;
841 if (__is_neg) [[unlikely]]
843 __s.assign(1, _S_plus_minus[1]);
845 if (__conv ==
'C' && (__ci * 100) != __yi)
848 if (__ci >= 100) [[unlikely]]
850 __s += std::format(_S_empty_spec, __ci / 100);
853 __s += _S_two_digits(__ci);
856 if (__conv ==
'Y' || __conv ==
'y')
857 __s += _S_two_digits(__yi % 100);
859 return __format::__write(
std::move(__out), __string_view(__s));
862 template<
typename _Tp,
typename _FormatContext>
863 typename _FormatContext::iterator
864 _M_D(
const _Tp& __t,
typename _FormatContext::iterator __out,
865 _FormatContext&)
const
867 auto __ymd = _S_date(__t);
868 basic_string<_CharT> __s;
869#if ! _GLIBCXX_USE_CXX11_ABI
872 __s = _S_two_digits((
unsigned)__ymd.month());
874 __s += _S_two_digits((
unsigned)__ymd.day());
876 __s += _S_two_digits(__builtin_abs((
int)__ymd.year()) % 100);
877 return __format::__write(
std::move(__out), __string_view(__s));
880 template<
typename _Tp,
typename _FormatContext>
881 typename _FormatContext::iterator
882 _M_d_e(
const _Tp& __t,
typename _FormatContext::iterator __out,
883 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
890 chrono::day __d = _S_day(__t);
891 unsigned __i = (unsigned)__d;
893 if (__mod) [[unlikely]]
897 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
901 auto __sv = _S_two_digits(__i);
903 if (__conv == _CharT(
'e') && __i < 10)
909 return __format::__write(
std::move(__out), __sv);
912 template<
typename _Tp,
typename _FormatContext>
913 typename _FormatContext::iterator
914 _M_F(
const _Tp& __t,
typename _FormatContext::iterator __out,
915 _FormatContext&)
const
917 auto __ymd = _S_date(__t);
918 auto __s = std::format(_GLIBCXX_WIDEN(
"{:04d}- - "),
920 auto __sv = _S_two_digits((
unsigned)__ymd.month());
921 __s[__s.size() - 5] = __sv[0];
922 __s[__s.size() - 4] = __sv[1];
923 __sv = _S_two_digits((
unsigned)__ymd.day());
924 __s[__s.size() - 2] = __sv[0];
925 __s[__s.size() - 1] = __sv[1];
927 return __format::__write(
std::move(__out), __sv);
930 template<
typename _Tp,
typename _FormatContext>
931 typename _FormatContext::iterator
932 _M_g_G(
const _Tp& __t,
typename _FormatContext::iterator __out,
933 _FormatContext& __ctx,
bool __full)
const
937 using namespace chrono;
938 auto __d = _S_days(__t);
940 __d -= (weekday(__d) - Monday) -
days(3);
942 year __y = year_month_day(__d).year();
943 return _M_C_y_Y(__y,
std::move(__out), __ctx,
"yY"[__full]);
946 template<
typename _Tp,
typename _FormatContext>
947 typename _FormatContext::iterator
948 _M_H_I(
const _Tp& __t,
typename _FormatContext::iterator __out,
949 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
956 const auto __hms = _S_hms(__t);
957 int __i = __hms.hours().count();
959 if (__mod) [[unlikely]]
963 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
967 if (__conv == _CharT(
'I'))
974 return __format::__write(
std::move(__out), _S_two_digits(__i));
977 template<
typename _Tp,
typename _FormatContext>
978 typename _FormatContext::iterator
979 _M_j(
const _Tp& __t,
typename _FormatContext::iterator __out,
980 _FormatContext&)
const
982 if constexpr (chrono::__is_duration_v<_Tp>)
985 unsigned __d = chrono::duration_cast<chrono::days>(__t).count();
986 return std::format_to(
std::move(__out), _S_empty_spec, __d);
991 using namespace chrono;
992 auto __day = _S_days(__t);
993 auto __ymd = _S_date(__t);
997 if constexpr (is_same_v<
typename decltype(__day)::clock, local_t>)
998 __d = __day - local_days(__ymd.year()/January/0);
1000 __d = __day - sys_days(__ymd.year()/January/0);
1001 return std::format_to(
std::move(__out), _GLIBCXX_WIDEN(
"{:03d}"),
1006 template<
typename _Tp,
typename _FormatContext>
1007 typename _FormatContext::iterator
1008 _M_m(
const _Tp& __t,
typename _FormatContext::iterator __out,
1009 _FormatContext& __ctx,
bool __mod)
const
1014 auto __m = _S_month(__t);
1015 auto __i = (unsigned)__m;
1017 if (__mod) [[unlikely]]
1020 __tm.tm_mon = __i - 1;
1021 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
1025 return __format::__write(
std::move(__out), _S_two_digits(__i));
1028 template<
typename _Tp,
typename _FormatContext>
1029 typename _FormatContext::iterator
1030 _M_M(
const _Tp& __t,
typename _FormatContext::iterator __out,
1031 _FormatContext& __ctx,
bool __mod)
const
1036 auto __m = _S_hms(__t).minutes();
1037 auto __i = __m.count();
1039 if (__mod) [[unlikely]]
1043 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
1047 return __format::__write(
std::move(__out), _S_two_digits(__i));
1050 template<
typename _Tp,
typename _FormatContext>
1051 typename _FormatContext::iterator
1052 _M_p(
const _Tp& __t,
typename _FormatContext::iterator __out,
1053 _FormatContext& __ctx)
const
1056 auto __hms = _S_hms(__t);
1057 locale __loc = _M_locale(__ctx);
1058 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1059 const _CharT* __ampm[2];
1060 __tp._M_am_pm(__ampm);
1061 return std::format_to(
std::move(__out), _S_empty_spec,
1062 __ampm[__hms.hours().count() >= 12]);
1065 template<
typename _Tp,
typename _FormatContext>
1066 typename _FormatContext::iterator
1067 _M_q(
const _Tp&,
typename _FormatContext::iterator __out,
1068 _FormatContext&)
const
1071 if constexpr (!chrono::__is_duration_v<_Tp>)
1072 __throw_format_error(
"format error: argument is not a duration");
1075 namespace __d = chrono::__detail;
1076 using period =
typename _Tp::period;
1077 return __d::__fmt_units_suffix<period, _CharT>(
std::move(__out));
1083 template<
typename _Tp,
typename _FormatContext>
1084 typename _FormatContext::iterator
1085 _M_r(
const _Tp& __tt,
typename _FormatContext::iterator __out,
1086 _FormatContext& __ctx)
const
1089 auto __t = _S_floor_seconds(__tt);
1090 locale __loc = _M_locale(__ctx);
1091 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1092 const _CharT* __ampm_fmt;
1093 __tp._M_am_pm_format(&__ampm_fmt);
1094 basic_string<_CharT> __fmt(_S_empty_spec);
1095 __fmt.insert(1u, 1u, _S_colon);
1096 __fmt.insert(2u, __ampm_fmt);
1097 return std::vformat_to(
std::move(__out), __fmt,
1098 std::make_format_args<_FormatContext>(__t));
1101 template<
typename _Tp,
typename _FormatContext>
1102 typename _FormatContext::iterator
1103 _M_R_T(
const _Tp& __t,
typename _FormatContext::iterator __out,
1104 _FormatContext& __ctx,
bool __secs)
const
1108 auto __hms = _S_hms(__t);
1110 auto __s = std::format(_GLIBCXX_WIDEN(
"{:02d}:00"),
1111 __hms.hours().count());
1112 auto __sv = _S_two_digits(__hms.minutes().count());
1113 __s[__s.size() - 2] = __sv[0];
1114 __s[__s.size() - 1] = __sv[1];
1116 __out = __format::__write(
std::move(__out), __sv);
1119 *__out++ = _S_colon;
1120 __out = _M_S(__hms,
std::move(__out), __ctx);
1125 template<
typename _Tp,
typename _FormatContext>
1126 typename _FormatContext::iterator
1127 _M_S(
const _Tp& __t,
typename _FormatContext::iterator __out,
1128 _FormatContext& __ctx,
bool __mod =
false)
const
1132 auto __hms = _S_hms(__t);
1134 if (__mod) [[unlikely]]
1137 __tm.tm_sec = (int)__hms.seconds().count();
1138 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
1142 if constexpr (__hms.fractional_width == 0)
1143 __out = __format::__write(
std::move(__out),
1144 _S_two_digits(__hms.seconds().count()));
1147 locale __loc = _M_locale(__ctx);
1148 auto __s = __hms.seconds();
1149 auto __ss = __hms.subseconds();
1150 using rep =
typename decltype(__ss)::rep;
1151 if constexpr (is_floating_point_v<rep>)
1153 chrono::duration<rep> __fs = __s + __ss;
1154 __out = std::format_to(
std::move(__out), __loc,
1155 _GLIBCXX_WIDEN(
"{:#0{}.{}Lf}"),
1157 3 + __hms.fractional_width,
1158 __hms.fractional_width);
1163 = use_facet<numpunct<_CharT>>(__loc);
1164 __out = __format::__write(
std::move(__out),
1165 _S_two_digits(__s.count()));
1166 *__out++ = __np.decimal_point();
1167 if constexpr (is_integral_v<rep>)
1168 __out = std::format_to(
std::move(__out),
1169 _GLIBCXX_WIDEN(
"{:0{}}"),
1171 __hms.fractional_width);
1174 auto __str = std::format(_S_empty_spec, __ss.count());
1175 __out = std::format_to(_GLIBCXX_WIDEN(
"{:0>{}s}"),
1177 __hms.fractional_width);
1186 template<
typename _Tp,
typename _FormatContext>
1187 typename _FormatContext::iterator
1188 _M_u_w(
const _Tp& __t,
typename _FormatContext::iterator __out,
1189 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
1196 chrono::weekday __wd = _S_weekday(__t);
1198 if (__mod) [[unlikely]]
1201 __tm.tm_wday = __wd.c_encoding();
1202 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
1206 unsigned __wdi = __conv ==
'u' ? __wd.iso_encoding()
1207 : __wd.c_encoding();
1208 const _CharT __d = _S_digit(__wdi);
1209 return __format::__write(
std::move(__out), __string_view(&__d, 1));
1212 template<
typename _Tp,
typename _FormatContext>
1213 typename _FormatContext::iterator
1214 _M_U_V_W(
const _Tp& __t,
typename _FormatContext::iterator __out,
1215 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
1223 using namespace chrono;
1224 auto __d = _S_days(__t);
1225 using _TDays =
decltype(__d);
1227 if (__mod) [[unlikely]]
1229 const year_month_day __ymd(__d);
1230 const year __y = __ymd.year();
1232 __tm.tm_year = (int)__y - 1900;
1233 __tm.tm_yday = (__d - _TDays(__y/January/1)).count();
1234 __tm.tm_wday = weekday(__d).c_encoding();
1235 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
1243 __d -= (weekday(__d) - Monday) -
days(3);
1246 __first = _TDays(year_month_day(__d).year()/January/1);
1251 if constexpr (
requires { __t.year(); })
1254 __y = year_month_day(__d).year();
1255 const weekday __weekstart = __conv ==
'U' ? Sunday : Monday;
1256 __first = _TDays(__y/January/__weekstart[1]);
1258 auto __weeks = chrono::floor<weeks>(__d - __first);
1259 __string_view __sv = _S_two_digits(__weeks.count() + 1);
1260 return __format::__write(
std::move(__out), __sv);
1263 template<
typename _Tp,
typename _FormatContext>
1264 typename _FormatContext::iterator
1265 _M_x(
const _Tp& __t,
typename _FormatContext::iterator __out,
1266 _FormatContext& __ctx,
bool __mod =
false)
const
1270 locale __loc = _M_locale(__ctx);
1271 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1272 const _CharT* __date_reps[2];
1273 __tp._M_date_formats(__date_reps);
1274 const _CharT* __rep = __date_reps[__mod];
1276 return _M_D(__t,
std::move(__out), __ctx);
1278 basic_string<_CharT> __fmt(_S_empty_spec);
1279 __fmt.insert(1u, 1u, _S_colon);
1280 __fmt.insert(2u, __rep);
1281 return std::vformat_to(
std::move(__out), __fmt,
1282 std::make_format_args<_FormatContext>(__t));
1285 template<
typename _Tp,
typename _FormatContext>
1286 typename _FormatContext::iterator
1287 _M_X(
const _Tp& __tt,
typename _FormatContext::iterator __out,
1288 _FormatContext& __ctx,
bool __mod =
false)
const
1292 auto __t = _S_floor_seconds(__tt);
1293 locale __loc = _M_locale(__ctx);
1294 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1295 const _CharT* __time_reps[2];
1296 __tp._M_time_formats(__time_reps);
1297 const _CharT* __rep = __time_reps[__mod];
1299 return _M_R_T(__t,
std::move(__out), __ctx,
true);
1301 basic_string<_CharT> __fmt(_S_empty_spec);
1302 __fmt.insert(1u, 1u, _S_colon);
1303 __fmt.insert(2u, __rep);
1304 return std::vformat_to(
std::move(__out), __fmt,
1305 std::make_format_args<_FormatContext>(__t));
1308 template<
typename _Tp,
typename _FormatContext>
1309 typename _FormatContext::iterator
1310 _M_z(
const _Tp& __t,
typename _FormatContext::iterator __out,
1311 _FormatContext&,
bool __mod =
false)
const
1313 using ::std::chrono::__detail::__utc_leap_second;
1314 using ::std::chrono::__detail::__local_time_fmt;
1316 auto __utc = __mod ? __string_view(_GLIBCXX_WIDEN(
"+00:00"), 6)
1317 : __string_view(_GLIBCXX_WIDEN(
"+0000"), 5);
1319 if constexpr (chrono::__is_time_point_v<_Tp>)
1321 if constexpr (is_same_v<
typename _Tp::clock,
1322 chrono::system_clock>)
1323 return __format::__write(
std::move(__out), __utc);
1325 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1327 if (__t._M_offset_sec)
1330 basic_string<_CharT> __s;
1331 if (*__t._M_offset_sec != 0s)
1333 chrono:: hh_mm_ss __hms(*__t._M_offset_sec);
1334 __s = _S_plus_minus[__hms.is_negative()];
1335 __s += _S_two_digits(__hms.hours().count());
1338 __s += _S_two_digits(__hms.minutes().count());
1341 return __format::__write(
std::move(__out), __sv);
1344 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1345 return __format::__write(
std::move(__out), __utc);
1347 __no_timezone_available();
1350 template<
typename _Tp,
typename _FormatContext>
1351 typename _FormatContext::iterator
1352 _M_Z(
const _Tp& __t,
typename _FormatContext::iterator __out,
1353 _FormatContext& __ctx)
const
1355 using ::std::chrono::__detail::__utc_leap_second;
1356 using ::std::chrono::__detail::__local_time_fmt;
1358 __string_view __utc(_GLIBCXX_WIDEN(
"UTC"), 3);
1359 if constexpr (chrono::__is_time_point_v<_Tp>)
1361 if constexpr (is_same_v<
typename _Tp::clock,
1362 chrono::system_clock>)
1363 return __format::__write(
std::move(__out), __utc);
1365 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1369 string_view __sv = *__t._M_abbrev;
1370 if constexpr (is_same_v<_CharT, char>)
1371 return __format::__write(
std::move(__out), __sv);
1375 basic_string<_CharT> __ws(__sv.size(), _CharT());
1376 auto& __ct = use_facet<ctype<_CharT>>(_M_locale(__ctx));
1377 __ct.widen(__sv.begin(), __sv.end(), __ws.data());
1378 __string_view __wsv = __ws;
1379 return __format::__write(
std::move(__out), __wsv);
1383 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1384 return __format::__write(
std::move(__out), __utc);
1386 __no_timezone_available();
1393 _S_digit(
int __n)
noexcept
1396 return _GLIBCXX_WIDEN(
"0123456789999999")[__n & 0xf];
1400 static basic_string_view<_CharT>
1401 _S_two_digits(
int __n)
noexcept
1404 _GLIBCXX_WIDEN(
"0001020304050607080910111213141516171819"
1405 "2021222324252627282930313233343536373839"
1406 "4041424344454647484950515253545556575859"
1407 "6061626364656667686970717273747576777879"
1408 "8081828384858687888990919293949596979899"
1409 "9999999999999999999999999999999999999999"
1410 "9999999999999999") + 2 * (__n & 0x7f),
1418 template<
typename _Tp>
1419 static decltype(
auto)
1420 _S_hms(
const _Tp& __t)
1422 using ::std::chrono::__detail::__utc_leap_second;
1423 using ::std::chrono::__detail::__local_time_fmt;
1425 if constexpr (__is_specialization_of<_Tp, chrono::hh_mm_ss>)
1427 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1429 else if constexpr (chrono::__is_duration_v<_Tp>)
1430 return chrono::hh_mm_ss<_Tp>(__t);
1431 else if constexpr (chrono::__is_time_point_v<_Tp>)
1432 return chrono::hh_mm_ss(__t - chrono::floor<chrono::days>(__t));
1433 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1434 return _S_hms(__t._M_time);
1437 __invalid_chrono_spec();
1438 return chrono::hh_mm_ss<chrono::seconds>();
1443 template<
typename _Tp>
1445 _S_days(
const _Tp& __t)
1447 using namespace chrono;
1448 using ::std::chrono::__detail::__utc_leap_second;
1449 using ::std::chrono::__detail::__local_time_fmt;
1451 if constexpr (__is_time_point_v<_Tp>)
1452 return chrono::floor<days>(__t);
1453 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1455 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1456 return chrono::floor<days>(__t._M_time);
1457 else if constexpr (is_same_v<_Tp, year_month_day>
1458 || is_same_v<_Tp, year_month_day_last>
1459 || is_same_v<_Tp, year_month_weekday>
1460 || is_same_v<_Tp, year_month_weekday_last>)
1461 return sys_days(__t);
1464 if constexpr (__is_duration_v<_Tp>)
1465 __not_valid_for_duration();
1467 __invalid_chrono_spec();
1468 return chrono::sys_days();
1473 template<
typename _Tp>
1474 static chrono::year_month_day
1475 _S_date(
const _Tp& __t)
1477 if constexpr (is_same_v<_Tp, chrono::year_month_day>)
1480 return chrono::year_month_day(_S_days(__t));
1483 template<
typename _Tp>
1485 _S_day(
const _Tp& __t)
1487 using namespace chrono;
1489 if constexpr (is_same_v<_Tp, day>)
1491 else if constexpr (
requires { __t.day(); })
1494 return _S_date(__t).day();
1497 template<
typename _Tp>
1498 static chrono::month
1499 _S_month(
const _Tp& __t)
1501 using namespace chrono;
1503 if constexpr (is_same_v<_Tp, month>)
1505 else if constexpr (
requires { __t.month(); })
1508 return _S_date(__t).month();
1511 template<
typename _Tp>
1513 _S_year(
const _Tp& __t)
1515 using namespace chrono;
1517 if constexpr (is_same_v<_Tp, year>)
1519 else if constexpr (
requires { __t.year(); })
1522 return _S_date(__t).year();
1525 template<
typename _Tp>
1526 static chrono::weekday
1527 _S_weekday(
const _Tp& __t)
1530 using ::std::chrono::__detail::__local_time_fmt;
1532 if constexpr (is_same_v<_Tp, weekday>)
1534 else if constexpr (
requires { __t.weekday(); })
1536 else if constexpr (is_same_v<_Tp, month_weekday>)
1537 return __t.weekday_indexed().weekday();
1538 else if constexpr (is_same_v<_Tp, month_weekday_last>)
1539 return __t.weekday_last().weekday();
1541 return weekday(_S_days(__t));
1545 template<
typename _Tp>
1547 _S_floor_seconds(
const _Tp& __t)
1549 using chrono::__detail::__local_time_fmt;
1550 if constexpr (chrono::__is_time_point_v<_Tp>
1551 || chrono::__is_duration_v<_Tp>)
1553 if constexpr (_Tp::period::den != 1)
1554 return chrono::floor<chrono::seconds>(__t);
1558 else if constexpr (__is_specialization_of<_Tp, chrono::hh_mm_ss>)
1560 if constexpr (_Tp::fractional_width != 0)
1561 return chrono::floor<chrono::seconds>(__t.to_duration());
1565 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1566 return _S_floor_seconds(__t._M_time);
1573 template<
typename _Iter>
1575 _M_locale_fmt(_Iter __out,
const locale& __loc,
const struct tm& __tm,
1576 char __fmt,
char __mod)
const
1578 basic_ostringstream<_CharT> __os;
1579 const auto& __tp = use_facet<time_put<_CharT>>(__loc);
1580 __tp.put(__os, __os, _S_space, &__tm, __fmt, __mod);
1582 __out = __format::__write(
std::move(__out), __os.view());
1590 template<
typename _Rep,
typename _Period,
typename _CharT>
1591 struct formatter<chrono::duration<_Rep, _Period>, _CharT>
1593 constexpr typename basic_format_parse_context<_CharT>::iterator
1594 parse(basic_format_parse_context<_CharT>& __pc)
1596 using namespace __format;
1597 auto __it = _M_f._M_parse(__pc, _Duration|_TimeOfDay);
1598 if constexpr (!is_floating_point_v<_Rep>)
1599 if (_M_f._M_spec._M_prec_kind != __format::_WP_none)
1600 __throw_format_error(
"format error: invalid precision for duration");
1604 template<
typename _Out>
1605 typename basic_format_context<_Out, _CharT>::iterator
1606 format(
const chrono::duration<_Rep, _Period>& __d,
1607 basic_format_context<_Out, _CharT>& __fc)
const
1609 return _M_f._M_format(chrono::abs(__d), __fc, __d < __d.zero());
1613 __format::__formatter_chrono<_CharT> _M_f;
1616 template<
typename _CharT>
1617 struct formatter<chrono::day, _CharT>
1619 template<
typename _ParseContext>
1620 constexpr typename _ParseContext::iterator
1621 parse(_ParseContext& __pc)
1622 {
return _M_f._M_parse(__pc, __format::_Day); }
1624 template<
typename _FormatContext>
1625 typename _FormatContext::iterator
1626 format(
const chrono::day& __t, _FormatContext& __fc)
const
1627 {
return _M_f._M_format(__t, __fc); }
1630 __format::__formatter_chrono<_CharT> _M_f;
1633 template<
typename _CharT>
1634 struct formatter<chrono::month, _CharT>
1636 template<
typename _ParseContext>
1637 constexpr typename _ParseContext::iterator
1638 parse(_ParseContext& __pc)
1639 {
return _M_f._M_parse(__pc, __format::_Month); }
1641 template<
typename _FormatContext>
1642 typename _FormatContext::iterator
1643 format(
const chrono::month& __t, _FormatContext& __fc)
const
1644 {
return _M_f._M_format(__t, __fc); }
1647 __format::__formatter_chrono<_CharT> _M_f;
1650 template<
typename _CharT>
1651 struct formatter<chrono::year, _CharT>
1653 template<
typename _ParseContext>
1654 constexpr typename _ParseContext::iterator
1655 parse(_ParseContext& __pc)
1656 {
return _M_f._M_parse(__pc, __format::_Year); }
1658 template<
typename _FormatContext>
1659 typename _FormatContext::iterator
1660 format(
const chrono::year& __t, _FormatContext& __fc)
const
1661 {
return _M_f._M_format(__t, __fc); }
1664 __format::__formatter_chrono<_CharT> _M_f;
1667 template<
typename _CharT>
1668 struct formatter<chrono::weekday, _CharT>
1670 template<
typename _ParseContext>
1671 constexpr typename _ParseContext::iterator
1672 parse(_ParseContext& __pc)
1673 {
return _M_f._M_parse(__pc, __format::_Weekday); }
1675 template<
typename _FormatContext>
1676 typename _FormatContext::iterator
1677 format(
const chrono::weekday& __t, _FormatContext& __fc)
const
1678 {
return _M_f._M_format(__t, __fc); }
1681 __format::__formatter_chrono<_CharT> _M_f;
1684 template<
typename _CharT>
1685 struct formatter<chrono::weekday_indexed, _CharT>
1687 template<
typename _ParseContext>
1688 constexpr typename _ParseContext::iterator
1689 parse(_ParseContext& __pc)
1690 {
return _M_f._M_parse(__pc, __format::_Weekday); }
1692 template<
typename _FormatContext>
1693 typename _FormatContext::iterator
1694 format(
const chrono::weekday_indexed& __t, _FormatContext& __fc)
const
1695 {
return _M_f._M_format(__t, __fc); }
1698 __format::__formatter_chrono<_CharT> _M_f;
1701 template<
typename _CharT>
1702 struct formatter<chrono::weekday_last, _CharT>
1704 template<
typename _ParseContext>
1705 constexpr typename _ParseContext::iterator
1706 parse(_ParseContext& __pc)
1707 {
return _M_f._M_parse(__pc, __format::_Weekday); }
1709 template<
typename _FormatContext>
1710 typename _FormatContext::iterator
1711 format(
const chrono::weekday_last& __t, _FormatContext& __fc)
const
1712 {
return _M_f._M_format(__t, __fc); }
1715 __format::__formatter_chrono<_CharT> _M_f;
1718 template<
typename _CharT>
1719 struct formatter<chrono::month_day, _CharT>
1721 template<
typename _ParseContext>
1722 constexpr typename _ParseContext::iterator
1723 parse(_ParseContext& __pc)
1724 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Day); }
1726 template<
typename _FormatContext>
1727 typename _FormatContext::iterator
1728 format(
const chrono::month_day& __t, _FormatContext& __fc)
const
1729 {
return _M_f._M_format(__t, __fc); }
1732 __format::__formatter_chrono<_CharT> _M_f;
1735 template<
typename _CharT>
1736 struct formatter<chrono::month_day_last, _CharT>
1738 template<
typename _ParseContext>
1739 constexpr typename _ParseContext::iterator
1740 parse(_ParseContext& __pc)
1741 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Day); }
1743 template<
typename _FormatContext>
1744 typename _FormatContext::iterator
1745 format(
const chrono::month_day_last& __t, _FormatContext& __fc)
const
1746 {
return _M_f._M_format(__t, __fc); }
1749 __format::__formatter_chrono<_CharT> _M_f;
1752 template<
typename _CharT>
1753 struct formatter<chrono::month_weekday, _CharT>
1755 template<
typename _ParseContext>
1756 constexpr typename _ParseContext::iterator
1757 parse(_ParseContext& __pc)
1758 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Weekday); }
1760 template<
typename _FormatContext>
1761 typename _FormatContext::iterator
1762 format(
const chrono::month_weekday& __t, _FormatContext& __fc)
const
1763 {
return _M_f._M_format(__t, __fc); }
1766 __format::__formatter_chrono<_CharT> _M_f;
1769 template<
typename _CharT>
1770 struct formatter<chrono::month_weekday_last, _CharT>
1772 template<
typename _ParseContext>
1773 constexpr typename _ParseContext::iterator
1774 parse(_ParseContext& __pc)
1775 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Weekday); }
1777 template<
typename _FormatContext>
1778 typename _FormatContext::iterator
1779 format(
const chrono::month_weekday_last& __t,
1780 _FormatContext& __fc)
const
1781 {
return _M_f._M_format(__t, __fc); }
1784 __format::__formatter_chrono<_CharT> _M_f;
1787 template<
typename _CharT>
1788 struct formatter<chrono::year_month, _CharT>
1790 template<
typename _ParseContext>
1791 constexpr typename _ParseContext::iterator
1792 parse(_ParseContext& __pc)
1793 {
return _M_f._M_parse(__pc, __format::_Year|__format::_Month); }
1795 template<
typename _FormatContext>
1796 typename _FormatContext::iterator
1797 format(
const chrono::year_month& __t, _FormatContext& __fc)
const
1798 {
return _M_f._M_format(__t, __fc); }
1801 __format::__formatter_chrono<_CharT> _M_f;
1804 template<
typename _CharT>
1805 struct formatter<chrono::year_month_day, _CharT>
1807 template<
typename _ParseContext>
1808 constexpr typename _ParseContext::iterator
1809 parse(_ParseContext& __pc)
1810 {
return _M_f._M_parse(__pc, __format::_Date); }
1812 template<
typename _FormatContext>
1813 typename _FormatContext::iterator
1814 format(
const chrono::year_month_day& __t, _FormatContext& __fc)
const
1815 {
return _M_f._M_format(__t, __fc); }
1818 __format::__formatter_chrono<_CharT> _M_f;
1821 template<
typename _CharT>
1822 struct formatter<chrono::year_month_day_last, _CharT>
1824 template<
typename _ParseContext>
1825 constexpr typename _ParseContext::iterator
1826 parse(_ParseContext& __pc)
1827 {
return _M_f._M_parse(__pc, __format::_Date); }
1829 template<
typename _FormatContext>
1830 typename _FormatContext::iterator
1831 format(
const chrono::year_month_day_last& __t,
1832 _FormatContext& __fc)
const
1833 {
return _M_f._M_format(__t, __fc); }
1836 __format::__formatter_chrono<_CharT> _M_f;
1839 template<
typename _CharT>
1840 struct formatter<chrono::year_month_weekday, _CharT>
1842 template<
typename _ParseContext>
1843 constexpr typename _ParseContext::iterator
1844 parse(_ParseContext& __pc)
1845 {
return _M_f._M_parse(__pc, __format::_Date); }
1847 template<
typename _FormatContext>
1848 typename _FormatContext::iterator
1849 format(
const chrono::year_month_weekday& __t,
1850 _FormatContext& __fc)
const
1851 {
return _M_f._M_format(__t, __fc); }
1854 __format::__formatter_chrono<_CharT> _M_f;
1857 template<
typename _CharT>
1858 struct formatter<chrono::year_month_weekday_last, _CharT>
1860 template<
typename _ParseContext>
1861 constexpr typename _ParseContext::iterator
1862 parse(_ParseContext& __pc)
1863 {
return _M_f._M_parse(__pc, __format::_Date); }
1865 template<
typename _FormatContext>
1866 typename _FormatContext::iterator
1867 format(
const chrono::year_month_weekday_last& __t,
1868 _FormatContext& __fc)
const
1869 {
return _M_f._M_format(__t, __fc); }
1872 __format::__formatter_chrono<_CharT> _M_f;
1875 template<
typename _Rep,
typename _Period,
typename _CharT>
1876 struct formatter<chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>, _CharT>
1878 template<
typename _ParseContext>
1879 constexpr typename _ParseContext::iterator
1880 parse(_ParseContext& __pc)
1881 {
return _M_f._M_parse(__pc, __format::_TimeOfDay); }
1883 template<
typename _FormatContext>
1884 typename _FormatContext::iterator
1885 format(
const chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>& __t,
1886 _FormatContext& __fc)
const
1887 {
return _M_f._M_format(__t, __fc); }
1890 __format::__formatter_chrono<_CharT> _M_f;
1893#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
1894 template<
typename _CharT>
1895 struct formatter<chrono::sys_info, _CharT>
1897 template<
typename _ParseContext>
1898 constexpr typename _ParseContext::iterator
1899 parse(_ParseContext& __pc)
1900 {
return _M_f._M_parse(__pc, __format::_ChronoParts{}); }
1902 template<
typename _FormatContext>
1903 typename _FormatContext::iterator
1904 format(
const chrono::sys_info& __i, _FormatContext& __fc)
const
1905 {
return _M_f._M_format(__i, __fc); }
1908 __format::__formatter_chrono<_CharT> _M_f;
1911 template<
typename _CharT>
1912 struct formatter<chrono::local_info, _CharT>
1914 template<
typename _ParseContext>
1915 constexpr typename _ParseContext::iterator
1916 parse(_ParseContext& __pc)
1917 {
return _M_f._M_parse(__pc, __format::_ChronoParts{}); }
1919 template<
typename _FormatContext>
1920 typename _FormatContext::iterator
1921 format(
const chrono::local_info& __i, _FormatContext& __fc)
const
1922 {
return _M_f._M_format(__i, __fc); }
1925 __format::__formatter_chrono<_CharT> _M_f;
1929 template<
typename _Duration,
typename _CharT>
1930 struct formatter<chrono::sys_time<_Duration>, _CharT>
1932 template<
typename _ParseContext>
1933 constexpr typename _ParseContext::iterator
1934 parse(_ParseContext& __pc)
1936 auto __next = _M_f._M_parse(__pc, __format::_ZonedDateTime);
1937 if constexpr (!__stream_insertable)
1938 if (_M_f._M_spec._M_chrono_specs.empty())
1939 __format::__invalid_chrono_spec();
1943 template<
typename _FormatContext>
1944 typename _FormatContext::iterator
1945 format(
const chrono::sys_time<_Duration>& __t,
1946 _FormatContext& __fc)
const
1947 {
return _M_f._M_format(__t, __fc); }
1950 static constexpr bool __stream_insertable
1951 =
requires (basic_ostream<_CharT>& __os,
1952 chrono::sys_time<_Duration> __t) { __os << __t; };
1954 __format::__formatter_chrono<_CharT> _M_f;
1957 template<
typename _Duration,
typename _CharT>
1958 struct formatter<chrono::utc_time<_Duration>, _CharT>
1959 : __format::__formatter_chrono<_CharT>
1961 template<
typename _ParseContext>
1962 constexpr typename _ParseContext::iterator
1963 parse(_ParseContext& __pc)
1964 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
1966 template<
typename _FormatContext>
1967 typename _FormatContext::iterator
1968 format(
const chrono::utc_time<_Duration>& __t,
1969 _FormatContext& __fc)
const
1974 using chrono::__detail::__utc_leap_second;
1975 using chrono::seconds;
1976 using chrono::sys_time;
1977 using _CDur = common_type_t<_Duration, seconds>;
1978 const auto __li = chrono::get_leap_second_info(__t);
1979 sys_time<_CDur> __s{__t.time_since_epoch() - __li.elapsed};
1980 if (!__li.is_leap_second) [[likely]]
1981 return _M_f._M_format(__s, __fc);
1983 return _M_f._M_format(__utc_leap_second(__s), __fc);
1987 friend formatter<chrono::__detail::__utc_leap_second<_Duration>, _CharT>;
1989 __format::__formatter_chrono<_CharT> _M_f;
1992 template<
typename _Duration,
typename _CharT>
1993 struct formatter<chrono::tai_time<_Duration>, _CharT>
1994 : __format::__formatter_chrono<_CharT>
1996 template<
typename _ParseContext>
1997 constexpr typename _ParseContext::iterator
1998 parse(_ParseContext& __pc)
1999 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2001 template<
typename _FormatContext>
2002 typename _FormatContext::iterator
2003 format(
const chrono::tai_time<_Duration>& __t,
2004 _FormatContext& __fc)
const
2009 constexpr chrono::days __tai_offset = chrono::days(4383);
2010 using _CDur = common_type_t<_Duration, chrono::days>;
2011 chrono::local_time<_CDur> __lt(__t.time_since_epoch() - __tai_offset);
2012 const string __abbrev(
"TAI", 3);
2013 const chrono::seconds __off = 0s;
2014 const auto __lf = chrono::local_time_format(__lt, &__abbrev, &__off);
2015 return _M_f._M_format(__lf, __fc);
2019 __format::__formatter_chrono<_CharT> _M_f;
2022 template<
typename _Duration,
typename _CharT>
2023 struct formatter<chrono::gps_time<_Duration>, _CharT>
2024 : __format::__formatter_chrono<_CharT>
2026 template<
typename _ParseContext>
2027 constexpr typename _ParseContext::iterator
2028 parse(_ParseContext& __pc)
2029 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2031 template<
typename _FormatContext>
2032 typename _FormatContext::iterator
2033 format(
const chrono::gps_time<_Duration>& __t,
2034 _FormatContext& __fc)
const
2039 constexpr chrono::days __gps_offset = chrono::days(3657);
2040 using _CDur = common_type_t<_Duration, chrono::days>;
2041 chrono::local_time<_CDur> __lt(__t.time_since_epoch() + __gps_offset);
2042 const string __abbrev(
"GPS", 3);
2043 const chrono::seconds __off = 0s;
2044 const auto __lf = chrono::local_time_format(__lt, &__abbrev, &__off);
2045 return _M_f._M_format(__lf, __fc);
2049 __format::__formatter_chrono<_CharT> _M_f;
2052 template<
typename _Duration,
typename _CharT>
2053 struct formatter<chrono::file_time<_Duration>, _CharT>
2055 template<
typename _ParseContext>
2056 constexpr typename _ParseContext::iterator
2057 parse(_ParseContext& __pc)
2058 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2060 template<
typename _FormatContext>
2061 typename _FormatContext::iterator
2062 format(
const chrono::file_time<_Duration>& __t,
2063 _FormatContext& __ctx)
const
2065 using namespace chrono;
2066 return _M_f._M_format(chrono::clock_cast<system_clock>(__t), __ctx);
2070 __format::__formatter_chrono<_CharT> _M_f;
2073 template<
typename _Duration,
typename _CharT>
2074 struct formatter<chrono::local_time<_Duration>, _CharT>
2076 template<
typename _ParseContext>
2077 constexpr typename _ParseContext::iterator
2078 parse(_ParseContext& __pc)
2079 {
return _M_f._M_parse(__pc, __format::_DateTime); }
2081 template<
typename _FormatContext>
2082 typename _FormatContext::iterator
2083 format(
const chrono::local_time<_Duration>& __t,
2084 _FormatContext& __ctx)
const
2085 {
return _M_f._M_format(__t, __ctx); }
2088 __format::__formatter_chrono<_CharT> _M_f;
2091 template<
typename _Duration,
typename _CharT>
2092 struct formatter<chrono::__detail::__local_time_fmt<_Duration>, _CharT>
2094 template<
typename _ParseContext>
2095 constexpr typename _ParseContext::iterator
2096 parse(_ParseContext& __pc)
2097 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2099 template<
typename _FormatContext>
2100 typename _FormatContext::iterator
2101 format(
const chrono::__detail::__local_time_fmt<_Duration>& __t,
2102 _FormatContext& __ctx)
const
2103 {
return _M_f._M_format(__t, __ctx); }
2106 __format::__formatter_chrono<_CharT> _M_f;
2109#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2110 template<
typename _Duration,
typename _TimeZonePtr,
typename _CharT>
2111 struct formatter<chrono::zoned_time<_Duration, _TimeZonePtr>, _CharT>
2112 : formatter<chrono::__detail::__local_time_fmt<_Duration>, _CharT>
2114 template<
typename _FormatContext>
2115 typename _FormatContext::iterator
2116 format(
const chrono::zoned_time<_Duration, _TimeZonePtr>& __tp,
2117 _FormatContext& __ctx)
const
2119 using chrono::__detail::__local_time_fmt;
2120 using _Base = formatter<__local_time_fmt<_Duration>, _CharT>;
2121 const chrono::sys_info __info = __tp.get_info();
2122 const auto __lf = chrono::local_time_format(__tp.get_local_time(),
2125 return _Base::format(__lf, __ctx);
2131 template<
typename _Duration,
typename _CharT>
2132 struct formatter<chrono::__detail::__utc_leap_second<_Duration>, _CharT>
2133 : formatter<chrono::utc_time<_Duration>, _CharT>
2135 template<
typename _FormatContext>
2136 typename _FormatContext::iterator
2137 format(
const chrono::__detail::__utc_leap_second<_Duration>& __t,
2138 _FormatContext& __fc)
const
2139 {
return this->_M_f._M_format(__t, __fc); }
2150 template<
typename _Duration = seconds>
2153 static_assert(is_same_v<common_type_t<_Duration, seconds>, _Duration>);
2156 _Parser(__format::_ChronoParts __need) : _M_need(__need) { }
2158 _Parser(_Parser&&) =
delete;
2159 void operator=(_Parser&&) =
delete;
2161 _Duration _M_time{};
2162 sys_days _M_sys_days{};
2163 year_month_day _M_ymd{};
2165 __format::_ChronoParts _M_need;
2167 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2168 basic_istream<_CharT, _Traits>&
2169 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2170 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2171 minutes* __offset =
nullptr);
2176 template<
typename _CharT,
typename _Traits>
2177 static int_least32_t
2178 _S_read_unsigned(basic_istream<_CharT, _Traits>& __is,
2179 ios_base::iostate& __err,
int __n)
2181 int_least32_t __val = _S_try_read_digit(__is, __err);
2182 if (__val == -1) [[unlikely]]
2183 __err |= ios_base::failbit;
2188 for (
int __i = 1; __i < __n1; ++__i)
2189 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
2195 while (__n1++ < __n) [[unlikely]]
2196 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
2198 if (__builtin_mul_overflow(__val, 10, &__val)
2199 || __builtin_add_overflow(__val, __dig, &__val))
2201 __err |= ios_base::failbit;
2211 template<
typename _CharT,
typename _Traits>
2212 static int_least32_t
2213 _S_read_signed(basic_istream<_CharT, _Traits>& __is,
2214 ios_base::iostate& __err,
int __n)
2216 auto __sign = __is.peek();
2217 if (__sign ==
'-' || __sign ==
'+')
2219 int_least32_t __val = _S_read_unsigned(__is, __err, __n);
2220 if (__err & ios_base::failbit)
2222 if (__sign ==
'-') [[unlikely]]
2230 template<
typename _CharT,
typename _Traits>
2231 static int_least32_t
2232 _S_try_read_digit(basic_istream<_CharT, _Traits>& __is,
2233 ios_base::iostate& __err)
2235 int_least32_t __val = -1;
2236 auto __i = __is.peek();
2237 if (!_Traits::eq_int_type(__i, _Traits::eof())) [[likely]]
2239 _CharT __c = _Traits::to_char_type(__i);
2240 if (_CharT(
'0') <= __c && __c <= _CharT(
'9')) [[likely]]
2243 __val = __c - _CharT(
'0');
2247 __err |= ios_base::eofbit;
2253 template<
typename _CharT,
typename _Traits>
2255 _S_read_chr(basic_istream<_CharT, _Traits>& __is,
2256 ios_base::iostate& __err, _CharT __c)
2258 auto __i = __is.peek();
2259 if (_Traits::eq_int_type(__i, _Traits::eof()))
2260 __err |= ios_base::eofbit;
2261 else if (_Traits::to_char_type(__i) == __c) [[likely]]
2266 __err |= ios_base::failbit;
2271 template<
typename _Duration>
2272 using _Parser_t = _Parser<common_type_t<_Duration, seconds>>;
2277 template<
typename _CharT,
typename _Traits,
typename _Rep,
typename _Period,
2278 typename _Alloc = allocator<_CharT>>
2279 inline basic_istream<_CharT, _Traits>&
2280 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2281 duration<_Rep, _Period>& __d,
2282 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2285 auto __need = __format::_ChronoParts::_TimeOfDay;
2286 __detail::_Parser_t<duration<_Rep, _Period>> __p(__need);
2287 if (__p(__is, __fmt, __abbrev, __offset))
2288 __d = chrono::duration_cast<duration<_Rep, _Period>>(__p._M_time);
2292 template<
typename _CharT,
typename _Traits>
2293 inline basic_ostream<_CharT, _Traits>&
2294 operator<<(basic_ostream<_CharT, _Traits>& __os,
const day& __d)
2296 using _Ctx = __format::__format_context<_CharT>;
2297 using _Str = basic_string_view<_CharT>;
2298 _Str __s = _GLIBCXX_WIDEN(
"{:02d} is not a valid day");
2300 __s = __s.substr(0, 6);
2301 auto __u = (unsigned)__d;
2302 __os << std::vformat(__s, make_format_args<_Ctx>(__u));
2306 template<
typename _CharT,
typename _Traits,
2307 typename _Alloc = allocator<_CharT>>
2308 inline basic_istream<_CharT, _Traits>&
2309 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2311 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2314 __detail::_Parser<> __p(__format::_ChronoParts::_Day);
2315 if (__p(__is, __fmt, __abbrev, __offset))
2316 __d = __p._M_ymd.day();
2320 template<
typename _CharT,
typename _Traits>
2321 inline basic_ostream<_CharT, _Traits>&
2322 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month& __m)
2324 using _Ctx = __format::__format_context<_CharT>;
2325 using _Str = basic_string_view<_CharT>;
2326 _Str __s = _GLIBCXX_WIDEN(
"{:L%b}{} is not a valid month");
2328 __os << std::vformat(__os.getloc(), __s.substr(0, 6),
2329 make_format_args<_Ctx>(__m));
2332 auto __u = (unsigned)__m;
2333 __os << std::vformat(__s.substr(6), make_format_args<_Ctx>(__u));
2338 template<
typename _CharT,
typename _Traits,
2339 typename _Alloc = allocator<_CharT>>
2340 inline basic_istream<_CharT, _Traits>&
2341 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2343 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2346 __detail::_Parser<> __p(__format::_ChronoParts::_Month);
2347 if (__p(__is, __fmt, __abbrev, __offset))
2348 __m = __p._M_ymd.month();
2352 template<
typename _CharT,
typename _Traits>
2353 inline basic_ostream<_CharT, _Traits>&
2354 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year& __y)
2356 using _Ctx = __format::__format_context<_CharT>;
2357 using _Str = basic_string_view<_CharT>;
2358 _Str __s = _GLIBCXX_WIDEN(
"-{:04d} is not a valid year");
2360 __s = __s.substr(0, 7);
2362 if (__i >= 0) [[likely]]
2363 __s.remove_prefix(1);
2366 __os << std::vformat(__s, make_format_args<_Ctx>(__i));
2370 template<
typename _CharT,
typename _Traits,
2371 typename _Alloc = allocator<_CharT>>
2372 inline basic_istream<_CharT, _Traits>&
2373 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2375 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2378 __detail::_Parser<> __p(__format::_ChronoParts::_Year);
2379 if (__p(__is, __fmt, __abbrev, __offset))
2380 __y = __p._M_ymd.year();
2384 template<
typename _CharT,
typename _Traits>
2385 inline basic_ostream<_CharT, _Traits>&
2386 operator<<(basic_ostream<_CharT, _Traits>& __os,
const weekday& __wd)
2388 using _Ctx = __format::__format_context<_CharT>;
2389 using _Str = basic_string_view<_CharT>;
2390 _Str __s = _GLIBCXX_WIDEN(
"{:L%a}{} is not a valid weekday");
2392 __os << std::vformat(__os.getloc(), __s.substr(0, 6),
2393 make_format_args<_Ctx>(__wd));
2396 auto __c = __wd.c_encoding();
2397 __os << std::vformat(__s.substr(6), make_format_args<_Ctx>(__c));
2402 template<
typename _CharT,
typename _Traits,
2403 typename _Alloc = allocator<_CharT>>
2404 inline basic_istream<_CharT, _Traits>&
2405 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2407 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2410 __detail::_Parser<> __p(__format::_ChronoParts::_Weekday);
2411 if (__p(__is, __fmt, __abbrev, __offset))
2416 template<
typename _CharT,
typename _Traits>
2417 inline basic_ostream<_CharT, _Traits>&
2418 operator<<(basic_ostream<_CharT, _Traits>& __os,
2419 const weekday_indexed& __wdi)
2424 basic_stringstream<_CharT> __os2;
2425 __os2.imbue(__os.getloc());
2426 __os2 << __wdi.weekday();
2427 const auto __i = __wdi.index();
2428 basic_string_view<_CharT> __s
2429 = _GLIBCXX_WIDEN(
"[ is not a valid index]");
2431 __os2 << std::format(_GLIBCXX_WIDEN(
"{}"), __i);
2432 if (__i >= 1 && __i <= 5)
2433 __os2 << __s.back();
2435 __os2 << __s.substr(1);
2436 __os << __os2.view();
2440 template<
typename _CharT,
typename _Traits>
2441 inline basic_ostream<_CharT, _Traits>&
2442 operator<<(basic_ostream<_CharT, _Traits>& __os,
2443 const weekday_last& __wdl)
2446 basic_stringstream<_CharT> __os2;
2447 __os2.imbue(__os.getloc());
2448 __os2 << __wdl.weekday() << _GLIBCXX_WIDEN(
"[last]");
2449 __os << __os2.view();
2453 template<
typename _CharT,
typename _Traits>
2454 inline basic_ostream<_CharT, _Traits>&
2455 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month_day& __md)
2458 basic_stringstream<_CharT> __os2;
2459 __os2.imbue(__os.getloc());
2460 __os2 << __md.month();
2461 if constexpr (is_same_v<_CharT, char>)
2465 __os2 << __md.day();
2466 __os << __os2.view();
2470 template<
typename _CharT,
typename _Traits,
2471 typename _Alloc = allocator<_CharT>>
2472 inline basic_istream<_CharT, _Traits>&
2473 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2475 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2478 using __format::_ChronoParts;
2479 auto __need = _ChronoParts::_Month | _ChronoParts::_Day;
2480 __detail::_Parser<> __p(__need);
2481 if (__p(__is, __fmt, __abbrev, __offset))
2482 __md = month_day(__p._M_ymd.month(), __p._M_ymd.day());
2486 template<
typename _CharT,
typename _Traits>
2487 inline basic_ostream<_CharT, _Traits>&
2488 operator<<(basic_ostream<_CharT, _Traits>& __os,
2489 const month_day_last& __mdl)
2492 basic_stringstream<_CharT> __os2;
2493 __os2.imbue(__os.getloc());
2494 __os2 << __mdl.month() << _GLIBCXX_WIDEN(
"/last");
2495 __os << __os2.view();
2499 template<
typename _CharT,
typename _Traits>
2500 inline basic_ostream<_CharT, _Traits>&
2501 operator<<(basic_ostream<_CharT, _Traits>& __os,
2502 const month_weekday& __mwd)
2505 basic_stringstream<_CharT> __os2;
2506 __os2.imbue(__os.getloc());
2507 __os2 << __mwd.month();
2508 if constexpr (is_same_v<_CharT, char>)
2512 __os2 << __mwd.weekday_indexed();
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_last& __mwdl)
2523 basic_stringstream<_CharT> __os2;
2524 __os2.imbue(__os.getloc());
2525 __os2 << __mwdl.month();
2526 if constexpr (is_same_v<_CharT, char>)
2530 __os2 << __mwdl.weekday_last();
2531 __os << __os2.view();
2535 template<
typename _CharT,
typename _Traits>
2536 inline basic_ostream<_CharT, _Traits>&
2537 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year_month& __ym)
2540 basic_stringstream<_CharT> __os2;
2541 __os2.imbue(__os.getloc());
2542 __os2 << __ym.year();
2543 if constexpr (is_same_v<_CharT, char>)
2547 __os2 << __ym.month();
2548 __os << __os2.view();
2552 template<
typename _CharT,
typename _Traits,
2553 typename _Alloc = allocator<_CharT>>
2554 inline basic_istream<_CharT, _Traits>&
2555 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2557 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2560 using __format::_ChronoParts;
2561 auto __need = _ChronoParts::_Year | _ChronoParts::_Month;
2562 __detail::_Parser<> __p(__need);
2563 if (__p(__is, __fmt, __abbrev, __offset))
2564 __ym = year_month(__p._M_ymd.year(), __p._M_ymd.month());
2568 template<
typename _CharT,
typename _Traits>
2569 inline basic_ostream<_CharT, _Traits>&
2570 operator<<(basic_ostream<_CharT, _Traits>& __os,
2571 const year_month_day& __ymd)
2573 using _Ctx = __format::__format_context<_CharT>;
2574 using _Str = basic_string_view<_CharT>;
2575 _Str __s = _GLIBCXX_WIDEN(
"{:%F} is not a valid date");
2576 __os << std::vformat(__ymd.ok() ? __s.substr(0, 5) : __s,
2577 make_format_args<_Ctx>(__ymd));
2581 template<
typename _CharT,
typename _Traits,
2582 typename _Alloc = allocator<_CharT>>
2583 inline basic_istream<_CharT, _Traits>&
2585 year_month_day& __ymd,
2589 using __format::_ChronoParts;
2590 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2591 | _ChronoParts::_Day;
2592 __detail::_Parser<> __p(__need);
2593 if (__p(__is, __fmt, __abbrev, __offset))
2598 template<
typename _CharT,
typename _Traits>
2601 const year_month_day_last& __ymdl)
2606 __os2 << __ymdl.year();
2607 if constexpr (is_same_v<_CharT, char>)
2611 __os2 << __ymdl.month_day_last();
2612 __os << __os2.view();
2616 template<
typename _CharT,
typename _Traits>
2617 inline basic_ostream<_CharT, _Traits>&
2618 operator<<(basic_ostream<_CharT, _Traits>& __os,
2619 const year_month_weekday& __ymwd)
2623 basic_stringstream<_CharT> __os2;
2624 __os2.
imbue(__os.getloc());
2626 if constexpr (is_same_v<_CharT, char>)
2630 __os2 << __ymwd.year() << __slash << __ymwd.month() << __slash
2631 << __ymwd.weekday_indexed();
2632 __os << __os2.view();
2636 template<
typename _CharT,
typename _Traits>
2637 inline basic_ostream<_CharT, _Traits>&
2638 operator<<(basic_ostream<_CharT, _Traits>& __os,
2639 const year_month_weekday_last& __ymwdl)
2643 basic_stringstream<_CharT> __os2;
2644 __os2.imbue(__os.getloc());
2646 if constexpr (is_same_v<_CharT, char>)
2650 __os2 << __ymwdl.year() << __slash << __ymwdl.month() << __slash
2651 << __ymwdl.weekday_last();
2652 __os << __os2.view();
2656 template<
typename _CharT,
typename _Traits,
typename _Duration>
2657 inline basic_ostream<_CharT, _Traits>&
2658 operator<<(basic_ostream<_CharT, _Traits>& __os,
2659 const hh_mm_ss<_Duration>& __hms)
2661 return __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%T}"), __hms);
2664#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2666 template<
typename _CharT,
typename _Traits>
2667 basic_ostream<_CharT, _Traits>&
2668 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_info& __i)
2670 __os <<
'[' << __i.begin <<
',' << __i.end
2671 <<
',' << hh_mm_ss(__i.offset) <<
',' << __i.save
2672 <<
',' << __i.abbrev <<
']';
2677 template<
typename _CharT,
typename _Traits>
2678 basic_ostream<_CharT, _Traits>&
2679 operator<<(basic_ostream<_CharT, _Traits>& __os,
const local_info& __li)
2682 if (__li.result == local_info::unique)
2686 if (__li.result == local_info::nonexistent)
2687 __os <<
"nonexistent";
2689 __os <<
"ambiguous";
2690 __os <<
" local time between " << __li.first;
2691 __os <<
" and " << __li.second;
2697 template<
typename _CharT,
typename _Traits,
typename _Duration,
2698 typename _TimeZonePtr>
2699 inline basic_ostream<_CharT, _Traits>&
2700 operator<<(basic_ostream<_CharT, _Traits>& __os,
2701 const zoned_time<_Duration, _TimeZonePtr>& __t)
2703 __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T %Z}"), __t);
2708 template<
typename _CharT,
typename _Traits,
typename _Duration>
2709 requires (!treat_as_floating_point_v<typename _Duration::rep>)
2710 && ratio_less_v<typename _Duration::period, days::period>
2711 inline basic_ostream<_CharT, _Traits>&
2712 operator<<(basic_ostream<_CharT, _Traits>& __os,
2713 const sys_time<_Duration>& __tp)
2715 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __tp);
2719 template<
typename _CharT,
typename _Traits>
2720 inline basic_ostream<_CharT, _Traits>&
2721 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_days& __dp)
2723 __os << year_month_day{__dp};
2727 template<
typename _CharT,
typename _Traits,
typename _Duration,
2728 typename _Alloc = allocator<_CharT>>
2729 basic_istream<_CharT, _Traits>&
2730 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2731 sys_time<_Duration>& __tp,
2732 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2738 using __format::_ChronoParts;
2739 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2740 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2741 __detail::_Parser_t<_Duration> __p(__need);
2742 if (__p(__is, __fmt, __abbrev, __offset))
2744 auto __st = __p._M_sys_days + __p._M_time - *__offset;
2745 __tp = chrono::time_point_cast<_Duration>(__st);
2750 template<
typename _CharT,
typename _Traits,
typename _Duration>
2751 inline basic_ostream<_CharT, _Traits>&
2752 operator<<(basic_ostream<_CharT, _Traits>& __os,
2753 const utc_time<_Duration>& __t)
2755 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
2759 template<
typename _CharT,
typename _Traits,
typename _Duration,
2760 typename _Alloc = allocator<_CharT>>
2761 inline basic_istream<_CharT, _Traits>&
2762 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2763 utc_time<_Duration>& __tp,
2764 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2767 sys_time<_Duration> __st;
2768 if (chrono::from_stream(__is, __fmt, __st, __abbrev, __offset))
2769 __tp = utc_clock::from_sys(__st);
2773 template<
typename _CharT,
typename _Traits,
typename _Duration>
2774 inline basic_ostream<_CharT, _Traits>&
2775 operator<<(basic_ostream<_CharT, _Traits>& __os,
2776 const tai_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 tai_time<_Duration>& __tp,
2787 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2790 utc_time<_Duration> __ut;
2791 if (chrono::from_stream(__is, __fmt, __ut, __abbrev, __offset))
2792 __tp = tai_clock::from_utc(__ut);
2796 template<
typename _CharT,
typename _Traits,
typename _Duration>
2797 inline basic_ostream<_CharT, _Traits>&
2798 operator<<(basic_ostream<_CharT, _Traits>& __os,
2799 const gps_time<_Duration>& __t)
2801 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
2805 template<
typename _CharT,
typename _Traits,
typename _Duration,
2806 typename _Alloc = allocator<_CharT>>
2807 inline basic_istream<_CharT, _Traits>&
2808 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2809 gps_time<_Duration>& __tp,
2810 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2813 utc_time<_Duration> __ut;
2814 if (chrono::from_stream(__is, __fmt, __ut, __abbrev, __offset))
2815 __tp = gps_clock::from_utc(__ut);
2819 template<
typename _CharT,
typename _Traits,
typename _Duration>
2820 inline basic_ostream<_CharT, _Traits>&
2821 operator<<(basic_ostream<_CharT, _Traits>& __os,
2822 const file_time<_Duration>& __t)
2824 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
2828 template<
typename _CharT,
typename _Traits,
typename _Duration,
2829 typename _Alloc = allocator<_CharT>>
2830 inline basic_istream<_CharT, _Traits>&
2831 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2832 file_time<_Duration>& __tp,
2833 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2836 sys_time<_Duration> __st;
2837 if (chrono::from_stream(__is, __fmt, __st, __abbrev, __offset))
2838 __tp = file_clock::from_sys(__st);
2842 template<
typename _CharT,
typename _Traits,
typename _Duration>
2843 inline basic_ostream<_CharT, _Traits>&
2844 operator<<(basic_ostream<_CharT, _Traits>& __os,
2845 const local_time<_Duration>& __lt)
2847 __os << sys_time<_Duration>{__lt.time_since_epoch()};
2851 template<
typename _CharT,
typename _Traits,
typename _Duration,
2852 typename _Alloc = allocator<_CharT>>
2853 basic_istream<_CharT, _Traits>&
2854 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2855 local_time<_Duration>& __tp,
2856 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2859 using __format::_ChronoParts;
2860 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2861 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2862 __detail::_Parser_t<_Duration> __p(__need);
2863 if (__p(__is, __fmt, __abbrev, __offset))
2865 days __d = __p._M_sys_days.time_since_epoch();
2866 auto __t = local_days(__d) + __p._M_time;
2867 __tp = chrono::time_point_cast<_Duration>(__t);
2876 template<
typename _Parsable,
typename _CharT,
2878 typename... _OptArgs>
2879 concept __parsable =
requires (basic_istream<_CharT, _Traits>& __is,
2880 const _CharT* __fmt, _Parsable& __tp,
2881 _OptArgs*... __args)
2882 { from_stream(__is, __fmt, __tp, __args...); };
2884 template<
typename _Parsable,
typename _CharT,
2885 typename _Traits = char_traits<_CharT>,
2886 typename _Alloc = allocator<_CharT>>
2890 using __string_type = basic_string<_CharT, _Traits, _Alloc>;
2893 _Parse(
const _CharT* __fmt, _Parsable& __tp,
2894 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2897 _M_abbrev(__abbrev), _M_offset(__offset)
2900 _Parse(_Parse&&) =
delete;
2901 _Parse& operator=(_Parse&&) =
delete;
2904 using __stream_type = basic_istream<_CharT, _Traits>;
2906 const _CharT*
const _M_fmt;
2907 _Parsable*
const _M_tp;
2908 __string_type*
const _M_abbrev;
2911 friend __stream_type&
2912 operator>>(__stream_type& __is, _Parse&& __p)
2915 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev,
2917 else if (__p._M_abbrev)
2918 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev);
2920 from_stream(__is, __p._M_fmt, *__p._M_tp);
2924 friend void operator>>(__stream_type&, _Parse&) =
delete;
2925 friend void operator>>(__stream_type&,
const _Parse&) =
delete;
2929 template<
typename _CharT, __detail::__parsable<_CharT> _Parsable>
2930 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
2932 parse(
const _CharT* __fmt, _Parsable& __tp)
2933 {
return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp); }
2935 template<
typename _CharT,
typename _Traits,
typename _Alloc,
2936 __detail::__parsable<_CharT, _Traits> _Parsable>
2939 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp)
2941 return __detail::_Parse<_Parsable, _CharT, _Traits>(__fmt.c_str(), __tp);
2944 template<
typename _CharT,
typename _Traits,
typename _Alloc,
2945 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
2946 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
2947 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
2949 parse(
const _CharT* __fmt, _Parsable& __tp,
2950 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
2953 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
2957 template<
typename _CharT,
typename _Traits,
typename _Alloc,
2958 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
2959 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
2962 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
2963 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
2966 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
2970 template<
typename _CharT,
typename _Traits =
char_traits<_CharT>,
2971 typename _StrT = basic_
string<_CharT, _Traits>,
2972 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
2973 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
2975 parse(
const _CharT* __fmt, _Parsable& __tp,
minutes& __offset)
2977 return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp,
nullptr,
2981 template<
typename _CharT,
typename _Traits,
typename _Alloc,
2982 typename _StrT = basic_string<_CharT, _Traits>,
2983 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
2986 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
2989 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
2994 template<
typename _CharT,
typename _Traits,
typename _Alloc,
2995 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
2996 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
2997 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
2999 parse(
const _CharT* __fmt, _Parsable& __tp,
3000 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
3003 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
3008 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3009 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
3010 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
3013 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
3014 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
3017 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
3023 template<
typename _Duration>
3024 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3025 basic_istream<_CharT, _Traits>&
3026 __detail::_Parser<_Duration>::
3027 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3028 basic_string<_CharT, _Traits, _Alloc>* __abbrev,
3031 using sentry =
typename basic_istream<_CharT, _Traits>::sentry;
3033 if (sentry __cerb(__is,
true); __cerb)
3035 locale __loc = __is.getloc();
3036 auto& __tmget = std::use_facet<std::time_get<_CharT>>(__loc);
3037 auto& __tmpunct = std::use_facet<std::__timepunct<_CharT>>(__loc);
3040 struct _Stream_state
3043 _Stream_state(basic_istream<_CharT, _Traits>& __i)
3045 _M_flags(__i.flags(ios_base::
skipws | ios_base::
dec)),
3051 _M_is.flags(_M_flags);
3055 _Stream_state(_Stream_state&&) =
delete;
3057 basic_istream<_CharT, _Traits>& _M_is;
3058 ios_base::fmtflags _M_flags;
3068 auto __read_unsigned = [&] (
int __n) {
3069 return _S_read_unsigned(__is, __err, __n);
3074 auto __read_signed = [&] (
int __n) {
3075 return _S_read_signed(__is, __err, __n);
3079 auto __read_chr = [&__is, &__err] (_CharT __c) {
3080 return _S_read_chr(__is, __err, __c);
3083 using __format::_ChronoParts;
3084 _ChronoParts __parts{};
3086 const year __bad_y = --year::min();
3087 const month __bad_mon(255);
3088 const day __bad_day(255);
3089 const weekday __bad_wday(255);
3090 const hours __bad_h(-1);
3091 const minutes __bad_min(-9999);
3094 year __y = __bad_y, __yy = __bad_y;
3095 year __iso_y = __bad_y, __iso_yy = __bad_y;
3096 month __m = __bad_mon;
3097 day __d = __bad_day;
3098 weekday __wday = __bad_wday;
3099 hours __h = __bad_h, __h12 = __bad_h;
3101 _Duration __s = __bad_sec;
3103 int __iso_wk = -1, __sunday_wk = -1, __monday_wk = -1;
3105 int __dayofyear = -1;
3107 minutes __tz_offset = __bad_min;
3108 basic_string<_CharT, _Traits> __tz_abbr;
3114 bool __is_flag =
false;
3133 _CharT __c = *__fmt++;
3140 else if (!__read_chr(__c)) [[unlikely]]
3151 if (__mod || __num) [[unlikely]]
3156 __tmget.get(__is, {}, __is, __err, &__tm,
3158 if (!__is_failed(__err))
3159 __wday = weekday(__tm.tm_wday);
3161 __parts |= _ChronoParts::_Weekday;
3167 if (__mod || __num) [[unlikely]]
3175 __tmget.get(__is, {}, __is, __err, &__tm,
3177 if (!__is_failed(__err))
3178 __m = month(__tm.tm_mon + 1);
3180 __parts |= _ChronoParts::_Month;
3184 if (__mod ==
'O' || __num) [[unlikely]]
3189 __tmget.get(__is, {}, __is, __err, &__tm,
3190 __fmt - 2 - (__mod ==
'E'), __fmt);
3191 if (!__is_failed(__err))
3193 __y = year(__tm.tm_year + 1900);
3194 __m = month(__tm.tm_mon + 1);
3195 __d = day(__tm.tm_mday);
3196 __h =
hours(__tm.tm_hour);
3198 __s = duration_cast<_Duration>(
seconds(__tm.tm_sec));
3201 __parts |= _ChronoParts::_DateTime;
3205 if (!__mod) [[likely]]
3207 auto __v = __read_signed(__num ? __num : 2);
3208 if (!__is_failed(__err))
3210 int __cmin = (int)year::min() / 100;
3211 int __cmax = (int)year::max() / 100;
3212 if (__cmin <= __v && __v <= __cmax)
3213 __century = __v * 100;
3218 else if (__mod ==
'E')
3221 __tmget.get(__is, {}, __is, __err, &__tm,
3223 if (!__is_failed(__err))
3224 __century = __tm.tm_year;
3233 if (!__mod) [[likely]]
3235 auto __v = __read_unsigned(__num ? __num : 2);
3236 if (!__is_failed(__err))
3239 else if (__mod ==
'O')
3242 __tmget.get(__is, {}, __is, __err, &__tm,
3244 if (!__is_failed(__err))
3245 __d = day(__tm.tm_mday);
3249 __parts |= _ChronoParts::_Day;
3253 if (__mod || __num) [[unlikely]]
3257 auto __month = __read_unsigned(2);
3259 auto __day = __read_unsigned(2);
3261 auto __year = __read_unsigned(2);
3262 if (__is_failed(__err))
3264 __y = year(__year + 1900 + 100 *
int(__year < 69));
3265 __m = month(__month);
3267 if (!year_month_day(__y, __m, __d).ok())
3269 __y = __yy = __iso_y = __iso_yy = __bad_y;
3275 __parts |= _ChronoParts::_Date;
3279 if (__mod) [[unlikely]]
3283 auto __year = __read_signed(__num ? __num : 4);
3285 auto __month = __read_unsigned(2);
3287 auto __day = __read_unsigned(2);
3288 if (__is_failed(__err))
3291 __m = month(__month);
3293 if (!year_month_day(__y, __m, __d).ok())
3295 __y = __yy = __iso_y = __iso_yy = __bad_y;
3301 __parts |= _ChronoParts::_Date;
3305 if (__mod) [[unlikely]]
3309 auto __val = __read_unsigned(__num ? __num : 2);
3310 if (__val >= 0 && __val <= 99)
3312 __iso_yy = year(__val);
3313 if (__century == -1)
3317 __iso_yy = __iso_y = __y = __yy = __bad_y;
3319 __parts |= _ChronoParts::_Year;
3323 if (__mod) [[unlikely]]
3326 __iso_y = year(__read_unsigned(__num ? __num : 4));
3327 __parts |= _ChronoParts::_Year;
3332 if (__mod ==
'E') [[unlikely]]
3334 else if (__mod ==
'O')
3339 __tmget.get(__is, {}, __is, __err, &__tm,
3341 if (!__is_failed(__err))
3345 __h12 =
hours(__tm.tm_hour);
3349 __h =
hours(__tm.tm_hour);
3358 auto __val = __read_unsigned(__num ? __num : 2);
3359 if (__c ==
'I' && __val >= 1 && __val <= 12)
3361 __h12 =
hours(__val);
3364 else if (__c ==
'H' && __val >= 0 && __val <= 23)
3371 if (_M_need & _ChronoParts::_TimeOfDay)
3376 __parts |= _ChronoParts::_TimeOfDay;
3380 if (__mod) [[unlikely]]
3382 else if (_M_need == _ChronoParts::_TimeOfDay)
3384 auto __val = __read_signed(__num ? __num : 3);
3385 if (!__is_failed(__err))
3388 __parts |= _ChronoParts::_TimeOfDay;
3393 __dayofyear = __read_unsigned(__num ? __num : 3);
3400 if (__mod ==
'E') [[unlikely]]
3402 else if (__mod ==
'O')
3405 __tmget.get(__is, {}, __is, __err, &__tm,
3407 if (!__is_failed(__err))
3408 __m = month(__tm.tm_mon + 1);
3412 auto __val = __read_unsigned(__num ? __num : 2);
3413 if (__val >= 1 && __val <= 12)
3418 __parts |= _ChronoParts::_Month;
3422 if (__mod ==
'E') [[unlikely]]
3424 else if (__mod ==
'O')
3427 __tmget.get(__is, {}, __is, __err, &__tm,
3429 if (!__is_failed(__err))
3434 auto __val = __read_unsigned(__num ? __num : 2);
3435 if (0 <= __val && __val < 60)
3439 if (_M_need & _ChronoParts::_TimeOfDay)
3444 __parts |= _ChronoParts::_TimeOfDay;
3454 const _CharT* __ampms[2];
3455 __tmpunct._M_am_pm(__ampms);
3456 int __n = 0, __which = 3;
3457 while (__which != 0)
3459 auto __i = __is.peek();
3460 if (_Traits::eq_int_type(__i, _Traits::eof()))
3470 else if (__ampms[0][__n + 1] == _CharT())
3481 else if (__ampms[1][__n + 1] == _CharT())
3492 if (__which == 0 || __which == 3)
3505 __tmget.get(__is, {}, __is, __err, &__tm,
3507 if (!__is_failed(__err))
3509 __h =
hours(__tm.tm_hour);
3514 __parts |= _ChronoParts::_TimeOfDay;
3519 if (__mod || __num) [[unlikely]]
3526 auto __val = __read_unsigned(2);
3527 if (__val == -1 || __val > 23) [[unlikely]]
3529 if (_M_need & _ChronoParts::_TimeOfDay)
3533 if (!__read_chr(
':')) [[unlikely]]
3537 __val = __read_unsigned(2);
3538 if (__val == -1 || __val > 60) [[unlikely]]
3540 if (_M_need & _ChronoParts::_TimeOfDay)
3548 __parts |= _ChronoParts::_TimeOfDay;
3551 else if (!__read_chr(
':')) [[unlikely]]
3557 if (__mod ==
'E') [[unlikely]]
3559 else if (__mod ==
'O')
3562 __tmget.get(__is, {}, __is, __err, &__tm,
3564 if (!__is_failed(__err))
3567 else if constexpr (ratio_equal_v<
typename _Duration::period,
3570 auto __val = __read_unsigned(__num ? __num : 2);
3571 if (0 <= __val && __val <= 59) [[likely]]
3575 if (_M_need & _ChronoParts::_TimeOfDay)
3582 basic_stringstream<_CharT> __buf;
3583 auto __digit = _S_try_read_digit(__is, __err);
3586 __buf.put(_CharT(
'0') + __digit);
3587 __digit = _S_try_read_digit(__is, __err);
3589 __buf.put(_CharT(
'0') + __digit);
3592 auto __i = __is.peek();
3593 if (_Traits::eq_int_type(__i, _Traits::eof()))
3597 auto& __np = use_facet<numpunct<_CharT>>(__loc);
3598 auto __dp = __np.decimal_point();
3599 _CharT __c = _Traits::to_char_type(__i);
3605 = hh_mm_ss<_Duration>::fractional_width;
3608 __digit = _S_try_read_digit(__is, __err);
3610 __buf.put(_CharT(
'0') + __digit);
3618 if (!__is_failed(__err))
3620 auto& __ng = use_facet<num_get<_CharT>>(__loc);
3623 __ng.get(__buf, {}, __buf, __err2, __val);
3624 if (__is_failed(__err2)) [[unlikely]]
3628 duration<long double> __fs(__val);
3629 __s = duration_cast<_Duration>(__fs);
3633 __parts |= _ChronoParts::_TimeOfDay;
3638 if (__mod ==
'E') [[unlikely]]
3640 else if (__mod ==
'O')
3645 __tmget.get(__is, {}, __is, __err, &__tm,
3647 if (!__is_failed(__err))
3648 __wday = weekday(__tm.tm_wday);
3655 const int __lo = __c ==
'u' ? 1 : 0;
3656 const int __hi = __lo + 6;
3657 auto __val = __read_unsigned(__num ? __num : 1);
3658 if (__lo <= __val && __val <= __hi)
3659 __wday = weekday(__val);
3662 __wday = __bad_wday;
3666 __parts |= _ChronoParts::_Weekday;
3672 if (__mod ==
'E') [[unlikely]]
3674 else if (__mod ==
'O')
3676 if (__c ==
'V') [[unlikely]]
3686 const int __lo = __c ==
'V' ? 1 : 0;
3687 const int __hi = 53;
3688 auto __val = __read_unsigned(__num ? __num : 2);
3689 if (__lo <= __val && __val <= __hi)
3694 __sunday_wk = __val;
3700 __monday_wk = __val;
3705 __iso_wk = __sunday_wk = __monday_wk = -1;
3711 if (__mod ==
'O' || __num) [[unlikely]]
3716 __tmget.get(__is, {}, __is, __err, &__tm,
3717 __fmt - 2 - (__mod ==
'E'), __fmt);
3718 if (!__is_failed(__err))
3720 __y = year(__tm.tm_year + 1900);
3721 __m = month(__tm.tm_mon + 1);
3722 __d = day(__tm.tm_mday);
3725 __parts |= _ChronoParts::_Date;
3729 if (__mod ==
'O' || __num) [[unlikely]]
3734 __tmget.get(__is, {}, __is, __err, &__tm,
3735 __fmt - 2 - (__mod ==
'E'), __fmt);
3736 if (!__is_failed(__err))
3738 __h =
hours(__tm.tm_hour);
3740 __s = duration_cast<_Duration>(
seconds(__tm.tm_sec));
3743 __parts |= _ChronoParts::_TimeOfDay;
3747 if (__mod) [[unlikely]]
3750 __tmget.get(__is, {}, __is, __err, &__tm,
3752 if (!__is_failed(__err))
3754 int __cent = __tm.tm_year < 2000 ? 1900 : 2000;
3755 __yy = year(__tm.tm_year - __cent);
3756 if (__century == -1)
3762 auto __val = __read_unsigned(__num ? __num : 2);
3763 if (__val >= 0 && __val <= 99)
3766 if (__century == -1)
3767 __century = __val < 69 ? 2000 : 1900;
3770 __y = __yy = __iso_yy = __iso_y = __bad_y;
3772 __parts |= _ChronoParts::_Year;
3776 if (__mod ==
'O') [[unlikely]]
3778 else if (__mod ==
'E')
3781 __tmget.get(__is, {}, __is, __err, &__tm,
3783 if (!__is_failed(__err))
3784 __y = year(__tm.tm_year);
3788 auto __val = __read_unsigned(__num ? __num : 4);
3789 if (!__is_failed(__err))
3792 __parts |= _ChronoParts::_Year;
3796 if (__num) [[unlikely]]
3803 auto __i = __is.peek();
3804 if (_Traits::eq_int_type(__i, _Traits::eof()))
3809 _CharT __ic = _Traits::to_char_type(__i);
3810 const bool __neg = __ic == _CharT(
'-');
3811 if (__ic == _CharT(
'-') || __ic == _CharT(
'+'))
3818 __hh = __read_unsigned(2);
3823 __hh = 10 * _S_try_read_digit(__is, __err);
3824 __hh += _S_try_read_digit(__is, __err);
3827 if (__is_failed(__err))
3831 if (_Traits::eq_int_type(__i, _Traits::eof()))
3834 __tz_offset =
minutes(__hh * (__neg ? -60 : 60));
3837 __ic = _Traits::to_char_type(__i);
3839 bool __read_mm =
false;
3842 if (__ic == _GLIBCXX_WIDEN(
":")[0])
3849 else if (_CharT(
'0') <= __ic && __ic <= _CharT(
'9'))
3855 int_least32_t __mm = 0;
3858 __mm = 10 * _S_try_read_digit(__is, __err);
3859 __mm += _S_try_read_digit(__is, __err);
3862 if (!__is_failed(__err))
3864 auto __z = __hh * 60 + __mm;
3865 __tz_offset =
minutes(__neg ? -__z : __z);
3871 if (__mod || __num) [[unlikely]]
3875 basic_string_view<_CharT> __x = _GLIBCXX_WIDEN(
"_/-+");
3879 auto __i = __is.peek();
3880 if (!_Traits::eq_int_type(__i, _Traits::eof()))
3882 _CharT __a = _Traits::to_char_type(__i);
3884 || __x.find(__a) != __x.npos)
3886 __tz_abbr.push_back(__a);
3895 if (__tz_abbr.empty())
3901 if (__mod || __num) [[unlikely]]
3905 _CharT __i = __is.peek();
3906 if (_Traits::eq_int_type(__i, _Traits::eof()))
3908 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
3916 if (__mod || __num) [[unlikely]]
3920 _CharT __i = __is.peek();
3921 if (_Traits::eq_int_type(__i, _Traits::eof()))
3923 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
3929 if (__mod || __num) [[unlikely]]
3937 if (__mod || __num) [[unlikely]]
3946 if (_CharT(
'1') <= __c && __c <= _CharT(
'9'))
3948 if (!__mod) [[likely]]
3951 auto __end = __fmt + _Traits::length(__fmt);
3953 = __format::__parse_integer(__fmt - 1, __end);
3954 if (__ptr) [[likely]]
3965 if (__is_failed(__err)) [[unlikely]]
3975 if (__yy != __bad_y && __y == __bad_y)
3976 __y =
years(__century) + __yy;
3977 if (__iso_yy != __bad_y && __iso_y == __bad_y)
3978 __iso_y =
years(__century) + __iso_yy;
3981 bool __can_use_doy =
false;
3982 bool __can_use_iso_wk =
false;
3983 bool __can_use_sun_wk =
false;
3984 bool __can_use_mon_wk =
false;
3987 if (__y != __bad_y && __dayofyear >= 0)
3989 __can_use_doy =
true;
3990 __parts |= _ChronoParts::_Date;
3992 else if (__y != __bad_y && __wday != __bad_wday && __sunday_wk >= 0)
3994 __can_use_sun_wk =
true;
3995 __parts |= _ChronoParts::_Date;
3997 else if (__y != __bad_y && __wday != __bad_wday && __monday_wk >= 0)
3999 __can_use_mon_wk =
true;
4000 __parts |= _ChronoParts::_Date;
4002 else if (__iso_y != __bad_y && __wday != __bad_wday && __iso_wk > 0)
4005 __can_use_iso_wk =
true;
4006 __parts |= _ChronoParts::_Date;
4009 if (__is_failed(__err)) [[unlikely]]
4011 else if (__is_flag) [[unlikely]]
4013 else if ((_M_need & __parts) == _M_need) [[likely]]
4035 const bool __need_wday = _M_need & _ChronoParts::_Weekday;
4039 const bool __need_time = _M_need & _ChronoParts::_TimeOfDay;
4041 if (__need_wday && __wday != __bad_wday)
4043 else if (_M_need & _ChronoParts::_Date)
4047 const bool __need_ymd = !__need_wday && !__need_time;
4049 if ((_M_need & _ChronoParts::_Year && __y == __bad_y)
4050 || (_M_need & _ChronoParts::_Month && __m == __bad_mon)
4051 || (_M_need & _ChronoParts::_Day && __d == __bad_day))
4058 if ((0 < __dayofyear && __dayofyear <= 365)
4059 || (__dayofyear == 366 && __y.is_leap()))
4062 _M_sys_days = sys_days(__y/January/1)
4063 +
days(__dayofyear - 1);
4065 _M_ymd = year_month_day(_M_sys_days);
4070 else if (__can_use_iso_wk)
4078 const sys_days __jan4(__iso_y/January/4);
4079 weekday __wd1(__jan4 -
days(3));
4080 if (__wd1 != Thursday)
4081 if (__wd1 != Wednesday || !__iso_y.is_leap())
4085 if (!__is_failed(__err)) [[likely]]
4088 sys_days __w(Thursday[1]/January/__iso_y);
4090 __w -= Thursday - Monday;
4092 __w += __wday - Monday;
4096 _M_ymd = year_month_day(_M_sys_days);
4099 else if (__can_use_sun_wk)
4102 sys_days __wk1(__y/January/Sunday[1]);
4103 _M_sys_days = __wk1 +
weeks(__sunday_wk - 1)
4104 +
days(__wday.c_encoding());
4105 _M_ymd = year_month_day(_M_sys_days);
4106 if (_M_ymd.year() != __y) [[unlikely]]
4109 else if (__can_use_mon_wk)
4112 sys_days __wk1(__y/January/Monday[1]);
4113 _M_sys_days = __wk1 +
weeks(__monday_wk - 1)
4114 +
days(__wday.c_encoding() - 1);
4115 _M_ymd = year_month_day(_M_sys_days);
4116 if (_M_ymd.year() != __y) [[unlikely]]
4128 if (_M_need & _ChronoParts::_Year)
4130 if (!__y.ok()) [[unlikely]]
4133 else if (__y == __bad_y)
4136 if (_M_need & _ChronoParts::_Month)
4138 if (!__m.ok()) [[unlikely]]
4141 else if (__m == __bad_mon)
4144 if (_M_need & _ChronoParts::_Day)
4146 if (__d < day(1) || __d > (__y/__m/last).day())
4149 else if (__d == __bad_day)
4152 if (year_month_day __ymd(__y, __m, __d); __ymd.ok())
4155 if (__need_wday || __need_time)
4156 _M_sys_days = sys_days(_M_ymd);
4163 _M_wd = weekday(_M_sys_days);
4169 if (__h == __bad_h && __h12 != __bad_h)
4173 else if (__ampm == 2)
4174 __h = __h12 ==
hours(12) ? __h12 : __h12 +
hours(12);
4179 auto __t = _M_time.zero();
4188 if (__min != __bad_min)
4194 if (__s != __bad_sec)
4206 if (!__is_failed(__err)) [[likely]]
4208 if (__offset && __tz_offset != __bad_min)
4209 *__offset = __tz_offset;
4210 if (__abbrev && !__tz_abbr.empty())
4218 __is.setstate(__err);
4222#undef _GLIBCXX_WIDEN
4227_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.
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.
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.