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));
160 template<
typename _Duration>
161 struct __local_time_fmt
163 local_time<_Duration> _M_time;
164 const string* _M_abbrev;
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 basic_ostringstream<_CharT> __os;
698 __os.imbue(_M_locale(__fc));
700 if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
703 auto __days = chrono::floor<chrono::days>(__t._M_time);
704 __os << chrono::year_month_day(__days) <<
' '
705 << chrono::hh_mm_ss(__t._M_time - __days);
711 if (!__t._M_abbrev) [[unlikely]]
712 __format::__no_timezone_available();
713 else if constexpr (is_same_v<_CharT, char>)
714 __os <<
' ' << *__t._M_abbrev;
718 for (
char __c : *__t._M_abbrev)
725 if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
726 __os << __t._M_date <<
' ' << __t._M_time;
727 else if constexpr (chrono::__is_time_point_v<_Tp>)
734 if constexpr (is_convertible_v<_Tp, chrono::sys_days>)
735 __os << _S_date(__t);
737 else if constexpr (is_convertible_v<_Tp, chrono::local_days>)
738 __os << _S_date(__t);
741 auto __days = chrono::floor<chrono::days>(__t);
742 __os << chrono::year_month_day(__days) <<
' '
743 << chrono::hh_mm_ss(__t - __days);
748 if constexpr (chrono::__is_duration_v<_Tp>)
749 if (__is_neg) [[unlikely]]
750 __os << _S_plus_minus[1];
756 return __format::__write_padded_as_spec(__str, __str.size(),
760 static constexpr const _CharT* _S_chars
761 = _GLIBCXX_WIDEN(
"0123456789+-:/ {}");
762 static constexpr const _CharT* _S_plus_minus = _S_chars + 10;
763 static constexpr _CharT _S_colon = _S_chars[12];
764 static constexpr _CharT _S_slash = _S_chars[13];
765 static constexpr _CharT _S_space = _S_chars[14];
766 static constexpr const _CharT* _S_empty_spec = _S_chars + 15;
768 template<
typename _Tp,
typename _FormatContext>
769 typename _FormatContext::iterator
770 _M_a_A(
const _Tp& __t,
typename _FormatContext::iterator __out,
771 _FormatContext& __ctx,
bool __full)
const
775 chrono::weekday __wd = _S_weekday(__t);
777 __throw_format_error(
"format error: invalid weekday");
779 locale __loc = _M_locale(__ctx);
780 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
781 const _CharT* __days[7];
783 __tp._M_days(__days);
785 __tp._M_days_abbreviated(__days);
786 __string_view __str(__days[__wd.c_encoding()]);
787 return __format::__write(
std::move(__out), __str);
790 template<
typename _Tp,
typename _FormatContext>
791 typename _FormatContext::iterator
792 _M_b_B(
const _Tp& __t,
typename _FormatContext::iterator __out,
793 _FormatContext& __ctx,
bool __full)
const
797 chrono::month __m = _S_month(__t);
799 __throw_format_error(
"format error: invalid month");
800 locale __loc = _M_locale(__ctx);
801 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
802 const _CharT* __months[12];
804 __tp._M_months(__months);
806 __tp._M_months_abbreviated(__months);
807 __string_view __str(__months[(
unsigned)__m - 1]);
808 return __format::__write(
std::move(__out), __str);
811 template<
typename _Tp,
typename _FormatContext>
812 typename _FormatContext::iterator
813 _M_c(
const _Tp& __tt,
typename _FormatContext::iterator __out,
814 _FormatContext& __ctx,
bool __mod =
false)
const
819 basic_string<_CharT> __fmt;
820 auto __t = _S_floor_seconds(__tt);
821 locale __loc = _M_locale(__ctx);
822 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
823 const _CharT* __formats[2];
824 __tp._M_date_time_formats(__formats);
825 if (*__formats[__mod]) [[likely]]
827 __fmt = _GLIBCXX_WIDEN(
"{:L}");
828 __fmt.insert(3u, __formats[__mod]);
831 __fmt = _GLIBCXX_WIDEN(
"{:L%a %b %e %T %Y}");
832 return std::vformat_to(
std::move(__out), __loc, __fmt,
833 std::make_format_args<_FormatContext>(__t));
836 template<
typename _Tp,
typename _FormatContext>
837 typename _FormatContext::iterator
838 _M_C_y_Y(
const _Tp& __t,
typename _FormatContext::iterator __out,
839 _FormatContext& __ctx, _CharT __conv, _CharT __mod = 0)
const
849 chrono::year __y = _S_year(__t);
851 if (__mod) [[unlikely]]
854 __tm.tm_year = (int)__y - 1900;
855 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
859 basic_string<_CharT> __s;
861 const bool __is_neg = __yi < 0;
862 __yi = __builtin_abs(__yi);
864 if (__conv ==
'Y' || __conv ==
'C')
866 int __ci = __yi / 100;
867 if (__is_neg) [[unlikely]]
869 __s.assign(1, _S_plus_minus[1]);
871 if (__conv ==
'C' && (__ci * 100) != __yi)
874 if (__ci >= 100) [[unlikely]]
876 __s += std::format(_S_empty_spec, __ci / 100);
879 __s += _S_two_digits(__ci);
882 if (__conv ==
'Y' || __conv ==
'y')
883 __s += _S_two_digits(__yi % 100);
885 return __format::__write(
std::move(__out), __string_view(__s));
888 template<
typename _Tp,
typename _FormatContext>
889 typename _FormatContext::iterator
890 _M_D(
const _Tp& __t,
typename _FormatContext::iterator __out,
891 _FormatContext&)
const
893 auto __ymd = _S_date(__t);
894 basic_string<_CharT> __s;
895#if ! _GLIBCXX_USE_CXX11_ABI
898 __s = _S_two_digits((
unsigned)__ymd.month());
900 __s += _S_two_digits((
unsigned)__ymd.day());
902 __s += _S_two_digits(__builtin_abs((
int)__ymd.year()) % 100);
903 return __format::__write(
std::move(__out), __string_view(__s));
906 template<
typename _Tp,
typename _FormatContext>
907 typename _FormatContext::iterator
908 _M_d_e(
const _Tp& __t,
typename _FormatContext::iterator __out,
909 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
916 chrono::day __d = _S_day(__t);
917 unsigned __i = (unsigned)__d;
919 if (__mod) [[unlikely]]
923 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
927 auto __sv = _S_two_digits(__i);
929 if (__conv == _CharT(
'e') && __i < 10)
935 return __format::__write(
std::move(__out), __sv);
938 template<
typename _Tp,
typename _FormatContext>
939 typename _FormatContext::iterator
940 _M_F(
const _Tp& __t,
typename _FormatContext::iterator __out,
941 _FormatContext&)
const
943 auto __ymd = _S_date(__t);
944 auto __s = std::format(_GLIBCXX_WIDEN(
"{:04d}- - "),
946 auto __sv = _S_two_digits((
unsigned)__ymd.month());
947 __s[__s.size() - 5] = __sv[0];
948 __s[__s.size() - 4] = __sv[1];
949 __sv = _S_two_digits((
unsigned)__ymd.day());
950 __s[__s.size() - 2] = __sv[0];
951 __s[__s.size() - 1] = __sv[1];
953 return __format::__write(
std::move(__out), __sv);
956 template<
typename _Tp,
typename _FormatContext>
957 typename _FormatContext::iterator
958 _M_g_G(
const _Tp& __t,
typename _FormatContext::iterator __out,
959 _FormatContext& __ctx,
bool __full)
const
963 using namespace chrono;
964 auto __d = _S_days(__t);
966 __d -= (weekday(__d) - Monday) -
days(3);
968 year __y = year_month_day(__d).year();
969 return _M_C_y_Y(__y,
std::move(__out), __ctx,
"yY"[__full]);
972 template<
typename _Tp,
typename _FormatContext>
973 typename _FormatContext::iterator
974 _M_H_I(
const _Tp& __t,
typename _FormatContext::iterator __out,
975 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
982 const auto __hms = _S_hms(__t);
983 int __i = __hms.hours().count();
985 if (__mod) [[unlikely]]
989 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
993 if (__conv == _CharT(
'I'))
1000 return __format::__write(
std::move(__out), _S_two_digits(__i));
1003 template<
typename _Tp,
typename _FormatContext>
1004 typename _FormatContext::iterator
1005 _M_j(
const _Tp& __t,
typename _FormatContext::iterator __out,
1006 _FormatContext&)
const
1008 if constexpr (chrono::__is_duration_v<_Tp>)
1011 unsigned __d = chrono::duration_cast<chrono::days>(__t).count();
1012 return std::format_to(
std::move(__out), _S_empty_spec, __d);
1017 using namespace chrono;
1018 auto __day = _S_days(__t);
1019 auto __ymd = _S_date(__t);
1023 if constexpr (is_same_v<
typename decltype(__day)::clock, local_t>)
1024 __d = __day - local_days(__ymd.year()/January/0);
1026 __d = __day - sys_days(__ymd.year()/January/0);
1027 return std::format_to(
std::move(__out), _GLIBCXX_WIDEN(
"{:03d}"),
1032 template<
typename _Tp,
typename _FormatContext>
1033 typename _FormatContext::iterator
1034 _M_m(
const _Tp& __t,
typename _FormatContext::iterator __out,
1035 _FormatContext& __ctx,
bool __mod)
const
1040 auto __m = _S_month(__t);
1041 auto __i = (unsigned)__m;
1043 if (__mod) [[unlikely]]
1046 __tm.tm_mon = __i - 1;
1047 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
1051 return __format::__write(
std::move(__out), _S_two_digits(__i));
1054 template<
typename _Tp,
typename _FormatContext>
1055 typename _FormatContext::iterator
1056 _M_M(
const _Tp& __t,
typename _FormatContext::iterator __out,
1057 _FormatContext& __ctx,
bool __mod)
const
1062 auto __m = _S_hms(__t).minutes();
1063 auto __i = __m.count();
1065 if (__mod) [[unlikely]]
1069 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
1073 return __format::__write(
std::move(__out), _S_two_digits(__i));
1076 template<
typename _Tp,
typename _FormatContext>
1077 typename _FormatContext::iterator
1078 _M_p(
const _Tp& __t,
typename _FormatContext::iterator __out,
1079 _FormatContext& __ctx)
const
1082 auto __hms = _S_hms(__t);
1083 locale __loc = _M_locale(__ctx);
1084 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1085 const _CharT* __ampm[2];
1086 __tp._M_am_pm(__ampm);
1087 return std::format_to(
std::move(__out), _S_empty_spec,
1088 __ampm[__hms.hours().count() >= 12]);
1091 template<
typename _Tp,
typename _FormatContext>
1092 typename _FormatContext::iterator
1093 _M_q(
const _Tp&,
typename _FormatContext::iterator __out,
1094 _FormatContext&)
const
1097 if constexpr (!chrono::__is_duration_v<_Tp>)
1098 __throw_format_error(
"format error: argument is not a duration");
1101 namespace __d = chrono::__detail;
1102 using period =
typename _Tp::period;
1103 return __d::__fmt_units_suffix<period, _CharT>(
std::move(__out));
1109 template<
typename _Tp,
typename _FormatContext>
1110 typename _FormatContext::iterator
1111 _M_r(
const _Tp& __tt,
typename _FormatContext::iterator __out,
1112 _FormatContext& __ctx)
const
1115 auto __t = _S_floor_seconds(__tt);
1116 locale __loc = _M_locale(__ctx);
1117 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1118 const _CharT* __ampm_fmt;
1119 __tp._M_am_pm_format(&__ampm_fmt);
1120 basic_string<_CharT> __fmt(_S_empty_spec);
1121 __fmt.insert(1u, 1u, _S_colon);
1122 __fmt.insert(2u, __ampm_fmt);
1123 return std::vformat_to(
std::move(__out), __fmt,
1124 std::make_format_args<_FormatContext>(__t));
1127 template<
typename _Tp,
typename _FormatContext>
1128 typename _FormatContext::iterator
1129 _M_R_T(
const _Tp& __t,
typename _FormatContext::iterator __out,
1130 _FormatContext& __ctx,
bool __secs)
const
1134 auto __hms = _S_hms(__t);
1136 auto __s = std::format(_GLIBCXX_WIDEN(
"{:02d}:00"),
1137 __hms.hours().count());
1138 auto __sv = _S_two_digits(__hms.minutes().count());
1139 __s[__s.size() - 2] = __sv[0];
1140 __s[__s.size() - 1] = __sv[1];
1142 __out = __format::__write(
std::move(__out), __sv);
1145 *__out++ = _S_colon;
1146 __out = _M_S(__hms,
std::move(__out), __ctx);
1151 template<
typename _Tp,
typename _FormatContext>
1152 typename _FormatContext::iterator
1153 _M_S(
const _Tp& __t,
typename _FormatContext::iterator __out,
1154 _FormatContext& __ctx,
bool __mod =
false)
const
1158 auto __hms = _S_hms(__t);
1160 if (__mod) [[unlikely]]
1163 __tm.tm_sec = (int)__hms.seconds().count();
1164 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
1168 if constexpr (__hms.fractional_width == 0)
1169 __out = __format::__write(
std::move(__out),
1170 _S_two_digits(__hms.seconds().count()));
1173 locale __loc = _M_locale(__ctx);
1174 auto __s = __hms.seconds();
1175 auto __ss = __hms.subseconds();
1176 using rep =
typename decltype(__ss)::rep;
1177 if constexpr (is_floating_point_v<rep>)
1179 chrono::duration<rep> __fs = __s + __ss;
1180 __out = std::format_to(
std::move(__out), __loc,
1181 _GLIBCXX_WIDEN(
"{:#0{}.{}Lf}"),
1183 3 + __hms.fractional_width,
1184 __hms.fractional_width);
1189 = use_facet<numpunct<_CharT>>(__loc);
1190 __out = __format::__write(
std::move(__out),
1191 _S_two_digits(__s.count()));
1192 *__out++ = __np.decimal_point();
1193 if constexpr (is_integral_v<rep>)
1194 __out = std::format_to(
std::move(__out),
1195 _GLIBCXX_WIDEN(
"{:0{}}"),
1197 __hms.fractional_width);
1200 auto __str = std::format(_S_empty_spec, __ss.count());
1201 __out = std::format_to(_GLIBCXX_WIDEN(
"{:0>{}s}"),
1203 __hms.fractional_width);
1212 template<
typename _Tp,
typename _FormatContext>
1213 typename _FormatContext::iterator
1214 _M_u_w(
const _Tp& __t,
typename _FormatContext::iterator __out,
1215 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
1222 chrono::weekday __wd = _S_weekday(__t);
1224 if (__mod) [[unlikely]]
1227 __tm.tm_wday = __wd.c_encoding();
1228 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
1232 unsigned __wdi = __conv ==
'u' ? __wd.iso_encoding()
1233 : __wd.c_encoding();
1234 const _CharT __d = _S_digit(__wdi);
1235 return __format::__write(
std::move(__out), __string_view(&__d, 1));
1238 template<
typename _Tp,
typename _FormatContext>
1239 typename _FormatContext::iterator
1240 _M_U_V_W(
const _Tp& __t,
typename _FormatContext::iterator __out,
1241 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
1249 using namespace chrono;
1250 auto __d = _S_days(__t);
1251 using _TDays =
decltype(__d);
1253 if (__mod) [[unlikely]]
1255 const year_month_day __ymd(__d);
1256 const year __y = __ymd.year();
1258 __tm.tm_year = (int)__y - 1900;
1259 __tm.tm_yday = (__d - _TDays(__y/January/1)).count();
1260 __tm.tm_wday = weekday(__d).c_encoding();
1261 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
1269 __d -= (weekday(__d) - Monday) -
days(3);
1272 __first = _TDays(year_month_day(__d).year()/January/1);
1277 if constexpr (
requires { __t.year(); })
1280 __y = year_month_day(__d).year();
1281 const weekday __weekstart = __conv ==
'U' ? Sunday : Monday;
1282 __first = _TDays(__y/January/__weekstart[1]);
1284 auto __weeks = chrono::floor<weeks>(__d - __first);
1285 __string_view __sv = _S_two_digits(__weeks.count() + 1);
1286 return __format::__write(
std::move(__out), __sv);
1289 template<
typename _Tp,
typename _FormatContext>
1290 typename _FormatContext::iterator
1291 _M_x(
const _Tp& __t,
typename _FormatContext::iterator __out,
1292 _FormatContext& __ctx,
bool __mod =
false)
const
1296 locale __loc = _M_locale(__ctx);
1297 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1298 const _CharT* __date_reps[2];
1299 __tp._M_date_formats(__date_reps);
1300 const _CharT* __rep = __date_reps[__mod];
1302 return _M_D(__t,
std::move(__out), __ctx);
1304 basic_string<_CharT> __fmt(_S_empty_spec);
1305 __fmt.insert(1u, 1u, _S_colon);
1306 __fmt.insert(2u, __rep);
1307 return std::vformat_to(
std::move(__out), __fmt,
1308 std::make_format_args<_FormatContext>(__t));
1311 template<
typename _Tp,
typename _FormatContext>
1312 typename _FormatContext::iterator
1313 _M_X(
const _Tp& __tt,
typename _FormatContext::iterator __out,
1314 _FormatContext& __ctx,
bool __mod =
false)
const
1318 auto __t = _S_floor_seconds(__tt);
1319 locale __loc = _M_locale(__ctx);
1320 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1321 const _CharT* __time_reps[2];
1322 __tp._M_time_formats(__time_reps);
1323 const _CharT* __rep = __time_reps[__mod];
1325 return _M_R_T(__t,
std::move(__out), __ctx,
true);
1327 basic_string<_CharT> __fmt(_S_empty_spec);
1328 __fmt.insert(1u, 1u, _S_colon);
1329 __fmt.insert(2u, __rep);
1330 return std::vformat_to(
std::move(__out), __fmt,
1331 std::make_format_args<_FormatContext>(__t));
1334 template<
typename _Tp,
typename _FormatContext>
1335 typename _FormatContext::iterator
1336 _M_z(
const _Tp& __t,
typename _FormatContext::iterator __out,
1337 _FormatContext&,
bool __mod =
false)
const
1339 using ::std::chrono::__detail::__utc_leap_second;
1340 using ::std::chrono::__detail::__local_time_fmt;
1342 auto __utc = __mod ? __string_view(_GLIBCXX_WIDEN(
"+00:00"), 6)
1343 : __string_view(_GLIBCXX_WIDEN(
"+0000"), 5);
1345 if constexpr (chrono::__is_time_point_v<_Tp>)
1347 if constexpr (is_same_v<
typename _Tp::clock,
1348 chrono::system_clock>)
1349 return __format::__write(
std::move(__out), __utc);
1351 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1353 if (__t._M_offset_sec)
1356 basic_string<_CharT> __s;
1357 if (*__t._M_offset_sec != 0s)
1359 chrono:: hh_mm_ss __hms(*__t._M_offset_sec);
1360 __s = _S_plus_minus[__hms.is_negative()];
1361 __s += _S_two_digits(__hms.hours().count());
1364 __s += _S_two_digits(__hms.minutes().count());
1367 return __format::__write(
std::move(__out), __sv);
1370 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1371 return __format::__write(
std::move(__out), __utc);
1373 __no_timezone_available();
1376 template<
typename _Tp,
typename _FormatContext>
1377 typename _FormatContext::iterator
1378 _M_Z(
const _Tp& __t,
typename _FormatContext::iterator __out,
1379 _FormatContext& __ctx)
const
1381 using ::std::chrono::__detail::__utc_leap_second;
1382 using ::std::chrono::__detail::__local_time_fmt;
1384 __string_view __utc(_GLIBCXX_WIDEN(
"UTC"), 3);
1385 if constexpr (chrono::__is_time_point_v<_Tp>)
1387 if constexpr (is_same_v<
typename _Tp::clock,
1388 chrono::system_clock>)
1389 return __format::__write(
std::move(__out), __utc);
1391 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1395 string_view __sv = *__t._M_abbrev;
1396 if constexpr (is_same_v<_CharT, char>)
1397 return __format::__write(
std::move(__out), __sv);
1401 basic_string<_CharT> __ws(__sv.size(), _CharT());
1402 auto& __ct = use_facet<ctype<_CharT>>(_M_locale(__ctx));
1403 __ct.widen(__sv.begin(), __sv.end(), __ws.data());
1404 __string_view __wsv = __ws;
1405 return __format::__write(
std::move(__out), __wsv);
1409 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1410 return __format::__write(
std::move(__out), __utc);
1412 __no_timezone_available();
1419 _S_digit(
int __n)
noexcept
1422 return _GLIBCXX_WIDEN(
"0123456789999999")[__n & 0xf];
1426 static basic_string_view<_CharT>
1427 _S_two_digits(
int __n)
noexcept
1430 _GLIBCXX_WIDEN(
"0001020304050607080910111213141516171819"
1431 "2021222324252627282930313233343536373839"
1432 "4041424344454647484950515253545556575859"
1433 "6061626364656667686970717273747576777879"
1434 "8081828384858687888990919293949596979899"
1435 "9999999999999999999999999999999999999999"
1436 "9999999999999999") + 2 * (__n & 0x7f),
1444 template<
typename _Tp>
1445 static decltype(
auto)
1446 _S_hms(
const _Tp& __t)
1448 using ::std::chrono::__detail::__utc_leap_second;
1449 using ::std::chrono::__detail::__local_time_fmt;
1451 if constexpr (__is_specialization_of<_Tp, chrono::hh_mm_ss>)
1453 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1455 else if constexpr (chrono::__is_duration_v<_Tp>)
1456 return chrono::hh_mm_ss<_Tp>(__t);
1457 else if constexpr (chrono::__is_time_point_v<_Tp>)
1458 return chrono::hh_mm_ss(__t - chrono::floor<chrono::days>(__t));
1459 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1460 return _S_hms(__t._M_time);
1463 __invalid_chrono_spec();
1464 return chrono::hh_mm_ss<chrono::seconds>();
1469 template<
typename _Tp>
1471 _S_days(
const _Tp& __t)
1473 using namespace chrono;
1474 using ::std::chrono::__detail::__utc_leap_second;
1475 using ::std::chrono::__detail::__local_time_fmt;
1477 if constexpr (__is_time_point_v<_Tp>)
1478 return chrono::floor<days>(__t);
1479 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1481 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1482 return chrono::floor<days>(__t._M_time);
1483 else if constexpr (is_same_v<_Tp, year_month_day>
1484 || is_same_v<_Tp, year_month_day_last>
1485 || is_same_v<_Tp, year_month_weekday>
1486 || is_same_v<_Tp, year_month_weekday_last>)
1487 return sys_days(__t);
1490 if constexpr (__is_duration_v<_Tp>)
1491 __not_valid_for_duration();
1493 __invalid_chrono_spec();
1494 return chrono::sys_days();
1499 template<
typename _Tp>
1500 static chrono::year_month_day
1501 _S_date(
const _Tp& __t)
1503 if constexpr (is_same_v<_Tp, chrono::year_month_day>)
1506 return chrono::year_month_day(_S_days(__t));
1509 template<
typename _Tp>
1511 _S_day(
const _Tp& __t)
1513 using namespace chrono;
1515 if constexpr (is_same_v<_Tp, day>)
1517 else if constexpr (
requires { __t.day(); })
1520 return _S_date(__t).day();
1523 template<
typename _Tp>
1524 static chrono::month
1525 _S_month(
const _Tp& __t)
1527 using namespace chrono;
1529 if constexpr (is_same_v<_Tp, month>)
1531 else if constexpr (
requires { __t.month(); })
1534 return _S_date(__t).month();
1537 template<
typename _Tp>
1539 _S_year(
const _Tp& __t)
1541 using namespace chrono;
1543 if constexpr (is_same_v<_Tp, year>)
1545 else if constexpr (
requires { __t.year(); })
1548 return _S_date(__t).year();
1551 template<
typename _Tp>
1552 static chrono::weekday
1553 _S_weekday(
const _Tp& __t)
1555 using namespace ::std::chrono;
1556 using ::std::chrono::__detail::__local_time_fmt;
1558 if constexpr (is_same_v<_Tp, weekday>)
1560 else if constexpr (
requires { __t.weekday(); })
1561 return __t.weekday();
1562 else if constexpr (is_same_v<_Tp, month_weekday>)
1563 return __t.weekday_indexed().weekday();
1564 else if constexpr (is_same_v<_Tp, month_weekday_last>)
1565 return __t.weekday_last().weekday();
1567 return weekday(_S_days(__t));
1571 template<
typename _Tp>
1573 _S_floor_seconds(
const _Tp& __t)
1575 using chrono::__detail::__local_time_fmt;
1576 if constexpr (chrono::__is_time_point_v<_Tp>
1577 || chrono::__is_duration_v<_Tp>)
1579 if constexpr (_Tp::period::den != 1)
1580 return chrono::floor<chrono::seconds>(__t);
1584 else if constexpr (__is_specialization_of<_Tp, chrono::hh_mm_ss>)
1586 if constexpr (_Tp::fractional_width != 0)
1587 return chrono::floor<chrono::seconds>(__t.to_duration());
1591 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1592 return _S_floor_seconds(__t._M_time);
1599 template<
typename _Iter>
1601 _M_locale_fmt(_Iter __out,
const locale& __loc,
const struct tm& __tm,
1602 char __fmt,
char __mod)
const
1604 basic_ostringstream<_CharT> __os;
1605 const auto& __tp = use_facet<time_put<_CharT>>(__loc);
1606 __tp.put(__os, __os, _S_space, &__tm, __fmt, __mod);
1608 __out = __format::__write(
std::move(__out), __os.view());
1616 template<
typename _Rep,
typename _Period,
typename _CharT>
1617 struct formatter<
chrono::duration<_Rep, _Period>, _CharT>
1619 constexpr typename basic_format_parse_context<_CharT>::iterator
1620 parse(basic_format_parse_context<_CharT>& __pc)
1622 using namespace __format;
1623 auto __it = _M_f._M_parse(__pc, _Duration|_TimeOfDay);
1624 if constexpr (!is_floating_point_v<_Rep>)
1625 if (_M_f._M_spec._M_prec_kind != __format::_WP_none)
1626 __throw_format_error(
"format error: invalid precision for duration");
1630 template<
typename _Out>
1631 typename basic_format_context<_Out, _CharT>::iterator
1632 format(
const chrono::duration<_Rep, _Period>& __d,
1633 basic_format_context<_Out, _CharT>& __fc)
const
1635 if constexpr (numeric_limits<_Rep>::is_signed)
1636 if (__d < __d.zero()) [[unlikely]]
1638 if constexpr (is_integral_v<_Rep>)
1642 using _URep = make_unsigned_t<_Rep>;
1643 auto __ucnt = -
static_cast<_URep
>(__d.count());
1644 auto __ud = chrono::duration<_URep, _Period>(__ucnt);
1645 return _M_f._M_format(__ud, __fc,
true);
1648 return _M_f._M_format(-__d, __fc,
true);
1650 return _M_f._M_format(__d, __fc,
false);
1654 __format::__formatter_chrono<_CharT> _M_f;
1657 template<
typename _CharT>
1658 struct formatter<
chrono::day, _CharT>
1660 template<
typename _ParseContext>
1661 constexpr typename _ParseContext::iterator
1662 parse(_ParseContext& __pc)
1663 {
return _M_f._M_parse(__pc, __format::_Day); }
1665 template<
typename _FormatContext>
1666 typename _FormatContext::iterator
1667 format(
const chrono::day& __t, _FormatContext& __fc)
const
1668 {
return _M_f._M_format(__t, __fc); }
1671 __format::__formatter_chrono<_CharT> _M_f;
1674 template<
typename _CharT>
1675 struct formatter<
chrono::month, _CharT>
1677 template<
typename _ParseContext>
1678 constexpr typename _ParseContext::iterator
1679 parse(_ParseContext& __pc)
1680 {
return _M_f._M_parse(__pc, __format::_Month); }
1682 template<
typename _FormatContext>
1683 typename _FormatContext::iterator
1684 format(
const chrono::month& __t, _FormatContext& __fc)
const
1685 {
return _M_f._M_format(__t, __fc); }
1688 __format::__formatter_chrono<_CharT> _M_f;
1691 template<
typename _CharT>
1692 struct formatter<
chrono::year, _CharT>
1694 template<
typename _ParseContext>
1695 constexpr typename _ParseContext::iterator
1696 parse(_ParseContext& __pc)
1697 {
return _M_f._M_parse(__pc, __format::_Year); }
1699 template<
typename _FormatContext>
1700 typename _FormatContext::iterator
1701 format(
const chrono::year& __t, _FormatContext& __fc)
const
1702 {
return _M_f._M_format(__t, __fc); }
1705 __format::__formatter_chrono<_CharT> _M_f;
1708 template<
typename _CharT>
1709 struct formatter<
chrono::weekday, _CharT>
1711 template<
typename _ParseContext>
1712 constexpr typename _ParseContext::iterator
1713 parse(_ParseContext& __pc)
1714 {
return _M_f._M_parse(__pc, __format::_Weekday); }
1716 template<
typename _FormatContext>
1717 typename _FormatContext::iterator
1718 format(
const chrono::weekday& __t, _FormatContext& __fc)
const
1719 {
return _M_f._M_format(__t, __fc); }
1722 __format::__formatter_chrono<_CharT> _M_f;
1725 template<
typename _CharT>
1726 struct formatter<
chrono::weekday_indexed, _CharT>
1728 template<
typename _ParseContext>
1729 constexpr typename _ParseContext::iterator
1730 parse(_ParseContext& __pc)
1731 {
return _M_f._M_parse(__pc, __format::_Weekday); }
1733 template<
typename _FormatContext>
1734 typename _FormatContext::iterator
1735 format(
const chrono::weekday_indexed& __t, _FormatContext& __fc)
const
1736 {
return _M_f._M_format(__t, __fc); }
1739 __format::__formatter_chrono<_CharT> _M_f;
1742 template<
typename _CharT>
1743 struct formatter<
chrono::weekday_last, _CharT>
1745 template<
typename _ParseContext>
1746 constexpr typename _ParseContext::iterator
1747 parse(_ParseContext& __pc)
1748 {
return _M_f._M_parse(__pc, __format::_Weekday); }
1750 template<
typename _FormatContext>
1751 typename _FormatContext::iterator
1752 format(
const chrono::weekday_last& __t, _FormatContext& __fc)
const
1753 {
return _M_f._M_format(__t, __fc); }
1756 __format::__formatter_chrono<_CharT> _M_f;
1759 template<
typename _CharT>
1760 struct formatter<
chrono::month_day, _CharT>
1762 template<
typename _ParseContext>
1763 constexpr typename _ParseContext::iterator
1764 parse(_ParseContext& __pc)
1765 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Day); }
1767 template<
typename _FormatContext>
1768 typename _FormatContext::iterator
1769 format(
const chrono::month_day& __t, _FormatContext& __fc)
const
1770 {
return _M_f._M_format(__t, __fc); }
1773 __format::__formatter_chrono<_CharT> _M_f;
1776 template<
typename _CharT>
1777 struct formatter<
chrono::month_day_last, _CharT>
1779 template<
typename _ParseContext>
1780 constexpr typename _ParseContext::iterator
1781 parse(_ParseContext& __pc)
1782 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Day); }
1784 template<
typename _FormatContext>
1785 typename _FormatContext::iterator
1786 format(
const chrono::month_day_last& __t, _FormatContext& __fc)
const
1787 {
return _M_f._M_format(__t, __fc); }
1790 __format::__formatter_chrono<_CharT> _M_f;
1793 template<
typename _CharT>
1794 struct formatter<
chrono::month_weekday, _CharT>
1796 template<
typename _ParseContext>
1797 constexpr typename _ParseContext::iterator
1798 parse(_ParseContext& __pc)
1799 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Weekday); }
1801 template<
typename _FormatContext>
1802 typename _FormatContext::iterator
1803 format(
const chrono::month_weekday& __t, _FormatContext& __fc)
const
1804 {
return _M_f._M_format(__t, __fc); }
1807 __format::__formatter_chrono<_CharT> _M_f;
1810 template<
typename _CharT>
1811 struct formatter<
chrono::month_weekday_last, _CharT>
1813 template<
typename _ParseContext>
1814 constexpr typename _ParseContext::iterator
1815 parse(_ParseContext& __pc)
1816 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Weekday); }
1818 template<
typename _FormatContext>
1819 typename _FormatContext::iterator
1820 format(
const chrono::month_weekday_last& __t,
1821 _FormatContext& __fc)
const
1822 {
return _M_f._M_format(__t, __fc); }
1825 __format::__formatter_chrono<_CharT> _M_f;
1828 template<
typename _CharT>
1829 struct formatter<
chrono::year_month, _CharT>
1831 template<
typename _ParseContext>
1832 constexpr typename _ParseContext::iterator
1833 parse(_ParseContext& __pc)
1834 {
return _M_f._M_parse(__pc, __format::_Year|__format::_Month); }
1836 template<
typename _FormatContext>
1837 typename _FormatContext::iterator
1838 format(
const chrono::year_month& __t, _FormatContext& __fc)
const
1839 {
return _M_f._M_format(__t, __fc); }
1842 __format::__formatter_chrono<_CharT> _M_f;
1845 template<
typename _CharT>
1846 struct formatter<
chrono::year_month_day, _CharT>
1848 template<
typename _ParseContext>
1849 constexpr typename _ParseContext::iterator
1850 parse(_ParseContext& __pc)
1851 {
return _M_f._M_parse(__pc, __format::_Date); }
1853 template<
typename _FormatContext>
1854 typename _FormatContext::iterator
1855 format(
const chrono::year_month_day& __t, _FormatContext& __fc)
const
1856 {
return _M_f._M_format(__t, __fc); }
1859 __format::__formatter_chrono<_CharT> _M_f;
1862 template<
typename _CharT>
1863 struct formatter<
chrono::year_month_day_last, _CharT>
1865 template<
typename _ParseContext>
1866 constexpr typename _ParseContext::iterator
1867 parse(_ParseContext& __pc)
1868 {
return _M_f._M_parse(__pc, __format::_Date); }
1870 template<
typename _FormatContext>
1871 typename _FormatContext::iterator
1872 format(
const chrono::year_month_day_last& __t,
1873 _FormatContext& __fc)
const
1874 {
return _M_f._M_format(__t, __fc); }
1877 __format::__formatter_chrono<_CharT> _M_f;
1880 template<
typename _CharT>
1881 struct formatter<
chrono::year_month_weekday, _CharT>
1883 template<
typename _ParseContext>
1884 constexpr typename _ParseContext::iterator
1885 parse(_ParseContext& __pc)
1886 {
return _M_f._M_parse(__pc, __format::_Date); }
1888 template<
typename _FormatContext>
1889 typename _FormatContext::iterator
1890 format(
const chrono::year_month_weekday& __t,
1891 _FormatContext& __fc)
const
1892 {
return _M_f._M_format(__t, __fc); }
1895 __format::__formatter_chrono<_CharT> _M_f;
1898 template<
typename _CharT>
1899 struct formatter<
chrono::year_month_weekday_last, _CharT>
1901 template<
typename _ParseContext>
1902 constexpr typename _ParseContext::iterator
1903 parse(_ParseContext& __pc)
1904 {
return _M_f._M_parse(__pc, __format::_Date); }
1906 template<
typename _FormatContext>
1907 typename _FormatContext::iterator
1908 format(
const chrono::year_month_weekday_last& __t,
1909 _FormatContext& __fc)
const
1910 {
return _M_f._M_format(__t, __fc); }
1913 __format::__formatter_chrono<_CharT> _M_f;
1916 template<
typename _Rep,
typename _Period,
typename _CharT>
1917 struct formatter<
chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>, _CharT>
1919 template<
typename _ParseContext>
1920 constexpr typename _ParseContext::iterator
1921 parse(_ParseContext& __pc)
1922 {
return _M_f._M_parse(__pc, __format::_TimeOfDay); }
1924 template<
typename _FormatContext>
1925 typename _FormatContext::iterator
1926 format(
const chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>& __t,
1927 _FormatContext& __fc)
const
1928 {
return _M_f._M_format(__t, __fc); }
1931 __format::__formatter_chrono<_CharT> _M_f;
1934#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
1935 template<
typename _CharT>
1936 struct formatter<
chrono::sys_info, _CharT>
1938 template<
typename _ParseContext>
1939 constexpr typename _ParseContext::iterator
1940 parse(_ParseContext& __pc)
1941 {
return _M_f._M_parse(__pc, __format::_ChronoParts{}); }
1943 template<
typename _FormatContext>
1944 typename _FormatContext::iterator
1945 format(
const chrono::sys_info& __i, _FormatContext& __fc)
const
1946 {
return _M_f._M_format(__i, __fc); }
1949 __format::__formatter_chrono<_CharT> _M_f;
1952 template<
typename _CharT>
1953 struct formatter<
chrono::local_info, _CharT>
1955 template<
typename _ParseContext>
1956 constexpr typename _ParseContext::iterator
1957 parse(_ParseContext& __pc)
1958 {
return _M_f._M_parse(__pc, __format::_ChronoParts{}); }
1960 template<
typename _FormatContext>
1961 typename _FormatContext::iterator
1962 format(
const chrono::local_info& __i, _FormatContext& __fc)
const
1963 {
return _M_f._M_format(__i, __fc); }
1966 __format::__formatter_chrono<_CharT> _M_f;
1970 template<
typename _Duration,
typename _CharT>
1971 struct formatter<
chrono::sys_time<_Duration>, _CharT>
1973 template<
typename _ParseContext>
1974 constexpr typename _ParseContext::iterator
1975 parse(_ParseContext& __pc)
1977 auto __next = _M_f._M_parse(__pc, __format::_ZonedDateTime);
1978 if constexpr (!__stream_insertable)
1979 if (_M_f._M_spec._M_chrono_specs.empty())
1980 __format::__invalid_chrono_spec();
1984 template<
typename _FormatContext>
1985 typename _FormatContext::iterator
1986 format(
const chrono::sys_time<_Duration>& __t,
1987 _FormatContext& __fc)
const
1988 {
return _M_f._M_format(__t, __fc); }
1991 static constexpr bool __stream_insertable
1992 =
requires (basic_ostream<_CharT>& __os,
1993 chrono::sys_time<_Duration> __t) { __os << __t; };
1995 __format::__formatter_chrono<_CharT> _M_f;
1998 template<
typename _Duration,
typename _CharT>
1999 struct formatter<
chrono::utc_time<_Duration>, _CharT>
2000 : __format::__formatter_chrono<_CharT>
2002 template<
typename _ParseContext>
2003 constexpr typename _ParseContext::iterator
2004 parse(_ParseContext& __pc)
2005 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2007 template<
typename _FormatContext>
2008 typename _FormatContext::iterator
2009 format(
const chrono::utc_time<_Duration>& __t,
2010 _FormatContext& __fc)
const
2015 using chrono::__detail::__utc_leap_second;
2016 using chrono::seconds;
2017 using chrono::sys_time;
2018 using _CDur = common_type_t<_Duration, seconds>;
2019 const auto __li = chrono::get_leap_second_info(__t);
2020 sys_time<_CDur> __s{__t.time_since_epoch() - __li.elapsed};
2021 if (!__li.is_leap_second) [[likely]]
2022 return _M_f._M_format(__s, __fc);
2024 return _M_f._M_format(__utc_leap_second(__s), __fc);
2028 friend formatter<chrono::__detail::__utc_leap_second<_Duration>, _CharT>;
2030 __format::__formatter_chrono<_CharT> _M_f;
2033 template<
typename _Duration,
typename _CharT>
2034 struct formatter<
chrono::tai_time<_Duration>, _CharT>
2035 : __format::__formatter_chrono<_CharT>
2037 template<
typename _ParseContext>
2038 constexpr typename _ParseContext::iterator
2039 parse(_ParseContext& __pc)
2040 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2042 template<
typename _FormatContext>
2043 typename _FormatContext::iterator
2044 format(
const chrono::tai_time<_Duration>& __t,
2045 _FormatContext& __fc)
const
2052 constexpr chrono::days __tai_offset = chrono::days(4383);
2053 using _CDur = common_type_t<_Duration, chrono::days>;
2054 chrono::local_time<_CDur> __lt(__t.time_since_epoch() - __tai_offset);
2055 const string __abbrev(
"TAI", 3);
2056 const chrono::seconds __off = 0s;
2057 const auto __lf = chrono::local_time_format(__lt, &__abbrev, &__off);
2058 return _M_f._M_format(__lf, __fc);
2062 __format::__formatter_chrono<_CharT> _M_f;
2065 template<
typename _Duration,
typename _CharT>
2066 struct formatter<
chrono::gps_time<_Duration>, _CharT>
2067 : __format::__formatter_chrono<_CharT>
2069 template<
typename _ParseContext>
2070 constexpr typename _ParseContext::iterator
2071 parse(_ParseContext& __pc)
2072 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2074 template<
typename _FormatContext>
2075 typename _FormatContext::iterator
2076 format(
const chrono::gps_time<_Duration>& __t,
2077 _FormatContext& __fc)
const
2084 constexpr chrono::days __gps_offset = chrono::days(3657);
2085 using _CDur = common_type_t<_Duration, chrono::days>;
2086 chrono::local_time<_CDur> __lt(__t.time_since_epoch() + __gps_offset);
2087 const string __abbrev(
"GPS", 3);
2088 const chrono::seconds __off = 0s;
2089 const auto __lf = chrono::local_time_format(__lt, &__abbrev, &__off);
2090 return _M_f._M_format(__lf, __fc);
2094 __format::__formatter_chrono<_CharT> _M_f;
2097 template<
typename _Duration,
typename _CharT>
2098 struct formatter<
chrono::file_time<_Duration>, _CharT>
2100 template<
typename _ParseContext>
2101 constexpr typename _ParseContext::iterator
2102 parse(_ParseContext& __pc)
2103 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2105 template<
typename _FormatContext>
2106 typename _FormatContext::iterator
2107 format(
const chrono::file_time<_Duration>& __t,
2108 _FormatContext& __ctx)
const
2110 using namespace chrono;
2111 return _M_f._M_format(chrono::clock_cast<system_clock>(__t), __ctx);
2115 __format::__formatter_chrono<_CharT> _M_f;
2118 template<
typename _Duration,
typename _CharT>
2119 struct formatter<
chrono::local_time<_Duration>, _CharT>
2121 template<
typename _ParseContext>
2122 constexpr typename _ParseContext::iterator
2123 parse(_ParseContext& __pc)
2124 {
return _M_f._M_parse(__pc, __format::_DateTime); }
2126 template<
typename _FormatContext>
2127 typename _FormatContext::iterator
2128 format(
const chrono::local_time<_Duration>& __t,
2129 _FormatContext& __ctx)
const
2130 {
return _M_f._M_format(__t, __ctx); }
2133 __format::__formatter_chrono<_CharT> _M_f;
2136 template<
typename _Duration,
typename _CharT>
2137 struct formatter<
chrono::__detail::__local_time_fmt<_Duration>, _CharT>
2139 template<
typename _ParseContext>
2140 constexpr typename _ParseContext::iterator
2141 parse(_ParseContext& __pc)
2142 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2144 template<
typename _FormatContext>
2145 typename _FormatContext::iterator
2146 format(
const chrono::__detail::__local_time_fmt<_Duration>& __t,
2147 _FormatContext& __ctx)
const
2148 {
return _M_f._M_format(__t, __ctx,
true); }
2151 __format::__formatter_chrono<_CharT> _M_f;
2154#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2155 template<
typename _Duration,
typename _TimeZonePtr,
typename _CharT>
2156 struct formatter<
chrono::zoned_time<_Duration, _TimeZonePtr>, _CharT>
2157 : formatter<chrono::__detail::__local_time_fmt<_Duration>, _CharT>
2159 template<
typename _FormatContext>
2160 typename _FormatContext::iterator
2161 format(
const chrono::zoned_time<_Duration, _TimeZonePtr>& __tp,
2162 _FormatContext& __ctx)
const
2164 using chrono::__detail::__local_time_fmt;
2165 using _Base = formatter<__local_time_fmt<_Duration>, _CharT>;
2166 const chrono::sys_info __info = __tp.get_info();
2167 const auto __lf = chrono::local_time_format(__tp.get_local_time(),
2170 return _Base::format(__lf, __ctx);
2176 template<
typename _Duration,
typename _CharT>
2177 struct formatter<
chrono::__detail::__utc_leap_second<_Duration>, _CharT>
2178 : formatter<chrono::utc_time<_Duration>, _CharT>
2180 template<
typename _FormatContext>
2181 typename _FormatContext::iterator
2182 format(
const chrono::__detail::__utc_leap_second<_Duration>& __t,
2183 _FormatContext& __fc)
const
2184 {
return this->_M_f._M_format(__t, __fc); }
2195 template<
typename _Duration = seconds>
2198 static_assert(is_same_v<common_type_t<_Duration, seconds>, _Duration>);
2201 _Parser(__format::_ChronoParts __need) : _M_need(__need) { }
2203 _Parser(_Parser&&) =
delete;
2204 void operator=(_Parser&&) =
delete;
2206 _Duration _M_time{};
2207 sys_days _M_sys_days{};
2208 year_month_day _M_ymd{};
2210 __format::_ChronoParts _M_need;
2211 unsigned _M_is_leap_second : 1 {};
2212 unsigned _M_reserved : 15 {};
2214 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2215 basic_istream<_CharT, _Traits>&
2216 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2217 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2218 minutes* __offset =
nullptr);
2223 template<
typename _CharT,
typename _Traits>
2224 static int_least32_t
2225 _S_read_unsigned(basic_istream<_CharT, _Traits>& __is,
2226 ios_base::iostate& __err,
int __n)
2228 int_least32_t __val = _S_try_read_digit(__is, __err);
2229 if (__val == -1) [[unlikely]]
2230 __err |= ios_base::failbit;
2235 for (
int __i = 1; __i < __n1; ++__i)
2236 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
2242 while (__n1++ < __n) [[unlikely]]
2243 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
2245 if (__builtin_mul_overflow(__val, 10, &__val)
2246 || __builtin_add_overflow(__val, __dig, &__val))
2248 __err |= ios_base::failbit;
2258 template<
typename _CharT,
typename _Traits>
2259 static int_least32_t
2260 _S_read_signed(basic_istream<_CharT, _Traits>& __is,
2261 ios_base::iostate& __err,
int __n)
2263 auto __sign = __is.peek();
2264 if (__sign ==
'-' || __sign ==
'+')
2266 int_least32_t __val = _S_read_unsigned(__is, __err, __n);
2267 if (__err & ios_base::failbit)
2269 if (__sign ==
'-') [[unlikely]]
2277 template<
typename _CharT,
typename _Traits>
2278 static int_least32_t
2279 _S_try_read_digit(basic_istream<_CharT, _Traits>& __is,
2280 ios_base::iostate& __err)
2282 int_least32_t __val = -1;
2283 auto __i = __is.peek();
2284 if (!_Traits::eq_int_type(__i, _Traits::eof())) [[likely]]
2286 _CharT __c = _Traits::to_char_type(__i);
2287 if (_CharT(
'0') <= __c && __c <= _CharT(
'9')) [[likely]]
2290 __val = __c - _CharT(
'0');
2294 __err |= ios_base::eofbit;
2300 template<
typename _CharT,
typename _Traits>
2302 _S_read_chr(basic_istream<_CharT, _Traits>& __is,
2303 ios_base::iostate& __err, _CharT __c)
2305 auto __i = __is.peek();
2306 if (_Traits::eq_int_type(__i, _Traits::eof()))
2307 __err |= ios_base::eofbit;
2308 else if (_Traits::to_char_type(__i) == __c) [[likely]]
2313 __err |= ios_base::failbit;
2318 template<
typename _Duration>
2319 using _Parser_t = _Parser<common_type_t<_Duration, seconds>>;
2324 template<
typename _CharT,
typename _Traits,
typename _Rep,
typename _Period,
2325 typename _Alloc = allocator<_CharT>>
2326 inline basic_istream<_CharT, _Traits>&
2327 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2329 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2332 auto __need = __format::_ChronoParts::_TimeOfDay;
2333 __detail::_Parser_t<duration<_Rep, _Period>> __p(__need);
2334 if (__p(__is, __fmt, __abbrev, __offset))
2339 template<
typename _CharT,
typename _Traits>
2340 inline basic_ostream<_CharT, _Traits>&
2341 operator<<(basic_ostream<_CharT, _Traits>& __os,
const day& __d)
2343 using _Ctx = __format::__format_context<_CharT>;
2344 using _Str = basic_string_view<_CharT>;
2345 _Str __s = _GLIBCXX_WIDEN(
"{:02d} is not a valid day");
2347 __s = __s.substr(0, 6);
2348 auto __u = (unsigned)__d;
2349 __os << std::vformat(__s, make_format_args<_Ctx>(__u));
2353 template<
typename _CharT,
typename _Traits,
2354 typename _Alloc = allocator<_CharT>>
2355 inline basic_istream<_CharT, _Traits>&
2356 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2358 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2361 __detail::_Parser<> __p(__format::_ChronoParts::_Day);
2362 if (__p(__is, __fmt, __abbrev, __offset))
2363 __d = __p._M_ymd.day();
2367 template<
typename _CharT,
typename _Traits>
2368 inline basic_ostream<_CharT, _Traits>&
2369 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month& __m)
2371 using _Ctx = __format::__format_context<_CharT>;
2372 using _Str = basic_string_view<_CharT>;
2373 _Str __s = _GLIBCXX_WIDEN(
"{:L%b}{} is not a valid month");
2375 __os << std::vformat(__os.getloc(), __s.substr(0, 6),
2376 make_format_args<_Ctx>(__m));
2379 auto __u = (unsigned)__m;
2380 __os << std::vformat(__s.substr(6), make_format_args<_Ctx>(__u));
2385 template<
typename _CharT,
typename _Traits,
2386 typename _Alloc = allocator<_CharT>>
2387 inline basic_istream<_CharT, _Traits>&
2388 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2390 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2393 __detail::_Parser<> __p(__format::_ChronoParts::_Month);
2394 if (__p(__is, __fmt, __abbrev, __offset))
2395 __m = __p._M_ymd.month();
2399 template<
typename _CharT,
typename _Traits>
2400 inline basic_ostream<_CharT, _Traits>&
2401 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year& __y)
2403 using _Ctx = __format::__format_context<_CharT>;
2404 using _Str = basic_string_view<_CharT>;
2405 _Str __s = _GLIBCXX_WIDEN(
"-{:04d} is not a valid year");
2407 __s = __s.substr(0, 7);
2409 if (__i >= 0) [[likely]]
2410 __s.remove_prefix(1);
2413 __os << std::vformat(__s, make_format_args<_Ctx>(__i));
2417 template<
typename _CharT,
typename _Traits,
2418 typename _Alloc = allocator<_CharT>>
2419 inline basic_istream<_CharT, _Traits>&
2420 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2422 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2425 __detail::_Parser<> __p(__format::_ChronoParts::_Year);
2426 if (__p(__is, __fmt, __abbrev, __offset))
2427 __y = __p._M_ymd.year();
2431 template<
typename _CharT,
typename _Traits>
2432 inline basic_ostream<_CharT, _Traits>&
2433 operator<<(basic_ostream<_CharT, _Traits>& __os,
const weekday& __wd)
2435 using _Ctx = __format::__format_context<_CharT>;
2436 using _Str = basic_string_view<_CharT>;
2437 _Str __s = _GLIBCXX_WIDEN(
"{:L%a}{} is not a valid weekday");
2439 __os << std::vformat(__os.getloc(), __s.substr(0, 6),
2440 make_format_args<_Ctx>(__wd));
2443 auto __c = __wd.c_encoding();
2444 __os << std::vformat(__s.substr(6), make_format_args<_Ctx>(__c));
2449 template<
typename _CharT,
typename _Traits,
2450 typename _Alloc = allocator<_CharT>>
2451 inline basic_istream<_CharT, _Traits>&
2452 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2454 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2457 __detail::_Parser<> __p(__format::_ChronoParts::_Weekday);
2458 if (__p(__is, __fmt, __abbrev, __offset))
2463 template<
typename _CharT,
typename _Traits>
2464 inline basic_ostream<_CharT, _Traits>&
2465 operator<<(basic_ostream<_CharT, _Traits>& __os,
2466 const weekday_indexed& __wdi)
2471 basic_stringstream<_CharT> __os2;
2472 __os2.imbue(__os.getloc());
2473 __os2 << __wdi.weekday();
2474 const auto __i = __wdi.index();
2475 basic_string_view<_CharT> __s
2476 = _GLIBCXX_WIDEN(
"[ is not a valid index]");
2478 __os2 << std::format(_GLIBCXX_WIDEN(
"{}"), __i);
2479 if (__i >= 1 && __i <= 5)
2480 __os2 << __s.back();
2482 __os2 << __s.substr(1);
2483 __os << __os2.view();
2487 template<
typename _CharT,
typename _Traits>
2488 inline basic_ostream<_CharT, _Traits>&
2489 operator<<(basic_ostream<_CharT, _Traits>& __os,
2490 const weekday_last& __wdl)
2493 basic_stringstream<_CharT> __os2;
2494 __os2.imbue(__os.getloc());
2495 __os2 << __wdl.weekday() << _GLIBCXX_WIDEN(
"[last]");
2496 __os << __os2.view();
2500 template<
typename _CharT,
typename _Traits>
2501 inline basic_ostream<_CharT, _Traits>&
2502 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month_day& __md)
2505 basic_stringstream<_CharT> __os2;
2506 __os2.imbue(__os.getloc());
2507 __os2 << __md.month();
2508 if constexpr (is_same_v<_CharT, char>)
2512 __os2 << __md.day();
2513 __os << __os2.view();
2517 template<
typename _CharT,
typename _Traits,
2518 typename _Alloc = allocator<_CharT>>
2519 inline basic_istream<_CharT, _Traits>&
2520 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2522 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2525 using __format::_ChronoParts;
2526 auto __need = _ChronoParts::_Month | _ChronoParts::_Day;
2527 __detail::_Parser<> __p(__need);
2528 if (__p(__is, __fmt, __abbrev, __offset))
2529 __md = month_day(__p._M_ymd.month(), __p._M_ymd.day());
2533 template<
typename _CharT,
typename _Traits>
2534 inline basic_ostream<_CharT, _Traits>&
2535 operator<<(basic_ostream<_CharT, _Traits>& __os,
2536 const month_day_last& __mdl)
2539 basic_stringstream<_CharT> __os2;
2540 __os2.imbue(__os.getloc());
2541 __os2 << __mdl.month() << _GLIBCXX_WIDEN(
"/last");
2542 __os << __os2.view();
2546 template<
typename _CharT,
typename _Traits>
2547 inline basic_ostream<_CharT, _Traits>&
2548 operator<<(basic_ostream<_CharT, _Traits>& __os,
2549 const month_weekday& __mwd)
2552 basic_stringstream<_CharT> __os2;
2553 __os2.imbue(__os.getloc());
2554 __os2 << __mwd.month();
2555 if constexpr (is_same_v<_CharT, char>)
2559 __os2 << __mwd.weekday_indexed();
2560 __os << __os2.view();
2564 template<
typename _CharT,
typename _Traits>
2565 inline basic_ostream<_CharT, _Traits>&
2566 operator<<(basic_ostream<_CharT, _Traits>& __os,
2567 const month_weekday_last& __mwdl)
2570 basic_stringstream<_CharT> __os2;
2571 __os2.imbue(__os.getloc());
2572 __os2 << __mwdl.month();
2573 if constexpr (is_same_v<_CharT, char>)
2577 __os2 << __mwdl.weekday_last();
2578 __os << __os2.view();
2582 template<
typename _CharT,
typename _Traits>
2583 inline basic_ostream<_CharT, _Traits>&
2584 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year_month& __ym)
2587 basic_stringstream<_CharT> __os2;
2588 __os2.imbue(__os.getloc());
2589 __os2 << __ym.year();
2590 if constexpr (is_same_v<_CharT, char>)
2594 __os2 << __ym.month();
2595 __os << __os2.view();
2599 template<
typename _CharT,
typename _Traits,
2600 typename _Alloc = allocator<_CharT>>
2601 inline basic_istream<_CharT, _Traits>&
2602 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2604 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2607 using __format::_ChronoParts;
2608 auto __need = _ChronoParts::_Year | _ChronoParts::_Month;
2609 __detail::_Parser<> __p(__need);
2610 if (__p(__is, __fmt, __abbrev, __offset))
2611 __ym = year_month(__p._M_ymd.year(), __p._M_ymd.month());
2615 template<
typename _CharT,
typename _Traits>
2616 inline basic_ostream<_CharT, _Traits>&
2617 operator<<(basic_ostream<_CharT, _Traits>& __os,
2618 const year_month_day& __ymd)
2620 using _Ctx = __format::__format_context<_CharT>;
2621 using _Str = basic_string_view<_CharT>;
2622 _Str __s = _GLIBCXX_WIDEN(
"{:%F} is not a valid date");
2623 __os << std::vformat(__ymd.ok() ? __s.substr(0, 5) : __s,
2624 make_format_args<_Ctx>(__ymd));
2628 template<
typename _CharT,
typename _Traits,
2629 typename _Alloc = allocator<_CharT>>
2630 inline basic_istream<_CharT, _Traits>&
2632 year_month_day& __ymd,
2636 using __format::_ChronoParts;
2637 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2638 | _ChronoParts::_Day;
2639 __detail::_Parser<> __p(__need);
2640 if (__p(__is, __fmt, __abbrev, __offset))
2645 template<
typename _CharT,
typename _Traits>
2648 const year_month_day_last& __ymdl)
2653 __os2 << __ymdl.year();
2654 if constexpr (is_same_v<_CharT, char>)
2658 __os2 << __ymdl.month_day_last();
2659 __os << __os2.view();
2663 template<
typename _CharT,
typename _Traits>
2664 inline basic_ostream<_CharT, _Traits>&
2665 operator<<(basic_ostream<_CharT, _Traits>& __os,
2666 const year_month_weekday& __ymwd)
2670 basic_stringstream<_CharT> __os2;
2671 __os2.
imbue(__os.getloc());
2673 if constexpr (is_same_v<_CharT, char>)
2677 __os2 << __ymwd.year() << __slash << __ymwd.month() << __slash
2678 << __ymwd.weekday_indexed();
2679 __os << __os2.view();
2683 template<
typename _CharT,
typename _Traits>
2684 inline basic_ostream<_CharT, _Traits>&
2685 operator<<(basic_ostream<_CharT, _Traits>& __os,
2686 const year_month_weekday_last& __ymwdl)
2690 basic_stringstream<_CharT> __os2;
2691 __os2.imbue(__os.getloc());
2693 if constexpr (is_same_v<_CharT, char>)
2697 __os2 << __ymwdl.year() << __slash << __ymwdl.month() << __slash
2698 << __ymwdl.weekday_last();
2699 __os << __os2.view();
2703 template<
typename _CharT,
typename _Traits,
typename _Duration>
2704 inline basic_ostream<_CharT, _Traits>&
2705 operator<<(basic_ostream<_CharT, _Traits>& __os,
2708 return __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%T}"), __hms);
2711#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2713 template<
typename _CharT,
typename _Traits>
2714 basic_ostream<_CharT, _Traits>&
2715 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_info& __i)
2717 __os <<
'[' << __i.begin <<
',' << __i.end
2718 <<
',' <<
hh_mm_ss(__i.offset) <<
',' << __i.save
2719 <<
',' << __i.abbrev <<
']';
2724 template<
typename _CharT,
typename _Traits>
2725 basic_ostream<_CharT, _Traits>&
2726 operator<<(basic_ostream<_CharT, _Traits>& __os,
const local_info& __li)
2729 if (__li.result == local_info::unique)
2733 if (__li.result == local_info::nonexistent)
2734 __os <<
"nonexistent";
2736 __os <<
"ambiguous";
2737 __os <<
" local time between " << __li.first;
2738 __os <<
" and " << __li.second;
2744 template<
typename _CharT,
typename _Traits,
typename _Duration,
2745 typename _TimeZonePtr>
2746 inline basic_ostream<_CharT, _Traits>&
2747 operator<<(basic_ostream<_CharT, _Traits>& __os,
2748 const zoned_time<_Duration, _TimeZonePtr>& __t)
2750 __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T %Z}"), __t);
2755 template<
typename _CharT,
typename _Traits,
typename _Duration>
2756 requires (!treat_as_floating_point_v<typename _Duration::rep>)
2757 && ratio_less_v<typename _Duration::period, days::period>
2758 inline basic_ostream<_CharT, _Traits>&
2759 operator<<(basic_ostream<_CharT, _Traits>& __os,
2760 const sys_time<_Duration>& __tp)
2762 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __tp);
2766 template<
typename _CharT,
typename _Traits>
2767 inline basic_ostream<_CharT, _Traits>&
2768 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_days& __dp)
2770 __os << year_month_day{__dp};
2774 template<
typename _CharT,
typename _Traits,
typename _Duration,
2775 typename _Alloc = allocator<_CharT>>
2776 basic_istream<_CharT, _Traits>&
2777 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2778 sys_time<_Duration>& __tp,
2779 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2785 using __format::_ChronoParts;
2786 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2787 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2788 __detail::_Parser_t<_Duration> __p(__need);
2789 if (__p(__is, __fmt, __abbrev, __offset))
2791 if (__p._M_is_leap_second)
2795 auto __st = __p._M_sys_days + __p._M_time - *__offset;
2802 template<
typename _CharT,
typename _Traits,
typename _Duration>
2803 inline basic_ostream<_CharT, _Traits>&
2804 operator<<(basic_ostream<_CharT, _Traits>& __os,
2805 const utc_time<_Duration>& __t)
2807 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
2811 template<
typename _CharT,
typename _Traits,
typename _Duration,
2812 typename _Alloc = allocator<_CharT>>
2813 inline basic_istream<_CharT, _Traits>&
2814 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2815 utc_time<_Duration>& __tp,
2816 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2822 using __format::_ChronoParts;
2823 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2824 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2825 __detail::_Parser_t<_Duration> __p(__need);
2826 if (__p(__is, __fmt, __abbrev, __offset))
2830 auto __ut = utc_clock::from_sys(__p._M_sys_days) + __p._M_time
2837 template<
typename _CharT,
typename _Traits,
typename _Duration>
2838 inline basic_ostream<_CharT, _Traits>&
2839 operator<<(basic_ostream<_CharT, _Traits>& __os,
2840 const tai_time<_Duration>& __t)
2842 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
2846 template<
typename _CharT,
typename _Traits,
typename _Duration,
2847 typename _Alloc = allocator<_CharT>>
2848 inline basic_istream<_CharT, _Traits>&
2849 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2850 tai_time<_Duration>& __tp,
2851 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2857 using __format::_ChronoParts;
2858 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2859 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2860 __detail::_Parser_t<_Duration> __p(__need);
2861 if (__p(__is, __fmt, __abbrev, __offset))
2863 if (__p._M_is_leap_second)
2867 constexpr sys_days __epoch(-
days(4383));
2868 auto __d = __p._M_sys_days - __epoch + __p._M_time - *__offset;
2869 tai_time<common_type_t<_Duration, seconds>> __tt(__d);
2876 template<
typename _CharT,
typename _Traits,
typename _Duration>
2877 inline basic_ostream<_CharT, _Traits>&
2878 operator<<(basic_ostream<_CharT, _Traits>& __os,
2879 const gps_time<_Duration>& __t)
2881 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
2885 template<
typename _CharT,
typename _Traits,
typename _Duration,
2886 typename _Alloc = allocator<_CharT>>
2887 inline basic_istream<_CharT, _Traits>&
2888 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2889 gps_time<_Duration>& __tp,
2890 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2896 using __format::_ChronoParts;
2897 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2898 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2899 __detail::_Parser_t<_Duration> __p(__need);
2900 if (__p(__is, __fmt, __abbrev, __offset))
2902 if (__p._M_is_leap_second)
2906 constexpr sys_days __epoch(
days(3657));
2907 auto __d = __p._M_sys_days - __epoch + __p._M_time - *__offset;
2908 gps_time<common_type_t<_Duration, seconds>> __gt(__d);
2915 template<
typename _CharT,
typename _Traits,
typename _Duration>
2916 inline basic_ostream<_CharT, _Traits>&
2917 operator<<(basic_ostream<_CharT, _Traits>& __os,
2918 const file_time<_Duration>& __t)
2920 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
2924 template<
typename _CharT,
typename _Traits,
typename _Duration,
2925 typename _Alloc = allocator<_CharT>>
2926 inline basic_istream<_CharT, _Traits>&
2927 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2928 file_time<_Duration>& __tp,
2929 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2932 sys_time<_Duration> __st;
2933 if (chrono::from_stream(__is, __fmt, __st, __abbrev, __offset))
2938 template<
typename _CharT,
typename _Traits,
typename _Duration>
2939 inline basic_ostream<_CharT, _Traits>&
2940 operator<<(basic_ostream<_CharT, _Traits>& __os,
2941 const local_time<_Duration>& __lt)
2943 __os << sys_time<_Duration>{__lt.time_since_epoch()};
2947 template<
typename _CharT,
typename _Traits,
typename _Duration,
2948 typename _Alloc = allocator<_CharT>>
2949 basic_istream<_CharT, _Traits>&
2950 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2951 local_time<_Duration>& __tp,
2952 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2955 using __format::_ChronoParts;
2956 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2957 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2958 __detail::_Parser_t<_Duration> __p(__need);
2959 if (__p(__is, __fmt, __abbrev, __offset))
2961 days __d = __p._M_sys_days.time_since_epoch();
2962 auto __t = local_days(__d) + __p._M_time;
2972 template<
typename _Parsable,
typename _CharT,
2973 typename _Traits = std::char_traits<_CharT>,
2974 typename... _OptArgs>
2975 concept __parsable =
requires (basic_istream<_CharT, _Traits>& __is,
2976 const _CharT* __fmt, _Parsable& __tp,
2977 _OptArgs*... __args)
2978 { from_stream(__is, __fmt, __tp, __args...); };
2980 template<
typename _Parsable,
typename _CharT,
2981 typename _Traits = char_traits<_CharT>,
2982 typename _Alloc = allocator<_CharT>>
2986 using __string_type = basic_string<_CharT, _Traits, _Alloc>;
2989 _Parse(
const _CharT* __fmt, _Parsable& __tp,
2990 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2993 _M_abbrev(__abbrev), _M_offset(__offset)
2996 _Parse(_Parse&&) =
delete;
2997 _Parse& operator=(_Parse&&) =
delete;
3000 using __stream_type = basic_istream<_CharT, _Traits>;
3002 const _CharT*
const _M_fmt;
3003 _Parsable*
const _M_tp;
3004 __string_type*
const _M_abbrev;
3007 friend __stream_type&
3008 operator>>(__stream_type& __is, _Parse&& __p)
3011 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev,
3013 else if (__p._M_abbrev)
3014 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev);
3016 from_stream(__is, __p._M_fmt, *__p._M_tp);
3020 friend void operator>>(__stream_type&, _Parse&) =
delete;
3021 friend void operator>>(__stream_type&,
const _Parse&) =
delete;
3025 template<
typename _CharT, __detail::__parsable<_CharT> _Parsable>
3026 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
3028 parse(
const _CharT* __fmt, _Parsable& __tp)
3029 {
return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp); }
3031 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3032 __detail::__parsable<_CharT, _Traits> _Parsable>
3035 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp)
3037 return __detail::_Parse<_Parsable, _CharT, _Traits>(__fmt.c_str(), __tp);
3040 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3041 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
3042 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
3043 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
3045 parse(
const _CharT* __fmt, _Parsable& __tp,
3046 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
3049 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
3053 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3054 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
3055 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
3058 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
3059 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
3062 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
3066 template<
typename _CharT,
typename _Traits =
char_traits<_CharT>,
3067 typename _StrT = basic_
string<_CharT, _Traits>,
3068 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
3069 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
3071 parse(
const _CharT* __fmt, _Parsable& __tp,
minutes& __offset)
3073 return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp,
nullptr,
3077 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3078 typename _StrT = basic_string<_CharT, _Traits>,
3079 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
3082 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
3085 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
3090 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3091 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
3092 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
3093 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
3095 parse(
const _CharT* __fmt, _Parsable& __tp,
3096 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
3099 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
3104 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3105 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
3106 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
3109 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
3110 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
3113 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
3119 template<
typename _Duration>
3120 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3121 basic_istream<_CharT, _Traits>&
3122 __detail::_Parser<_Duration>::
3123 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3124 basic_string<_CharT, _Traits, _Alloc>* __abbrev,
3127 using sentry =
typename basic_istream<_CharT, _Traits>::sentry;
3129 if (sentry __cerb(__is,
true); __cerb)
3131 locale __loc = __is.getloc();
3136 struct _Stream_state
3139 _Stream_state(basic_istream<_CharT, _Traits>& __i)
3141 _M_flags(__i.flags(ios_base::
skipws | ios_base::
dec)),
3147 _M_is.flags(_M_flags);
3151 _Stream_state(_Stream_state&&) =
delete;
3153 basic_istream<_CharT, _Traits>& _M_is;
3154 ios_base::fmtflags _M_flags;
3164 auto __read_unsigned = [&] (
int __n) {
3165 return _S_read_unsigned(__is, __err, __n);
3170 auto __read_signed = [&] (
int __n) {
3171 return _S_read_signed(__is, __err, __n);
3175 auto __read_chr = [&__is, &__err] (_CharT __c) {
3176 return _S_read_chr(__is, __err, __c);
3179 using __format::_ChronoParts;
3180 _ChronoParts __parts{};
3182 const year __bad_y = --year::min();
3183 const month __bad_mon(255);
3184 const day __bad_day(255);
3185 const weekday __bad_wday(255);
3186 const hours __bad_h(-1);
3187 const minutes __bad_min(-9999);
3190 year __y = __bad_y, __yy = __bad_y;
3191 year __iso_y = __bad_y, __iso_yy = __bad_y;
3192 month __m = __bad_mon;
3193 day __d = __bad_day;
3194 weekday __wday = __bad_wday;
3195 hours __h = __bad_h, __h12 = __bad_h;
3197 _Duration __s = __bad_sec;
3199 int __iso_wk = -1, __sunday_wk = -1, __monday_wk = -1;
3201 int __dayofyear = -1;
3203 minutes __tz_offset = __bad_min;
3204 basic_string<_CharT, _Traits> __tz_abbr;
3206 if ((_M_need & _ChronoParts::_TimeOfDay)
3207 && (_M_need & _ChronoParts::_Year))
3213 __parts = _ChronoParts::_TimeOfDay;
3220 bool __is_flag =
false;
3222 constexpr bool __is_floating
3223 = treat_as_floating_point_v<typename _Duration::rep>;
3242 _CharT __c = *__fmt++;
3249 else if (!__read_chr(__c)) [[unlikely]]
3260 if (__mod || __num) [[unlikely]]
3265 __tmget.get(__is, {}, __is, __err, &__tm,
3267 if (!__is_failed(__err))
3268 __wday = weekday(__tm.tm_wday);
3270 __parts |= _ChronoParts::_Weekday;
3276 if (__mod || __num) [[unlikely]]
3284 __tmget.get(__is, {}, __is, __err, &__tm,
3286 if (!__is_failed(__err))
3287 __m = month(__tm.tm_mon + 1);
3289 __parts |= _ChronoParts::_Month;
3293 if (__mod ==
'O' || __num) [[unlikely]]
3298 __tmget.get(__is, {}, __is, __err, &__tm,
3299 __fmt - 2 - (__mod ==
'E'), __fmt);
3300 if (!__is_failed(__err))
3302 __y = year(__tm.tm_year + 1900);
3303 __m = month(__tm.tm_mon + 1);
3304 __d = day(__tm.tm_mday);
3305 __h =
hours(__tm.tm_hour);
3310 __parts |= _ChronoParts::_DateTime;
3314 if (!__mod) [[likely]]
3316 auto __v = __read_signed(__num ? __num : 2);
3317 if (!__is_failed(__err))
3319 int __cmin = (int)year::min() / 100;
3320 int __cmax = (int)year::max() / 100;
3321 if (__cmin <= __v && __v <= __cmax)
3322 __century = __v * 100;
3327 else if (__mod ==
'E')
3330 __tmget.get(__is, {}, __is, __err, &__tm,
3332 if (!__is_failed(__err))
3333 __century = __tm.tm_year;
3342 if (!__mod) [[likely]]
3344 auto __v = __read_unsigned(__num ? __num : 2);
3345 if (!__is_failed(__err))
3348 else if (__mod ==
'O')
3351 __tmget.get(__is, {}, __is, __err, &__tm,
3353 if (!__is_failed(__err))
3354 __d = day(__tm.tm_mday);
3358 __parts |= _ChronoParts::_Day;
3362 if (__mod || __num) [[unlikely]]
3366 auto __month = __read_unsigned(2);
3368 auto __day = __read_unsigned(2);
3370 auto __year = __read_unsigned(2);
3371 if (__is_failed(__err))
3373 __y = year(__year + 1900 + 100 *
int(__year < 69));
3374 __m = month(__month);
3376 if (!year_month_day(__y, __m, __d).ok())
3378 __y = __yy = __iso_y = __iso_yy = __bad_y;
3384 __parts |= _ChronoParts::_Date;
3388 if (__mod) [[unlikely]]
3392 auto __year = __read_signed(__num ? __num : 4);
3394 auto __month = __read_unsigned(2);
3396 auto __day = __read_unsigned(2);
3397 if (__is_failed(__err))
3400 __m = month(__month);
3402 if (!year_month_day(__y, __m, __d).ok())
3404 __y = __yy = __iso_y = __iso_yy = __bad_y;
3410 __parts |= _ChronoParts::_Date;
3414 if (__mod) [[unlikely]]
3418 auto __val = __read_unsigned(__num ? __num : 2);
3419 if (__val >= 0 && __val <= 99)
3421 __iso_yy = year(__val);
3422 if (__century == -1)
3426 __iso_yy = __iso_y = __y = __yy = __bad_y;
3428 __parts |= _ChronoParts::_Year;
3432 if (__mod) [[unlikely]]
3435 __iso_y = year(__read_unsigned(__num ? __num : 4));
3436 __parts |= _ChronoParts::_Year;
3441 if (__mod ==
'E') [[unlikely]]
3443 else if (__mod ==
'O')
3448 __tmget.get(__is, {}, __is, __err, &__tm,
3450 if (!__is_failed(__err))
3454 __h12 =
hours(__tm.tm_hour);
3458 __h =
hours(__tm.tm_hour);
3467 auto __val = __read_unsigned(__num ? __num : 2);
3468 if (__c ==
'I' && __val >= 1 && __val <= 12)
3470 __h12 =
hours(__val);
3473 else if (__c ==
'H' && __val >= 0 && __val <= 23)
3480 if (_M_need & _ChronoParts::_TimeOfDay)
3485 __parts |= _ChronoParts::_TimeOfDay;
3489 if (__mod) [[unlikely]]
3491 else if (_M_need == _ChronoParts::_TimeOfDay)
3493 auto __val = __read_signed(__num ? __num : 3);
3494 if (!__is_failed(__err))
3497 __parts |= _ChronoParts::_TimeOfDay;
3502 __dayofyear = __read_unsigned(__num ? __num : 3);
3509 if (__mod ==
'E') [[unlikely]]
3511 else if (__mod ==
'O')
3514 __tmget.get(__is, {}, __is, __err, &__tm,
3516 if (!__is_failed(__err))
3517 __m = month(__tm.tm_mon + 1);
3521 auto __val = __read_unsigned(__num ? __num : 2);
3522 if (__val >= 1 && __val <= 12)
3527 __parts |= _ChronoParts::_Month;
3531 if (__mod ==
'E') [[unlikely]]
3533 else if (__mod ==
'O')
3536 __tmget.get(__is, {}, __is, __err, &__tm,
3538 if (!__is_failed(__err))
3543 auto __val = __read_unsigned(__num ? __num : 2);
3544 if (0 <= __val && __val < 60)
3548 if (_M_need & _ChronoParts::_TimeOfDay)
3553 __parts |= _ChronoParts::_TimeOfDay;
3563 const _CharT* __ampms[2];
3564 __tmpunct._M_am_pm(__ampms);
3565 int __n = 0, __which = 3;
3566 while (__which != 0)
3568 auto __i = __is.peek();
3569 if (_Traits::eq_int_type(__i, _Traits::eof()))
3579 else if (__ampms[0][__n + 1] == _CharT())
3590 else if (__ampms[1][__n + 1] == _CharT())
3601 if (__which == 0 || __which == 3)
3614 __tmget.get(__is, {}, __is, __err, &__tm,
3616 if (!__is_failed(__err))
3618 __h =
hours(__tm.tm_hour);
3623 __parts |= _ChronoParts::_TimeOfDay;
3628 if (__mod || __num) [[unlikely]]
3635 auto __val = __read_unsigned(2);
3636 if (__val == -1 || __val > 23) [[unlikely]]
3638 if (_M_need & _ChronoParts::_TimeOfDay)
3642 if (!__read_chr(
':')) [[unlikely]]
3646 __val = __read_unsigned(2);
3647 if (__val == -1 || __val > 60) [[unlikely]]
3649 if (_M_need & _ChronoParts::_TimeOfDay)
3657 __parts |= _ChronoParts::_TimeOfDay;
3660 else if (!__read_chr(
':')) [[unlikely]]
3666 if (__mod ==
'E') [[unlikely]]
3668 else if (__mod ==
'O')
3671 __tmget.get(__is, {}, __is, __err, &__tm,
3673 if (!__is_failed(__err))
3676 else if constexpr (_Duration::period::den == 1
3679 auto __val = __read_unsigned(__num ? __num : 2);
3680 if (0 <= __val && __val <= 59) [[likely]]
3684 if (_M_need & _ChronoParts::_TimeOfDay)
3692 auto __digit = _S_try_read_digit(__is, __err);
3695 __buf.put(
'0' + __digit);
3696 __digit = _S_try_read_digit(__is, __err);
3698 __buf.put(
'0' + __digit);
3701 auto __i = __is.peek();
3702 if (_Traits::eq_int_type(__i, _Traits::eof()))
3710 __dp = __np.decimal_point();
3712 _CharT __c = _Traits::to_char_type(__i);
3718 = hh_mm_ss<_Duration>::fractional_width;
3721 __digit = _S_try_read_digit(__is, __err);
3723 __buf.put(
'0' + __digit);
3731 if (!__is_failed(__err)) [[likely]]
3733 long double __val{};
3734#if __cpp_lib_to_chars
3736 auto __first = __str.data();
3737 auto __last = __first + __str.size();
3741 if ((
bool)ec || ptr != __last) [[unlikely]]
3749 if constexpr (__is_floating)
3756 __parts |= _ChronoParts::_TimeOfDay;
3761 if (__mod ==
'E') [[unlikely]]
3763 else if (__mod ==
'O')
3768 __tmget.get(__is, {}, __is, __err, &__tm,
3770 if (!__is_failed(__err))
3771 __wday = weekday(__tm.tm_wday);
3778 const int __lo = __c ==
'u' ? 1 : 0;
3779 const int __hi = __lo + 6;
3780 auto __val = __read_unsigned(__num ? __num : 1);
3781 if (__lo <= __val && __val <= __hi)
3782 __wday = weekday(__val);
3785 __wday = __bad_wday;
3789 __parts |= _ChronoParts::_Weekday;
3795 if (__mod ==
'E') [[unlikely]]
3797 else if (__mod ==
'O')
3799 if (__c ==
'V') [[unlikely]]
3809 const int __lo = __c ==
'V' ? 1 : 0;
3810 const int __hi = 53;
3811 auto __val = __read_unsigned(__num ? __num : 2);
3812 if (__lo <= __val && __val <= __hi)
3817 __sunday_wk = __val;
3823 __monday_wk = __val;
3828 __iso_wk = __sunday_wk = __monday_wk = -1;
3834 if (__mod ==
'O' || __num) [[unlikely]]
3839 __tmget.get(__is, {}, __is, __err, &__tm,
3840 __fmt - 2 - (__mod ==
'E'), __fmt);
3841 if (!__is_failed(__err))
3843 __y = year(__tm.tm_year + 1900);
3844 __m = month(__tm.tm_mon + 1);
3845 __d = day(__tm.tm_mday);
3848 __parts |= _ChronoParts::_Date;
3852 if (__mod ==
'O' || __num) [[unlikely]]
3857 __tmget.get(__is, {}, __is, __err, &__tm,
3858 __fmt - 2 - (__mod ==
'E'), __fmt);
3859 if (!__is_failed(__err))
3861 __h =
hours(__tm.tm_hour);
3866 __parts |= _ChronoParts::_TimeOfDay;
3870 if (__mod) [[unlikely]]
3873 __tmget.get(__is, {}, __is, __err, &__tm,
3875 if (!__is_failed(__err))
3877 int __cent = __tm.tm_year < 2000 ? 1900 : 2000;
3878 __yy = year(__tm.tm_year - __cent);
3879 if (__century == -1)
3885 auto __val = __read_unsigned(__num ? __num : 2);
3886 if (__val >= 0 && __val <= 99)
3889 if (__century == -1)
3890 __century = __val < 69 ? 2000 : 1900;
3893 __y = __yy = __iso_yy = __iso_y = __bad_y;
3895 __parts |= _ChronoParts::_Year;
3899 if (__mod ==
'O') [[unlikely]]
3901 else if (__mod ==
'E')
3904 __tmget.get(__is, {}, __is, __err, &__tm,
3906 if (!__is_failed(__err))
3907 __y = year(__tm.tm_year);
3911 auto __val = __read_unsigned(__num ? __num : 4);
3912 if (!__is_failed(__err))
3915 __parts |= _ChronoParts::_Year;
3919 if (__num) [[unlikely]]
3926 auto __i = __is.peek();
3927 if (_Traits::eq_int_type(__i, _Traits::eof()))
3932 _CharT __ic = _Traits::to_char_type(__i);
3933 const bool __neg = __ic == _CharT(
'-');
3934 if (__ic == _CharT(
'-') || __ic == _CharT(
'+'))
3941 __hh = __read_unsigned(2);
3946 auto __d1 = _S_try_read_digit(__is, __err);
3947 auto __d2 = _S_try_read_digit(__is, __err);
3948 if (__d1 >= 0 && __d2 >= 0) [[likely]]
3949 __hh = 10 * __d1 + __d2;
3954 if (__is_failed(__err))
3958 if (_Traits::eq_int_type(__i, _Traits::eof()))
3961 __tz_offset =
minutes(__hh * (__neg ? -60 : 60));
3964 __ic = _Traits::to_char_type(__i);
3966 bool __read_mm =
false;
3969 if (__ic == _GLIBCXX_WIDEN(
":")[0])
3976 else if (_CharT(
'0') <= __ic && __ic <= _CharT(
'9'))
3982 int_least32_t __mm = 0;
3985 auto __d1 = _S_try_read_digit(__is, __err);
3986 auto __d2 = _S_try_read_digit(__is, __err);
3987 if (__d1 >= 0 && __d2 >= 0) [[likely]]
3988 __mm = 10 * __d1 + __d2;
3993 if (!__is_failed(__err))
3995 auto __z = __hh * 60 + __mm;
3996 __tz_offset =
minutes(__neg ? -__z : __z);
4002 if (__mod || __num) [[unlikely]]
4006 basic_string_view<_CharT> __x = _GLIBCXX_WIDEN(
"_/-+");
4010 auto __i = __is.peek();
4011 if (!_Traits::eq_int_type(__i, _Traits::eof()))
4013 _CharT __a = _Traits::to_char_type(__i);
4015 || __x.find(__a) != __x.npos)
4017 __tz_abbr.push_back(__a);
4026 if (__tz_abbr.empty())
4032 if (__mod || __num) [[unlikely]]
4036 _CharT __i = __is.peek();
4037 if (_Traits::eq_int_type(__i, _Traits::eof()))
4039 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
4047 if (__mod || __num) [[unlikely]]
4051 _CharT __i = __is.peek();
4052 if (_Traits::eq_int_type(__i, _Traits::eof()))
4054 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
4060 if (__mod || __num) [[unlikely]]
4068 if (__mod || __num) [[unlikely]]
4077 if (_CharT(
'1') <= __c && __c <= _CharT(
'9'))
4079 if (!__mod) [[likely]]
4082 auto __end = __fmt + _Traits::length(__fmt);
4084 = __format::__parse_integer(__fmt - 1, __end);
4085 if (__ptr) [[likely]]
4096 if (__is_failed(__err)) [[unlikely]]
4106 if (__yy != __bad_y && __y == __bad_y)
4107 __y =
years(__century) + __yy;
4108 if (__iso_yy != __bad_y && __iso_y == __bad_y)
4109 __iso_y =
years(__century) + __iso_yy;
4112 bool __can_use_doy =
false;
4113 bool __can_use_iso_wk =
false;
4114 bool __can_use_sun_wk =
false;
4115 bool __can_use_mon_wk =
false;
4118 if (__y != __bad_y && __dayofyear >= 0)
4120 __can_use_doy =
true;
4121 __parts |= _ChronoParts::_Date;
4123 else if (__y != __bad_y && __wday != __bad_wday && __sunday_wk >= 0)
4125 __can_use_sun_wk =
true;
4126 __parts |= _ChronoParts::_Date;
4128 else if (__y != __bad_y && __wday != __bad_wday && __monday_wk >= 0)
4130 __can_use_mon_wk =
true;
4131 __parts |= _ChronoParts::_Date;
4133 else if (__iso_y != __bad_y && __wday != __bad_wday && __iso_wk > 0)
4136 __can_use_iso_wk =
true;
4137 __parts |= _ChronoParts::_Date;
4140 if (__is_failed(__err)) [[unlikely]]
4142 else if (__is_flag) [[unlikely]]
4144 else if ((_M_need & __parts) == _M_need) [[likely]]
4166 const bool __need_wday = _M_need & _ChronoParts::_Weekday;
4170 const bool __need_time = _M_need & _ChronoParts::_TimeOfDay;
4172 if (__need_wday && __wday != __bad_wday)
4174 else if (_M_need & _ChronoParts::_Date)
4178 const bool __need_ymd = !__need_wday && !__need_time;
4180 if ((_M_need & _ChronoParts::_Year && __y == __bad_y)
4181 || (_M_need & _ChronoParts::_Month && __m == __bad_mon)
4182 || (_M_need & _ChronoParts::_Day && __d == __bad_day))
4189 if ((0 < __dayofyear && __dayofyear <= 365)
4190 || (__dayofyear == 366 && __y.is_leap()))
4193 _M_sys_days = sys_days(__y/January/1)
4194 +
days(__dayofyear - 1);
4196 _M_ymd = year_month_day(_M_sys_days);
4201 else if (__can_use_iso_wk)
4209 const sys_days __jan4(__iso_y/January/4);
4210 weekday __wd1(__jan4 -
days(3));
4211 if (__wd1 != Thursday)
4212 if (__wd1 != Wednesday || !__iso_y.is_leap())
4216 if (!__is_failed(__err)) [[likely]]
4219 sys_days __w(Thursday[1]/January/__iso_y);
4221 __w -= Thursday - Monday;
4223 __w += __wday - Monday;
4227 _M_ymd = year_month_day(_M_sys_days);
4230 else if (__can_use_sun_wk)
4233 sys_days __wk1(__y/January/Sunday[1]);
4234 _M_sys_days = __wk1 +
weeks(__sunday_wk - 1)
4235 +
days(__wday.c_encoding());
4236 _M_ymd = year_month_day(_M_sys_days);
4237 if (_M_ymd.year() != __y) [[unlikely]]
4240 else if (__can_use_mon_wk)
4243 sys_days __wk1(__y/January/Monday[1]);
4244 _M_sys_days = __wk1 +
weeks(__monday_wk - 1)
4245 +
days(__wday.c_encoding() - 1);
4246 _M_ymd = year_month_day(_M_sys_days);
4247 if (_M_ymd.year() != __y) [[unlikely]]
4259 if (_M_need & _ChronoParts::_Year)
4261 if (!__y.ok()) [[unlikely]]
4264 else if (__y == __bad_y)
4267 if (_M_need & _ChronoParts::_Month)
4269 if (!__m.ok()) [[unlikely]]
4272 else if (__m == __bad_mon)
4275 if (_M_need & _ChronoParts::_Day)
4277 if (__d < day(1) || __d > (__y/__m/last).day())
4280 else if (__d == __bad_day)
4283 if (year_month_day __ymd(__y, __m, __d); __ymd.ok())
4286 if (__need_wday || __need_time)
4287 _M_sys_days = sys_days(_M_ymd);
4294 _M_wd = weekday(_M_sys_days);
4300 if (__h == __bad_h && __h12 != __bad_h)
4304 else if (__ampm == 2)
4305 __h = __h12 ==
hours(12) ? __h12 : __h12 +
hours(12);
4310 auto __t = _M_time.zero();
4319 if (__min != __bad_min)
4325 if (__s != __bad_sec)
4329 _M_is_leap_second = __s >=
seconds(60);
4338 if (!__is_failed(__err)) [[likely]]
4340 if (__offset && __tz_offset != __bad_min)
4341 *__offset = __tz_offset;
4342 if (__abbrev && !__tz_abbr.empty())
4350 __is.setstate(__err);
4354#undef _GLIBCXX_WIDEN
4359_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)
constexpr enable_if_t< __is_duration_v< _ToDur > &&!treat_as_floating_point_v< typename _ToDur::rep >, time_point< _Clock, _ToDur > > round(const time_point< _Clock, _Dur > &__tp)
duration< int64_t, ratio< 604800 > > weeks
weeks
duration< int64_t, ratio< 86400 > > days
days
duration< int64_t, ratio< 31556952 > > years
years
duration< int64_t, ratio< 3600 > > hours
hours
duration< int64_t, ratio< 60 > > minutes
minutes
constexpr __enable_if_t< __is_duration< _ToDur >::value, time_point< _Clock, _ToDur > > time_point_cast(const time_point< _Clock, _Dur > &__t)
basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const duration< _Rep, _Period > &__d)
duration< int64_t > seconds
seconds
constexpr __enable_if_is_duration< _ToDur > duration_cast(const duration< _Rep, _Period > &__d)
basic_stringstream< char > stringstream
Class for char mixed input and output memory streams.
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.
const _Facet & use_facet(const locale &__loc)
Return a facet.
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).
ios_base & fixed(ios_base &__base)
Calls base.setf(ios_base::fixed, ios_base::floatfield).
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.
Managing sequences of characters and character-like objects.
constexpr iterator begin() noexcept
chrono::duration represents a distance between two points in time
_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...
static const locale & classic()
Return reference to the C locale.