30#ifndef _GLIBCXX_CHRONO_IO_H
31#define _GLIBCXX_CHRONO_IO_H 1
34#pragma GCC system_header
37#if __cplusplus >= 202002L
48namespace std _GLIBCXX_VISIBILITY(default)
50_GLIBCXX_BEGIN_NAMESPACE_VERSION
65 template<
typename _CharT>
67 _Widen(
const char* __narrow,
const wchar_t* __wide)
69 if constexpr (is_same_v<_CharT, wchar_t>)
74#define _GLIBCXX_WIDEN_(C, S) ::std::chrono::__detail::_Widen<C>(S, L##S)
75#define _GLIBCXX_WIDEN(S) _GLIBCXX_WIDEN_(_CharT, S)
77 template<
typename _Period,
typename _CharT>
79 __units_suffix()
noexcept
84#define _GLIBCXX_UNITS_SUFFIX(period, suffix) \
85 if constexpr (is_same_v<_Period, period>) \
86 return _GLIBCXX_WIDEN(suffix); \
89 _GLIBCXX_UNITS_SUFFIX(atto,
"as")
90 _GLIBCXX_UNITS_SUFFIX(femto,
"fs")
91 _GLIBCXX_UNITS_SUFFIX(pico,
"ps")
92 _GLIBCXX_UNITS_SUFFIX(nano,
"ns")
93 _GLIBCXX_UNITS_SUFFIX(milli,
"ms")
94#if _GLIBCXX_USE_ALT_MICROSECONDS_SUFFIX
97 _GLIBCXX_UNITS_SUFFIX(micro,
"\u00b5s")
99 _GLIBCXX_UNITS_SUFFIX(micro,
"us")
101 _GLIBCXX_UNITS_SUFFIX(centi,
"cs")
102 _GLIBCXX_UNITS_SUFFIX(deci,
"ds")
103 _GLIBCXX_UNITS_SUFFIX(
ratio<1>,
"s")
104 _GLIBCXX_UNITS_SUFFIX(deca,
"das")
105 _GLIBCXX_UNITS_SUFFIX(hecto,
"hs")
106 _GLIBCXX_UNITS_SUFFIX(kilo,
"ks")
107 _GLIBCXX_UNITS_SUFFIX(mega,
"Ms")
108 _GLIBCXX_UNITS_SUFFIX(giga,
"Gs")
109 _GLIBCXX_UNITS_SUFFIX(tera,
"Ts")
110 _GLIBCXX_UNITS_SUFFIX(tera,
"Ts")
111 _GLIBCXX_UNITS_SUFFIX(peta,
"Ps")
112 _GLIBCXX_UNITS_SUFFIX(exa,
"Es")
116#undef _GLIBCXX_UNITS_SUFFIX
120 template<
typename _Period,
typename _CharT,
typename _Out>
122 __fmt_units_suffix(_Out __out)
noexcept
124 if (
auto __s = __detail::__units_suffix<_Period, _CharT>(); __s.size())
125 return __format::__write(
std::move(__out), __s);
126 else if constexpr (_Period::den == 1)
127 return std::format_to(
std::move(__out), _GLIBCXX_WIDEN(
"[{}]s"),
128 (uintmax_t)_Period::num);
130 return std::format_to(
std::move(__out), _GLIBCXX_WIDEN(
"[{}/{}]s"),
131 (uintmax_t)_Period::num,
132 (uintmax_t)_Period::den);
141 template<
typename _CharT,
typename _Traits,
142 typename _Rep,
typename _Period>
148 using period =
typename _Period::type;
156 __detail::__fmt_units_suffix<period, _CharT>(_Out(__s));
166 template<
typename _Duration>
167 struct __local_time_fmt
169 local_time<_Duration> _M_time;
170 const string* _M_abbrev;
176 template<
typename _Duration>
177 using __local_time_fmt_for
178 = __local_time_fmt<common_type_t<_Duration, seconds>>;
191 template<
typename _Duration>
192 inline __detail::__local_time_fmt<_Duration>
194 const string* __abbrev =
nullptr,
195 const seconds* __offset_sec =
nullptr)
196 {
return {__time, __abbrev, __offset_sec}; }
204 [[noreturn,__gnu__::__always_inline__]]
206 __no_timezone_available()
207 { __throw_format_error(
"format error: no timezone available for %Z or %z"); }
209 [[noreturn,__gnu__::__always_inline__]]
211 __not_valid_for_duration()
212 { __throw_format_error(
"format error: chrono-format-spec not valid for "
213 "chrono::duration"); }
215 [[noreturn,__gnu__::__always_inline__]]
217 __invalid_chrono_spec()
218 { __throw_format_error(
"format error: chrono-format-spec not valid for "
221 template<
typename _CharT>
222 struct _ChronoSpec : _Spec<_CharT>
224 basic_string_view<_CharT> _M_chrono_specs;
233 _M_locale_specific() const noexcept
234 {
return this->_M_reserved; }
237 _M_locale_specific(
bool __b)
noexcept
238 { this->_M_reserved = __b; }
245 _Year = 1, _Month = 2, _Day = 4, _Weekday = 8, _TimeOfDay = 16,
247 _Date = _Year | _Month | _Day | _Weekday,
248 _DateTime = _Date | _TimeOfDay,
249 _ZonedDateTime = _DateTime | _TimeZone,
253 constexpr _ChronoParts
254 operator|(_ChronoParts __x, _ChronoParts __y)
noexcept
255 {
return static_cast<_ChronoParts
>((int)__x | (int)__y); }
257 constexpr _ChronoParts&
258 operator|=(_ChronoParts& __x, _ChronoParts __y)
noexcept
259 {
return __x = __x | __y; }
262 template<
typename _CharT>
263 struct __formatter_chrono
265 using __string_view = basic_string_view<_CharT>;
266 using __string = basic_string<_CharT>;
268 template<
typename _ParseContext>
269 constexpr typename _ParseContext::iterator
270 _M_parse(_ParseContext& __pc, _ChronoParts __parts)
272 auto __first = __pc.
begin();
273 auto __last = __pc.end();
275 _ChronoSpec<_CharT> __spec{};
277 auto __finalize = [
this, &__spec] {
281 auto __finished = [&] {
282 if (__first == __last || *__first ==
'}')
293 __first = __spec._M_parse_fill_and_align(__first, __last);
297 __first = __spec._M_parse_width(__first, __last, __pc);
301 if (__parts & _ChronoParts::_Duration)
303 __first = __spec._M_parse_precision(__first, __last, __pc);
308 __first = __spec._M_parse_locale(__first, __last);
315 __string_view __str(__first, __last - __first);
316 auto __end = __str.find(
'}');
317 if (__end != __str.npos)
319 __str.remove_suffix(__str.length() - __end);
320 __last = __first + __end;
322 if (__str.find(
'{') != __str.npos)
323 __throw_format_error(
"chrono format error: '{' in chrono-specs");
330 const auto __chrono_specs = __first++;
331 if (*__chrono_specs !=
'%')
332 __throw_format_error(
"chrono format error: no '%' at start of "
338 bool __locale_specific =
false;
340 while (__first != __last)
342 enum _Mods { _Mod_none, _Mod_E, _Mod_O, _Mod_E_O };
343 _Mods __allowed_mods = _Mod_none;
345 _CharT __c = *__first++;
351 __locale_specific =
true;
357 __locale_specific =
true;
360 __needed = _DateTime;
361 __allowed_mods = _Mod_E;
362 __locale_specific =
true;
366 __allowed_mods = _Mod_E;
371 __allowed_mods = _Mod_O;
383 __needed = _TimeOfDay;
384 __allowed_mods = _Mod_O;
387 if (!(__parts & _Duration))
392 __allowed_mods = _Mod_O;
395 __needed = _TimeOfDay;
396 __allowed_mods = _Mod_O;
400 __locale_specific =
true;
404 __needed = _TimeOfDay;
408 __needed = _Duration;
411 __needed = _TimeOfDay;
412 __allowed_mods = _Mod_O;
417 __allowed_mods = _Mod_O;
423 __allowed_mods = _Mod_O;
427 __locale_specific =
true;
428 __allowed_mods = _Mod_E;
431 __needed = _TimeOfDay;
432 __locale_specific =
true;
433 __allowed_mods = _Mod_E;
437 __allowed_mods = _Mod_E_O;
441 __allowed_mods = _Mod_E;
444 __needed = _TimeZone;
445 __allowed_mods = _Mod_E_O;
448 __needed = _TimeZone;
456 if (__mod) [[unlikely]]
458 __allowed_mods = _Mod_none;
464 __throw_format_error(
"chrono format error: invalid "
465 " specifier in chrono-specs");
468 if ((__mod ==
'E' && !(__allowed_mods & _Mod_E))
469 || (__mod ==
'O' && !(__allowed_mods & _Mod_O)))
470 __throw_format_error(
"chrono format error: invalid "
471 " modifier in chrono-specs");
472 if (__mod && __c !=
'z')
473 __locale_specific =
true;
476 if ((__parts & __needed) != __needed)
477 __throw_format_error(
"chrono format error: format argument "
478 "does not contain the information "
479 "required by the chrono-specs");
482 size_t __pos = __string_view(__first, __last - __first).find(
'%');
487 if (__pos == __string_view::npos)
493 __first += __pos + 1;
498 if (__conv || __mod != _CharT())
499 __throw_format_error(
"chrono format error: unescaped '%' in "
503 _M_spec._M_chrono_specs
504 = __string_view(__chrono_specs, __first - __chrono_specs);
505 _M_spec._M_locale_specific(__locale_specific);
515 template<
typename _Tp,
typename _FormatContext>
516 typename _FormatContext::iterator
517 _M_format(
const _Tp& __t, _FormatContext& __fc,
518 bool __is_neg =
false)
const
520 auto __first = _M_spec._M_chrono_specs.begin();
521 const auto __last = _M_spec._M_chrono_specs.end();
522 if (__first == __last)
523 return _M_format_to_ostream(__t, __fc, __is_neg);
525#if defined _GLIBCXX_USE_NL_LANGINFO_L && __CHAR_BIT__ == 8
529 if constexpr (is_same_v<_CharT, char>)
530 if constexpr (__unicode::__literal_encoding_is_utf8())
531 if (_M_spec._M_localized && _M_spec._M_locale_specific())
533 extern locale __with_encoding_conversion(
const locale&);
537 locale __loc = __fc.locale();
538 if (__loc != locale::classic())
539 __fc._M_loc = __with_encoding_conversion(__loc);
543 _Sink_iter<_CharT> __out;
544 __format::_Str_sink<_CharT> __sink;
545 bool __write_direct =
false;
546 if constexpr (is_same_v<
typename _FormatContext::iterator,
549 if (_M_spec._M_width_kind == __format::_WP_none)
552 __write_direct =
true;
555 __out = __sink.out();
558 __out = __sink.out();
562 if constexpr (__is_specialization_of<_Tp, chrono::hh_mm_ss>)
563 __is_neg = __t.is_negative();
565 auto __print_sign = [&__is_neg, &__out] {
566 if constexpr (chrono::__is_duration_v<_Tp>
567 || __is_specialization_of<_Tp, chrono::hh_mm_ss>)
570 *__out++ = _S_plus_minus[1];
577 constexpr const _CharT* __literals = _GLIBCXX_WIDEN(
"\n\t%");
584 _CharT __c = *__first++;
589 __out = _M_a_A(__t,
std::move(__out), __fc, __c ==
'A');
594 __out = _M_b_B(__t,
std::move(__out), __fc, __c ==
'B');
597 __out = _M_c(__t,
std::move(__out), __fc, __mod ==
'E');
602 __out = _M_C_y_Y(__t,
std::move(__out), __fc, __c, __mod);
606 __out = _M_d_e(__t,
std::move(__out), __fc, __c, __mod ==
'O');
609 __out = _M_D(__t,
std::move(__out), __fc);
612 __out = _M_F(__t,
std::move(__out), __fc);
616 __out = _M_g_G(__t,
std::move(__out), __fc, __c ==
'G');
620 __out = _M_H_I(__t, __print_sign(), __fc, __c, __mod ==
'O');
623 __out = _M_j(__t, __print_sign(), __fc);
626 __out = _M_m(__t,
std::move(__out), __fc, __mod ==
'O');
629 __out = _M_M(__t, __print_sign(), __fc, __mod ==
'O');
632 __out = _M_p(__t,
std::move(__out), __fc);
635 __out = _M_q(__t,
std::move(__out), __fc);
639 if constexpr (chrono::__is_duration_v<_Tp>)
642 __out = std::format_to(__print_sign(), _S_empty_spec,
645 __throw_format_error(
"chrono format error: argument is "
649 __out = _M_r(__t, __print_sign(), __fc);
653 __out = _M_R_T(__t, __print_sign(), __fc, __c ==
'T');
656 __out = _M_S(__t, __print_sign(), __fc, __mod ==
'O');
660 __out = _M_u_w(__t,
std::move(__out), __fc, __c, __mod ==
'O');
665 __out = _M_U_V_W(__t,
std::move(__out), __fc, __c,
669 __out = _M_x(__t,
std::move(__out), __fc, __mod ==
'E');
672 __out = _M_X(__t, __print_sign(), __fc, __mod ==
'E');
675 __out = _M_z(__t,
std::move(__out), __fc, (
bool)__mod);
678 __out = _M_Z(__t,
std::move(__out), __fc);
681 *__out++ = __literals[0];
684 *__out++ = __literals[1];
687 *__out++ = __literals[2];
699 __string_view __str(__first, __last - __first);
700 size_t __pos = __str.find(
'%');
705 if (__pos == __str.npos)
709 __str.remove_suffix(__str.length() - __pos);
710 __first += __pos + 1;
712 __out = __format::__write(
std::move(__out), __str);
715 while (__first != __last);
717 if constexpr (is_same_v<
typename _FormatContext::iterator,
723 return __format::__write_padded_as_spec(__str, __str.size(),
727 _ChronoSpec<_CharT> _M_spec;
731 template<
typename _FormatContext>
733 _M_locale(_FormatContext& __fc)
const
735 if (!_M_spec._M_localized)
738 return __fc.locale();
746 template<
typename _Tp,
typename _FormatContext>
747 typename _FormatContext::iterator
748 _M_format_to_ostream(
const _Tp& __t, _FormatContext& __fc,
751 using ::std::chrono::__detail::__utc_leap_second;
752 using ::std::chrono::__detail::__local_time_fmt;
754 basic_ostringstream<_CharT> __os;
755 __os.imbue(_M_locale(__fc));
757 if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
760 auto __days = chrono::floor<chrono::days>(__t._M_time);
761 __os << chrono::year_month_day(__days) <<
' '
762 << chrono::hh_mm_ss(__t._M_time - __days);
768 if (!__t._M_abbrev) [[unlikely]]
769 __format::__no_timezone_available();
770 else if constexpr (is_same_v<_CharT, char>)
771 __os <<
' ' << *__t._M_abbrev;
775 for (
char __c : *__t._M_abbrev)
782 if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
783 __os << __t._M_date <<
' ' << __t._M_time;
784 else if constexpr (chrono::__is_time_point_v<_Tp>)
791 if constexpr (is_convertible_v<_Tp, chrono::sys_days>)
792 __os << _S_date(__t);
795 auto __days = chrono::floor<chrono::days>(__t);
796 __os << chrono::year_month_day(__days) <<
' '
797 << chrono::hh_mm_ss(__t - __days);
802 if constexpr (chrono::__is_duration_v<_Tp>)
803 if (__is_neg) [[unlikely]]
804 __os << _S_plus_minus[1];
810 return __format::__write_padded_as_spec(__str, __str.size(),
814 static constexpr const _CharT* _S_chars
815 = _GLIBCXX_WIDEN(
"0123456789+-:/ {}");
816 static constexpr const _CharT* _S_plus_minus = _S_chars + 10;
817 static constexpr _CharT _S_colon = _S_chars[12];
818 static constexpr _CharT _S_slash = _S_chars[13];
819 static constexpr _CharT _S_space = _S_chars[14];
820 static constexpr const _CharT* _S_empty_spec = _S_chars + 15;
822 template<
typename _OutIter>
824 _M_write(_OutIter __out,
const locale& __loc, __string_view __s)
const
826#if defined _GLIBCXX_USE_NL_LANGINFO_L && __CHAR_BIT__ == 8
831 if constexpr (is_same_v<_CharT, char>)
832 if constexpr (__unicode::__literal_encoding_is_utf8())
833 if (_M_spec._M_localized && _M_spec._M_locale_specific()
834 && __loc != locale::classic())
837 __locale_encoding_to_utf8(
const locale&, string_view,
void*);
839 __s = __locale_encoding_to_utf8(__loc, __s, &__buf);
842 return __format::__write(
std::move(__out), __s);
845 template<
typename _Tp,
typename _FormatContext>
846 typename _FormatContext::iterator
847 _M_a_A(
const _Tp& __t,
typename _FormatContext::iterator __out,
848 _FormatContext& __ctx,
bool __full)
const
852 chrono::weekday __wd = _S_weekday(__t);
854 __throw_format_error(
"format error: invalid weekday");
856 locale __loc = _M_locale(__ctx);
857 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
858 const _CharT* __days[7];
860 __tp._M_days(__days);
862 __tp._M_days_abbreviated(__days);
863 __string_view __str(__days[__wd.c_encoding()]);
864 return _M_write(
std::move(__out), __loc, __str);
867 template<
typename _Tp,
typename _FormatContext>
868 typename _FormatContext::iterator
869 _M_b_B(
const _Tp& __t,
typename _FormatContext::iterator __out,
870 _FormatContext& __ctx,
bool __full)
const
874 chrono::month __m = _S_month(__t);
876 __throw_format_error(
"format error: invalid month");
877 locale __loc = _M_locale(__ctx);
878 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
879 const _CharT* __months[12];
881 __tp._M_months(__months);
883 __tp._M_months_abbreviated(__months);
884 __string_view __str(__months[(
unsigned)__m - 1]);
885 return _M_write(
std::move(__out), __loc, __str);
888 template<
typename _Tp,
typename _FormatContext>
889 typename _FormatContext::iterator
890 _M_c(
const _Tp& __tt,
typename _FormatContext::iterator __out,
891 _FormatContext& __ctx,
bool __mod =
false)
const
896 basic_string<_CharT> __fmt;
897 auto __t = _S_floor_seconds(__tt);
898 locale __loc = _M_locale(__ctx);
899 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
900 const _CharT* __formats[2];
901 __tp._M_date_time_formats(__formats);
902 if (*__formats[__mod]) [[likely]]
904 __fmt = _GLIBCXX_WIDEN(
"{:L}");
905 __fmt.insert(3u, __formats[__mod]);
908 __fmt = _GLIBCXX_WIDEN(
"{:L%a %b %e %T %Y}");
909 return std::vformat_to(
std::move(__out), __loc, __fmt,
910 std::make_format_args<_FormatContext>(__t));
913 template<
typename _Tp,
typename _FormatContext>
914 typename _FormatContext::iterator
915 _M_C_y_Y(
const _Tp& __t,
typename _FormatContext::iterator __out,
916 _FormatContext& __ctx, _CharT __conv, _CharT __mod = 0)
const
926 chrono::year __y = _S_year(__t);
928 if (__mod && _M_spec._M_localized) [[unlikely]]
929 if (
auto __loc = __ctx.locale(); __loc != locale::classic())
932 __tm.tm_year = (int)__y - 1900;
933 return _M_locale_fmt(
std::move(__out), __loc, __tm,
937 basic_string<_CharT> __s;
939 const bool __is_neg = __yi < 0;
940 __yi = __builtin_abs(__yi);
942 if (__conv ==
'Y' || __conv ==
'C')
944 int __ci = __yi / 100;
945 if (__is_neg) [[unlikely]]
947 __s.assign(1, _S_plus_minus[1]);
949 if (__conv ==
'C' && (__ci * 100) != __yi)
952 if (__ci >= 100) [[unlikely]]
954 __s += std::format(_S_empty_spec, __ci / 100);
957 __s += _S_two_digits(__ci);
960 if (__conv ==
'Y' || __conv ==
'y')
961 __s += _S_two_digits(__yi % 100);
963 return __format::__write(
std::move(__out), __string_view(__s));
966 template<
typename _Tp,
typename _FormatContext>
967 typename _FormatContext::iterator
968 _M_D(
const _Tp& __t,
typename _FormatContext::iterator __out,
969 _FormatContext&)
const
971 auto __ymd = _S_date(__t);
972 basic_string<_CharT> __s;
973#if ! _GLIBCXX_USE_CXX11_ABI
976 __s = _S_two_digits((
unsigned)__ymd.month());
978 __s += _S_two_digits((
unsigned)__ymd.day());
980 __s += _S_two_digits(__builtin_abs((
int)__ymd.year()) % 100);
981 return __format::__write(
std::move(__out), __string_view(__s));
984 template<
typename _Tp,
typename _FormatContext>
985 typename _FormatContext::iterator
986 _M_d_e(
const _Tp& __t,
typename _FormatContext::iterator __out,
987 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
994 chrono::day __d = _S_day(__t);
995 unsigned __i = (unsigned)__d;
997 if (__mod && _M_spec._M_localized) [[unlikely]]
998 if (
auto __loc = __ctx.locale(); __loc != locale::classic())
1002 return _M_locale_fmt(
std::move(__out), __loc, __tm,
1006 auto __sv = _S_two_digits(__i);
1008 if (__conv == _CharT(
'e') && __i < 10)
1010 __buf[0] = _S_space;
1014 return __format::__write(
std::move(__out), __sv);
1017 template<
typename _Tp,
typename _FormatContext>
1018 typename _FormatContext::iterator
1019 _M_F(
const _Tp& __t,
typename _FormatContext::iterator __out,
1020 _FormatContext&)
const
1022 auto __ymd = _S_date(__t);
1023 auto __s = std::format(_GLIBCXX_WIDEN(
"{:04d}- - "),
1025 auto __sv = _S_two_digits((
unsigned)__ymd.month());
1026 __s[__s.size() - 5] = __sv[0];
1027 __s[__s.size() - 4] = __sv[1];
1028 __sv = _S_two_digits((
unsigned)__ymd.day());
1029 __s[__s.size() - 2] = __sv[0];
1030 __s[__s.size() - 1] = __sv[1];
1032 return __format::__write(
std::move(__out), __sv);
1035 template<
typename _Tp,
typename _FormatContext>
1036 typename _FormatContext::iterator
1037 _M_g_G(
const _Tp& __t,
typename _FormatContext::iterator __out,
1038 _FormatContext& __ctx,
bool __full)
const
1042 using namespace chrono;
1043 auto __d = _S_days(__t);
1045 __d -= (weekday(__d) - Monday) -
days(3);
1047 year __y = year_month_day(__d).year();
1048 return _M_C_y_Y(__y,
std::move(__out), __ctx,
"yY"[__full]);
1051 template<
typename _Tp,
typename _FormatContext>
1052 typename _FormatContext::iterator
1053 _M_H_I(
const _Tp& __t,
typename _FormatContext::iterator __out,
1054 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
1061 const auto __hms = _S_hms(__t);
1062 int __i = __hms.hours().count();
1064 if (__mod && _M_spec._M_localized) [[unlikely]]
1065 if (
auto __loc = __ctx.locale(); __loc != locale::classic())
1069 return _M_locale_fmt(
std::move(__out), __loc, __tm,
1073 if (__conv == _CharT(
'I'))
1080 return __format::__write(
std::move(__out), _S_two_digits(__i));
1083 template<
typename _Tp,
typename _FormatContext>
1084 typename _FormatContext::iterator
1085 _M_j(
const _Tp& __t,
typename _FormatContext::iterator __out,
1086 _FormatContext&)
const
1088 if constexpr (chrono::__is_duration_v<_Tp>)
1091 unsigned __d = chrono::duration_cast<chrono::days>(__t).count();
1092 return std::format_to(
std::move(__out), _S_empty_spec, __d);
1097 using namespace chrono;
1098 auto __day = _S_days(__t);
1099 auto __ymd = _S_date(__t);
1103 if constexpr (is_same_v<
typename decltype(__day)::clock, local_t>)
1104 __d = __day - local_days(__ymd.year()/January/0);
1106 __d = __day - sys_days(__ymd.year()/January/0);
1107 return std::format_to(
std::move(__out), _GLIBCXX_WIDEN(
"{:03d}"),
1112 template<
typename _Tp,
typename _FormatContext>
1113 typename _FormatContext::iterator
1114 _M_m(
const _Tp& __t,
typename _FormatContext::iterator __out,
1115 _FormatContext& __ctx,
bool __mod)
const
1120 auto __m = _S_month(__t);
1121 auto __i = (unsigned)__m;
1123 if (__mod && _M_spec._M_localized) [[unlikely]]
1124 if (
auto __loc = __ctx.locale(); __loc != locale::classic())
1127 __tm.tm_mon = __i - 1;
1128 return _M_locale_fmt(
std::move(__out), __loc, __tm,
1132 return __format::__write(
std::move(__out), _S_two_digits(__i));
1135 template<
typename _Tp,
typename _FormatContext>
1136 typename _FormatContext::iterator
1137 _M_M(
const _Tp& __t,
typename _FormatContext::iterator __out,
1138 _FormatContext& __ctx,
bool __mod)
const
1143 auto __m = _S_hms(__t).minutes();
1144 auto __i = __m.count();
1146 if (__mod && _M_spec._M_localized) [[unlikely]]
1147 if (
auto __loc = __ctx.locale(); __loc != locale::classic())
1151 return _M_locale_fmt(
std::move(__out), __loc, __tm,
1155 return __format::__write(
std::move(__out), _S_two_digits(__i));
1158 template<
typename _Tp,
typename _FormatContext>
1159 typename _FormatContext::iterator
1160 _M_p(
const _Tp& __t,
typename _FormatContext::iterator __out,
1161 _FormatContext& __ctx)
const
1164 auto __hms = _S_hms(__t);
1165 locale __loc = _M_locale(__ctx);
1166 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1167 const _CharT* __ampm[2];
1168 __tp._M_am_pm(__ampm);
1169 return _M_write(
std::move(__out), __loc,
1170 __ampm[__hms.hours().count() >= 12]);
1173 template<
typename _Tp,
typename _FormatContext>
1174 typename _FormatContext::iterator
1175 _M_q(
const _Tp&,
typename _FormatContext::iterator __out,
1176 _FormatContext&)
const
1179 if constexpr (!chrono::__is_duration_v<_Tp>)
1180 __throw_format_error(
"format error: argument is not a duration");
1183 namespace __d = chrono::__detail;
1184 using period =
typename _Tp::period;
1185 return __d::__fmt_units_suffix<period, _CharT>(
std::move(__out));
1191 template<
typename _Tp,
typename _FormatContext>
1192 typename _FormatContext::iterator
1193 _M_r(
const _Tp& __tt,
typename _FormatContext::iterator __out,
1194 _FormatContext& __ctx)
const
1197 auto __t = _S_floor_seconds(__tt);
1198 locale __loc = _M_locale(__ctx);
1199 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1200 const _CharT* __ampm_fmt;
1201 __tp._M_am_pm_format(&__ampm_fmt);
1202 basic_string<_CharT> __fmt(_S_empty_spec);
1203 __fmt.insert(1u, 1u, _S_colon);
1204 __fmt.insert(2u, __ampm_fmt);
1205 using _FmtStr = _Runtime_format_string<_CharT>;
1206 return _M_write(
std::move(__out), __loc,
1207 std::format(__loc, _FmtStr(__fmt), __t));
1210 template<
typename _Tp,
typename _FormatContext>
1211 typename _FormatContext::iterator
1212 _M_R_T(
const _Tp& __t,
typename _FormatContext::iterator __out,
1213 _FormatContext& __ctx,
bool __secs)
const
1217 auto __hms = _S_hms(__t);
1219 auto __s = std::format(_GLIBCXX_WIDEN(
"{:02d}:00"),
1220 __hms.hours().count());
1221 auto __sv = _S_two_digits(__hms.minutes().count());
1222 __s[__s.size() - 2] = __sv[0];
1223 __s[__s.size() - 1] = __sv[1];
1225 __out = __format::__write(
std::move(__out), __sv);
1228 *__out++ = _S_colon;
1229 __out = _M_S(__hms,
std::move(__out), __ctx);
1234 template<
typename _Tp,
typename _FormatContext>
1235 typename _FormatContext::iterator
1236 _M_S(
const _Tp& __t,
typename _FormatContext::iterator __out,
1237 _FormatContext& __ctx,
bool __mod =
false)
const
1241 auto __hms = _S_hms(__t);
1242 auto __s = __hms.seconds();
1244 if (__mod) [[unlikely]]
1246 if (_M_spec._M_localized)
1247 if (
auto __loc = __ctx.locale(); __loc != locale::classic())
1250 __tm.tm_sec = (int)__s.count();
1251 return _M_locale_fmt(
std::move(__out), __loc, __tm,
1256 return __format::__write(
std::move(__out),
1257 _S_two_digits(__s.count()));
1260 if constexpr (__hms.fractional_width == 0)
1261 __out = __format::__write(
std::move(__out),
1262 _S_two_digits(__s.count()));
1265 locale __loc = _M_locale(__ctx);
1266 auto __ss = __hms.subseconds();
1267 using rep =
typename decltype(__ss)::rep;
1268 if constexpr (is_floating_point_v<rep>)
1270 chrono::duration<rep> __fs = __s + __ss;
1271 __out = std::format_to(
std::move(__out), __loc,
1272 _GLIBCXX_WIDEN(
"{:#0{}.{}Lf}"),
1274 3 + __hms.fractional_width,
1275 __hms.fractional_width);
1280 = use_facet<numpunct<_CharT>>(__loc);
1281 __out = __format::__write(
std::move(__out),
1282 _S_two_digits(__s.count()));
1283 *__out++ = __np.decimal_point();
1284 if constexpr (is_integral_v<rep>)
1285 __out = std::format_to(
std::move(__out),
1286 _GLIBCXX_WIDEN(
"{:0{}}"),
1288 __hms.fractional_width);
1291 auto __str = std::format(_S_empty_spec, __ss.count());
1292 __out = std::format_to(_GLIBCXX_WIDEN(
"{:0>{}s}"),
1294 __hms.fractional_width);
1303 template<
typename _Tp,
typename _FormatContext>
1304 typename _FormatContext::iterator
1305 _M_u_w(
const _Tp& __t,
typename _FormatContext::iterator __out,
1306 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
1313 chrono::weekday __wd = _S_weekday(__t);
1315 if (__mod && _M_spec._M_localized) [[unlikely]]
1316 if (
auto __loc = __ctx.locale(); __loc != locale::classic())
1319 __tm.tm_wday = __wd.c_encoding();
1320 return _M_locale_fmt(
std::move(__out), __loc, __tm,
1324 unsigned __wdi = __conv ==
'u' ? __wd.iso_encoding()
1325 : __wd.c_encoding();
1326 const _CharT __d = _S_digit(__wdi);
1327 return __format::__write(
std::move(__out), __string_view(&__d, 1));
1330 template<
typename _Tp,
typename _FormatContext>
1331 typename _FormatContext::iterator
1332 _M_U_V_W(
const _Tp& __t,
typename _FormatContext::iterator __out,
1333 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
1341 using namespace chrono;
1342 auto __d = _S_days(__t);
1343 using _TDays =
decltype(__d);
1345 if (__mod && _M_spec._M_localized) [[unlikely]]
1346 if (
auto __loc = __ctx.locale(); __loc != locale::classic())
1348 const year_month_day __ymd(__d);
1349 const year __y = __ymd.year();
1351 __tm.tm_year = (int)__y - 1900;
1352 __tm.tm_yday = (__d - _TDays(__y/January/1)).count();
1353 __tm.tm_wday = weekday(__d).c_encoding();
1354 return _M_locale_fmt(
std::move(__out), __loc, __tm,
1362 __d -= (weekday(__d) - Monday) -
days(3);
1365 __first = _TDays(year_month_day(__d).year()/January/1);
1370 if constexpr (
requires { __t.year(); })
1373 __y = year_month_day(__d).year();
1374 const weekday __weekstart = __conv ==
'U' ? Sunday : Monday;
1375 __first = _TDays(__y/January/__weekstart[1]);
1377 auto __weeks = chrono::floor<weeks>(__d - __first);
1378 __string_view __sv = _S_two_digits(__weeks.count() + 1);
1379 return __format::__write(
std::move(__out), __sv);
1382 template<
typename _Tp,
typename _FormatContext>
1383 typename _FormatContext::iterator
1384 _M_x(
const _Tp& __t,
typename _FormatContext::iterator __out,
1385 _FormatContext& __ctx,
bool __mod =
false)
const
1389 locale __loc = _M_locale(__ctx);
1390 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1391 const _CharT* __date_reps[2];
1392 __tp._M_date_formats(__date_reps);
1393 const _CharT* __rep = __date_reps[__mod];
1395 return _M_D(__t,
std::move(__out), __ctx);
1397 basic_string<_CharT> __fmt(_S_empty_spec);
1398 __fmt.insert(1u, 1u, _S_colon);
1399 __fmt.insert(2u, __rep);
1400 using _FmtStr = _Runtime_format_string<_CharT>;
1401 return _M_write(
std::move(__out), __loc,
1402 std::format(__loc, _FmtStr(__fmt), __t));
1405 template<
typename _Tp,
typename _FormatContext>
1406 typename _FormatContext::iterator
1407 _M_X(
const _Tp& __tt,
typename _FormatContext::iterator __out,
1408 _FormatContext& __ctx,
bool __mod =
false)
const
1412 auto __t = _S_floor_seconds(__tt);
1413 locale __loc = _M_locale(__ctx);
1414 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1415 const _CharT* __time_reps[2];
1416 __tp._M_time_formats(__time_reps);
1417 const _CharT* __rep = __time_reps[__mod];
1419 return _M_R_T(__t,
std::move(__out), __ctx,
true);
1421 basic_string<_CharT> __fmt(_S_empty_spec);
1422 __fmt.insert(1u, 1u, _S_colon);
1423 __fmt.insert(2u, __rep);
1424 using _FmtStr = _Runtime_format_string<_CharT>;
1425 return _M_write(
std::move(__out), __loc,
1426 std::format(__loc, _FmtStr(__fmt), __t));
1429 template<
typename _Tp,
typename _FormatContext>
1430 typename _FormatContext::iterator
1431 _M_z(
const _Tp& __t,
typename _FormatContext::iterator __out,
1432 _FormatContext&,
bool __mod =
false)
const
1434 using ::std::chrono::__detail::__utc_leap_second;
1435 using ::std::chrono::__detail::__local_time_fmt;
1437 auto __utc = __mod ? __string_view(_GLIBCXX_WIDEN(
"+00:00"), 6)
1438 : __string_view(_GLIBCXX_WIDEN(
"+0000"), 5);
1440 if constexpr (chrono::__is_time_point_v<_Tp>)
1442 if constexpr (is_same_v<
typename _Tp::clock,
1443 chrono::system_clock>)
1444 return __format::__write(
std::move(__out), __utc);
1446 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1448 if (__t._M_offset_sec)
1451 basic_string<_CharT> __s;
1452 if (*__t._M_offset_sec != 0s)
1454 chrono:: hh_mm_ss __hms(*__t._M_offset_sec);
1455 __s = _S_plus_minus[__hms.is_negative()];
1456 __s += _S_two_digits(__hms.hours().count());
1459 __s += _S_two_digits(__hms.minutes().count());
1462 return __format::__write(
std::move(__out), __sv);
1465 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1466 return __format::__write(
std::move(__out), __utc);
1468 __no_timezone_available();
1471 template<
typename _Tp,
typename _FormatContext>
1472 typename _FormatContext::iterator
1473 _M_Z(
const _Tp& __t,
typename _FormatContext::iterator __out,
1474 _FormatContext& __ctx)
const
1476 using ::std::chrono::__detail::__utc_leap_second;
1477 using ::std::chrono::__detail::__local_time_fmt;
1479 __string_view __utc(_GLIBCXX_WIDEN(
"UTC"), 3);
1480 if constexpr (chrono::__is_time_point_v<_Tp>)
1482 if constexpr (is_same_v<
typename _Tp::clock,
1483 chrono::system_clock>)
1484 return __format::__write(
std::move(__out), __utc);
1486 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1490 string_view __sv = *__t._M_abbrev;
1491 if constexpr (is_same_v<_CharT, char>)
1492 return __format::__write(
std::move(__out), __sv);
1496 basic_string<_CharT> __ws(__sv.size(), _CharT());
1497 auto& __ct = use_facet<ctype<_CharT>>(_M_locale(__ctx));
1498 __ct.widen(__sv.begin(), __sv.end(), __ws.data());
1499 __string_view __wsv = __ws;
1500 return __format::__write(
std::move(__out), __wsv);
1504 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1505 return __format::__write(
std::move(__out), __utc);
1507 __no_timezone_available();
1514 _S_digit(
int __n)
noexcept
1517 return _GLIBCXX_WIDEN(
"0123456789999999")[__n & 0xf];
1521 static basic_string_view<_CharT>
1522 _S_two_digits(
int __n)
noexcept
1525 _GLIBCXX_WIDEN(
"0001020304050607080910111213141516171819"
1526 "2021222324252627282930313233343536373839"
1527 "4041424344454647484950515253545556575859"
1528 "6061626364656667686970717273747576777879"
1529 "8081828384858687888990919293949596979899"
1530 "9999999999999999999999999999999999999999"
1531 "9999999999999999") + 2 * (__n & 0x7f),
1539 template<
typename _Tp>
1540 static decltype(
auto)
1541 _S_hms(
const _Tp& __t)
1543 using ::std::chrono::__detail::__utc_leap_second;
1544 using ::std::chrono::__detail::__local_time_fmt;
1546 if constexpr (__is_specialization_of<_Tp, chrono::hh_mm_ss>)
1548 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1550 else if constexpr (chrono::__is_duration_v<_Tp>)
1551 return chrono::hh_mm_ss<_Tp>(__t);
1552 else if constexpr (chrono::__is_time_point_v<_Tp>)
1553 return chrono::hh_mm_ss(__t - chrono::floor<chrono::days>(__t));
1554 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1555 return _S_hms(__t._M_time);
1558 __invalid_chrono_spec();
1559 return chrono::hh_mm_ss<chrono::seconds>();
1564 template<
typename _Tp>
1566 _S_days(
const _Tp& __t)
1568 using namespace chrono;
1569 using ::std::chrono::__detail::__utc_leap_second;
1570 using ::std::chrono::__detail::__local_time_fmt;
1572 if constexpr (__is_time_point_v<_Tp>)
1573 return chrono::floor<days>(__t);
1574 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1576 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1577 return chrono::floor<days>(__t._M_time);
1578 else if constexpr (is_same_v<_Tp, year_month_day>
1579 || is_same_v<_Tp, year_month_day_last>
1580 || is_same_v<_Tp, year_month_weekday>
1581 || is_same_v<_Tp, year_month_weekday_last>)
1582 return sys_days(__t);
1585 if constexpr (__is_duration_v<_Tp>)
1586 __not_valid_for_duration();
1588 __invalid_chrono_spec();
1589 return chrono::sys_days();
1594 template<
typename _Tp>
1595 static chrono::year_month_day
1596 _S_date(
const _Tp& __t)
1598 if constexpr (is_same_v<_Tp, chrono::year_month_day>)
1601 return chrono::year_month_day(_S_days(__t));
1604 template<
typename _Tp>
1606 _S_day(
const _Tp& __t)
1608 using namespace chrono;
1610 if constexpr (is_same_v<_Tp, day>)
1612 else if constexpr (
requires { __t.day(); })
1615 return _S_date(__t).day();
1618 template<
typename _Tp>
1619 static chrono::month
1620 _S_month(
const _Tp& __t)
1622 using namespace chrono;
1624 if constexpr (is_same_v<_Tp, month>)
1626 else if constexpr (
requires { __t.month(); })
1629 return _S_date(__t).month();
1632 template<
typename _Tp>
1634 _S_year(
const _Tp& __t)
1636 using namespace chrono;
1638 if constexpr (is_same_v<_Tp, year>)
1640 else if constexpr (
requires { __t.year(); })
1643 return _S_date(__t).year();
1646 template<
typename _Tp>
1647 static chrono::weekday
1648 _S_weekday(
const _Tp& __t)
1650 using namespace ::std::chrono;
1651 using ::std::chrono::__detail::__local_time_fmt;
1653 if constexpr (is_same_v<_Tp, weekday>)
1655 else if constexpr (
requires { __t.weekday(); })
1656 return __t.weekday();
1657 else if constexpr (is_same_v<_Tp, month_weekday>)
1658 return __t.weekday_indexed().weekday();
1659 else if constexpr (is_same_v<_Tp, month_weekday_last>)
1660 return __t.weekday_last().weekday();
1662 return weekday(_S_days(__t));
1666 template<
typename _Tp>
1668 _S_floor_seconds(
const _Tp& __t)
1670 using chrono::__detail::__local_time_fmt;
1671 if constexpr (chrono::__is_time_point_v<_Tp>
1672 || chrono::__is_duration_v<_Tp>)
1674 if constexpr (_Tp::period::den != 1)
1675 return chrono::floor<chrono::seconds>(__t);
1679 else if constexpr (__is_specialization_of<_Tp, chrono::hh_mm_ss>)
1681 if constexpr (_Tp::fractional_width != 0)
1682 return chrono::floor<chrono::seconds>(__t.to_duration());
1686 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1687 return _S_floor_seconds(__t._M_time);
1694 template<
typename _Iter>
1696 _M_locale_fmt(_Iter __out,
const locale& __loc,
const struct tm& __tm,
1697 char __fmt,
char __mod)
const
1699 basic_ostringstream<_CharT> __os;
1700 const auto& __tp = use_facet<time_put<_CharT>>(__loc);
1701 __tp.put(__os, __os, _S_space, &__tm, __fmt, __mod);
1703 __out = _M_write(
std::move(__out), __loc, __os.view());
1711 template<
typename _Rep,
typename _Period,
typename _CharT>
1712 requires __format::__formattable_impl<_Rep, _CharT>
1713 struct formatter<
chrono::duration<_Rep, _Period>, _CharT>
1715 constexpr typename basic_format_parse_context<_CharT>::iterator
1716 parse(basic_format_parse_context<_CharT>& __pc)
1718 using namespace __format;
1719 auto __it = _M_f._M_parse(__pc, _Duration|_TimeOfDay);
1720 if constexpr (!is_floating_point_v<_Rep>)
1721 if (_M_f._M_spec._M_prec_kind != __format::_WP_none)
1722 __throw_format_error(
"format error: invalid precision for duration");
1726 template<
typename _Out>
1727 typename basic_format_context<_Out, _CharT>::iterator
1728 format(
const chrono::duration<_Rep, _Period>& __d,
1729 basic_format_context<_Out, _CharT>& __fc)
const
1731 if constexpr (numeric_limits<_Rep>::is_signed)
1732 if (__d < __d.zero()) [[unlikely]]
1734 if constexpr (is_integral_v<_Rep>)
1738 using _URep = make_unsigned_t<_Rep>;
1739 auto __ucnt = -
static_cast<_URep
>(__d.count());
1740 auto __ud = chrono::duration<_URep, _Period>(__ucnt);
1741 return _M_f._M_format(__ud, __fc,
true);
1744 return _M_f._M_format(-__d, __fc,
true);
1746 return _M_f._M_format(__d, __fc,
false);
1750 __format::__formatter_chrono<_CharT> _M_f;
1753 template<
typename _CharT>
1754 struct formatter<
chrono::day, _CharT>
1756 template<
typename _ParseContext>
1757 constexpr typename _ParseContext::iterator
1758 parse(_ParseContext& __pc)
1759 {
return _M_f._M_parse(__pc, __format::_Day); }
1761 template<
typename _FormatContext>
1762 typename _FormatContext::iterator
1763 format(
const chrono::day& __t, _FormatContext& __fc)
const
1764 {
return _M_f._M_format(__t, __fc); }
1767 __format::__formatter_chrono<_CharT> _M_f;
1770 template<
typename _CharT>
1771 struct formatter<
chrono::month, _CharT>
1773 template<
typename _ParseContext>
1774 constexpr typename _ParseContext::iterator
1775 parse(_ParseContext& __pc)
1776 {
return _M_f._M_parse(__pc, __format::_Month); }
1778 template<
typename _FormatContext>
1779 typename _FormatContext::iterator
1780 format(
const chrono::month& __t, _FormatContext& __fc)
const
1781 {
return _M_f._M_format(__t, __fc); }
1784 __format::__formatter_chrono<_CharT> _M_f;
1787 template<
typename _CharT>
1788 struct formatter<
chrono::year, _CharT>
1790 template<
typename _ParseContext>
1791 constexpr typename _ParseContext::iterator
1792 parse(_ParseContext& __pc)
1793 {
return _M_f._M_parse(__pc, __format::_Year); }
1795 template<
typename _FormatContext>
1796 typename _FormatContext::iterator
1797 format(
const chrono::year& __t, _FormatContext& __fc)
const
1798 {
return _M_f._M_format(__t, __fc); }
1801 __format::__formatter_chrono<_CharT> _M_f;
1804 template<
typename _CharT>
1805 struct formatter<
chrono::weekday, _CharT>
1807 template<
typename _ParseContext>
1808 constexpr typename _ParseContext::iterator
1809 parse(_ParseContext& __pc)
1810 {
return _M_f._M_parse(__pc, __format::_Weekday); }
1812 template<
typename _FormatContext>
1813 typename _FormatContext::iterator
1814 format(
const chrono::weekday& __t, _FormatContext& __fc)
const
1815 {
return _M_f._M_format(__t, __fc); }
1818 __format::__formatter_chrono<_CharT> _M_f;
1821 template<
typename _CharT>
1822 struct formatter<
chrono::weekday_indexed, _CharT>
1824 template<
typename _ParseContext>
1825 constexpr typename _ParseContext::iterator
1826 parse(_ParseContext& __pc)
1827 {
return _M_f._M_parse(__pc, __format::_Weekday); }
1829 template<
typename _FormatContext>
1830 typename _FormatContext::iterator
1831 format(
const chrono::weekday_indexed& __t, _FormatContext& __fc)
const
1832 {
return _M_f._M_format(__t, __fc); }
1835 __format::__formatter_chrono<_CharT> _M_f;
1838 template<
typename _CharT>
1839 struct formatter<
chrono::weekday_last, _CharT>
1841 template<
typename _ParseContext>
1842 constexpr typename _ParseContext::iterator
1843 parse(_ParseContext& __pc)
1844 {
return _M_f._M_parse(__pc, __format::_Weekday); }
1846 template<
typename _FormatContext>
1847 typename _FormatContext::iterator
1848 format(
const chrono::weekday_last& __t, _FormatContext& __fc)
const
1849 {
return _M_f._M_format(__t, __fc); }
1852 __format::__formatter_chrono<_CharT> _M_f;
1855 template<
typename _CharT>
1856 struct formatter<
chrono::month_day, _CharT>
1858 template<
typename _ParseContext>
1859 constexpr typename _ParseContext::iterator
1860 parse(_ParseContext& __pc)
1861 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Day); }
1863 template<
typename _FormatContext>
1864 typename _FormatContext::iterator
1865 format(
const chrono::month_day& __t, _FormatContext& __fc)
const
1866 {
return _M_f._M_format(__t, __fc); }
1869 __format::__formatter_chrono<_CharT> _M_f;
1872 template<
typename _CharT>
1873 struct formatter<
chrono::month_day_last, _CharT>
1875 template<
typename _ParseContext>
1876 constexpr typename _ParseContext::iterator
1877 parse(_ParseContext& __pc)
1878 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Day); }
1880 template<
typename _FormatContext>
1881 typename _FormatContext::iterator
1882 format(
const chrono::month_day_last& __t, _FormatContext& __fc)
const
1883 {
return _M_f._M_format(__t, __fc); }
1886 __format::__formatter_chrono<_CharT> _M_f;
1889 template<
typename _CharT>
1890 struct formatter<
chrono::month_weekday, _CharT>
1892 template<
typename _ParseContext>
1893 constexpr typename _ParseContext::iterator
1894 parse(_ParseContext& __pc)
1895 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Weekday); }
1897 template<
typename _FormatContext>
1898 typename _FormatContext::iterator
1899 format(
const chrono::month_weekday& __t, _FormatContext& __fc)
const
1900 {
return _M_f._M_format(__t, __fc); }
1903 __format::__formatter_chrono<_CharT> _M_f;
1906 template<
typename _CharT>
1907 struct formatter<
chrono::month_weekday_last, _CharT>
1909 template<
typename _ParseContext>
1910 constexpr typename _ParseContext::iterator
1911 parse(_ParseContext& __pc)
1912 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Weekday); }
1914 template<
typename _FormatContext>
1915 typename _FormatContext::iterator
1916 format(
const chrono::month_weekday_last& __t,
1917 _FormatContext& __fc)
const
1918 {
return _M_f._M_format(__t, __fc); }
1921 __format::__formatter_chrono<_CharT> _M_f;
1924 template<
typename _CharT>
1925 struct formatter<
chrono::year_month, _CharT>
1927 template<
typename _ParseContext>
1928 constexpr typename _ParseContext::iterator
1929 parse(_ParseContext& __pc)
1930 {
return _M_f._M_parse(__pc, __format::_Year|__format::_Month); }
1932 template<
typename _FormatContext>
1933 typename _FormatContext::iterator
1934 format(
const chrono::year_month& __t, _FormatContext& __fc)
const
1935 {
return _M_f._M_format(__t, __fc); }
1938 __format::__formatter_chrono<_CharT> _M_f;
1941 template<
typename _CharT>
1942 struct formatter<
chrono::year_month_day, _CharT>
1944 template<
typename _ParseContext>
1945 constexpr typename _ParseContext::iterator
1946 parse(_ParseContext& __pc)
1947 {
return _M_f._M_parse(__pc, __format::_Date); }
1949 template<
typename _FormatContext>
1950 typename _FormatContext::iterator
1951 format(
const chrono::year_month_day& __t, _FormatContext& __fc)
const
1952 {
return _M_f._M_format(__t, __fc); }
1955 __format::__formatter_chrono<_CharT> _M_f;
1958 template<
typename _CharT>
1959 struct formatter<
chrono::year_month_day_last, _CharT>
1961 template<
typename _ParseContext>
1962 constexpr typename _ParseContext::iterator
1963 parse(_ParseContext& __pc)
1964 {
return _M_f._M_parse(__pc, __format::_Date); }
1966 template<
typename _FormatContext>
1967 typename _FormatContext::iterator
1968 format(
const chrono::year_month_day_last& __t,
1969 _FormatContext& __fc)
const
1970 {
return _M_f._M_format(__t, __fc); }
1973 __format::__formatter_chrono<_CharT> _M_f;
1976 template<
typename _CharT>
1977 struct formatter<
chrono::year_month_weekday, _CharT>
1979 template<
typename _ParseContext>
1980 constexpr typename _ParseContext::iterator
1981 parse(_ParseContext& __pc)
1982 {
return _M_f._M_parse(__pc, __format::_Date); }
1984 template<
typename _FormatContext>
1985 typename _FormatContext::iterator
1986 format(
const chrono::year_month_weekday& __t,
1987 _FormatContext& __fc)
const
1988 {
return _M_f._M_format(__t, __fc); }
1991 __format::__formatter_chrono<_CharT> _M_f;
1994 template<
typename _CharT>
1995 struct formatter<
chrono::year_month_weekday_last, _CharT>
1997 template<
typename _ParseContext>
1998 constexpr typename _ParseContext::iterator
1999 parse(_ParseContext& __pc)
2000 {
return _M_f._M_parse(__pc, __format::_Date); }
2002 template<
typename _FormatContext>
2003 typename _FormatContext::iterator
2004 format(
const chrono::year_month_weekday_last& __t,
2005 _FormatContext& __fc)
const
2006 {
return _M_f._M_format(__t, __fc); }
2009 __format::__formatter_chrono<_CharT> _M_f;
2012 template<
typename _Rep,
typename _Period,
typename _CharT>
2013 struct formatter<
chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>, _CharT>
2015 template<
typename _ParseContext>
2016 constexpr typename _ParseContext::iterator
2017 parse(_ParseContext& __pc)
2018 {
return _M_f._M_parse(__pc, __format::_TimeOfDay); }
2020 template<
typename _FormatContext>
2021 typename _FormatContext::iterator
2022 format(
const chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>& __t,
2023 _FormatContext& __fc)
const
2024 {
return _M_f._M_format(__t, __fc); }
2027 __format::__formatter_chrono<_CharT> _M_f;
2030#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2031 template<
typename _CharT>
2032 struct formatter<
chrono::sys_info, _CharT>
2034 template<
typename _ParseContext>
2035 constexpr typename _ParseContext::iterator
2036 parse(_ParseContext& __pc)
2037 {
return _M_f._M_parse(__pc, __format::_ChronoParts{}); }
2039 template<
typename _FormatContext>
2040 typename _FormatContext::iterator
2041 format(
const chrono::sys_info& __i, _FormatContext& __fc)
const
2042 {
return _M_f._M_format(__i, __fc); }
2045 __format::__formatter_chrono<_CharT> _M_f;
2048 template<
typename _CharT>
2049 struct formatter<
chrono::local_info, _CharT>
2051 template<
typename _ParseContext>
2052 constexpr typename _ParseContext::iterator
2053 parse(_ParseContext& __pc)
2054 {
return _M_f._M_parse(__pc, __format::_ChronoParts{}); }
2056 template<
typename _FormatContext>
2057 typename _FormatContext::iterator
2058 format(
const chrono::local_info& __i, _FormatContext& __fc)
const
2059 {
return _M_f._M_format(__i, __fc); }
2062 __format::__formatter_chrono<_CharT> _M_f;
2066 template<
typename _Duration,
typename _CharT>
2067 struct formatter<
chrono::sys_time<_Duration>, _CharT>
2069 template<
typename _ParseContext>
2070 constexpr typename _ParseContext::iterator
2071 parse(_ParseContext& __pc)
2073 auto __next = _M_f._M_parse(__pc, __format::_ZonedDateTime);
2074 if constexpr (!__stream_insertable)
2075 if (_M_f._M_spec._M_chrono_specs.empty())
2076 __format::__invalid_chrono_spec();
2080 template<
typename _FormatContext>
2081 typename _FormatContext::iterator
2082 format(
const chrono::sys_time<_Duration>& __t,
2083 _FormatContext& __fc)
const
2084 {
return _M_f._M_format(__t, __fc); }
2087 static constexpr bool __stream_insertable
2088 =
requires (basic_ostream<_CharT>& __os,
2089 chrono::sys_time<_Duration> __t) { __os << __t; };
2091 __format::__formatter_chrono<_CharT> _M_f;
2094 template<
typename _Duration,
typename _CharT>
2095 struct formatter<
chrono::utc_time<_Duration>, _CharT>
2096 : __format::__formatter_chrono<_CharT>
2098 template<
typename _ParseContext>
2099 constexpr typename _ParseContext::iterator
2100 parse(_ParseContext& __pc)
2101 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2103 template<
typename _FormatContext>
2104 typename _FormatContext::iterator
2105 format(
const chrono::utc_time<_Duration>& __t,
2106 _FormatContext& __fc)
const
2111 using chrono::__detail::__utc_leap_second;
2112 using chrono::seconds;
2113 using chrono::sys_time;
2114 using _CDur = common_type_t<_Duration, seconds>;
2115 const auto __li = chrono::get_leap_second_info(__t);
2116 sys_time<_CDur> __s{__t.time_since_epoch() - __li.elapsed};
2117 if (!__li.is_leap_second) [[likely]]
2118 return _M_f._M_format(__s, __fc);
2120 return _M_f._M_format(__utc_leap_second(__s), __fc);
2124 friend formatter<chrono::__detail::__utc_leap_second<_Duration>, _CharT>;
2126 __format::__formatter_chrono<_CharT> _M_f;
2129 template<
typename _Duration,
typename _CharT>
2130 struct formatter<
chrono::tai_time<_Duration>, _CharT>
2131 : __format::__formatter_chrono<_CharT>
2133 template<
typename _ParseContext>
2134 constexpr typename _ParseContext::iterator
2135 parse(_ParseContext& __pc)
2136 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2138 template<
typename _FormatContext>
2139 typename _FormatContext::iterator
2140 format(
const chrono::tai_time<_Duration>& __t,
2141 _FormatContext& __fc)
const
2148 constexpr chrono::days __tai_offset = chrono::days(4383);
2149 using _CDur = common_type_t<_Duration, chrono::days>;
2150 chrono::local_time<_CDur> __lt(__t.time_since_epoch() - __tai_offset);
2151 const string __abbrev(
"TAI", 3);
2152 const chrono::seconds __off = 0s;
2153 const auto __lf = chrono::local_time_format(__lt, &__abbrev, &__off);
2154 return _M_f._M_format(__lf, __fc);
2158 __format::__formatter_chrono<_CharT> _M_f;
2161 template<
typename _Duration,
typename _CharT>
2162 struct formatter<
chrono::gps_time<_Duration>, _CharT>
2163 : __format::__formatter_chrono<_CharT>
2165 template<
typename _ParseContext>
2166 constexpr typename _ParseContext::iterator
2167 parse(_ParseContext& __pc)
2168 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2170 template<
typename _FormatContext>
2171 typename _FormatContext::iterator
2172 format(
const chrono::gps_time<_Duration>& __t,
2173 _FormatContext& __fc)
const
2180 constexpr chrono::days __gps_offset = chrono::days(3657);
2181 using _CDur = common_type_t<_Duration, chrono::days>;
2182 chrono::local_time<_CDur> __lt(__t.time_since_epoch() + __gps_offset);
2183 const string __abbrev(
"GPS", 3);
2184 const chrono::seconds __off = 0s;
2185 const auto __lf = chrono::local_time_format(__lt, &__abbrev, &__off);
2186 return _M_f._M_format(__lf, __fc);
2190 __format::__formatter_chrono<_CharT> _M_f;
2193 template<
typename _Duration,
typename _CharT>
2194 struct formatter<
chrono::file_time<_Duration>, _CharT>
2196 template<
typename _ParseContext>
2197 constexpr typename _ParseContext::iterator
2198 parse(_ParseContext& __pc)
2199 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2201 template<
typename _FormatContext>
2202 typename _FormatContext::iterator
2203 format(
const chrono::file_time<_Duration>& __t,
2204 _FormatContext& __ctx)
const
2206 using namespace chrono;
2207 return _M_f._M_format(chrono::clock_cast<system_clock>(__t), __ctx);
2211 __format::__formatter_chrono<_CharT> _M_f;
2214 template<
typename _Duration,
typename _CharT>
2215 struct formatter<
chrono::local_time<_Duration>, _CharT>
2217 template<
typename _ParseContext>
2218 constexpr typename _ParseContext::iterator
2219 parse(_ParseContext& __pc)
2220 {
return _M_f._M_parse(__pc, __format::_DateTime); }
2222 template<
typename _FormatContext>
2223 typename _FormatContext::iterator
2224 format(
const chrono::local_time<_Duration>& __t,
2225 _FormatContext& __ctx)
const
2226 {
return _M_f._M_format(__t, __ctx); }
2229 __format::__formatter_chrono<_CharT> _M_f;
2232 template<
typename _Duration,
typename _CharT>
2233 struct formatter<
chrono::__detail::__local_time_fmt<_Duration>, _CharT>
2235 template<
typename _ParseContext>
2236 constexpr typename _ParseContext::iterator
2237 parse(_ParseContext& __pc)
2238 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2240 template<
typename _FormatContext>
2241 typename _FormatContext::iterator
2242 format(
const chrono::__detail::__local_time_fmt<_Duration>& __t,
2243 _FormatContext& __ctx)
const
2244 {
return _M_f._M_format(__t, __ctx,
true); }
2247 __format::__formatter_chrono<_CharT> _M_f;
2250#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2251 template<
typename _Duration,
typename _TimeZonePtr,
typename _CharT>
2252 struct formatter<
chrono::zoned_time<_Duration, _TimeZonePtr>, _CharT>
2253 : formatter<chrono::__detail::__local_time_fmt_for<_Duration>, _CharT>
2255 template<
typename _FormatContext>
2256 typename _FormatContext::iterator
2257 format(
const chrono::zoned_time<_Duration, _TimeZonePtr>& __tp,
2258 _FormatContext& __ctx)
const
2260 using _Ltf = chrono::__detail::__local_time_fmt_for<_Duration>;
2261 using _Base = formatter<_Ltf, _CharT>;
2262 const chrono::sys_info __info = __tp.get_info();
2263 const auto __lf = chrono::local_time_format(__tp.get_local_time(),
2266 return _Base::format(__lf, __ctx);
2272 template<
typename _Duration,
typename _CharT>
2273 struct formatter<
chrono::__detail::__utc_leap_second<_Duration>, _CharT>
2274 : formatter<chrono::utc_time<_Duration>, _CharT>
2276 template<
typename _FormatContext>
2277 typename _FormatContext::iterator
2278 format(
const chrono::__detail::__utc_leap_second<_Duration>& __t,
2279 _FormatContext& __fc)
const
2280 {
return this->_M_f._M_format(__t, __fc); }
2291 template<
typename _Duration = seconds>
2294 static_assert(is_same_v<common_type_t<_Duration, seconds>, _Duration>);
2297 _Parser(__format::_ChronoParts __need) : _M_need(__need) { }
2299 _Parser(_Parser&&) =
delete;
2300 void operator=(_Parser&&) =
delete;
2302 _Duration _M_time{};
2303 sys_days _M_sys_days{};
2304 year_month_day _M_ymd{};
2306 __format::_ChronoParts _M_need;
2307 unsigned _M_is_leap_second : 1 {};
2308 unsigned _M_reserved : 15 {};
2310 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2311 basic_istream<_CharT, _Traits>&
2312 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2313 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2314 minutes* __offset =
nullptr);
2319 template<
typename _CharT,
typename _Traits>
2320 static int_least32_t
2321 _S_read_unsigned(basic_istream<_CharT, _Traits>& __is,
2322 ios_base::iostate& __err,
int __n)
2324 int_least32_t __val = _S_try_read_digit(__is, __err);
2325 if (__val == -1) [[unlikely]]
2326 __err |= ios_base::failbit;
2331 for (
int __i = 1; __i < __n1; ++__i)
2332 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
2338 while (__n1++ < __n) [[unlikely]]
2339 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
2341 if (__builtin_mul_overflow(__val, 10, &__val)
2342 || __builtin_add_overflow(__val, __dig, &__val))
2344 __err |= ios_base::failbit;
2354 template<
typename _CharT,
typename _Traits>
2355 static int_least32_t
2356 _S_read_signed(basic_istream<_CharT, _Traits>& __is,
2357 ios_base::iostate& __err,
int __n)
2359 auto __sign = __is.peek();
2360 if (__sign ==
'-' || __sign ==
'+')
2362 int_least32_t __val = _S_read_unsigned(__is, __err, __n);
2363 if (__err & ios_base::failbit)
2365 if (__sign ==
'-') [[unlikely]]
2373 template<
typename _CharT,
typename _Traits>
2374 static int_least32_t
2375 _S_try_read_digit(basic_istream<_CharT, _Traits>& __is,
2376 ios_base::iostate& __err)
2378 int_least32_t __val = -1;
2379 auto __i = __is.peek();
2380 if (!_Traits::eq_int_type(__i, _Traits::eof())) [[likely]]
2382 _CharT __c = _Traits::to_char_type(__i);
2383 if (_CharT(
'0') <= __c && __c <= _CharT(
'9')) [[likely]]
2386 __val = __c - _CharT(
'0');
2390 __err |= ios_base::eofbit;
2396 template<
typename _CharT,
typename _Traits>
2398 _S_read_chr(basic_istream<_CharT, _Traits>& __is,
2399 ios_base::iostate& __err, _CharT __c)
2401 auto __i = __is.peek();
2402 if (_Traits::eq_int_type(__i, _Traits::eof()))
2403 __err |= ios_base::eofbit;
2404 else if (_Traits::to_char_type(__i) == __c) [[likely]]
2409 __err |= ios_base::failbit;
2414 template<
typename _Duration>
2415 using _Parser_t = _Parser<common_type_t<_Duration, seconds>>;
2417 template<
typename _Duration>
2421 if constexpr (_Duration::period::den == 1)
2423 switch (_Duration::period::num)
2425 case minutes::period::num:
2426 case hours::period::num:
2427 case days::period::num:
2428 case weeks::period::num:
2429 case years::period::num:
2446 template<
typename _ToDur,
typename _Tp>
2448 __round(
const _Tp& __t)
2450 if constexpr (__is_duration_v<_Tp>)
2452 if constexpr (treat_as_floating_point_v<typename _Tp::rep>)
2454 else if constexpr (__detail::__use_floor<_ToDur>())
2461 static_assert(__is_time_point_v<_Tp>);
2462 using _Tpt = time_point<typename _Tp::clock, _ToDur>;
2463 return _Tpt(__detail::__round<_ToDur>(__t.time_since_epoch()));
2470 template<
typename _CharT,
typename _Traits,
typename _Rep,
typename _Period,
2471 typename _Alloc = allocator<_CharT>>
2472 inline basic_istream<_CharT, _Traits>&
2473 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2475 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2478 auto __need = __format::_ChronoParts::_TimeOfDay;
2479 __detail::_Parser_t<duration<_Rep, _Period>> __p(__need);
2480 if (__p(__is, __fmt, __abbrev, __offset))
2481 __d = __detail::__round<duration<_Rep, _Period>>(__p._M_time);
2485 template<
typename _CharT,
typename _Traits>
2486 inline basic_ostream<_CharT, _Traits>&
2487 operator<<(basic_ostream<_CharT, _Traits>& __os,
const day& __d)
2489 using _Ctx = __format::__format_context<_CharT>;
2490 using _Str = basic_string_view<_CharT>;
2491 _Str __s = _GLIBCXX_WIDEN(
"{:02d} is not a valid day");
2493 __s = __s.substr(0, 6);
2494 auto __u = (unsigned)__d;
2495 __os << std::vformat(__s, make_format_args<_Ctx>(__u));
2499 template<
typename _CharT,
typename _Traits,
2500 typename _Alloc = allocator<_CharT>>
2501 inline basic_istream<_CharT, _Traits>&
2502 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2504 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2507 __detail::_Parser<> __p(__format::_ChronoParts::_Day);
2508 if (__p(__is, __fmt, __abbrev, __offset))
2509 __d = __p._M_ymd.day();
2513 template<
typename _CharT,
typename _Traits>
2514 inline basic_ostream<_CharT, _Traits>&
2515 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month& __m)
2517 using _Ctx = __format::__format_context<_CharT>;
2518 using _Str = basic_string_view<_CharT>;
2519 _Str __s = _GLIBCXX_WIDEN(
"{:L%b}{} is not a valid month");
2521 __os << std::vformat(__os.getloc(), __s.substr(0, 6),
2522 make_format_args<_Ctx>(__m));
2525 auto __u = (unsigned)__m;
2526 __os << std::vformat(__s.substr(6), make_format_args<_Ctx>(__u));
2531 template<
typename _CharT,
typename _Traits,
2532 typename _Alloc = allocator<_CharT>>
2533 inline basic_istream<_CharT, _Traits>&
2534 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2536 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2539 __detail::_Parser<> __p(__format::_ChronoParts::_Month);
2540 if (__p(__is, __fmt, __abbrev, __offset))
2541 __m = __p._M_ymd.month();
2545 template<
typename _CharT,
typename _Traits>
2546 inline basic_ostream<_CharT, _Traits>&
2547 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year& __y)
2549 using _Ctx = __format::__format_context<_CharT>;
2550 using _Str = basic_string_view<_CharT>;
2551 _Str __s = _GLIBCXX_WIDEN(
"-{:04d} is not a valid year");
2553 __s = __s.substr(0, 7);
2555 if (__i >= 0) [[likely]]
2556 __s.remove_prefix(1);
2559 __os << std::vformat(__s, make_format_args<_Ctx>(__i));
2563 template<
typename _CharT,
typename _Traits,
2564 typename _Alloc = allocator<_CharT>>
2565 inline basic_istream<_CharT, _Traits>&
2566 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2568 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2571 __detail::_Parser<> __p(__format::_ChronoParts::_Year);
2572 if (__p(__is, __fmt, __abbrev, __offset))
2573 __y = __p._M_ymd.year();
2577 template<
typename _CharT,
typename _Traits>
2578 inline basic_ostream<_CharT, _Traits>&
2579 operator<<(basic_ostream<_CharT, _Traits>& __os,
const weekday& __wd)
2581 using _Ctx = __format::__format_context<_CharT>;
2582 using _Str = basic_string_view<_CharT>;
2583 _Str __s = _GLIBCXX_WIDEN(
"{:L%a}{} is not a valid weekday");
2585 __os << std::vformat(__os.getloc(), __s.substr(0, 6),
2586 make_format_args<_Ctx>(__wd));
2589 auto __c = __wd.c_encoding();
2590 __os << std::vformat(__s.substr(6), make_format_args<_Ctx>(__c));
2595 template<
typename _CharT,
typename _Traits,
2596 typename _Alloc = allocator<_CharT>>
2597 inline basic_istream<_CharT, _Traits>&
2598 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2600 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2603 __detail::_Parser<> __p(__format::_ChronoParts::_Weekday);
2604 if (__p(__is, __fmt, __abbrev, __offset))
2609 template<
typename _CharT,
typename _Traits>
2610 inline basic_ostream<_CharT, _Traits>&
2611 operator<<(basic_ostream<_CharT, _Traits>& __os,
2612 const weekday_indexed& __wdi)
2617 basic_stringstream<_CharT> __os2;
2618 __os2.imbue(__os.getloc());
2619 __os2 << __wdi.weekday();
2620 const auto __i = __wdi.index();
2621 basic_string_view<_CharT> __s
2622 = _GLIBCXX_WIDEN(
"[ is not a valid index]");
2624 __os2 << std::format(_GLIBCXX_WIDEN(
"{}"), __i);
2625 if (__i >= 1 && __i <= 5)
2626 __os2 << __s.back();
2628 __os2 << __s.substr(1);
2629 __os << __os2.view();
2633 template<
typename _CharT,
typename _Traits>
2634 inline basic_ostream<_CharT, _Traits>&
2635 operator<<(basic_ostream<_CharT, _Traits>& __os,
2636 const weekday_last& __wdl)
2639 basic_stringstream<_CharT> __os2;
2640 __os2.imbue(__os.getloc());
2641 __os2 << __wdl.weekday() << _GLIBCXX_WIDEN(
"[last]");
2642 __os << __os2.view();
2646 template<
typename _CharT,
typename _Traits>
2647 inline basic_ostream<_CharT, _Traits>&
2648 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month_day& __md)
2651 basic_stringstream<_CharT> __os2;
2652 __os2.imbue(__os.getloc());
2653 __os2 << __md.month();
2654 if constexpr (is_same_v<_CharT, char>)
2658 __os2 << __md.day();
2659 __os << __os2.view();
2663 template<
typename _CharT,
typename _Traits,
2664 typename _Alloc = allocator<_CharT>>
2665 inline basic_istream<_CharT, _Traits>&
2666 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2668 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2671 using __format::_ChronoParts;
2672 auto __need = _ChronoParts::_Month | _ChronoParts::_Day;
2673 __detail::_Parser<> __p(__need);
2674 if (__p(__is, __fmt, __abbrev, __offset))
2675 __md = month_day(__p._M_ymd.month(), __p._M_ymd.day());
2679 template<
typename _CharT,
typename _Traits>
2680 inline basic_ostream<_CharT, _Traits>&
2681 operator<<(basic_ostream<_CharT, _Traits>& __os,
2682 const month_day_last& __mdl)
2685 basic_stringstream<_CharT> __os2;
2686 __os2.imbue(__os.getloc());
2687 __os2 << __mdl.month() << _GLIBCXX_WIDEN(
"/last");
2688 __os << __os2.view();
2692 template<
typename _CharT,
typename _Traits>
2693 inline basic_ostream<_CharT, _Traits>&
2694 operator<<(basic_ostream<_CharT, _Traits>& __os,
2695 const month_weekday& __mwd)
2698 basic_stringstream<_CharT> __os2;
2699 __os2.imbue(__os.getloc());
2700 __os2 << __mwd.month();
2701 if constexpr (is_same_v<_CharT, char>)
2705 __os2 << __mwd.weekday_indexed();
2706 __os << __os2.view();
2710 template<
typename _CharT,
typename _Traits>
2711 inline basic_ostream<_CharT, _Traits>&
2712 operator<<(basic_ostream<_CharT, _Traits>& __os,
2713 const month_weekday_last& __mwdl)
2716 basic_stringstream<_CharT> __os2;
2717 __os2.imbue(__os.getloc());
2718 __os2 << __mwdl.month();
2719 if constexpr (is_same_v<_CharT, char>)
2723 __os2 << __mwdl.weekday_last();
2724 __os << __os2.view();
2728 template<
typename _CharT,
typename _Traits>
2729 inline basic_ostream<_CharT, _Traits>&
2730 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year_month& __ym)
2733 basic_stringstream<_CharT> __os2;
2734 __os2.imbue(__os.getloc());
2735 __os2 << __ym.year();
2736 if constexpr (is_same_v<_CharT, char>)
2740 __os2 << __ym.month();
2741 __os << __os2.view();
2745 template<
typename _CharT,
typename _Traits,
2746 typename _Alloc = allocator<_CharT>>
2747 inline basic_istream<_CharT, _Traits>&
2748 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2750 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2753 using __format::_ChronoParts;
2754 auto __need = _ChronoParts::_Year | _ChronoParts::_Month;
2755 __detail::_Parser<> __p(__need);
2756 if (__p(__is, __fmt, __abbrev, __offset))
2757 __ym = year_month(__p._M_ymd.year(), __p._M_ymd.month());
2761 template<
typename _CharT,
typename _Traits>
2762 inline basic_ostream<_CharT, _Traits>&
2763 operator<<(basic_ostream<_CharT, _Traits>& __os,
2764 const year_month_day& __ymd)
2766 using _Ctx = __format::__format_context<_CharT>;
2767 using _Str = basic_string_view<_CharT>;
2768 _Str __s = _GLIBCXX_WIDEN(
"{:%F} is not a valid date");
2769 __os << std::vformat(__ymd.ok() ? __s.substr(0, 5) : __s,
2770 make_format_args<_Ctx>(__ymd));
2774 template<
typename _CharT,
typename _Traits,
2775 typename _Alloc = allocator<_CharT>>
2776 inline basic_istream<_CharT, _Traits>&
2778 year_month_day& __ymd,
2782 using __format::_ChronoParts;
2783 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2784 | _ChronoParts::_Day;
2785 __detail::_Parser<> __p(__need);
2786 if (__p(__is, __fmt, __abbrev, __offset))
2791 template<
typename _CharT,
typename _Traits>
2794 const year_month_day_last& __ymdl)
2799 __os2 << __ymdl.year();
2800 if constexpr (is_same_v<_CharT, char>)
2804 __os2 << __ymdl.month_day_last();
2805 __os << __os2.view();
2809 template<
typename _CharT,
typename _Traits>
2810 inline basic_ostream<_CharT, _Traits>&
2811 operator<<(basic_ostream<_CharT, _Traits>& __os,
2812 const year_month_weekday& __ymwd)
2816 basic_stringstream<_CharT> __os2;
2817 __os2.
imbue(__os.getloc());
2819 if constexpr (is_same_v<_CharT, char>)
2823 __os2 << __ymwd.year() << __slash << __ymwd.month() << __slash
2824 << __ymwd.weekday_indexed();
2825 __os << __os2.view();
2829 template<
typename _CharT,
typename _Traits>
2830 inline basic_ostream<_CharT, _Traits>&
2831 operator<<(basic_ostream<_CharT, _Traits>& __os,
2832 const year_month_weekday_last& __ymwdl)
2836 basic_stringstream<_CharT> __os2;
2837 __os2.imbue(__os.getloc());
2839 if constexpr (is_same_v<_CharT, char>)
2843 __os2 << __ymwdl.year() << __slash << __ymwdl.month() << __slash
2844 << __ymwdl.weekday_last();
2845 __os << __os2.view();
2849 template<
typename _CharT,
typename _Traits,
typename _Duration>
2850 inline basic_ostream<_CharT, _Traits>&
2851 operator<<(basic_ostream<_CharT, _Traits>& __os,
2854 return __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%T}"), __hms);
2857#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2859 template<
typename _CharT,
typename _Traits>
2860 basic_ostream<_CharT, _Traits>&
2861 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_info& __i)
2863 __os <<
'[' << __i.begin <<
',' << __i.end
2864 <<
',' <<
hh_mm_ss(__i.offset) <<
',' << __i.save
2865 <<
',' << __i.abbrev <<
']';
2870 template<
typename _CharT,
typename _Traits>
2871 basic_ostream<_CharT, _Traits>&
2872 operator<<(basic_ostream<_CharT, _Traits>& __os,
const local_info& __li)
2875 if (__li.result == local_info::unique)
2879 if (__li.result == local_info::nonexistent)
2880 __os <<
"nonexistent";
2882 __os <<
"ambiguous";
2883 __os <<
" local time between " << __li.first;
2884 __os <<
" and " << __li.second;
2890 template<
typename _CharT,
typename _Traits,
typename _Duration,
2891 typename _TimeZonePtr>
2892 inline basic_ostream<_CharT, _Traits>&
2893 operator<<(basic_ostream<_CharT, _Traits>& __os,
2894 const zoned_time<_Duration, _TimeZonePtr>& __t)
2896 __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T %Z}"), __t);
2901 template<
typename _CharT,
typename _Traits,
typename _Duration>
2902 requires (!treat_as_floating_point_v<typename _Duration::rep>)
2903 && ratio_less_v<typename _Duration::period, days::period>
2904 inline basic_ostream<_CharT, _Traits>&
2905 operator<<(basic_ostream<_CharT, _Traits>& __os,
2906 const sys_time<_Duration>& __tp)
2908 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __tp);
2912 template<
typename _CharT,
typename _Traits>
2913 inline basic_ostream<_CharT, _Traits>&
2914 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_days& __dp)
2916 __os << year_month_day{__dp};
2920 template<
typename _CharT,
typename _Traits,
typename _Duration,
2921 typename _Alloc = allocator<_CharT>>
2922 basic_istream<_CharT, _Traits>&
2923 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2924 sys_time<_Duration>& __tp,
2925 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2931 using __format::_ChronoParts;
2932 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2933 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2934 __detail::_Parser_t<_Duration> __p(__need);
2935 if (__p(__is, __fmt, __abbrev, __offset))
2937 if (__p._M_is_leap_second)
2941 auto __st = __p._M_sys_days + __p._M_time - *__offset;
2942 __tp = __detail::__round<_Duration>(__st);
2948 template<
typename _CharT,
typename _Traits,
typename _Duration>
2949 inline basic_ostream<_CharT, _Traits>&
2950 operator<<(basic_ostream<_CharT, _Traits>& __os,
2951 const utc_time<_Duration>& __t)
2953 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
2957 template<
typename _CharT,
typename _Traits,
typename _Duration,
2958 typename _Alloc = allocator<_CharT>>
2959 inline basic_istream<_CharT, _Traits>&
2960 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2961 utc_time<_Duration>& __tp,
2962 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2968 using __format::_ChronoParts;
2969 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2970 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2971 __detail::_Parser_t<_Duration> __p(__need);
2972 if (__p(__is, __fmt, __abbrev, __offset))
2976 auto __ut = utc_clock::from_sys(__p._M_sys_days) + __p._M_time
2978 __tp = __detail::__round<_Duration>(__ut);
2983 template<
typename _CharT,
typename _Traits,
typename _Duration>
2984 inline basic_ostream<_CharT, _Traits>&
2985 operator<<(basic_ostream<_CharT, _Traits>& __os,
2986 const tai_time<_Duration>& __t)
2988 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
2992 template<
typename _CharT,
typename _Traits,
typename _Duration,
2993 typename _Alloc = allocator<_CharT>>
2994 inline basic_istream<_CharT, _Traits>&
2995 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2996 tai_time<_Duration>& __tp,
2997 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3003 using __format::_ChronoParts;
3004 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3005 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
3006 __detail::_Parser_t<_Duration> __p(__need);
3007 if (__p(__is, __fmt, __abbrev, __offset))
3009 if (__p._M_is_leap_second)
3013 constexpr sys_days __epoch(-
days(4383));
3014 auto __d = __p._M_sys_days - __epoch + __p._M_time - *__offset;
3015 tai_time<common_type_t<_Duration, seconds>> __tt(__d);
3016 __tp = __detail::__round<_Duration>(__tt);
3022 template<
typename _CharT,
typename _Traits,
typename _Duration>
3023 inline basic_ostream<_CharT, _Traits>&
3024 operator<<(basic_ostream<_CharT, _Traits>& __os,
3025 const gps_time<_Duration>& __t)
3027 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
3031 template<
typename _CharT,
typename _Traits,
typename _Duration,
3032 typename _Alloc = allocator<_CharT>>
3033 inline basic_istream<_CharT, _Traits>&
3034 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3035 gps_time<_Duration>& __tp,
3036 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3042 using __format::_ChronoParts;
3043 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3044 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
3045 __detail::_Parser_t<_Duration> __p(__need);
3046 if (__p(__is, __fmt, __abbrev, __offset))
3048 if (__p._M_is_leap_second)
3052 constexpr sys_days __epoch(
days(3657));
3053 auto __d = __p._M_sys_days - __epoch + __p._M_time - *__offset;
3054 gps_time<common_type_t<_Duration, seconds>> __gt(__d);
3055 __tp = __detail::__round<_Duration>(__gt);
3061 template<
typename _CharT,
typename _Traits,
typename _Duration>
3062 inline basic_ostream<_CharT, _Traits>&
3063 operator<<(basic_ostream<_CharT, _Traits>& __os,
3064 const file_time<_Duration>& __t)
3066 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
3070 template<
typename _CharT,
typename _Traits,
typename _Duration,
3071 typename _Alloc = allocator<_CharT>>
3072 inline basic_istream<_CharT, _Traits>&
3073 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3074 file_time<_Duration>& __tp,
3075 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3078 sys_time<_Duration> __st;
3079 if (chrono::from_stream(__is, __fmt, __st, __abbrev, __offset))
3080 __tp = __detail::__round<_Duration>(file_clock::from_sys(__st));
3084 template<
typename _CharT,
typename _Traits,
typename _Duration>
3085 inline basic_ostream<_CharT, _Traits>&
3086 operator<<(basic_ostream<_CharT, _Traits>& __os,
3087 const local_time<_Duration>& __lt)
3089 __os << sys_time<_Duration>{__lt.time_since_epoch()};
3093 template<
typename _CharT,
typename _Traits,
typename _Duration,
3094 typename _Alloc = allocator<_CharT>>
3095 basic_istream<_CharT, _Traits>&
3096 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3097 local_time<_Duration>& __tp,
3098 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3101 using __format::_ChronoParts;
3102 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3103 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
3104 __detail::_Parser_t<_Duration> __p(__need);
3105 if (__p(__is, __fmt, __abbrev, __offset))
3107 days __d = __p._M_sys_days.time_since_epoch();
3108 auto __t = local_days(__d) + __p._M_time;
3109 __tp = __detail::__round<_Duration>(__t);
3120 void from_stream() =
delete;
3122 template<
typename _Parsable,
typename _CharT,
3123 typename _Traits = std::char_traits<_CharT>,
3124 typename... _OptArgs>
3125 concept __parsable =
requires (basic_istream<_CharT, _Traits>& __is,
3126 const _CharT* __fmt, _Parsable& __tp,
3127 _OptArgs*... __args)
3128 { from_stream(__is, __fmt, __tp, __args...); };
3130 template<
typename _Parsable,
typename _CharT,
3131 typename _Traits = char_traits<_CharT>,
3132 typename _Alloc = allocator<_CharT>>
3136 using __string_type = basic_string<_CharT, _Traits, _Alloc>;
3139 _Parse(
const _CharT* __fmt, _Parsable& __tp,
3140 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3143 _M_abbrev(__abbrev), _M_offset(__offset)
3146 _Parse(_Parse&&) =
delete;
3147 _Parse& operator=(_Parse&&) =
delete;
3150 using __stream_type = basic_istream<_CharT, _Traits>;
3152 const _CharT*
const _M_fmt;
3153 _Parsable*
const _M_tp;
3154 __string_type*
const _M_abbrev;
3157 friend __stream_type&
3158 operator>>(__stream_type& __is, _Parse&& __p)
3161 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev,
3163 else if (__p._M_abbrev)
3164 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev);
3166 from_stream(__is, __p._M_fmt, *__p._M_tp);
3170 friend void operator>>(__stream_type&, _Parse&) =
delete;
3171 friend void operator>>(__stream_type&,
const _Parse&) =
delete;
3175 template<
typename _CharT, __detail::__parsable<_CharT> _Parsable>
3176 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
3178 parse(
const _CharT* __fmt, _Parsable& __tp)
3179 {
return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp); }
3181 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3182 __detail::__parsable<_CharT, _Traits> _Parsable>
3185 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp)
3187 return __detail::_Parse<_Parsable, _CharT, _Traits>(__fmt.c_str(), __tp);
3190 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3191 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
3192 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
3193 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
3195 parse(
const _CharT* __fmt, _Parsable& __tp,
3196 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
3199 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
3203 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3204 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
3205 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
3208 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
3209 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
3212 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
3216 template<
typename _CharT,
typename _Traits =
char_traits<_CharT>,
3217 typename _StrT = basic_
string<_CharT, _Traits>,
3218 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
3219 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
3221 parse(
const _CharT* __fmt, _Parsable& __tp,
minutes& __offset)
3223 return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp,
nullptr,
3227 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3228 typename _StrT = basic_string<_CharT, _Traits>,
3229 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
3232 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
3235 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
3240 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3241 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
3242 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
3243 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
3245 parse(
const _CharT* __fmt, _Parsable& __tp,
3246 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
3249 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
3254 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3255 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
3256 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
3259 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
3260 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
3263 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
3269 template<
typename _Duration>
3270 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3271 basic_istream<_CharT, _Traits>&
3272 __detail::_Parser<_Duration>::
3273 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3274 basic_string<_CharT, _Traits, _Alloc>* __abbrev,
3277 using sentry =
typename basic_istream<_CharT, _Traits>::sentry;
3279 if (sentry __cerb(__is,
true); __cerb)
3281 locale __loc = __is.getloc();
3286 struct _Stream_state
3289 _Stream_state(basic_istream<_CharT, _Traits>& __i)
3291 _M_flags(__i.flags(ios_base::
skipws | ios_base::
dec)),
3297 _M_is.flags(_M_flags);
3301 _Stream_state(_Stream_state&&) =
delete;
3303 basic_istream<_CharT, _Traits>& _M_is;
3304 ios_base::fmtflags _M_flags;
3314 auto __read_unsigned = [&] (
int __n) {
3315 return _S_read_unsigned(__is, __err, __n);
3320 auto __read_signed = [&] (
int __n) {
3321 return _S_read_signed(__is, __err, __n);
3325 auto __read_chr = [&__is, &__err] (_CharT __c) {
3326 return _S_read_chr(__is, __err, __c);
3329 using __format::_ChronoParts;
3330 _ChronoParts __parts{};
3332 const year __bad_y = --year::min();
3333 const month __bad_mon(255);
3334 const day __bad_day(255);
3335 const weekday __bad_wday(255);
3336 const hours __bad_h(-1);
3337 const minutes __bad_min(-9999);
3340 year __y = __bad_y, __yy = __bad_y;
3341 year __iso_y = __bad_y, __iso_yy = __bad_y;
3342 month __m = __bad_mon;
3343 day __d = __bad_day;
3344 weekday __wday = __bad_wday;
3345 hours __h = __bad_h, __h12 = __bad_h;
3347 _Duration __s = __bad_sec;
3349 int __iso_wk = -1, __sunday_wk = -1, __monday_wk = -1;
3351 int __dayofyear = -1;
3353 minutes __tz_offset = __bad_min;
3354 basic_string<_CharT, _Traits> __tz_abbr;
3356 if ((_M_need & _ChronoParts::_TimeOfDay)
3357 && (_M_need & _ChronoParts::_Year))
3363 __parts = _ChronoParts::_TimeOfDay;
3370 bool __is_flag =
false;
3372 constexpr bool __is_floating
3373 = treat_as_floating_point_v<typename _Duration::rep>;
3392 _CharT __c = *__fmt++;
3399 else if (!__read_chr(__c)) [[unlikely]]
3410 if (__mod || __num) [[unlikely]]
3415 __tmget.get(__is, {}, __is, __err, &__tm,
3417 if (!__is_failed(__err))
3418 __wday = weekday(__tm.tm_wday);
3420 __parts |= _ChronoParts::_Weekday;
3426 if (__mod || __num) [[unlikely]]
3434 __tmget.get(__is, {}, __is, __err, &__tm,
3436 if (!__is_failed(__err))
3437 __m = month(__tm.tm_mon + 1);
3439 __parts |= _ChronoParts::_Month;
3443 if (__mod ==
'O' || __num) [[unlikely]]
3448 __tmget.get(__is, {}, __is, __err, &__tm,
3449 __fmt - 2 - (__mod ==
'E'), __fmt);
3450 if (!__is_failed(__err))
3452 __y = year(__tm.tm_year + 1900);
3453 __m = month(__tm.tm_mon + 1);
3454 __d = day(__tm.tm_mday);
3455 __h =
hours(__tm.tm_hour);
3460 __parts |= _ChronoParts::_DateTime;
3464 if (!__mod) [[likely]]
3466 auto __v = __read_signed(__num ? __num : 2);
3467 if (!__is_failed(__err))
3469 int __cmin = (int)year::min() / 100;
3470 int __cmax = (int)year::max() / 100;
3471 if (__cmin <= __v && __v <= __cmax)
3472 __century = __v * 100;
3477 else if (__mod ==
'E')
3480 __tmget.get(__is, {}, __is, __err, &__tm,
3482 if (!__is_failed(__err))
3483 __century = __tm.tm_year;
3492 if (!__mod) [[likely]]
3494 auto __v = __read_unsigned(__num ? __num : 2);
3495 if (!__is_failed(__err))
3498 else if (__mod ==
'O')
3501 __tmget.get(__is, {}, __is, __err, &__tm,
3503 if (!__is_failed(__err))
3504 __d = day(__tm.tm_mday);
3508 __parts |= _ChronoParts::_Day;
3512 if (__mod || __num) [[unlikely]]
3516 auto __month = __read_unsigned(2);
3518 auto __day = __read_unsigned(2);
3520 auto __year = __read_unsigned(2);
3521 if (__is_failed(__err))
3523 __y = year(__year + 1900 + 100 *
int(__year < 69));
3524 __m = month(__month);
3526 if (!year_month_day(__y, __m, __d).ok())
3528 __y = __yy = __iso_y = __iso_yy = __bad_y;
3534 __parts |= _ChronoParts::_Date;
3538 if (__mod) [[unlikely]]
3542 auto __year = __read_signed(__num ? __num : 4);
3544 auto __month = __read_unsigned(2);
3546 auto __day = __read_unsigned(2);
3547 if (__is_failed(__err))
3550 __m = month(__month);
3552 if (!year_month_day(__y, __m, __d).ok())
3554 __y = __yy = __iso_y = __iso_yy = __bad_y;
3560 __parts |= _ChronoParts::_Date;
3564 if (__mod) [[unlikely]]
3568 auto __val = __read_unsigned(__num ? __num : 2);
3569 if (__val >= 0 && __val <= 99)
3571 __iso_yy = year(__val);
3572 if (__century == -1)
3576 __iso_yy = __iso_y = __y = __yy = __bad_y;
3578 __parts |= _ChronoParts::_Year;
3582 if (__mod) [[unlikely]]
3585 __iso_y = year(__read_unsigned(__num ? __num : 4));
3586 __parts |= _ChronoParts::_Year;
3591 if (__mod ==
'E') [[unlikely]]
3593 else if (__mod ==
'O')
3598 __tmget.get(__is, {}, __is, __err, &__tm,
3600 if (!__is_failed(__err))
3604 __h12 =
hours(__tm.tm_hour);
3608 __h =
hours(__tm.tm_hour);
3617 auto __val = __read_unsigned(__num ? __num : 2);
3618 if (__c ==
'I' && __val >= 1 && __val <= 12)
3620 __h12 =
hours(__val);
3623 else if (__c ==
'H' && __val >= 0 && __val <= 23)
3630 if (_M_need & _ChronoParts::_TimeOfDay)
3635 __parts |= _ChronoParts::_TimeOfDay;
3639 if (__mod) [[unlikely]]
3641 else if (_M_need == _ChronoParts::_TimeOfDay)
3643 auto __val = __read_signed(__num ? __num : 3);
3644 if (!__is_failed(__err))
3647 __parts |= _ChronoParts::_TimeOfDay;
3652 __dayofyear = __read_unsigned(__num ? __num : 3);
3659 if (__mod ==
'E') [[unlikely]]
3661 else if (__mod ==
'O')
3664 __tmget.get(__is, {}, __is, __err, &__tm,
3666 if (!__is_failed(__err))
3667 __m = month(__tm.tm_mon + 1);
3671 auto __val = __read_unsigned(__num ? __num : 2);
3672 if (__val >= 1 && __val <= 12)
3677 __parts |= _ChronoParts::_Month;
3681 if (__mod ==
'E') [[unlikely]]
3683 else if (__mod ==
'O')
3686 __tmget.get(__is, {}, __is, __err, &__tm,
3688 if (!__is_failed(__err))
3693 auto __val = __read_unsigned(__num ? __num : 2);
3694 if (0 <= __val && __val < 60)
3698 if (_M_need & _ChronoParts::_TimeOfDay)
3703 __parts |= _ChronoParts::_TimeOfDay;
3713 const _CharT* __ampms[2];
3714 __tmpunct._M_am_pm(__ampms);
3715 int __n = 0, __which = 3;
3716 while (__which != 0)
3718 auto __i = __is.peek();
3719 if (_Traits::eq_int_type(__i, _Traits::eof()))
3729 else if (__ampms[0][__n + 1] == _CharT())
3740 else if (__ampms[1][__n + 1] == _CharT())
3751 if (__which == 0 || __which == 3)
3764 __tmget.get(__is, {}, __is, __err, &__tm,
3766 if (!__is_failed(__err))
3768 __h =
hours(__tm.tm_hour);
3773 __parts |= _ChronoParts::_TimeOfDay;
3778 if (__mod || __num) [[unlikely]]
3785 auto __val = __read_unsigned(2);
3786 if (__val == -1 || __val > 23) [[unlikely]]
3788 if (_M_need & _ChronoParts::_TimeOfDay)
3792 if (!__read_chr(
':')) [[unlikely]]
3796 __val = __read_unsigned(2);
3797 if (__val == -1 || __val > 60) [[unlikely]]
3799 if (_M_need & _ChronoParts::_TimeOfDay)
3807 __parts |= _ChronoParts::_TimeOfDay;
3810 else if (!__read_chr(
':')) [[unlikely]]
3816 if (__mod ==
'E') [[unlikely]]
3818 else if (__mod ==
'O')
3821 __tmget.get(__is, {}, __is, __err, &__tm,
3823 if (!__is_failed(__err))
3826 else if constexpr (_Duration::period::den == 1
3829 auto __val = __read_unsigned(__num ? __num : 2);
3830 if (0 <= __val && __val <= 59) [[likely]]
3834 if (_M_need & _ChronoParts::_TimeOfDay)
3841 basic_stringstream<_CharT> __buf;
3842 auto __digit = _S_try_read_digit(__is, __err);
3845 __buf.put(_CharT(
'0') + __digit);
3846 __digit = _S_try_read_digit(__is, __err);
3848 __buf.put(_CharT(
'0') + __digit);
3851 auto __i = __is.peek();
3852 if (_Traits::eq_int_type(__i, _Traits::eof()))
3860 __dp = __np.decimal_point();
3862 _CharT __c = _Traits::to_char_type(__i);
3868 = hh_mm_ss<_Duration>::fractional_width;
3871 __digit = _S_try_read_digit(__is, __err);
3873 __buf.put(_CharT(
'0') + __digit);
3881 if (!__is_failed(__err)) [[likely]]
3883 long double __val{};
3884#if __cpp_lib_to_chars
3886 auto __first = __str.data();
3887 auto __last = __first + __str.size();
3891 if ((
bool)ec || ptr != __last) [[unlikely]]
3899 if constexpr (__is_floating)
3906 __parts |= _ChronoParts::_TimeOfDay;
3911 if (__mod ==
'E') [[unlikely]]
3913 else if (__mod ==
'O')
3918 __tmget.get(__is, {}, __is, __err, &__tm,
3920 if (!__is_failed(__err))
3921 __wday = weekday(__tm.tm_wday);
3928 const int __lo = __c ==
'u' ? 1 : 0;
3929 const int __hi = __lo + 6;
3930 auto __val = __read_unsigned(__num ? __num : 1);
3931 if (__lo <= __val && __val <= __hi)
3932 __wday = weekday(__val);
3935 __wday = __bad_wday;
3939 __parts |= _ChronoParts::_Weekday;
3945 if (__mod ==
'E') [[unlikely]]
3947 else if (__mod ==
'O')
3949 if (__c ==
'V') [[unlikely]]
3959 const int __lo = __c ==
'V' ? 1 : 0;
3960 const int __hi = 53;
3961 auto __val = __read_unsigned(__num ? __num : 2);
3962 if (__lo <= __val && __val <= __hi)
3967 __sunday_wk = __val;
3973 __monday_wk = __val;
3978 __iso_wk = __sunday_wk = __monday_wk = -1;
3984 if (__mod ==
'O' || __num) [[unlikely]]
3989 __tmget.get(__is, {}, __is, __err, &__tm,
3990 __fmt - 2 - (__mod ==
'E'), __fmt);
3991 if (!__is_failed(__err))
3993 __y = year(__tm.tm_year + 1900);
3994 __m = month(__tm.tm_mon + 1);
3995 __d = day(__tm.tm_mday);
3998 __parts |= _ChronoParts::_Date;
4002 if (__mod ==
'O' || __num) [[unlikely]]
4007 __tmget.get(__is, {}, __is, __err, &__tm,
4008 __fmt - 2 - (__mod ==
'E'), __fmt);
4009 if (!__is_failed(__err))
4011 __h =
hours(__tm.tm_hour);
4016 __parts |= _ChronoParts::_TimeOfDay;
4020 if (__mod) [[unlikely]]
4023 __tmget.get(__is, {}, __is, __err, &__tm,
4025 if (!__is_failed(__err))
4027 int __cent = __tm.tm_year < 2000 ? 1900 : 2000;
4028 __yy = year(__tm.tm_year - __cent);
4029 if (__century == -1)
4035 auto __val = __read_unsigned(__num ? __num : 2);
4036 if (__val >= 0 && __val <= 99)
4039 if (__century == -1)
4040 __century = __val < 69 ? 2000 : 1900;
4043 __y = __yy = __iso_yy = __iso_y = __bad_y;
4045 __parts |= _ChronoParts::_Year;
4049 if (__mod ==
'O') [[unlikely]]
4051 else if (__mod ==
'E')
4054 __tmget.get(__is, {}, __is, __err, &__tm,
4056 if (!__is_failed(__err))
4057 __y = year(__tm.tm_year);
4061 auto __val = __read_unsigned(__num ? __num : 4);
4062 if (!__is_failed(__err))
4065 __parts |= _ChronoParts::_Year;
4069 if (__num) [[unlikely]]
4076 auto __i = __is.peek();
4077 if (_Traits::eq_int_type(__i, _Traits::eof()))
4082 _CharT __ic = _Traits::to_char_type(__i);
4083 const bool __neg = __ic == _CharT(
'-');
4084 if (__ic == _CharT(
'-') || __ic == _CharT(
'+'))
4091 __hh = __read_unsigned(2);
4096 __hh = 10 * _S_try_read_digit(__is, __err);
4097 __hh += _S_try_read_digit(__is, __err);
4100 if (__is_failed(__err))
4104 if (_Traits::eq_int_type(__i, _Traits::eof()))
4107 __tz_offset =
minutes(__hh * (__neg ? -60 : 60));
4110 __ic = _Traits::to_char_type(__i);
4112 bool __read_mm =
false;
4115 if (__ic == _GLIBCXX_WIDEN(
":")[0])
4122 else if (_CharT(
'0') <= __ic && __ic <= _CharT(
'9'))
4128 int_least32_t __mm = 0;
4131 __mm = 10 * _S_try_read_digit(__is, __err);
4132 __mm += _S_try_read_digit(__is, __err);
4135 if (!__is_failed(__err))
4137 auto __z = __hh * 60 + __mm;
4138 __tz_offset =
minutes(__neg ? -__z : __z);
4144 if (__mod || __num) [[unlikely]]
4148 basic_string_view<_CharT> __x = _GLIBCXX_WIDEN(
"_/-+");
4152 auto __i = __is.peek();
4153 if (!_Traits::eq_int_type(__i, _Traits::eof()))
4155 _CharT __a = _Traits::to_char_type(__i);
4157 || __x.find(__a) != __x.npos)
4159 __tz_abbr.push_back(__a);
4168 if (__tz_abbr.empty())
4174 if (__mod || __num) [[unlikely]]
4178 _CharT __i = __is.peek();
4179 if (_Traits::eq_int_type(__i, _Traits::eof()))
4181 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
4189 if (__mod || __num) [[unlikely]]
4193 _CharT __i = __is.peek();
4194 if (_Traits::eq_int_type(__i, _Traits::eof()))
4196 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
4202 if (__mod || __num) [[unlikely]]
4210 if (__mod || __num) [[unlikely]]
4219 if (_CharT(
'1') <= __c && __c <= _CharT(
'9'))
4221 if (!__mod) [[likely]]
4224 auto __end = __fmt + _Traits::length(__fmt);
4226 = __format::__parse_integer(__fmt - 1, __end);
4227 if (__ptr) [[likely]]
4238 if (__is_failed(__err)) [[unlikely]]
4248 if (__yy != __bad_y && __y == __bad_y)
4249 __y =
years(__century) + __yy;
4250 if (__iso_yy != __bad_y && __iso_y == __bad_y)
4251 __iso_y =
years(__century) + __iso_yy;
4254 bool __can_use_doy =
false;
4255 bool __can_use_iso_wk =
false;
4256 bool __can_use_sun_wk =
false;
4257 bool __can_use_mon_wk =
false;
4260 if (__y != __bad_y && __dayofyear >= 0)
4262 __can_use_doy =
true;
4263 __parts |= _ChronoParts::_Date;
4265 else if (__y != __bad_y && __wday != __bad_wday && __sunday_wk >= 0)
4267 __can_use_sun_wk =
true;
4268 __parts |= _ChronoParts::_Date;
4270 else if (__y != __bad_y && __wday != __bad_wday && __monday_wk >= 0)
4272 __can_use_mon_wk =
true;
4273 __parts |= _ChronoParts::_Date;
4275 else if (__iso_y != __bad_y && __wday != __bad_wday && __iso_wk > 0)
4278 __can_use_iso_wk =
true;
4279 __parts |= _ChronoParts::_Date;
4282 if (__is_failed(__err)) [[unlikely]]
4284 else if (__is_flag) [[unlikely]]
4286 else if ((_M_need & __parts) == _M_need) [[likely]]
4308 const bool __need_wday = _M_need & _ChronoParts::_Weekday;
4312 const bool __need_time = _M_need & _ChronoParts::_TimeOfDay;
4314 if (__need_wday && __wday != __bad_wday)
4316 else if (_M_need & _ChronoParts::_Date)
4320 const bool __need_ymd = !__need_wday && !__need_time;
4322 if ((_M_need & _ChronoParts::_Year && __y == __bad_y)
4323 || (_M_need & _ChronoParts::_Month && __m == __bad_mon)
4324 || (_M_need & _ChronoParts::_Day && __d == __bad_day))
4331 if ((0 < __dayofyear && __dayofyear <= 365)
4332 || (__dayofyear == 366 && __y.is_leap()))
4335 _M_sys_days = sys_days(__y/January/1)
4336 +
days(__dayofyear - 1);
4338 _M_ymd = year_month_day(_M_sys_days);
4343 else if (__can_use_iso_wk)
4351 const sys_days __jan4(__iso_y/January/4);
4352 weekday __wd1(__jan4 -
days(3));
4353 if (__wd1 != Thursday)
4354 if (__wd1 != Wednesday || !__iso_y.is_leap())
4358 if (!__is_failed(__err)) [[likely]]
4361 sys_days __w(Thursday[1]/January/__iso_y);
4363 __w -= Thursday - Monday;
4365 __w += __wday - Monday;
4369 _M_ymd = year_month_day(_M_sys_days);
4372 else if (__can_use_sun_wk)
4375 sys_days __wk1(__y/January/Sunday[1]);
4376 _M_sys_days = __wk1 +
weeks(__sunday_wk - 1)
4377 +
days(__wday.c_encoding());
4378 _M_ymd = year_month_day(_M_sys_days);
4379 if (_M_ymd.year() != __y) [[unlikely]]
4382 else if (__can_use_mon_wk)
4385 sys_days __wk1(__y/January/Monday[1]);
4386 _M_sys_days = __wk1 +
weeks(__monday_wk - 1)
4387 +
days(__wday.c_encoding() - 1);
4388 _M_ymd = year_month_day(_M_sys_days);
4389 if (_M_ymd.year() != __y) [[unlikely]]
4401 if (_M_need & _ChronoParts::_Year)
4403 if (!__y.ok()) [[unlikely]]
4406 else if (__y == __bad_y)
4409 if (_M_need & _ChronoParts::_Month)
4411 if (!__m.ok()) [[unlikely]]
4414 else if (__m == __bad_mon)
4417 if (_M_need & _ChronoParts::_Day)
4419 if (__d < day(1) || __d > (__y/__m/last).day())
4422 else if (__d == __bad_day)
4425 if (year_month_day __ymd(__y, __m, __d); __ymd.ok())
4428 if (__need_wday || __need_time)
4429 _M_sys_days = sys_days(_M_ymd);
4436 _M_wd = weekday(_M_sys_days);
4442 if (__h == __bad_h && __h12 != __bad_h)
4446 else if (__ampm == 2)
4447 __h = __h12 ==
hours(12) ? __h12 : __h12 +
hours(12);
4452 auto __t = _M_time.zero();
4461 if (__min != __bad_min)
4467 if (__s != __bad_sec)
4471 _M_is_leap_second = __s >=
seconds(60);
4480 if (!__is_failed(__err)) [[likely]]
4482 if (__offset && __tz_offset != __bad_min)
4483 *__offset = __tz_offset;
4484 if (__abbrev && !__tz_abbr.empty())
4492 __is.setstate(__err);
4496#undef _GLIBCXX_WIDEN
4501_GLIBCXX_END_NAMESPACE_VERSION
__detail::__local_time_fmt< _Duration > local_time_format(local_time< _Duration > __time, const string *__abbrev=nullptr, const seconds *__offset_sec=nullptr)
duration< int64_t, ratio< 604800 > > weeks
weeks
constexpr __enable_if_is_duration< _ToDur > floor(const duration< _Rep, _Period > &__d)
constexpr enable_if_t< __and_< __is_duration< _ToDur >, __not_< treat_as_floating_point< typename _ToDur::rep > > >::value, _ToDur > round(const duration< _Rep, _Period > &__d)
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
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)
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).
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.