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& __t,
typename _FormatContext::iterator __out,
891 _FormatContext& __ctx,
bool __mod =
false)
const
896 using namespace chrono;
897 using ::std::chrono::__detail::__utc_leap_second;
898 using ::std::chrono::__detail::__local_time_fmt;
908#ifdef _GLIBCXX_HAVE_STRUCT_TM_TM_ZONE
911 if constexpr (__is_time_point_v<_Tp>)
914 if constexpr (!is_same_v<typename _Tp::clock, local_t>)
915 __tm.tm_zone =
const_cast<char*
>(
"UTC");
917 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
922 __tm.tm_zone =
const_cast<char*
>(__t._M_abbrev->c_str());
925 __tm.tm_zone =
const_cast<char*
>(
"UTC");
928 auto __d = _S_days(__t);
929 using _TDays =
decltype(__d);
930 const year_month_day __ymd(__d);
931 const auto __y = __ymd.year();
932 const auto __hms = _S_hms(__t);
934 __tm.tm_year = (int)__y - 1900;
935 __tm.tm_yday = (__d - _TDays(__y/January/1)).count();
936 __tm.tm_mon = (unsigned)__ymd.month() - 1;
937 __tm.tm_mday = (unsigned)__ymd.day();
938 __tm.tm_wday = weekday(__d).c_encoding();
939 __tm.tm_hour = __hms.hours().count();
940 __tm.tm_min = __hms.minutes().count();
941 __tm.tm_sec = __hms.seconds().count();
943 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
'c',
947 template<
typename _Tp,
typename _FormatContext>
948 typename _FormatContext::iterator
949 _M_C_y_Y(
const _Tp& __t,
typename _FormatContext::iterator __out,
950 _FormatContext& __ctx, _CharT __conv, _CharT __mod = 0)
const
960 chrono::year __y = _S_year(__t);
962 if (__mod && _M_spec._M_localized) [[unlikely]]
963 if (
auto __loc = __ctx.locale(); __loc != locale::classic())
966 __tm.tm_year = (int)__y - 1900;
967 return _M_locale_fmt(
std::move(__out), __loc, __tm,
971 basic_string<_CharT> __s;
973 const bool __is_neg = __yi < 0;
974 __yi = __builtin_abs(__yi);
976 if (__conv ==
'Y' || __conv ==
'C')
978 int __ci = __yi / 100;
979 if (__is_neg) [[unlikely]]
981 __s.assign(1, _S_plus_minus[1]);
983 if (__conv ==
'C' && (__ci * 100) != __yi)
986 if (__ci >= 100) [[unlikely]]
988 __s += std::format(_S_empty_spec, __ci / 100);
991 __s += _S_two_digits(__ci);
994 if (__conv ==
'Y' || __conv ==
'y')
995 __s += _S_two_digits(__yi % 100);
997 return __format::__write(
std::move(__out), __string_view(__s));
1000 template<
typename _Tp,
typename _FormatContext>
1001 typename _FormatContext::iterator
1002 _M_D(
const _Tp& __t,
typename _FormatContext::iterator __out,
1003 _FormatContext&)
const
1005 auto __ymd = _S_date(__t);
1006 basic_string<_CharT> __s;
1007#if ! _GLIBCXX_USE_CXX11_ABI
1010 __s = _S_two_digits((
unsigned)__ymd.month());
1012 __s += _S_two_digits((
unsigned)__ymd.day());
1014 __s += _S_two_digits(__builtin_abs((
int)__ymd.year()) % 100);
1015 return __format::__write(
std::move(__out), __string_view(__s));
1018 template<
typename _Tp,
typename _FormatContext>
1019 typename _FormatContext::iterator
1020 _M_d_e(
const _Tp& __t,
typename _FormatContext::iterator __out,
1021 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
1028 chrono::day __d = _S_day(__t);
1029 unsigned __i = (unsigned)__d;
1031 if (__mod && _M_spec._M_localized) [[unlikely]]
1032 if (
auto __loc = __ctx.locale(); __loc != locale::classic())
1036 return _M_locale_fmt(
std::move(__out), __loc, __tm,
1040 auto __sv = _S_two_digits(__i);
1042 if (__conv == _CharT(
'e') && __i < 10)
1044 __buf[0] = _S_space;
1048 return __format::__write(
std::move(__out), __sv);
1051 template<
typename _Tp,
typename _FormatContext>
1052 typename _FormatContext::iterator
1053 _M_F(
const _Tp& __t,
typename _FormatContext::iterator __out,
1054 _FormatContext&)
const
1056 auto __ymd = _S_date(__t);
1057 auto __s = std::format(_GLIBCXX_WIDEN(
"{:04d}- - "),
1059 auto __sv = _S_two_digits((
unsigned)__ymd.month());
1060 __s[__s.size() - 5] = __sv[0];
1061 __s[__s.size() - 4] = __sv[1];
1062 __sv = _S_two_digits((
unsigned)__ymd.day());
1063 __s[__s.size() - 2] = __sv[0];
1064 __s[__s.size() - 1] = __sv[1];
1066 return __format::__write(
std::move(__out), __sv);
1069 template<
typename _Tp,
typename _FormatContext>
1070 typename _FormatContext::iterator
1071 _M_g_G(
const _Tp& __t,
typename _FormatContext::iterator __out,
1072 _FormatContext& __ctx,
bool __full)
const
1076 using namespace chrono;
1077 auto __d = _S_days(__t);
1079 __d -= (weekday(__d) - Monday) -
days(3);
1081 year __y = year_month_day(__d).year();
1082 return _M_C_y_Y(__y,
std::move(__out), __ctx,
"yY"[__full]);
1085 template<
typename _Tp,
typename _FormatContext>
1086 typename _FormatContext::iterator
1087 _M_H_I(
const _Tp& __t,
typename _FormatContext::iterator __out,
1088 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
1095 const auto __hms = _S_hms(__t);
1096 int __i = __hms.hours().count();
1098 if (__mod && _M_spec._M_localized) [[unlikely]]
1099 if (
auto __loc = __ctx.locale(); __loc != locale::classic())
1103 return _M_locale_fmt(
std::move(__out), __loc, __tm,
1107 if (__conv == _CharT(
'I'))
1114 return __format::__write(
std::move(__out), _S_two_digits(__i));
1117 template<
typename _Tp,
typename _FormatContext>
1118 typename _FormatContext::iterator
1119 _M_j(
const _Tp& __t,
typename _FormatContext::iterator __out,
1120 _FormatContext&)
const
1122 if constexpr (chrono::__is_duration_v<_Tp>)
1125 unsigned __d = chrono::duration_cast<chrono::days>(__t).count();
1126 return std::format_to(
std::move(__out), _S_empty_spec, __d);
1131 using namespace chrono;
1132 auto __day = _S_days(__t);
1133 auto __ymd = _S_date(__t);
1137 if constexpr (is_same_v<
typename decltype(__day)::clock, local_t>)
1138 __d = __day - local_days(__ymd.year()/January/0);
1140 __d = __day - sys_days(__ymd.year()/January/0);
1141 return std::format_to(
std::move(__out), _GLIBCXX_WIDEN(
"{:03d}"),
1146 template<
typename _Tp,
typename _FormatContext>
1147 typename _FormatContext::iterator
1148 _M_m(
const _Tp& __t,
typename _FormatContext::iterator __out,
1149 _FormatContext& __ctx,
bool __mod)
const
1154 auto __m = _S_month(__t);
1155 auto __i = (unsigned)__m;
1157 if (__mod && _M_spec._M_localized) [[unlikely]]
1158 if (
auto __loc = __ctx.locale(); __loc != locale::classic())
1161 __tm.tm_mon = __i - 1;
1162 return _M_locale_fmt(
std::move(__out), __loc, __tm,
1166 return __format::__write(
std::move(__out), _S_two_digits(__i));
1169 template<
typename _Tp,
typename _FormatContext>
1170 typename _FormatContext::iterator
1171 _M_M(
const _Tp& __t,
typename _FormatContext::iterator __out,
1172 _FormatContext& __ctx,
bool __mod)
const
1177 auto __m = _S_hms(__t).minutes();
1178 auto __i = __m.count();
1180 if (__mod && _M_spec._M_localized) [[unlikely]]
1181 if (
auto __loc = __ctx.locale(); __loc != locale::classic())
1185 return _M_locale_fmt(
std::move(__out), __loc, __tm,
1189 return __format::__write(
std::move(__out), _S_two_digits(__i));
1192 template<
typename _Tp,
typename _FormatContext>
1193 typename _FormatContext::iterator
1194 _M_p(
const _Tp& __t,
typename _FormatContext::iterator __out,
1195 _FormatContext& __ctx)
const
1198 auto __hms = _S_hms(__t);
1199 locale __loc = _M_locale(__ctx);
1200 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1201 const _CharT* __ampm[2];
1202 __tp._M_am_pm(__ampm);
1203 return _M_write(
std::move(__out), __loc,
1204 __ampm[__hms.hours().count() >= 12]);
1207 template<
typename _Tp,
typename _FormatContext>
1208 typename _FormatContext::iterator
1209 _M_q(
const _Tp&,
typename _FormatContext::iterator __out,
1210 _FormatContext&)
const
1213 if constexpr (!chrono::__is_duration_v<_Tp>)
1214 __throw_format_error(
"format error: argument is not a duration");
1217 namespace __d = chrono::__detail;
1218 using period =
typename _Tp::period;
1219 return __d::__fmt_units_suffix<period, _CharT>(
std::move(__out));
1225 template<
typename _Tp,
typename _FormatContext>
1226 typename _FormatContext::iterator
1227 _M_r(
const _Tp& __tt,
typename _FormatContext::iterator __out,
1228 _FormatContext& __ctx)
const
1231 auto __t = _S_floor_seconds(__tt);
1232 locale __loc = _M_locale(__ctx);
1233 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1234 const _CharT* __ampm_fmt;
1235 __tp._M_am_pm_format(&__ampm_fmt);
1236 basic_string<_CharT> __fmt(_S_empty_spec);
1237 __fmt.insert(1u, 1u, _S_colon);
1238 __fmt.insert(2u, __ampm_fmt);
1239 using _FmtStr = _Runtime_format_string<_CharT>;
1240 return _M_write(
std::move(__out), __loc,
1241 std::format(__loc, _FmtStr(__fmt), __t));
1244 template<
typename _Tp,
typename _FormatContext>
1245 typename _FormatContext::iterator
1246 _M_R_T(
const _Tp& __t,
typename _FormatContext::iterator __out,
1247 _FormatContext& __ctx,
bool __secs)
const
1251 auto __hms = _S_hms(__t);
1253 auto __s = std::format(_GLIBCXX_WIDEN(
"{:02d}:00"),
1254 __hms.hours().count());
1255 auto __sv = _S_two_digits(__hms.minutes().count());
1256 __s[__s.size() - 2] = __sv[0];
1257 __s[__s.size() - 1] = __sv[1];
1259 __out = __format::__write(
std::move(__out), __sv);
1262 *__out++ = _S_colon;
1263 __out = _M_S(__hms,
std::move(__out), __ctx);
1268 template<
typename _Tp,
typename _FormatContext>
1269 typename _FormatContext::iterator
1270 _M_S(
const _Tp& __t,
typename _FormatContext::iterator __out,
1271 _FormatContext& __ctx,
bool __mod =
false)
const
1275 auto __hms = _S_hms(__t);
1276 auto __s = __hms.seconds();
1278 if (__mod) [[unlikely]]
1280 if (_M_spec._M_localized)
1281 if (
auto __loc = __ctx.locale(); __loc != locale::classic())
1284 __tm.tm_sec = (int)__s.count();
1285 return _M_locale_fmt(
std::move(__out), __loc, __tm,
1290 return __format::__write(
std::move(__out),
1291 _S_two_digits(__s.count()));
1294 if constexpr (__hms.fractional_width == 0)
1295 __out = __format::__write(
std::move(__out),
1296 _S_two_digits(__s.count()));
1299 locale __loc = _M_locale(__ctx);
1300 auto __ss = __hms.subseconds();
1301 using rep =
typename decltype(__ss)::rep;
1302 if constexpr (is_floating_point_v<rep>)
1304 chrono::duration<rep> __fs = __s + __ss;
1305 __out = std::format_to(
std::move(__out), __loc,
1306 _GLIBCXX_WIDEN(
"{:#0{}.{}Lf}"),
1308 3 + __hms.fractional_width,
1309 __hms.fractional_width);
1314 = use_facet<numpunct<_CharT>>(__loc);
1315 __out = __format::__write(
std::move(__out),
1316 _S_two_digits(__s.count()));
1317 *__out++ = __np.decimal_point();
1318 if constexpr (is_integral_v<rep>)
1319 __out = std::format_to(
std::move(__out),
1320 _GLIBCXX_WIDEN(
"{:0{}}"),
1322 __hms.fractional_width);
1325 auto __str = std::format(_S_empty_spec, __ss.count());
1326 __out = std::format_to(_GLIBCXX_WIDEN(
"{:0>{}s}"),
1328 __hms.fractional_width);
1337 template<
typename _Tp,
typename _FormatContext>
1338 typename _FormatContext::iterator
1339 _M_u_w(
const _Tp& __t,
typename _FormatContext::iterator __out,
1340 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
1347 chrono::weekday __wd = _S_weekday(__t);
1349 if (__mod && _M_spec._M_localized) [[unlikely]]
1350 if (
auto __loc = __ctx.locale(); __loc != locale::classic())
1353 __tm.tm_wday = __wd.c_encoding();
1354 return _M_locale_fmt(
std::move(__out), __loc, __tm,
1358 unsigned __wdi = __conv ==
'u' ? __wd.iso_encoding()
1359 : __wd.c_encoding();
1360 const _CharT __d = _S_digit(__wdi);
1361 return __format::__write(
std::move(__out), __string_view(&__d, 1));
1364 template<
typename _Tp,
typename _FormatContext>
1365 typename _FormatContext::iterator
1366 _M_U_V_W(
const _Tp& __t,
typename _FormatContext::iterator __out,
1367 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
1375 using namespace chrono;
1376 auto __d = _S_days(__t);
1377 using _TDays =
decltype(__d);
1379 if (__mod && _M_spec._M_localized) [[unlikely]]
1380 if (
auto __loc = __ctx.locale(); __loc != locale::classic())
1382 const year_month_day __ymd(__d);
1383 const year __y = __ymd.year();
1385 __tm.tm_year = (int)__y - 1900;
1386 __tm.tm_yday = (__d - _TDays(__y/January/1)).count();
1387 __tm.tm_wday = weekday(__d).c_encoding();
1388 return _M_locale_fmt(
std::move(__out), __loc, __tm,
1396 __d -= (weekday(__d) - Monday) -
days(3);
1399 __first = _TDays(year_month_day(__d).year()/January/1);
1404 if constexpr (
requires { __t.year(); })
1407 __y = year_month_day(__d).year();
1408 const weekday __weekstart = __conv ==
'U' ? Sunday : Monday;
1409 __first = _TDays(__y/January/__weekstart[1]);
1411 auto __weeks = chrono::floor<weeks>(__d - __first);
1412 __string_view __sv = _S_two_digits(__weeks.count() + 1);
1413 return __format::__write(
std::move(__out), __sv);
1416 template<
typename _Tp,
typename _FormatContext>
1417 typename _FormatContext::iterator
1418 _M_x(
const _Tp& __t,
typename _FormatContext::iterator __out,
1419 _FormatContext& __ctx,
bool __mod =
false)
const
1423 locale __loc = _M_locale(__ctx);
1424 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1425 const _CharT* __date_reps[2];
1426 __tp._M_date_formats(__date_reps);
1427 const _CharT* __rep = __date_reps[__mod];
1429 return _M_D(__t,
std::move(__out), __ctx);
1431 basic_string<_CharT> __fmt(_S_empty_spec);
1432 __fmt.insert(1u, 1u, _S_colon);
1433 __fmt.insert(2u, __rep);
1434 using _FmtStr = _Runtime_format_string<_CharT>;
1435 return _M_write(
std::move(__out), __loc,
1436 std::format(__loc, _FmtStr(__fmt), __t));
1439 template<
typename _Tp,
typename _FormatContext>
1440 typename _FormatContext::iterator
1441 _M_X(
const _Tp& __tt,
typename _FormatContext::iterator __out,
1442 _FormatContext& __ctx,
bool __mod =
false)
const
1446 auto __t = _S_floor_seconds(__tt);
1447 locale __loc = _M_locale(__ctx);
1448 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1449 const _CharT* __time_reps[2];
1450 __tp._M_time_formats(__time_reps);
1451 const _CharT* __rep = __time_reps[__mod];
1453 return _M_R_T(__t,
std::move(__out), __ctx,
true);
1455 basic_string<_CharT> __fmt(_S_empty_spec);
1456 __fmt.insert(1u, 1u, _S_colon);
1457 __fmt.insert(2u, __rep);
1458 using _FmtStr = _Runtime_format_string<_CharT>;
1459 return _M_write(
std::move(__out), __loc,
1460 std::format(__loc, _FmtStr(__fmt), __t));
1463 template<
typename _Tp,
typename _FormatContext>
1464 typename _FormatContext::iterator
1465 _M_z(
const _Tp& __t,
typename _FormatContext::iterator __out,
1466 _FormatContext&,
bool __mod =
false)
const
1468 using ::std::chrono::__detail::__utc_leap_second;
1469 using ::std::chrono::__detail::__local_time_fmt;
1471 auto __utc = __mod ? __string_view(_GLIBCXX_WIDEN(
"+00:00"), 6)
1472 : __string_view(_GLIBCXX_WIDEN(
"+0000"), 5);
1474 if constexpr (chrono::__is_time_point_v<_Tp>)
1476 if constexpr (is_same_v<
typename _Tp::clock,
1477 chrono::system_clock>)
1478 return __format::__write(
std::move(__out), __utc);
1480 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1482 if (__t._M_offset_sec)
1485 basic_string<_CharT> __s;
1486 if (*__t._M_offset_sec != 0s)
1488 chrono:: hh_mm_ss __hms(*__t._M_offset_sec);
1489 __s = _S_plus_minus[__hms.is_negative()];
1490 __s += _S_two_digits(__hms.hours().count());
1493 __s += _S_two_digits(__hms.minutes().count());
1496 return __format::__write(
std::move(__out), __sv);
1499 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1500 return __format::__write(
std::move(__out), __utc);
1502 __no_timezone_available();
1505 template<
typename _Tp,
typename _FormatContext>
1506 typename _FormatContext::iterator
1507 _M_Z(
const _Tp& __t,
typename _FormatContext::iterator __out,
1508 _FormatContext& __ctx)
const
1510 using ::std::chrono::__detail::__utc_leap_second;
1511 using ::std::chrono::__detail::__local_time_fmt;
1513 __string_view __utc(_GLIBCXX_WIDEN(
"UTC"), 3);
1514 if constexpr (chrono::__is_time_point_v<_Tp>)
1516 if constexpr (is_same_v<
typename _Tp::clock,
1517 chrono::system_clock>)
1518 return __format::__write(
std::move(__out), __utc);
1520 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1524 string_view __sv = *__t._M_abbrev;
1525 if constexpr (is_same_v<_CharT, char>)
1526 return __format::__write(
std::move(__out), __sv);
1530 basic_string<_CharT> __ws(__sv.size(), _CharT());
1531 auto& __ct = use_facet<ctype<_CharT>>(_M_locale(__ctx));
1532 __ct.widen(__sv.begin(), __sv.end(), __ws.data());
1533 __string_view __wsv = __ws;
1534 return __format::__write(
std::move(__out), __wsv);
1538 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1539 return __format::__write(
std::move(__out), __utc);
1541 __no_timezone_available();
1548 _S_digit(
int __n)
noexcept
1551 return _GLIBCXX_WIDEN(
"0123456789999999")[__n & 0xf];
1555 static basic_string_view<_CharT>
1556 _S_two_digits(
int __n)
noexcept
1559 _GLIBCXX_WIDEN(
"0001020304050607080910111213141516171819"
1560 "2021222324252627282930313233343536373839"
1561 "4041424344454647484950515253545556575859"
1562 "6061626364656667686970717273747576777879"
1563 "8081828384858687888990919293949596979899"
1564 "9999999999999999999999999999999999999999"
1565 "9999999999999999") + 2 * (__n & 0x7f),
1573 template<
typename _Tp>
1574 static decltype(
auto)
1575 _S_hms(
const _Tp& __t)
1577 using ::std::chrono::__detail::__utc_leap_second;
1578 using ::std::chrono::__detail::__local_time_fmt;
1580 if constexpr (__is_specialization_of<_Tp, chrono::hh_mm_ss>)
1582 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1584 else if constexpr (chrono::__is_duration_v<_Tp>)
1585 return chrono::hh_mm_ss<_Tp>(__t);
1586 else if constexpr (chrono::__is_time_point_v<_Tp>)
1587 return chrono::hh_mm_ss(__t - chrono::floor<chrono::days>(__t));
1588 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1589 return _S_hms(__t._M_time);
1592 __invalid_chrono_spec();
1593 return chrono::hh_mm_ss<chrono::seconds>();
1598 template<
typename _Tp>
1600 _S_days(
const _Tp& __t)
1602 using namespace chrono;
1603 using ::std::chrono::__detail::__utc_leap_second;
1604 using ::std::chrono::__detail::__local_time_fmt;
1606 if constexpr (__is_time_point_v<_Tp>)
1607 return chrono::floor<days>(__t);
1608 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1610 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1611 return chrono::floor<days>(__t._M_time);
1612 else if constexpr (is_same_v<_Tp, year_month_day>
1613 || is_same_v<_Tp, year_month_day_last>
1614 || is_same_v<_Tp, year_month_weekday>
1615 || is_same_v<_Tp, year_month_weekday_last>)
1616 return sys_days(__t);
1619 if constexpr (__is_duration_v<_Tp>)
1620 __not_valid_for_duration();
1622 __invalid_chrono_spec();
1623 return chrono::sys_days();
1628 template<
typename _Tp>
1629 static chrono::year_month_day
1630 _S_date(
const _Tp& __t)
1632 if constexpr (is_same_v<_Tp, chrono::year_month_day>)
1635 return chrono::year_month_day(_S_days(__t));
1638 template<
typename _Tp>
1640 _S_day(
const _Tp& __t)
1642 using namespace chrono;
1644 if constexpr (is_same_v<_Tp, day>)
1646 else if constexpr (
requires { __t.day(); })
1649 return _S_date(__t).day();
1652 template<
typename _Tp>
1653 static chrono::month
1654 _S_month(
const _Tp& __t)
1656 using namespace chrono;
1658 if constexpr (is_same_v<_Tp, month>)
1660 else if constexpr (
requires { __t.month(); })
1663 return _S_date(__t).month();
1666 template<
typename _Tp>
1668 _S_year(
const _Tp& __t)
1670 using namespace chrono;
1672 if constexpr (is_same_v<_Tp, year>)
1674 else if constexpr (
requires { __t.year(); })
1677 return _S_date(__t).year();
1680 template<
typename _Tp>
1681 static chrono::weekday
1682 _S_weekday(
const _Tp& __t)
1684 using namespace ::std::chrono;
1685 using ::std::chrono::__detail::__local_time_fmt;
1687 if constexpr (is_same_v<_Tp, weekday>)
1689 else if constexpr (
requires { __t.weekday(); })
1690 return __t.weekday();
1691 else if constexpr (is_same_v<_Tp, month_weekday>)
1692 return __t.weekday_indexed().weekday();
1693 else if constexpr (is_same_v<_Tp, month_weekday_last>)
1694 return __t.weekday_last().weekday();
1696 return weekday(_S_days(__t));
1700 template<
typename _Tp>
1702 _S_floor_seconds(
const _Tp& __t)
1704 using chrono::__detail::__local_time_fmt;
1705 if constexpr (chrono::__is_time_point_v<_Tp>
1706 || chrono::__is_duration_v<_Tp>)
1708 if constexpr (_Tp::period::den != 1)
1709 return chrono::floor<chrono::seconds>(__t);
1713 else if constexpr (__is_specialization_of<_Tp, chrono::hh_mm_ss>)
1715 if constexpr (_Tp::fractional_width != 0)
1716 return chrono::floor<chrono::seconds>(__t.to_duration());
1720 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1721 return _S_floor_seconds(__t._M_time);
1728 template<
typename _Iter>
1730 _M_locale_fmt(_Iter __out,
const locale& __loc,
const struct tm& __tm,
1731 char __fmt,
char __mod)
const
1733 basic_ostringstream<_CharT> __os;
1735 const auto& __tp = use_facet<time_put<_CharT>>(__loc);
1736 __tp.put(__os, __os, _S_space, &__tm, __fmt, __mod);
1738 __out = _M_write(
std::move(__out), __loc, __os.view());
1746 template<
typename _Rep,
typename _Period,
typename _CharT>
1747 requires __format::__formattable_impl<_Rep, _CharT>
1748 struct formatter<
chrono::duration<_Rep, _Period>, _CharT>
1750 constexpr typename basic_format_parse_context<_CharT>::iterator
1751 parse(basic_format_parse_context<_CharT>& __pc)
1753 using namespace __format;
1754 auto __it = _M_f._M_parse(__pc, _Duration|_TimeOfDay);
1755 if constexpr (!is_floating_point_v<_Rep>)
1756 if (_M_f._M_spec._M_prec_kind != __format::_WP_none)
1757 __throw_format_error(
"format error: invalid precision for duration");
1761 template<
typename _Out>
1762 typename basic_format_context<_Out, _CharT>::iterator
1763 format(
const chrono::duration<_Rep, _Period>& __d,
1764 basic_format_context<_Out, _CharT>& __fc)
const
1766 if constexpr (numeric_limits<_Rep>::is_signed)
1767 if (__d < __d.zero()) [[unlikely]]
1769 if constexpr (is_integral_v<_Rep>)
1773 using _URep = make_unsigned_t<_Rep>;
1774 auto __ucnt = -
static_cast<_URep
>(__d.count());
1775 auto __ud = chrono::duration<_URep, _Period>(__ucnt);
1776 return _M_f._M_format(__ud, __fc,
true);
1779 return _M_f._M_format(-__d, __fc,
true);
1781 return _M_f._M_format(__d, __fc,
false);
1785 __format::__formatter_chrono<_CharT> _M_f;
1788 template<
typename _CharT>
1789 struct formatter<
chrono::day, _CharT>
1791 template<
typename _ParseContext>
1792 constexpr typename _ParseContext::iterator
1793 parse(_ParseContext& __pc)
1794 {
return _M_f._M_parse(__pc, __format::_Day); }
1796 template<
typename _FormatContext>
1797 typename _FormatContext::iterator
1798 format(
const chrono::day& __t, _FormatContext& __fc)
const
1799 {
return _M_f._M_format(__t, __fc); }
1802 __format::__formatter_chrono<_CharT> _M_f;
1805 template<
typename _CharT>
1806 struct formatter<
chrono::month, _CharT>
1808 template<
typename _ParseContext>
1809 constexpr typename _ParseContext::iterator
1810 parse(_ParseContext& __pc)
1811 {
return _M_f._M_parse(__pc, __format::_Month); }
1813 template<
typename _FormatContext>
1814 typename _FormatContext::iterator
1815 format(
const chrono::month& __t, _FormatContext& __fc)
const
1816 {
return _M_f._M_format(__t, __fc); }
1819 __format::__formatter_chrono<_CharT> _M_f;
1822 template<
typename _CharT>
1823 struct formatter<
chrono::year, _CharT>
1825 template<
typename _ParseContext>
1826 constexpr typename _ParseContext::iterator
1827 parse(_ParseContext& __pc)
1828 {
return _M_f._M_parse(__pc, __format::_Year); }
1830 template<
typename _FormatContext>
1831 typename _FormatContext::iterator
1832 format(
const chrono::year& __t, _FormatContext& __fc)
const
1833 {
return _M_f._M_format(__t, __fc); }
1836 __format::__formatter_chrono<_CharT> _M_f;
1839 template<
typename _CharT>
1840 struct formatter<
chrono::weekday, _CharT>
1842 template<
typename _ParseContext>
1843 constexpr typename _ParseContext::iterator
1844 parse(_ParseContext& __pc)
1845 {
return _M_f._M_parse(__pc, __format::_Weekday); }
1847 template<
typename _FormatContext>
1848 typename _FormatContext::iterator
1849 format(
const chrono::weekday& __t, _FormatContext& __fc)
const
1850 {
return _M_f._M_format(__t, __fc); }
1853 __format::__formatter_chrono<_CharT> _M_f;
1856 template<
typename _CharT>
1857 struct formatter<
chrono::weekday_indexed, _CharT>
1859 template<
typename _ParseContext>
1860 constexpr typename _ParseContext::iterator
1861 parse(_ParseContext& __pc)
1862 {
return _M_f._M_parse(__pc, __format::_Weekday); }
1864 template<
typename _FormatContext>
1865 typename _FormatContext::iterator
1866 format(
const chrono::weekday_indexed& __t, _FormatContext& __fc)
const
1867 {
return _M_f._M_format(__t, __fc); }
1870 __format::__formatter_chrono<_CharT> _M_f;
1873 template<
typename _CharT>
1874 struct formatter<
chrono::weekday_last, _CharT>
1876 template<
typename _ParseContext>
1877 constexpr typename _ParseContext::iterator
1878 parse(_ParseContext& __pc)
1879 {
return _M_f._M_parse(__pc, __format::_Weekday); }
1881 template<
typename _FormatContext>
1882 typename _FormatContext::iterator
1883 format(
const chrono::weekday_last& __t, _FormatContext& __fc)
const
1884 {
return _M_f._M_format(__t, __fc); }
1887 __format::__formatter_chrono<_CharT> _M_f;
1890 template<
typename _CharT>
1891 struct formatter<
chrono::month_day, _CharT>
1893 template<
typename _ParseContext>
1894 constexpr typename _ParseContext::iterator
1895 parse(_ParseContext& __pc)
1896 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Day); }
1898 template<
typename _FormatContext>
1899 typename _FormatContext::iterator
1900 format(
const chrono::month_day& __t, _FormatContext& __fc)
const
1901 {
return _M_f._M_format(__t, __fc); }
1904 __format::__formatter_chrono<_CharT> _M_f;
1907 template<
typename _CharT>
1908 struct formatter<
chrono::month_day_last, _CharT>
1910 template<
typename _ParseContext>
1911 constexpr typename _ParseContext::iterator
1912 parse(_ParseContext& __pc)
1913 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Day); }
1915 template<
typename _FormatContext>
1916 typename _FormatContext::iterator
1917 format(
const chrono::month_day_last& __t, _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::month_weekday, _CharT>
1927 template<
typename _ParseContext>
1928 constexpr typename _ParseContext::iterator
1929 parse(_ParseContext& __pc)
1930 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Weekday); }
1932 template<
typename _FormatContext>
1933 typename _FormatContext::iterator
1934 format(
const chrono::month_weekday& __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::month_weekday_last, _CharT>
1944 template<
typename _ParseContext>
1945 constexpr typename _ParseContext::iterator
1946 parse(_ParseContext& __pc)
1947 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Weekday); }
1949 template<
typename _FormatContext>
1950 typename _FormatContext::iterator
1951 format(
const chrono::month_weekday_last& __t,
1952 _FormatContext& __fc)
const
1953 {
return _M_f._M_format(__t, __fc); }
1956 __format::__formatter_chrono<_CharT> _M_f;
1959 template<
typename _CharT>
1960 struct formatter<
chrono::year_month, _CharT>
1962 template<
typename _ParseContext>
1963 constexpr typename _ParseContext::iterator
1964 parse(_ParseContext& __pc)
1965 {
return _M_f._M_parse(__pc, __format::_Year|__format::_Month); }
1967 template<
typename _FormatContext>
1968 typename _FormatContext::iterator
1969 format(
const chrono::year_month& __t, _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_day, _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_day& __t, _FormatContext& __fc)
const
1987 {
return _M_f._M_format(__t, __fc); }
1990 __format::__formatter_chrono<_CharT> _M_f;
1993 template<
typename _CharT>
1994 struct formatter<
chrono::year_month_day_last, _CharT>
1996 template<
typename _ParseContext>
1997 constexpr typename _ParseContext::iterator
1998 parse(_ParseContext& __pc)
1999 {
return _M_f._M_parse(__pc, __format::_Date); }
2001 template<
typename _FormatContext>
2002 typename _FormatContext::iterator
2003 format(
const chrono::year_month_day_last& __t,
2004 _FormatContext& __fc)
const
2005 {
return _M_f._M_format(__t, __fc); }
2008 __format::__formatter_chrono<_CharT> _M_f;
2011 template<
typename _CharT>
2012 struct formatter<
chrono::year_month_weekday, _CharT>
2014 template<
typename _ParseContext>
2015 constexpr typename _ParseContext::iterator
2016 parse(_ParseContext& __pc)
2017 {
return _M_f._M_parse(__pc, __format::_Date); }
2019 template<
typename _FormatContext>
2020 typename _FormatContext::iterator
2021 format(
const chrono::year_month_weekday& __t,
2022 _FormatContext& __fc)
const
2023 {
return _M_f._M_format(__t, __fc); }
2026 __format::__formatter_chrono<_CharT> _M_f;
2029 template<
typename _CharT>
2030 struct formatter<
chrono::year_month_weekday_last, _CharT>
2032 template<
typename _ParseContext>
2033 constexpr typename _ParseContext::iterator
2034 parse(_ParseContext& __pc)
2035 {
return _M_f._M_parse(__pc, __format::_Date); }
2037 template<
typename _FormatContext>
2038 typename _FormatContext::iterator
2039 format(
const chrono::year_month_weekday_last& __t,
2040 _FormatContext& __fc)
const
2041 {
return _M_f._M_format(__t, __fc); }
2044 __format::__formatter_chrono<_CharT> _M_f;
2047 template<
typename _Rep,
typename _Period,
typename _CharT>
2048 struct formatter<
chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>, _CharT>
2050 template<
typename _ParseContext>
2051 constexpr typename _ParseContext::iterator
2052 parse(_ParseContext& __pc)
2053 {
return _M_f._M_parse(__pc, __format::_TimeOfDay); }
2055 template<
typename _FormatContext>
2056 typename _FormatContext::iterator
2057 format(
const chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>& __t,
2058 _FormatContext& __fc)
const
2059 {
return _M_f._M_format(__t, __fc); }
2062 __format::__formatter_chrono<_CharT> _M_f;
2065#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2066 template<
typename _CharT>
2067 struct formatter<
chrono::sys_info, _CharT>
2069 template<
typename _ParseContext>
2070 constexpr typename _ParseContext::iterator
2071 parse(_ParseContext& __pc)
2072 {
return _M_f._M_parse(__pc, __format::_ChronoParts{}); }
2074 template<
typename _FormatContext>
2075 typename _FormatContext::iterator
2076 format(
const chrono::sys_info& __i, _FormatContext& __fc)
const
2077 {
return _M_f._M_format(__i, __fc); }
2080 __format::__formatter_chrono<_CharT> _M_f;
2083 template<
typename _CharT>
2084 struct formatter<
chrono::local_info, _CharT>
2086 template<
typename _ParseContext>
2087 constexpr typename _ParseContext::iterator
2088 parse(_ParseContext& __pc)
2089 {
return _M_f._M_parse(__pc, __format::_ChronoParts{}); }
2091 template<
typename _FormatContext>
2092 typename _FormatContext::iterator
2093 format(
const chrono::local_info& __i, _FormatContext& __fc)
const
2094 {
return _M_f._M_format(__i, __fc); }
2097 __format::__formatter_chrono<_CharT> _M_f;
2101 template<
typename _Duration,
typename _CharT>
2102 struct formatter<
chrono::sys_time<_Duration>, _CharT>
2104 template<
typename _ParseContext>
2105 constexpr typename _ParseContext::iterator
2106 parse(_ParseContext& __pc)
2108 auto __next = _M_f._M_parse(__pc, __format::_ZonedDateTime);
2109 if constexpr (!__stream_insertable)
2110 if (_M_f._M_spec._M_chrono_specs.empty())
2111 __format::__invalid_chrono_spec();
2115 template<
typename _FormatContext>
2116 typename _FormatContext::iterator
2117 format(
const chrono::sys_time<_Duration>& __t,
2118 _FormatContext& __fc)
const
2119 {
return _M_f._M_format(__t, __fc); }
2122 static constexpr bool __stream_insertable
2123 =
requires (basic_ostream<_CharT>& __os,
2124 chrono::sys_time<_Duration> __t) { __os << __t; };
2126 __format::__formatter_chrono<_CharT> _M_f;
2129 template<
typename _Duration,
typename _CharT>
2130 struct formatter<
chrono::utc_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::utc_time<_Duration>& __t,
2141 _FormatContext& __fc)
const
2146 using chrono::__detail::__utc_leap_second;
2147 using chrono::seconds;
2148 using chrono::sys_time;
2149 using _CDur = common_type_t<_Duration, seconds>;
2150 const auto __li = chrono::get_leap_second_info(__t);
2151 sys_time<_CDur> __s{__t.time_since_epoch() - __li.elapsed};
2152 if (!__li.is_leap_second) [[likely]]
2153 return _M_f._M_format(__s, __fc);
2155 return _M_f._M_format(__utc_leap_second(__s), __fc);
2159 friend formatter<chrono::__detail::__utc_leap_second<_Duration>, _CharT>;
2161 __format::__formatter_chrono<_CharT> _M_f;
2164 template<
typename _Duration,
typename _CharT>
2165 struct formatter<
chrono::tai_time<_Duration>, _CharT>
2166 : __format::__formatter_chrono<_CharT>
2168 template<
typename _ParseContext>
2169 constexpr typename _ParseContext::iterator
2170 parse(_ParseContext& __pc)
2171 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2173 template<
typename _FormatContext>
2174 typename _FormatContext::iterator
2175 format(
const chrono::tai_time<_Duration>& __t,
2176 _FormatContext& __fc)
const
2183 constexpr chrono::days __tai_offset = chrono::days(4383);
2184 using _CDur = common_type_t<_Duration, chrono::days>;
2185 chrono::local_time<_CDur> __lt(__t.time_since_epoch() - __tai_offset);
2186 const string __abbrev(
"TAI", 3);
2187 const chrono::seconds __off = 0s;
2188 const auto __lf = chrono::local_time_format(__lt, &__abbrev, &__off);
2189 return _M_f._M_format(__lf, __fc);
2193 __format::__formatter_chrono<_CharT> _M_f;
2196 template<
typename _Duration,
typename _CharT>
2197 struct formatter<
chrono::gps_time<_Duration>, _CharT>
2198 : __format::__formatter_chrono<_CharT>
2200 template<
typename _ParseContext>
2201 constexpr typename _ParseContext::iterator
2202 parse(_ParseContext& __pc)
2203 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2205 template<
typename _FormatContext>
2206 typename _FormatContext::iterator
2207 format(
const chrono::gps_time<_Duration>& __t,
2208 _FormatContext& __fc)
const
2215 constexpr chrono::days __gps_offset = chrono::days(3657);
2216 using _CDur = common_type_t<_Duration, chrono::days>;
2217 chrono::local_time<_CDur> __lt(__t.time_since_epoch() + __gps_offset);
2218 const string __abbrev(
"GPS", 3);
2219 const chrono::seconds __off = 0s;
2220 const auto __lf = chrono::local_time_format(__lt, &__abbrev, &__off);
2221 return _M_f._M_format(__lf, __fc);
2225 __format::__formatter_chrono<_CharT> _M_f;
2228 template<
typename _Duration,
typename _CharT>
2229 struct formatter<
chrono::file_time<_Duration>, _CharT>
2231 template<
typename _ParseContext>
2232 constexpr typename _ParseContext::iterator
2233 parse(_ParseContext& __pc)
2234 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2236 template<
typename _FormatContext>
2237 typename _FormatContext::iterator
2238 format(
const chrono::file_time<_Duration>& __t,
2239 _FormatContext& __ctx)
const
2241 using namespace chrono;
2242 return _M_f._M_format(chrono::clock_cast<system_clock>(__t), __ctx);
2246 __format::__formatter_chrono<_CharT> _M_f;
2249 template<
typename _Duration,
typename _CharT>
2250 struct formatter<
chrono::local_time<_Duration>, _CharT>
2252 template<
typename _ParseContext>
2253 constexpr typename _ParseContext::iterator
2254 parse(_ParseContext& __pc)
2255 {
return _M_f._M_parse(__pc, __format::_DateTime); }
2257 template<
typename _FormatContext>
2258 typename _FormatContext::iterator
2259 format(
const chrono::local_time<_Duration>& __t,
2260 _FormatContext& __ctx)
const
2261 {
return _M_f._M_format(__t, __ctx); }
2264 __format::__formatter_chrono<_CharT> _M_f;
2267 template<
typename _Duration,
typename _CharT>
2268 struct formatter<
chrono::__detail::__local_time_fmt<_Duration>, _CharT>
2270 template<
typename _ParseContext>
2271 constexpr typename _ParseContext::iterator
2272 parse(_ParseContext& __pc)
2273 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2275 template<
typename _FormatContext>
2276 typename _FormatContext::iterator
2277 format(
const chrono::__detail::__local_time_fmt<_Duration>& __t,
2278 _FormatContext& __ctx)
const
2279 {
return _M_f._M_format(__t, __ctx,
true); }
2282 __format::__formatter_chrono<_CharT> _M_f;
2285#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2286 template<
typename _Duration,
typename _TimeZonePtr,
typename _CharT>
2287 struct formatter<
chrono::zoned_time<_Duration, _TimeZonePtr>, _CharT>
2288 : formatter<chrono::__detail::__local_time_fmt_for<_Duration>, _CharT>
2290 template<
typename _FormatContext>
2291 typename _FormatContext::iterator
2292 format(
const chrono::zoned_time<_Duration, _TimeZonePtr>& __tp,
2293 _FormatContext& __ctx)
const
2295 using _Ltf = chrono::__detail::__local_time_fmt_for<_Duration>;
2296 using _Base = formatter<_Ltf, _CharT>;
2297 const chrono::sys_info __info = __tp.get_info();
2298 const auto __lf = chrono::local_time_format(__tp.get_local_time(),
2301 return _Base::format(__lf, __ctx);
2307 template<
typename _Duration,
typename _CharT>
2308 struct formatter<
chrono::__detail::__utc_leap_second<_Duration>, _CharT>
2309 : formatter<chrono::utc_time<_Duration>, _CharT>
2311 template<
typename _FormatContext>
2312 typename _FormatContext::iterator
2313 format(
const chrono::__detail::__utc_leap_second<_Duration>& __t,
2314 _FormatContext& __fc)
const
2315 {
return this->_M_f._M_format(__t, __fc); }
2326 template<
typename _Duration = seconds>
2329 static_assert(is_same_v<common_type_t<_Duration, seconds>, _Duration>);
2332 _Parser(__format::_ChronoParts __need) : _M_need(__need) { }
2334 _Parser(_Parser&&) =
delete;
2335 void operator=(_Parser&&) =
delete;
2337 _Duration _M_time{};
2338 sys_days _M_sys_days{};
2339 year_month_day _M_ymd{};
2341 __format::_ChronoParts _M_need;
2342 unsigned _M_is_leap_second : 1 {};
2343 unsigned _M_reserved : 15 {};
2345 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2346 basic_istream<_CharT, _Traits>&
2347 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2348 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2349 minutes* __offset =
nullptr);
2354 template<
typename _CharT,
typename _Traits>
2355 static int_least32_t
2356 _S_read_unsigned(basic_istream<_CharT, _Traits>& __is,
2357 ios_base::iostate& __err,
int __n)
2359 int_least32_t __val = _S_try_read_digit(__is, __err);
2360 if (__val == -1) [[unlikely]]
2361 __err |= ios_base::failbit;
2366 for (
int __i = 1; __i < __n1; ++__i)
2367 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
2373 while (__n1++ < __n) [[unlikely]]
2374 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
2376 if (__builtin_mul_overflow(__val, 10, &__val)
2377 || __builtin_add_overflow(__val, __dig, &__val))
2379 __err |= ios_base::failbit;
2389 template<
typename _CharT,
typename _Traits>
2390 static int_least32_t
2391 _S_read_signed(basic_istream<_CharT, _Traits>& __is,
2392 ios_base::iostate& __err,
int __n)
2394 auto __sign = __is.peek();
2395 if (__sign ==
'-' || __sign ==
'+')
2397 int_least32_t __val = _S_read_unsigned(__is, __err, __n);
2398 if (__err & ios_base::failbit)
2400 if (__sign ==
'-') [[unlikely]]
2408 template<
typename _CharT,
typename _Traits>
2409 static int_least32_t
2410 _S_try_read_digit(basic_istream<_CharT, _Traits>& __is,
2411 ios_base::iostate& __err)
2413 int_least32_t __val = -1;
2414 auto __i = __is.peek();
2415 if (!_Traits::eq_int_type(__i, _Traits::eof())) [[likely]]
2417 _CharT __c = _Traits::to_char_type(__i);
2418 if (_CharT(
'0') <= __c && __c <= _CharT(
'9')) [[likely]]
2421 __val = __c - _CharT(
'0');
2425 __err |= ios_base::eofbit;
2431 template<
typename _CharT,
typename _Traits>
2433 _S_read_chr(basic_istream<_CharT, _Traits>& __is,
2434 ios_base::iostate& __err, _CharT __c)
2436 auto __i = __is.peek();
2437 if (_Traits::eq_int_type(__i, _Traits::eof()))
2438 __err |= ios_base::eofbit;
2439 else if (_Traits::to_char_type(__i) == __c) [[likely]]
2444 __err |= ios_base::failbit;
2449 template<
typename _Duration>
2450 using _Parser_t = _Parser<common_type_t<_Duration, seconds>>;
2452 template<
typename _Duration>
2456 if constexpr (_Duration::period::den == 1)
2458 switch (_Duration::period::num)
2460 case minutes::period::num:
2461 case hours::period::num:
2462 case days::period::num:
2463 case weeks::period::num:
2464 case years::period::num:
2481 template<
typename _ToDur,
typename _Tp>
2483 __round(
const _Tp& __t)
2485 if constexpr (__is_duration_v<_Tp>)
2487 if constexpr (treat_as_floating_point_v<typename _Tp::rep>)
2489 else if constexpr (__detail::__use_floor<_ToDur>())
2496 static_assert(__is_time_point_v<_Tp>);
2497 using _Tpt = time_point<typename _Tp::clock, _ToDur>;
2498 return _Tpt(__detail::__round<_ToDur>(__t.time_since_epoch()));
2505 template<
typename _CharT,
typename _Traits,
typename _Rep,
typename _Period,
2506 typename _Alloc = allocator<_CharT>>
2507 inline basic_istream<_CharT, _Traits>&
2508 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2510 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2513 auto __need = __format::_ChronoParts::_TimeOfDay;
2514 __detail::_Parser_t<duration<_Rep, _Period>> __p(__need);
2515 if (__p(__is, __fmt, __abbrev, __offset))
2516 __d = __detail::__round<duration<_Rep, _Period>>(__p._M_time);
2520 template<
typename _CharT,
typename _Traits>
2521 inline basic_ostream<_CharT, _Traits>&
2522 operator<<(basic_ostream<_CharT, _Traits>& __os,
const day& __d)
2524 using _Ctx = __format::__format_context<_CharT>;
2525 using _Str = basic_string_view<_CharT>;
2526 _Str __s = _GLIBCXX_WIDEN(
"{:02d} is not a valid day");
2528 __s = __s.substr(0, 6);
2529 auto __u = (unsigned)__d;
2530 __os << std::vformat(__s, make_format_args<_Ctx>(__u));
2534 template<
typename _CharT,
typename _Traits,
2535 typename _Alloc = allocator<_CharT>>
2536 inline basic_istream<_CharT, _Traits>&
2537 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2539 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2542 __detail::_Parser<> __p(__format::_ChronoParts::_Day);
2543 if (__p(__is, __fmt, __abbrev, __offset))
2544 __d = __p._M_ymd.day();
2548 template<
typename _CharT,
typename _Traits>
2549 inline basic_ostream<_CharT, _Traits>&
2550 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month& __m)
2552 using _Ctx = __format::__format_context<_CharT>;
2553 using _Str = basic_string_view<_CharT>;
2554 _Str __s = _GLIBCXX_WIDEN(
"{:L%b}{} is not a valid month");
2556 __os << std::vformat(__os.getloc(), __s.substr(0, 6),
2557 make_format_args<_Ctx>(__m));
2560 auto __u = (unsigned)__m;
2561 __os << std::vformat(__s.substr(6), make_format_args<_Ctx>(__u));
2566 template<
typename _CharT,
typename _Traits,
2567 typename _Alloc = allocator<_CharT>>
2568 inline basic_istream<_CharT, _Traits>&
2569 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2571 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2574 __detail::_Parser<> __p(__format::_ChronoParts::_Month);
2575 if (__p(__is, __fmt, __abbrev, __offset))
2576 __m = __p._M_ymd.month();
2580 template<
typename _CharT,
typename _Traits>
2581 inline basic_ostream<_CharT, _Traits>&
2582 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year& __y)
2584 using _Ctx = __format::__format_context<_CharT>;
2585 using _Str = basic_string_view<_CharT>;
2586 _Str __s = _GLIBCXX_WIDEN(
"-{:04d} is not a valid year");
2588 __s = __s.substr(0, 7);
2590 if (__i >= 0) [[likely]]
2591 __s.remove_prefix(1);
2594 __os << std::vformat(__s, make_format_args<_Ctx>(__i));
2598 template<
typename _CharT,
typename _Traits,
2599 typename _Alloc = allocator<_CharT>>
2600 inline basic_istream<_CharT, _Traits>&
2601 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2603 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2606 __detail::_Parser<> __p(__format::_ChronoParts::_Year);
2607 if (__p(__is, __fmt, __abbrev, __offset))
2608 __y = __p._M_ymd.year();
2612 template<
typename _CharT,
typename _Traits>
2613 inline basic_ostream<_CharT, _Traits>&
2614 operator<<(basic_ostream<_CharT, _Traits>& __os,
const weekday& __wd)
2616 using _Ctx = __format::__format_context<_CharT>;
2617 using _Str = basic_string_view<_CharT>;
2618 _Str __s = _GLIBCXX_WIDEN(
"{:L%a}{} is not a valid weekday");
2620 __os << std::vformat(__os.getloc(), __s.substr(0, 6),
2621 make_format_args<_Ctx>(__wd));
2624 auto __c = __wd.c_encoding();
2625 __os << std::vformat(__s.substr(6), make_format_args<_Ctx>(__c));
2630 template<
typename _CharT,
typename _Traits,
2631 typename _Alloc = allocator<_CharT>>
2632 inline basic_istream<_CharT, _Traits>&
2633 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2635 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2638 __detail::_Parser<> __p(__format::_ChronoParts::_Weekday);
2639 if (__p(__is, __fmt, __abbrev, __offset))
2644 template<
typename _CharT,
typename _Traits>
2645 inline basic_ostream<_CharT, _Traits>&
2646 operator<<(basic_ostream<_CharT, _Traits>& __os,
2647 const weekday_indexed& __wdi)
2652 basic_stringstream<_CharT> __os2;
2653 __os2.imbue(__os.getloc());
2654 __os2 << __wdi.weekday();
2655 const auto __i = __wdi.index();
2656 basic_string_view<_CharT> __s
2657 = _GLIBCXX_WIDEN(
"[ is not a valid index]");
2659 __os2 << std::format(_GLIBCXX_WIDEN(
"{}"), __i);
2660 if (__i >= 1 && __i <= 5)
2661 __os2 << __s.back();
2663 __os2 << __s.substr(1);
2664 __os << __os2.view();
2668 template<
typename _CharT,
typename _Traits>
2669 inline basic_ostream<_CharT, _Traits>&
2670 operator<<(basic_ostream<_CharT, _Traits>& __os,
2671 const weekday_last& __wdl)
2674 basic_stringstream<_CharT> __os2;
2675 __os2.imbue(__os.getloc());
2676 __os2 << __wdl.weekday() << _GLIBCXX_WIDEN(
"[last]");
2677 __os << __os2.view();
2681 template<
typename _CharT,
typename _Traits>
2682 inline basic_ostream<_CharT, _Traits>&
2683 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month_day& __md)
2686 basic_stringstream<_CharT> __os2;
2687 __os2.imbue(__os.getloc());
2688 __os2 << __md.month();
2689 if constexpr (is_same_v<_CharT, char>)
2693 __os2 << __md.day();
2694 __os << __os2.view();
2698 template<
typename _CharT,
typename _Traits,
2699 typename _Alloc = allocator<_CharT>>
2700 inline basic_istream<_CharT, _Traits>&
2701 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2703 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2706 using __format::_ChronoParts;
2707 auto __need = _ChronoParts::_Month | _ChronoParts::_Day;
2708 __detail::_Parser<> __p(__need);
2709 if (__p(__is, __fmt, __abbrev, __offset))
2710 __md = month_day(__p._M_ymd.month(), __p._M_ymd.day());
2714 template<
typename _CharT,
typename _Traits>
2715 inline basic_ostream<_CharT, _Traits>&
2716 operator<<(basic_ostream<_CharT, _Traits>& __os,
2717 const month_day_last& __mdl)
2720 basic_stringstream<_CharT> __os2;
2721 __os2.imbue(__os.getloc());
2722 __os2 << __mdl.month() << _GLIBCXX_WIDEN(
"/last");
2723 __os << __os2.view();
2727 template<
typename _CharT,
typename _Traits>
2728 inline basic_ostream<_CharT, _Traits>&
2729 operator<<(basic_ostream<_CharT, _Traits>& __os,
2730 const month_weekday& __mwd)
2733 basic_stringstream<_CharT> __os2;
2734 __os2.imbue(__os.getloc());
2735 __os2 << __mwd.month();
2736 if constexpr (is_same_v<_CharT, char>)
2740 __os2 << __mwd.weekday_indexed();
2741 __os << __os2.view();
2745 template<
typename _CharT,
typename _Traits>
2746 inline basic_ostream<_CharT, _Traits>&
2747 operator<<(basic_ostream<_CharT, _Traits>& __os,
2748 const month_weekday_last& __mwdl)
2751 basic_stringstream<_CharT> __os2;
2752 __os2.imbue(__os.getloc());
2753 __os2 << __mwdl.month();
2754 if constexpr (is_same_v<_CharT, char>)
2758 __os2 << __mwdl.weekday_last();
2759 __os << __os2.view();
2763 template<
typename _CharT,
typename _Traits>
2764 inline basic_ostream<_CharT, _Traits>&
2765 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year_month& __ym)
2768 basic_stringstream<_CharT> __os2;
2769 __os2.imbue(__os.getloc());
2770 __os2 << __ym.year();
2771 if constexpr (is_same_v<_CharT, char>)
2775 __os2 << __ym.month();
2776 __os << __os2.view();
2780 template<
typename _CharT,
typename _Traits,
2781 typename _Alloc = allocator<_CharT>>
2782 inline basic_istream<_CharT, _Traits>&
2783 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2785 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2788 using __format::_ChronoParts;
2789 auto __need = _ChronoParts::_Year | _ChronoParts::_Month;
2790 __detail::_Parser<> __p(__need);
2791 if (__p(__is, __fmt, __abbrev, __offset))
2792 __ym = year_month(__p._M_ymd.year(), __p._M_ymd.month());
2796 template<
typename _CharT,
typename _Traits>
2797 inline basic_ostream<_CharT, _Traits>&
2798 operator<<(basic_ostream<_CharT, _Traits>& __os,
2799 const year_month_day& __ymd)
2801 using _Ctx = __format::__format_context<_CharT>;
2802 using _Str = basic_string_view<_CharT>;
2803 _Str __s = _GLIBCXX_WIDEN(
"{:%F} is not a valid date");
2804 __os << std::vformat(__ymd.ok() ? __s.substr(0, 5) : __s,
2805 make_format_args<_Ctx>(__ymd));
2809 template<
typename _CharT,
typename _Traits,
2810 typename _Alloc = allocator<_CharT>>
2811 inline basic_istream<_CharT, _Traits>&
2813 year_month_day& __ymd,
2817 using __format::_ChronoParts;
2818 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2819 | _ChronoParts::_Day;
2820 __detail::_Parser<> __p(__need);
2821 if (__p(__is, __fmt, __abbrev, __offset))
2826 template<
typename _CharT,
typename _Traits>
2829 const year_month_day_last& __ymdl)
2834 __os2 << __ymdl.year();
2835 if constexpr (is_same_v<_CharT, char>)
2839 __os2 << __ymdl.month_day_last();
2840 __os << __os2.view();
2844 template<
typename _CharT,
typename _Traits>
2845 inline basic_ostream<_CharT, _Traits>&
2846 operator<<(basic_ostream<_CharT, _Traits>& __os,
2847 const year_month_weekday& __ymwd)
2851 basic_stringstream<_CharT> __os2;
2852 __os2.
imbue(__os.getloc());
2854 if constexpr (is_same_v<_CharT, char>)
2858 __os2 << __ymwd.year() << __slash << __ymwd.month() << __slash
2859 << __ymwd.weekday_indexed();
2860 __os << __os2.view();
2864 template<
typename _CharT,
typename _Traits>
2865 inline basic_ostream<_CharT, _Traits>&
2866 operator<<(basic_ostream<_CharT, _Traits>& __os,
2867 const year_month_weekday_last& __ymwdl)
2871 basic_stringstream<_CharT> __os2;
2872 __os2.imbue(__os.getloc());
2874 if constexpr (is_same_v<_CharT, char>)
2878 __os2 << __ymwdl.year() << __slash << __ymwdl.month() << __slash
2879 << __ymwdl.weekday_last();
2880 __os << __os2.view();
2884 template<
typename _CharT,
typename _Traits,
typename _Duration>
2885 inline basic_ostream<_CharT, _Traits>&
2886 operator<<(basic_ostream<_CharT, _Traits>& __os,
2889 return __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%T}"), __hms);
2892#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2894 template<
typename _CharT,
typename _Traits>
2895 basic_ostream<_CharT, _Traits>&
2896 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_info& __i)
2898 __os <<
'[' << __i.begin <<
',' << __i.end
2899 <<
',' <<
hh_mm_ss(__i.offset) <<
',' << __i.save
2900 <<
',' << __i.abbrev <<
']';
2905 template<
typename _CharT,
typename _Traits>
2906 basic_ostream<_CharT, _Traits>&
2907 operator<<(basic_ostream<_CharT, _Traits>& __os,
const local_info& __li)
2910 if (__li.result == local_info::unique)
2914 if (__li.result == local_info::nonexistent)
2915 __os <<
"nonexistent";
2917 __os <<
"ambiguous";
2918 __os <<
" local time between " << __li.first;
2919 __os <<
" and " << __li.second;
2925 template<
typename _CharT,
typename _Traits,
typename _Duration,
2926 typename _TimeZonePtr>
2927 inline basic_ostream<_CharT, _Traits>&
2928 operator<<(basic_ostream<_CharT, _Traits>& __os,
2929 const zoned_time<_Duration, _TimeZonePtr>& __t)
2931 __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T %Z}"), __t);
2936 template<
typename _CharT,
typename _Traits,
typename _Duration>
2937 requires (!treat_as_floating_point_v<typename _Duration::rep>)
2938 && ratio_less_v<typename _Duration::period, days::period>
2939 inline basic_ostream<_CharT, _Traits>&
2940 operator<<(basic_ostream<_CharT, _Traits>& __os,
2941 const sys_time<_Duration>& __tp)
2943 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __tp);
2947 template<
typename _CharT,
typename _Traits>
2948 inline basic_ostream<_CharT, _Traits>&
2949 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_days& __dp)
2951 __os << year_month_day{__dp};
2955 template<
typename _CharT,
typename _Traits,
typename _Duration,
2956 typename _Alloc = allocator<_CharT>>
2957 basic_istream<_CharT, _Traits>&
2958 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2959 sys_time<_Duration>& __tp,
2960 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2966 using __format::_ChronoParts;
2967 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2968 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2969 __detail::_Parser_t<_Duration> __p(__need);
2970 if (__p(__is, __fmt, __abbrev, __offset))
2972 if (__p._M_is_leap_second)
2976 auto __st = __p._M_sys_days + __p._M_time - *__offset;
2977 __tp = __detail::__round<_Duration>(__st);
2983 template<
typename _CharT,
typename _Traits,
typename _Duration>
2984 inline basic_ostream<_CharT, _Traits>&
2985 operator<<(basic_ostream<_CharT, _Traits>& __os,
2986 const utc_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 utc_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))
3011 auto __ut = utc_clock::from_sys(__p._M_sys_days) + __p._M_time
3013 __tp = __detail::__round<_Duration>(__ut);
3018 template<
typename _CharT,
typename _Traits,
typename _Duration>
3019 inline basic_ostream<_CharT, _Traits>&
3020 operator<<(basic_ostream<_CharT, _Traits>& __os,
3021 const tai_time<_Duration>& __t)
3023 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
3027 template<
typename _CharT,
typename _Traits,
typename _Duration,
3028 typename _Alloc = allocator<_CharT>>
3029 inline basic_istream<_CharT, _Traits>&
3030 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3031 tai_time<_Duration>& __tp,
3032 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3038 using __format::_ChronoParts;
3039 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3040 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
3041 __detail::_Parser_t<_Duration> __p(__need);
3042 if (__p(__is, __fmt, __abbrev, __offset))
3044 if (__p._M_is_leap_second)
3048 constexpr sys_days __epoch(-
days(4383));
3049 auto __d = __p._M_sys_days - __epoch + __p._M_time - *__offset;
3050 tai_time<common_type_t<_Duration, seconds>> __tt(__d);
3051 __tp = __detail::__round<_Duration>(__tt);
3057 template<
typename _CharT,
typename _Traits,
typename _Duration>
3058 inline basic_ostream<_CharT, _Traits>&
3059 operator<<(basic_ostream<_CharT, _Traits>& __os,
3060 const gps_time<_Duration>& __t)
3062 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
3066 template<
typename _CharT,
typename _Traits,
typename _Duration,
3067 typename _Alloc = allocator<_CharT>>
3068 inline basic_istream<_CharT, _Traits>&
3069 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3070 gps_time<_Duration>& __tp,
3071 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3077 using __format::_ChronoParts;
3078 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3079 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
3080 __detail::_Parser_t<_Duration> __p(__need);
3081 if (__p(__is, __fmt, __abbrev, __offset))
3083 if (__p._M_is_leap_second)
3087 constexpr sys_days __epoch(
days(3657));
3088 auto __d = __p._M_sys_days - __epoch + __p._M_time - *__offset;
3089 gps_time<common_type_t<_Duration, seconds>> __gt(__d);
3090 __tp = __detail::__round<_Duration>(__gt);
3096 template<
typename _CharT,
typename _Traits,
typename _Duration>
3097 inline basic_ostream<_CharT, _Traits>&
3098 operator<<(basic_ostream<_CharT, _Traits>& __os,
3099 const file_time<_Duration>& __t)
3101 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
3105 template<
typename _CharT,
typename _Traits,
typename _Duration,
3106 typename _Alloc = allocator<_CharT>>
3107 inline basic_istream<_CharT, _Traits>&
3108 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3109 file_time<_Duration>& __tp,
3110 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3113 sys_time<_Duration> __st;
3114 if (chrono::from_stream(__is, __fmt, __st, __abbrev, __offset))
3115 __tp = __detail::__round<_Duration>(file_clock::from_sys(__st));
3119 template<
typename _CharT,
typename _Traits,
typename _Duration>
3120 inline basic_ostream<_CharT, _Traits>&
3121 operator<<(basic_ostream<_CharT, _Traits>& __os,
3122 const local_time<_Duration>& __lt)
3124 __os << sys_time<_Duration>{__lt.time_since_epoch()};
3128 template<
typename _CharT,
typename _Traits,
typename _Duration,
3129 typename _Alloc = allocator<_CharT>>
3130 basic_istream<_CharT, _Traits>&
3131 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3132 local_time<_Duration>& __tp,
3133 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3136 using __format::_ChronoParts;
3137 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3138 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
3139 __detail::_Parser_t<_Duration> __p(__need);
3140 if (__p(__is, __fmt, __abbrev, __offset))
3142 days __d = __p._M_sys_days.time_since_epoch();
3143 auto __t = local_days(__d) + __p._M_time;
3144 __tp = __detail::__round<_Duration>(__t);
3155 void from_stream() =
delete;
3157 template<
typename _Parsable,
typename _CharT,
3158 typename _Traits = std::char_traits<_CharT>,
3159 typename... _OptArgs>
3160 concept __parsable =
requires (basic_istream<_CharT, _Traits>& __is,
3161 const _CharT* __fmt, _Parsable& __tp,
3162 _OptArgs*... __args)
3163 { from_stream(__is, __fmt, __tp, __args...); };
3165 template<
typename _Parsable,
typename _CharT,
3166 typename _Traits = char_traits<_CharT>,
3167 typename _Alloc = allocator<_CharT>>
3171 using __string_type = basic_string<_CharT, _Traits, _Alloc>;
3174 _Parse(
const _CharT* __fmt, _Parsable& __tp,
3175 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3178 _M_abbrev(__abbrev), _M_offset(__offset)
3181 _Parse(_Parse&&) =
delete;
3182 _Parse& operator=(_Parse&&) =
delete;
3185 using __stream_type = basic_istream<_CharT, _Traits>;
3187 const _CharT*
const _M_fmt;
3188 _Parsable*
const _M_tp;
3189 __string_type*
const _M_abbrev;
3192 friend __stream_type&
3193 operator>>(__stream_type& __is, _Parse&& __p)
3196 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev,
3198 else if (__p._M_abbrev)
3199 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev);
3201 from_stream(__is, __p._M_fmt, *__p._M_tp);
3205 friend void operator>>(__stream_type&, _Parse&) =
delete;
3206 friend void operator>>(__stream_type&,
const _Parse&) =
delete;
3210 template<
typename _CharT, __detail::__parsable<_CharT> _Parsable>
3211 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
3213 parse(
const _CharT* __fmt, _Parsable& __tp)
3214 {
return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp); }
3216 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3217 __detail::__parsable<_CharT, _Traits> _Parsable>
3220 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp)
3222 return __detail::_Parse<_Parsable, _CharT, _Traits>(__fmt.c_str(), __tp);
3225 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3226 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
3227 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
3228 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
3230 parse(
const _CharT* __fmt, _Parsable& __tp,
3231 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
3234 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
3238 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3239 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
3240 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
3243 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
3244 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
3247 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
3251 template<
typename _CharT,
typename _Traits =
char_traits<_CharT>,
3252 typename _StrT = basic_
string<_CharT, _Traits>,
3253 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
3254 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
3256 parse(
const _CharT* __fmt, _Parsable& __tp,
minutes& __offset)
3258 return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp,
nullptr,
3262 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3263 typename _StrT = basic_string<_CharT, _Traits>,
3264 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
3267 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
3270 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
3275 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3276 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
3277 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
3278 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
3280 parse(
const _CharT* __fmt, _Parsable& __tp,
3281 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
3284 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
3289 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3290 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
3291 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
3294 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
3295 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
3298 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
3304 template<
typename _Duration>
3305 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3306 basic_istream<_CharT, _Traits>&
3307 __detail::_Parser<_Duration>::
3308 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3309 basic_string<_CharT, _Traits, _Alloc>* __abbrev,
3312 using sentry =
typename basic_istream<_CharT, _Traits>::sentry;
3314 if (sentry __cerb(__is,
true); __cerb)
3316 locale __loc = __is.getloc();
3321 struct _Stream_state
3324 _Stream_state(basic_istream<_CharT, _Traits>& __i)
3326 _M_flags(__i.flags(ios_base::
skipws | ios_base::
dec)),
3332 _M_is.flags(_M_flags);
3336 _Stream_state(_Stream_state&&) =
delete;
3338 basic_istream<_CharT, _Traits>& _M_is;
3339 ios_base::fmtflags _M_flags;
3349 auto __read_unsigned = [&] (
int __n) {
3350 return _S_read_unsigned(__is, __err, __n);
3355 auto __read_signed = [&] (
int __n) {
3356 return _S_read_signed(__is, __err, __n);
3360 auto __read_chr = [&__is, &__err] (_CharT __c) {
3361 return _S_read_chr(__is, __err, __c);
3364 using __format::_ChronoParts;
3365 _ChronoParts __parts{};
3367 const year __bad_y = --year::min();
3368 const month __bad_mon(255);
3369 const day __bad_day(255);
3370 const weekday __bad_wday(255);
3371 const hours __bad_h(-1);
3372 const minutes __bad_min(-9999);
3375 year __y = __bad_y, __yy = __bad_y;
3376 year __iso_y = __bad_y, __iso_yy = __bad_y;
3377 month __m = __bad_mon;
3378 day __d = __bad_day;
3379 weekday __wday = __bad_wday;
3380 hours __h = __bad_h, __h12 = __bad_h;
3382 _Duration __s = __bad_sec;
3384 int __iso_wk = -1, __sunday_wk = -1, __monday_wk = -1;
3386 int __dayofyear = -1;
3388 minutes __tz_offset = __bad_min;
3389 basic_string<_CharT, _Traits> __tz_abbr;
3391 if ((_M_need & _ChronoParts::_TimeOfDay)
3392 && (_M_need & _ChronoParts::_Year))
3398 __parts = _ChronoParts::_TimeOfDay;
3405 bool __is_flag =
false;
3407 constexpr bool __is_floating
3408 = treat_as_floating_point_v<typename _Duration::rep>;
3427 _CharT __c = *__fmt++;
3434 else if (!__read_chr(__c)) [[unlikely]]
3445 if (__mod || __num) [[unlikely]]
3450 __tmget.get(__is, {}, __is, __err, &__tm,
3452 if (!__is_failed(__err))
3453 __wday = weekday(__tm.tm_wday);
3455 __parts |= _ChronoParts::_Weekday;
3461 if (__mod || __num) [[unlikely]]
3469 __tmget.get(__is, {}, __is, __err, &__tm,
3471 if (!__is_failed(__err))
3472 __m = month(__tm.tm_mon + 1);
3474 __parts |= _ChronoParts::_Month;
3478 if (__mod ==
'O' || __num) [[unlikely]]
3483 __tmget.get(__is, {}, __is, __err, &__tm,
3484 __fmt - 2 - (__mod ==
'E'), __fmt);
3485 if (!__is_failed(__err))
3487 __y = year(__tm.tm_year + 1900);
3488 __m = month(__tm.tm_mon + 1);
3489 __d = day(__tm.tm_mday);
3490 __h =
hours(__tm.tm_hour);
3495 __parts |= _ChronoParts::_DateTime;
3499 if (!__mod) [[likely]]
3501 auto __v = __read_signed(__num ? __num : 2);
3502 if (!__is_failed(__err))
3504 int __cmin = (int)year::min() / 100;
3505 int __cmax = (int)year::max() / 100;
3506 if (__cmin <= __v && __v <= __cmax)
3507 __century = __v * 100;
3512 else if (__mod ==
'E')
3515 __tmget.get(__is, {}, __is, __err, &__tm,
3517 if (!__is_failed(__err))
3518 __century = __tm.tm_year;
3527 if (!__mod) [[likely]]
3529 auto __v = __read_unsigned(__num ? __num : 2);
3530 if (!__is_failed(__err))
3533 else if (__mod ==
'O')
3536 __tmget.get(__is, {}, __is, __err, &__tm,
3538 if (!__is_failed(__err))
3539 __d = day(__tm.tm_mday);
3543 __parts |= _ChronoParts::_Day;
3547 if (__mod || __num) [[unlikely]]
3551 auto __month = __read_unsigned(2);
3553 auto __day = __read_unsigned(2);
3555 auto __year = __read_unsigned(2);
3556 if (__is_failed(__err))
3558 __y = year(__year + 1900 + 100 *
int(__year < 69));
3559 __m = month(__month);
3561 if (!year_month_day(__y, __m, __d).ok())
3563 __y = __yy = __iso_y = __iso_yy = __bad_y;
3569 __parts |= _ChronoParts::_Date;
3573 if (__mod) [[unlikely]]
3577 auto __year = __read_signed(__num ? __num : 4);
3579 auto __month = __read_unsigned(2);
3581 auto __day = __read_unsigned(2);
3582 if (__is_failed(__err))
3585 __m = month(__month);
3587 if (!year_month_day(__y, __m, __d).ok())
3589 __y = __yy = __iso_y = __iso_yy = __bad_y;
3595 __parts |= _ChronoParts::_Date;
3599 if (__mod) [[unlikely]]
3603 auto __val = __read_unsigned(__num ? __num : 2);
3604 if (__val >= 0 && __val <= 99)
3606 __iso_yy = year(__val);
3607 if (__century == -1)
3611 __iso_yy = __iso_y = __y = __yy = __bad_y;
3613 __parts |= _ChronoParts::_Year;
3617 if (__mod) [[unlikely]]
3620 __iso_y = year(__read_unsigned(__num ? __num : 4));
3621 __parts |= _ChronoParts::_Year;
3626 if (__mod ==
'E') [[unlikely]]
3628 else if (__mod ==
'O')
3633 __tmget.get(__is, {}, __is, __err, &__tm,
3635 if (!__is_failed(__err))
3639 __h12 =
hours(__tm.tm_hour);
3643 __h =
hours(__tm.tm_hour);
3652 auto __val = __read_unsigned(__num ? __num : 2);
3653 if (__c ==
'I' && __val >= 1 && __val <= 12)
3655 __h12 =
hours(__val);
3658 else if (__c ==
'H' && __val >= 0 && __val <= 23)
3665 if (_M_need & _ChronoParts::_TimeOfDay)
3670 __parts |= _ChronoParts::_TimeOfDay;
3674 if (__mod) [[unlikely]]
3676 else if (_M_need == _ChronoParts::_TimeOfDay)
3678 auto __val = __read_signed(__num ? __num : 3);
3679 if (!__is_failed(__err))
3682 __parts |= _ChronoParts::_TimeOfDay;
3687 __dayofyear = __read_unsigned(__num ? __num : 3);
3694 if (__mod ==
'E') [[unlikely]]
3696 else if (__mod ==
'O')
3699 __tmget.get(__is, {}, __is, __err, &__tm,
3701 if (!__is_failed(__err))
3702 __m = month(__tm.tm_mon + 1);
3706 auto __val = __read_unsigned(__num ? __num : 2);
3707 if (__val >= 1 && __val <= 12)
3712 __parts |= _ChronoParts::_Month;
3716 if (__mod ==
'E') [[unlikely]]
3718 else if (__mod ==
'O')
3721 __tmget.get(__is, {}, __is, __err, &__tm,
3723 if (!__is_failed(__err))
3728 auto __val = __read_unsigned(__num ? __num : 2);
3729 if (0 <= __val && __val < 60)
3733 if (_M_need & _ChronoParts::_TimeOfDay)
3738 __parts |= _ChronoParts::_TimeOfDay;
3748 const _CharT* __ampms[2];
3749 __tmpunct._M_am_pm(__ampms);
3750 int __n = 0, __which = 3;
3751 while (__which != 0)
3753 auto __i = __is.peek();
3754 if (_Traits::eq_int_type(__i, _Traits::eof()))
3764 else if (__ampms[0][__n + 1] == _CharT())
3775 else if (__ampms[1][__n + 1] == _CharT())
3786 if (__which == 0 || __which == 3)
3799 __tmget.get(__is, {}, __is, __err, &__tm,
3801 if (!__is_failed(__err))
3803 __h =
hours(__tm.tm_hour);
3808 __parts |= _ChronoParts::_TimeOfDay;
3813 if (__mod || __num) [[unlikely]]
3820 auto __val = __read_unsigned(2);
3821 if (__val == -1 || __val > 23) [[unlikely]]
3823 if (_M_need & _ChronoParts::_TimeOfDay)
3827 if (!__read_chr(
':')) [[unlikely]]
3831 __val = __read_unsigned(2);
3832 if (__val == -1 || __val > 60) [[unlikely]]
3834 if (_M_need & _ChronoParts::_TimeOfDay)
3842 __parts |= _ChronoParts::_TimeOfDay;
3845 else if (!__read_chr(
':')) [[unlikely]]
3851 if (__mod ==
'E') [[unlikely]]
3853 else if (__mod ==
'O')
3856 __tmget.get(__is, {}, __is, __err, &__tm,
3858 if (!__is_failed(__err))
3861 else if constexpr (_Duration::period::den == 1
3864 auto __val = __read_unsigned(__num ? __num : 2);
3865 if (0 <= __val && __val <= 59) [[likely]]
3869 if (_M_need & _ChronoParts::_TimeOfDay)
3876 basic_stringstream<_CharT> __buf;
3877 auto __digit = _S_try_read_digit(__is, __err);
3880 __buf.put(_CharT(
'0') + __digit);
3881 __digit = _S_try_read_digit(__is, __err);
3883 __buf.put(_CharT(
'0') + __digit);
3886 auto __i = __is.peek();
3887 if (_Traits::eq_int_type(__i, _Traits::eof()))
3895 __dp = __np.decimal_point();
3897 _CharT __c = _Traits::to_char_type(__i);
3903 = hh_mm_ss<_Duration>::fractional_width;
3906 __digit = _S_try_read_digit(__is, __err);
3908 __buf.put(_CharT(
'0') + __digit);
3916 if (!__is_failed(__err)) [[likely]]
3918 long double __val{};
3919#if __cpp_lib_to_chars
3921 auto __first = __str.data();
3922 auto __last = __first + __str.size();
3926 if ((
bool)ec || ptr != __last) [[unlikely]]
3934 if constexpr (__is_floating)
3941 __parts |= _ChronoParts::_TimeOfDay;
3946 if (__mod ==
'E') [[unlikely]]
3948 else if (__mod ==
'O')
3953 __tmget.get(__is, {}, __is, __err, &__tm,
3955 if (!__is_failed(__err))
3956 __wday = weekday(__tm.tm_wday);
3963 const int __lo = __c ==
'u' ? 1 : 0;
3964 const int __hi = __lo + 6;
3965 auto __val = __read_unsigned(__num ? __num : 1);
3966 if (__lo <= __val && __val <= __hi)
3967 __wday = weekday(__val);
3970 __wday = __bad_wday;
3974 __parts |= _ChronoParts::_Weekday;
3980 if (__mod ==
'E') [[unlikely]]
3982 else if (__mod ==
'O')
3984 if (__c ==
'V') [[unlikely]]
3994 const int __lo = __c ==
'V' ? 1 : 0;
3995 const int __hi = 53;
3996 auto __val = __read_unsigned(__num ? __num : 2);
3997 if (__lo <= __val && __val <= __hi)
4002 __sunday_wk = __val;
4008 __monday_wk = __val;
4013 __iso_wk = __sunday_wk = __monday_wk = -1;
4019 if (__mod ==
'O' || __num) [[unlikely]]
4024 __tmget.get(__is, {}, __is, __err, &__tm,
4025 __fmt - 2 - (__mod ==
'E'), __fmt);
4026 if (!__is_failed(__err))
4028 __y = year(__tm.tm_year + 1900);
4029 __m = month(__tm.tm_mon + 1);
4030 __d = day(__tm.tm_mday);
4033 __parts |= _ChronoParts::_Date;
4037 if (__mod ==
'O' || __num) [[unlikely]]
4042 __tmget.get(__is, {}, __is, __err, &__tm,
4043 __fmt - 2 - (__mod ==
'E'), __fmt);
4044 if (!__is_failed(__err))
4046 __h =
hours(__tm.tm_hour);
4051 __parts |= _ChronoParts::_TimeOfDay;
4055 if (__mod) [[unlikely]]
4058 __tmget.get(__is, {}, __is, __err, &__tm,
4060 if (!__is_failed(__err))
4062 int __cent = __tm.tm_year < 2000 ? 1900 : 2000;
4063 __yy = year(__tm.tm_year - __cent);
4064 if (__century == -1)
4070 auto __val = __read_unsigned(__num ? __num : 2);
4071 if (__val >= 0 && __val <= 99)
4074 if (__century == -1)
4075 __century = __val < 69 ? 2000 : 1900;
4078 __y = __yy = __iso_yy = __iso_y = __bad_y;
4080 __parts |= _ChronoParts::_Year;
4084 if (__mod ==
'O') [[unlikely]]
4086 else if (__mod ==
'E')
4089 __tmget.get(__is, {}, __is, __err, &__tm,
4091 if (!__is_failed(__err))
4092 __y = year(__tm.tm_year);
4096 auto __val = __read_unsigned(__num ? __num : 4);
4097 if (!__is_failed(__err))
4100 __parts |= _ChronoParts::_Year;
4104 if (__num) [[unlikely]]
4111 auto __i = __is.peek();
4112 if (_Traits::eq_int_type(__i, _Traits::eof()))
4117 _CharT __ic = _Traits::to_char_type(__i);
4118 const bool __neg = __ic == _CharT(
'-');
4119 if (__ic == _CharT(
'-') || __ic == _CharT(
'+'))
4126 __hh = __read_unsigned(2);
4131 __hh = 10 * _S_try_read_digit(__is, __err);
4132 __hh += _S_try_read_digit(__is, __err);
4135 if (__is_failed(__err))
4139 if (_Traits::eq_int_type(__i, _Traits::eof()))
4142 __tz_offset =
minutes(__hh * (__neg ? -60 : 60));
4145 __ic = _Traits::to_char_type(__i);
4147 bool __read_mm =
false;
4150 if (__ic == _GLIBCXX_WIDEN(
":")[0])
4157 else if (_CharT(
'0') <= __ic && __ic <= _CharT(
'9'))
4163 int_least32_t __mm = 0;
4166 __mm = 10 * _S_try_read_digit(__is, __err);
4167 __mm += _S_try_read_digit(__is, __err);
4170 if (!__is_failed(__err))
4172 auto __z = __hh * 60 + __mm;
4173 __tz_offset =
minutes(__neg ? -__z : __z);
4179 if (__mod || __num) [[unlikely]]
4183 basic_string_view<_CharT> __x = _GLIBCXX_WIDEN(
"_/-+");
4187 auto __i = __is.peek();
4188 if (!_Traits::eq_int_type(__i, _Traits::eof()))
4190 _CharT __a = _Traits::to_char_type(__i);
4192 || __x.find(__a) != __x.npos)
4194 __tz_abbr.push_back(__a);
4203 if (__tz_abbr.empty())
4209 if (__mod || __num) [[unlikely]]
4213 _CharT __i = __is.peek();
4214 if (_Traits::eq_int_type(__i, _Traits::eof()))
4216 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
4224 if (__mod || __num) [[unlikely]]
4228 _CharT __i = __is.peek();
4229 if (_Traits::eq_int_type(__i, _Traits::eof()))
4231 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
4237 if (__mod || __num) [[unlikely]]
4245 if (__mod || __num) [[unlikely]]
4254 if (_CharT(
'1') <= __c && __c <= _CharT(
'9'))
4256 if (!__mod) [[likely]]
4259 auto __end = __fmt + _Traits::length(__fmt);
4261 = __format::__parse_integer(__fmt - 1, __end);
4262 if (__ptr) [[likely]]
4273 if (__is_failed(__err)) [[unlikely]]
4283 if (__yy != __bad_y && __y == __bad_y)
4284 __y =
years(__century) + __yy;
4285 if (__iso_yy != __bad_y && __iso_y == __bad_y)
4286 __iso_y =
years(__century) + __iso_yy;
4289 bool __can_use_doy =
false;
4290 bool __can_use_iso_wk =
false;
4291 bool __can_use_sun_wk =
false;
4292 bool __can_use_mon_wk =
false;
4295 if (__y != __bad_y && __dayofyear >= 0)
4297 __can_use_doy =
true;
4298 __parts |= _ChronoParts::_Date;
4300 else if (__y != __bad_y && __wday != __bad_wday && __sunday_wk >= 0)
4302 __can_use_sun_wk =
true;
4303 __parts |= _ChronoParts::_Date;
4305 else if (__y != __bad_y && __wday != __bad_wday && __monday_wk >= 0)
4307 __can_use_mon_wk =
true;
4308 __parts |= _ChronoParts::_Date;
4310 else if (__iso_y != __bad_y && __wday != __bad_wday && __iso_wk > 0)
4313 __can_use_iso_wk =
true;
4314 __parts |= _ChronoParts::_Date;
4317 if (__is_failed(__err)) [[unlikely]]
4319 else if (__is_flag) [[unlikely]]
4321 else if ((_M_need & __parts) == _M_need) [[likely]]
4343 const bool __need_wday = _M_need & _ChronoParts::_Weekday;
4347 const bool __need_time = _M_need & _ChronoParts::_TimeOfDay;
4349 if (__need_wday && __wday != __bad_wday)
4351 else if (_M_need & _ChronoParts::_Date)
4355 const bool __need_ymd = !__need_wday && !__need_time;
4357 if ((_M_need & _ChronoParts::_Year && __y == __bad_y)
4358 || (_M_need & _ChronoParts::_Month && __m == __bad_mon)
4359 || (_M_need & _ChronoParts::_Day && __d == __bad_day))
4366 if ((0 < __dayofyear && __dayofyear <= 365)
4367 || (__dayofyear == 366 && __y.is_leap()))
4370 _M_sys_days = sys_days(__y/January/1)
4371 +
days(__dayofyear - 1);
4373 _M_ymd = year_month_day(_M_sys_days);
4378 else if (__can_use_iso_wk)
4386 const sys_days __jan4(__iso_y/January/4);
4387 weekday __wd1(__jan4 -
days(3));
4388 if (__wd1 != Thursday)
4389 if (__wd1 != Wednesday || !__iso_y.is_leap())
4393 if (!__is_failed(__err)) [[likely]]
4396 sys_days __w(Thursday[1]/January/__iso_y);
4398 __w -= Thursday - Monday;
4400 __w += __wday - Monday;
4404 _M_ymd = year_month_day(_M_sys_days);
4407 else if (__can_use_sun_wk)
4410 sys_days __wk1(__y/January/Sunday[1]);
4411 _M_sys_days = __wk1 +
weeks(__sunday_wk - 1)
4412 +
days(__wday.c_encoding());
4413 _M_ymd = year_month_day(_M_sys_days);
4414 if (_M_ymd.year() != __y) [[unlikely]]
4417 else if (__can_use_mon_wk)
4420 sys_days __wk1(__y/January/Monday[1]);
4421 _M_sys_days = __wk1 +
weeks(__monday_wk - 1)
4422 +
days(__wday.c_encoding() - 1);
4423 _M_ymd = year_month_day(_M_sys_days);
4424 if (_M_ymd.year() != __y) [[unlikely]]
4436 if (_M_need & _ChronoParts::_Year)
4438 if (!__y.ok()) [[unlikely]]
4441 else if (__y == __bad_y)
4444 if (_M_need & _ChronoParts::_Month)
4446 if (!__m.ok()) [[unlikely]]
4449 else if (__m == __bad_mon)
4452 if (_M_need & _ChronoParts::_Day)
4454 if (__d < day(1) || __d > (__y/__m/last).day())
4457 else if (__d == __bad_day)
4460 if (year_month_day __ymd(__y, __m, __d); __ymd.ok())
4463 if (__need_wday || __need_time)
4464 _M_sys_days = sys_days(_M_ymd);
4471 _M_wd = weekday(_M_sys_days);
4477 if (__h == __bad_h && __h12 != __bad_h)
4481 else if (__ampm == 2)
4482 __h = __h12 ==
hours(12) ? __h12 : __h12 +
hours(12);
4487 auto __t = _M_time.zero();
4496 if (__min != __bad_min)
4502 if (__s != __bad_sec)
4506 _M_is_leap_second = __s >=
seconds(60);
4515 if (!__is_failed(__err)) [[likely]]
4517 if (__offset && __tz_offset != __bad_min)
4518 *__offset = __tz_offset;
4519 if (__abbrev && !__tz_abbr.empty())
4527 __is.setstate(__err);
4531#undef _GLIBCXX_WIDEN
4536_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.