30#ifndef _GLIBCXX_CHRONO_IO_H
31#define _GLIBCXX_CHRONO_IO_H 1
33#pragma GCC system_header
35#if __cplusplus >= 202002L
46_GLIBCXX_BEGIN_NAMESPACE_VERSION
61 template<
typename _CharT>
70#define _GLIBCXX_WIDEN_(C, S) ::std::chrono::__detail::_Widen<C>(S, L##S)
71#define _GLIBCXX_WIDEN(S) _GLIBCXX_WIDEN_(_CharT, S)
73 template<
typename _Period,
typename _CharT>
80#define _GLIBCXX_UNITS_SUFFIX(period, suffix) \
81 if constexpr (is_same_v<_Period, period>) \
82 return _GLIBCXX_WIDEN(suffix); \
90#if _GLIBCXX_USE_ALT_MICROSECONDS_SUFFIX
112#undef _GLIBCXX_UNITS_SUFFIX
116 template<
typename _Period,
typename _CharT,
typename _Out>
120 if (
auto __s = __detail::__units_suffix<_Period, _CharT>();
__s.size())
122 else if constexpr (_Period::den == 1)
124 (uintmax_t)_Period::num);
127 (uintmax_t)_Period::num,
128 (uintmax_t)_Period::den);
137 template<
typename _CharT,
typename _Traits,
138 typename _Rep,
typename _Period>
144 using period =
typename _Period::type;
148 __s.precision(
__os.precision());
150 __detail::__fmt_units_suffix<period, _CharT>(_Out(
__s));
159 template<
typename _Duration>
163 const string* _M_abbrev;
180 template<
typename _Duration>
181 inline __detail::__local_time_fmt<_Duration>
193 [[noreturn,__gnu__::__always_inline__]]
195 __no_timezone_available()
196 { __throw_format_error(
"format error: no timezone available for %Z or %z"); }
198 [[noreturn,__gnu__::__always_inline__]]
200 __not_valid_for_duration()
201 { __throw_format_error(
"format error: chrono-format-spec not valid for "
202 "chrono::duration"); }
204 [[noreturn,__gnu__::__always_inline__]]
206 __invalid_chrono_spec()
207 { __throw_format_error(
"format error: chrono-format-spec not valid for "
210 template<
typename _CharT>
211 struct _ChronoSpec : _Spec<_CharT>
213 basic_string_view<_CharT> _M_chrono_specs;
220 _Year = 1, _Month = 2, _Day = 4, _Weekday = 8, _TimeOfDay = 16,
222 _Date = _Year | _Month | _Day | _Weekday,
223 _DateTime = _Date | _TimeOfDay,
224 _ZonedDateTime = _DateTime | _TimeZone,
228 constexpr _ChronoParts
229 operator|(_ChronoParts __x, _ChronoParts __y)
noexcept
230 {
return static_cast<_ChronoParts
>((int)__x | (
int)__y); }
232 constexpr _ChronoParts&
233 operator|=(_ChronoParts& __x, _ChronoParts __y)
noexcept
234 {
return __x = __x | __y; }
237 template<
typename _CharT>
238 struct __formatter_chrono
240 using __string_view = basic_string_view<_CharT>;
241 using __string = basic_string<_CharT>;
243 template<
typename _ParseContext>
244 constexpr typename _ParseContext::iterator
245 _M_parse(_ParseContext& __pc, _ChronoParts __parts)
247 auto __first = __pc.
begin();
248 auto __last = __pc.end();
250 _ChronoSpec<_CharT> __spec{};
252 auto __finalize = [
this, &__spec] {
256 auto __finished = [&] {
257 if (__first == __last || *__first ==
'}')
268 __first = __spec._M_parse_fill_and_align(__first, __last);
272 __first = __spec._M_parse_width(__first, __last, __pc);
276 if (__parts & _ChronoParts::_Duration)
278 __first = __spec._M_parse_precision(__first, __last, __pc);
283 __first = __spec._M_parse_locale(__first, __last);
290 __string_view __str(__first, __last - __first);
291 auto __end = __str.find(
'}');
292 if (__end != __str.npos)
294 __str.remove_suffix(__str.length() - __end);
295 __last = __first + __end;
297 if (__str.find(
'{') != __str.npos)
298 __throw_format_error(
"chrono format error: '{' in chrono-specs");
305 const auto __chrono_specs = __first++;
306 if (*__chrono_specs !=
'%')
307 __throw_format_error(
"chrono format error: no '%' at start of "
314 while (__first != __last)
316 enum _Mods { _Mod_none, _Mod_E, _Mod_O, _Mod_E_O };
317 _Mods __allowed_mods = _Mod_none;
319 _CharT __c = *__first++;
332 __needed = _DateTime;
333 __allowed_mods = _Mod_E;
337 __allowed_mods = _Mod_E;
342 __allowed_mods = _Mod_O;
354 __needed = _TimeOfDay;
355 __allowed_mods = _Mod_O;
358 if (!(__parts & _Duration))
363 __allowed_mods = _Mod_O;
366 __needed = _TimeOfDay;
367 __allowed_mods = _Mod_O;
373 __needed = _TimeOfDay;
377 __needed = _Duration;
380 __needed = _TimeOfDay;
381 __allowed_mods = _Mod_O;
386 __allowed_mods = _Mod_O;
392 __allowed_mods = _Mod_O;
396 __allowed_mods = _Mod_E;
399 __needed = _TimeOfDay;
400 __allowed_mods = _Mod_E;
404 __allowed_mods = _Mod_E_O;
408 __allowed_mods = _Mod_E;
411 __needed = _TimeZone;
412 __allowed_mods = _Mod_E_O;
415 __needed = _TimeZone;
423 if (__mod) [[unlikely]]
425 __allowed_mods = _Mod_none;
431 __throw_format_error(
"chrono format error: invalid "
432 " specifier in chrono-specs");
435 if ((__mod ==
'E' && !(__allowed_mods & _Mod_E))
436 || (__mod ==
'O' && !(__allowed_mods & _Mod_O)))
437 __throw_format_error(
"chrono format error: invalid "
438 " modifier in chrono-specs");
441 if ((__parts & __needed) != __needed)
442 __throw_format_error(
"chrono format error: format argument "
443 "does not contain the information "
444 "required by the chrono-specs");
447 size_t __pos = __string_view(__first, __last - __first).find(
'%');
452 if (__pos == __string_view::npos)
458 __first += __pos + 1;
463 if (__conv || __mod != _CharT())
464 __throw_format_error(
"chrono format error: unescaped '%' in "
468 _M_spec._M_chrono_specs
469 = __string_view(__chrono_specs, __first - __chrono_specs);
479 template<
typename _Tp,
typename _FormatContext>
480 typename _FormatContext::iterator
481 _M_format(
const _Tp& __t, _FormatContext& __fc,
482 bool __is_neg =
false)
const
484 auto __first = _M_spec._M_chrono_specs.begin();
485 const auto __last = _M_spec._M_chrono_specs.end();
486 if (__first == __last)
487 return _M_format_to_ostream(__t, __fc, __is_neg);
489 _Sink_iter<_CharT> __out;
490 __format::_Str_sink<_CharT> __sink;
491 bool __write_direct =
false;
492 if constexpr (is_same_v<
typename _FormatContext::iterator,
495 if (_M_spec._M_width_kind == __format::_WP_none)
498 __write_direct =
true;
501 __out = __sink.out();
504 __out = __sink.out();
508 if constexpr (__is_specialization_of<_Tp, chrono::hh_mm_ss>)
509 __is_neg = __t.is_negative();
511 auto __print_sign = [&__is_neg, &__out] {
512 if constexpr (chrono::__is_duration_v<_Tp>
513 || __is_specialization_of<_Tp, chrono::hh_mm_ss>)
516 *__out++ = _S_plus_minus[1];
523 constexpr const _CharT* __literals = _GLIBCXX_WIDEN(
"\n\t%");
530 _CharT __c = *__first++;
535 __out = _M_a_A(__t,
std::move(__out), __fc, __c ==
'A');
540 __out = _M_b_B(__t,
std::move(__out), __fc, __c ==
'B');
543 __out = _M_c(__t,
std::move(__out), __fc, __mod ==
'E');
548 __out = _M_C_y_Y(__t,
std::move(__out), __fc, __c, __mod);
552 __out = _M_d_e(__t,
std::move(__out), __fc, __c, __mod ==
'O');
555 __out = _M_D(__t,
std::move(__out), __fc);
558 __out = _M_F(__t,
std::move(__out), __fc);
562 __out = _M_g_G(__t,
std::move(__out), __fc, __c ==
'G');
566 __out = _M_H_I(__t, __print_sign(), __fc, __c, __mod ==
'O');
569 __out = _M_j(__t, __print_sign(), __fc);
572 __out = _M_m(__t,
std::move(__out), __fc, __mod ==
'O');
575 __out = _M_M(__t, __print_sign(), __fc, __mod ==
'O');
578 __out = _M_p(__t,
std::move(__out), __fc);
581 __out = _M_q(__t,
std::move(__out), __fc);
585 if constexpr (chrono::__is_duration_v<_Tp>)
589 __throw_format_error(
"chrono format error: argument is "
593 __out = _M_r(__t, __print_sign(), __fc);
597 __out = _M_R_T(__t, __print_sign(), __fc, __c ==
'T');
600 __out = _M_S(__t, __print_sign(), __fc, __mod ==
'O');
604 __out = _M_u_w(__t,
std::move(__out), __fc, __c, __mod ==
'O');
609 __out = _M_U_V_W(__t,
std::move(__out), __fc, __c,
613 __out = _M_x(__t,
std::move(__out), __fc, __mod ==
'E');
616 __out = _M_X(__t, __print_sign(), __fc, __mod ==
'E');
619 __out = _M_z(__t,
std::move(__out), __fc, (
bool)__mod);
622 __out = _M_Z(__t,
std::move(__out), __fc);
625 *__out++ = __literals[0];
628 *__out++ = __literals[1];
631 *__out++ = __literals[2];
643 __string_view __str(__first, __last - __first);
644 size_t __pos = __str.find(
'%');
649 if (__pos == __str.npos)
653 __str.remove_suffix(__str.length() - __pos);
654 __first += __pos + 1;
656 __out = __format::__write(
std::move(__out), __str);
659 while (__first != __last);
661 if constexpr (is_same_v<
typename _FormatContext::iterator,
667 return __format::__write_padded_as_spec(__str, __str.size(),
671 _ChronoSpec<_CharT> _M_spec;
675 template<
typename _FormatContext>
677 _M_locale(_FormatContext& __fc)
const
679 if (!_M_spec._M_localized)
682 return __fc.locale();
690 template<
typename _Tp,
typename _FormatContext>
691 typename _FormatContext::iterator
692 _M_format_to_ostream(
const _Tp& __t, _FormatContext& __fc,
695 using ::std::chrono::__detail::__utc_leap_second;
696 using ::std::chrono::__detail::__local_time_fmt;
698 if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
699 return _M_format_to_ostream(__t._M_time, __fc,
false);
702 basic_ostringstream<_CharT> __os;
703 __os.imbue(_M_locale(__fc));
705 if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
706 __os << __t._M_date <<
' ' << __t._M_time;
707 else if constexpr (chrono::__is_time_point_v<_Tp>)
714 if constexpr (is_convertible_v<_Tp, chrono::sys_days>)
715 __os << _S_date(__t);
718 auto __days = chrono::floor<chrono::days>(__t);
719 __os << chrono::year_month_day(__days) <<
' '
720 << chrono::hh_mm_ss(__t - __days);
725 if constexpr (chrono::__is_duration_v<_Tp>)
726 if (__is_neg) [[unlikely]]
727 __os << _S_plus_minus[1];
732 return __format::__write_padded_as_spec(__str, __str.size(),
737 static constexpr const _CharT* _S_chars
738 = _GLIBCXX_WIDEN(
"0123456789+-:/ {}");
739 static constexpr const _CharT* _S_plus_minus = _S_chars + 10;
740 static constexpr _CharT _S_colon = _S_chars[12];
741 static constexpr _CharT _S_slash = _S_chars[13];
742 static constexpr _CharT _S_space = _S_chars[14];
743 static constexpr const _CharT* _S_empty_spec = _S_chars + 15;
745 template<
typename _Tp,
typename _FormatContext>
746 typename _FormatContext::iterator
747 _M_a_A(
const _Tp& __t,
typename _FormatContext::iterator __out,
748 _FormatContext& __ctx,
bool __full)
const
752 chrono::weekday __wd = _S_weekday(__t);
754 __throw_format_error(
"format error: invalid weekday");
756 locale __loc = _M_locale(__ctx);
757 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
758 const _CharT* __days[7];
760 __tp._M_days(__days);
762 __tp._M_days_abbreviated(__days);
763 __string_view __str(__days[__wd.c_encoding()]);
764 return __format::__write(
std::move(__out), __str);
767 template<
typename _Tp,
typename _FormatContext>
768 typename _FormatContext::iterator
769 _M_b_B(
const _Tp& __t,
typename _FormatContext::iterator __out,
770 _FormatContext& __ctx,
bool __full)
const
774 chrono::month __m = _S_month(__t);
776 __throw_format_error(
"format error: invalid month");
777 locale __loc = _M_locale(__ctx);
778 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
779 const _CharT* __months[12];
781 __tp._M_months(__months);
783 __tp._M_months_abbreviated(__months);
784 __string_view __str(__months[(
unsigned)__m - 1]);
785 return __format::__write(
std::move(__out), __str);
788 template<
typename _Tp,
typename _FormatContext>
789 typename _FormatContext::iterator
790 _M_c(
const _Tp& __tt,
typename _FormatContext::iterator __out,
791 _FormatContext& __ctx,
bool __mod =
false)
const
796 basic_string<_CharT> __fmt;
797 auto __t = _S_floor_seconds(__tt);
798 locale __loc = _M_locale(__ctx);
799 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
800 const _CharT* __formats[2];
801 __tp._M_date_time_formats(__formats);
802 if (*__formats[__mod]) [[likely]]
804 __fmt = _GLIBCXX_WIDEN(
"{:L}");
805 __fmt.insert(3u, __formats[__mod]);
808 __fmt = _GLIBCXX_WIDEN(
"{:L%a %b %e %T %Y}");
813 template<
typename _Tp,
typename _FormatContext>
814 typename _FormatContext::iterator
815 _M_C_y_Y(
const _Tp& __t,
typename _FormatContext::iterator __out,
816 _FormatContext& __ctx, _CharT __conv, _CharT __mod = 0)
const
826 chrono::year __y = _S_year(__t);
828 if (__mod) [[unlikely]]
831 __tm.tm_year = (int)__y - 1900;
832 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
836 basic_string<_CharT> __s;
838 const bool __is_neg = __yi < 0;
839 __yi = __builtin_abs(__yi);
841 if (__conv ==
'Y' || __conv ==
'C')
843 int __ci = __yi / 100;
844 if (__is_neg) [[unlikely]]
846 __s.assign(1, _S_plus_minus[1]);
848 if (__conv ==
'C' && (__ci * 100) != __yi)
851 if (__ci >= 100) [[unlikely]]
853 __s += std::format(_S_empty_spec, __ci / 100);
856 __s += _S_two_digits(__ci);
859 if (__conv ==
'Y' || __conv ==
'y')
860 __s += _S_two_digits(__yi % 100);
862 return __format::__write(
std::move(__out), __string_view(__s));
865 template<
typename _Tp,
typename _FormatContext>
866 typename _FormatContext::iterator
867 _M_D(
const _Tp& __t,
typename _FormatContext::iterator __out,
868 _FormatContext&)
const
870 auto __ymd = _S_date(__t);
871 basic_string<_CharT> __s;
872#if ! _GLIBCXX_USE_CXX11_ABI
875 __s = _S_two_digits((
unsigned)__ymd.month());
877 __s += _S_two_digits((
unsigned)__ymd.day());
879 __s += _S_two_digits(__builtin_abs((
int)__ymd.year()) % 100);
880 return __format::__write(
std::move(__out), __string_view(__s));
883 template<
typename _Tp,
typename _FormatContext>
884 typename _FormatContext::iterator
885 _M_d_e(
const _Tp& __t,
typename _FormatContext::iterator __out,
886 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
893 chrono::day __d = _S_day(__t);
894 unsigned __i = (unsigned)__d;
896 if (__mod) [[unlikely]]
900 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
904 auto __sv = _S_two_digits(__i);
906 if (__conv == _CharT(
'e') && __i < 10)
912 return __format::__write(
std::move(__out), __sv);
915 template<
typename _Tp,
typename _FormatContext>
916 typename _FormatContext::iterator
917 _M_F(
const _Tp& __t,
typename _FormatContext::iterator __out,
918 _FormatContext&)
const
920 auto __ymd = _S_date(__t);
921 auto __s = std::format(_GLIBCXX_WIDEN(
"{:04d}- - "),
923 auto __sv = _S_two_digits((
unsigned)__ymd.month());
924 __s[__s.size() - 5] = __sv[0];
925 __s[__s.size() - 4] = __sv[1];
926 __sv = _S_two_digits((
unsigned)__ymd.day());
927 __s[__s.size() - 2] = __sv[0];
928 __s[__s.size() - 1] = __sv[1];
930 return __format::__write(
std::move(__out), __sv);
933 template<
typename _Tp,
typename _FormatContext>
934 typename _FormatContext::iterator
935 _M_g_G(
const _Tp& __t,
typename _FormatContext::iterator __out,
936 _FormatContext& __ctx,
bool __full)
const
940 using namespace chrono;
941 auto __d = _S_days(__t);
943 __d -= (weekday(__d) - Monday) -
days(3);
945 year __y = year_month_day(__d).year();
946 return _M_C_y_Y(__y,
std::move(__out), __ctx,
"yY"[__full]);
949 template<
typename _Tp,
typename _FormatContext>
950 typename _FormatContext::iterator
951 _M_H_I(
const _Tp& __t,
typename _FormatContext::iterator __out,
952 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
959 const auto __hms = _S_hms(__t);
960 int __i = __hms.hours().count();
962 if (__mod) [[unlikely]]
966 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
970 if (__conv == _CharT(
'I'))
977 return __format::__write(
std::move(__out), _S_two_digits(__i));
980 template<
typename _Tp,
typename _FormatContext>
981 typename _FormatContext::iterator
982 _M_j(
const _Tp& __t,
typename _FormatContext::iterator __out,
983 _FormatContext&)
const
985 if constexpr (chrono::__is_duration_v<_Tp>)
988 unsigned __d = chrono::duration_cast<chrono::days>(__t).count();
994 using namespace chrono;
995 auto __day = _S_days(__t);
996 auto __ymd = _S_date(__t);
1000 if constexpr (is_same_v<
typename decltype(__day)::clock, local_t>)
1001 __d = __day - local_days(__ymd.year()/January/0);
1003 __d = __day - sys_days(__ymd.year()/January/0);
1009 template<
typename _Tp,
typename _FormatContext>
1010 typename _FormatContext::iterator
1011 _M_m(
const _Tp& __t,
typename _FormatContext::iterator __out,
1012 _FormatContext& __ctx,
bool __mod)
const
1017 auto __m = _S_month(__t);
1018 auto __i = (unsigned)__m;
1020 if (__mod) [[unlikely]]
1023 __tm.tm_mon = __i - 1;
1024 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
1028 return __format::__write(
std::move(__out), _S_two_digits(__i));
1031 template<
typename _Tp,
typename _FormatContext>
1032 typename _FormatContext::iterator
1033 _M_M(
const _Tp& __t,
typename _FormatContext::iterator __out,
1034 _FormatContext& __ctx,
bool __mod)
const
1039 auto __m = _S_hms(__t).minutes();
1040 auto __i = __m.count();
1042 if (__mod) [[unlikely]]
1046 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
1050 return __format::__write(
std::move(__out), _S_two_digits(__i));
1053 template<
typename _Tp,
typename _FormatContext>
1054 typename _FormatContext::iterator
1055 _M_p(
const _Tp& __t,
typename _FormatContext::iterator __out,
1056 _FormatContext& __ctx)
const
1059 auto __hms = _S_hms(__t);
1060 locale __loc = _M_locale(__ctx);
1061 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1062 const _CharT* __ampm[2];
1063 __tp._M_am_pm(__ampm);
1065 __ampm[__hms.hours().count() >= 12]);
1068 template<
typename _Tp,
typename _FormatContext>
1069 typename _FormatContext::iterator
1070 _M_q(
const _Tp&,
typename _FormatContext::iterator __out,
1071 _FormatContext&)
const
1074 if constexpr (!chrono::__is_duration_v<_Tp>)
1075 __throw_format_error(
"format error: argument is not a duration");
1078 namespace __d = chrono::__detail;
1079 using period =
typename _Tp::period;
1080 return __d::__fmt_units_suffix<period, _CharT>(
std::move(__out));
1086 template<
typename _Tp,
typename _FormatContext>
1087 typename _FormatContext::iterator
1088 _M_r(
const _Tp& __tt,
typename _FormatContext::iterator __out,
1089 _FormatContext& __ctx)
const
1092 auto __t = _S_floor_seconds(__tt);
1093 locale __loc = _M_locale(__ctx);
1094 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1095 const _CharT* __ampm_fmt;
1096 __tp._M_am_pm_format(&__ampm_fmt);
1097 basic_string<_CharT> __fmt(_S_empty_spec);
1098 __fmt.insert(1u, 1u, _S_colon);
1099 __fmt.insert(2u, __ampm_fmt);
1104 template<
typename _Tp,
typename _FormatContext>
1105 typename _FormatContext::iterator
1106 _M_R_T(
const _Tp& __t,
typename _FormatContext::iterator __out,
1107 _FormatContext& __ctx,
bool __secs)
const
1111 auto __hms = _S_hms(__t);
1113 auto __s = std::format(_GLIBCXX_WIDEN(
"{:02d}:00"),
1114 __hms.hours().count());
1115 auto __sv = _S_two_digits(__hms.minutes().count());
1116 __s[__s.size() - 2] = __sv[0];
1117 __s[__s.size() - 1] = __sv[1];
1119 __out = __format::__write(
std::move(__out), __sv);
1122 *__out++ = _S_colon;
1123 __out = _M_S(__hms,
std::move(__out), __ctx);
1128 template<
typename _Tp,
typename _FormatContext>
1129 typename _FormatContext::iterator
1130 _M_S(
const _Tp& __t,
typename _FormatContext::iterator __out,
1131 _FormatContext& __ctx,
bool __mod =
false)
const
1135 auto __hms = _S_hms(__t);
1137 if (__mod) [[unlikely]]
1140 __tm.tm_sec = (int)__hms.seconds().count();
1141 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
1145 if constexpr (__hms.fractional_width == 0)
1146 __out = __format::__write(
std::move(__out),
1147 _S_two_digits(__hms.seconds().count()));
1150 locale __loc = _M_locale(__ctx);
1151 auto __s = __hms.seconds();
1152 auto __ss = __hms.subseconds();
1153 using rep =
typename decltype(__ss)::rep;
1154 if constexpr (is_floating_point_v<rep>)
1156 chrono::duration<rep> __fs = __s + __ss;
1158 _GLIBCXX_WIDEN(
"{:#0{}.{}Lf}"),
1160 3 + __hms.fractional_width,
1161 __hms.fractional_width);
1166 = use_facet<numpunct<_CharT>>(__loc);
1167 __out = __format::__write(
std::move(__out),
1168 _S_two_digits(__s.count()));
1169 *__out++ = __np.decimal_point();
1170 if constexpr (is_integral_v<rep>)
1172 _GLIBCXX_WIDEN(
"{:0{}}"),
1174 __hms.fractional_width);
1177 auto __str = std::format(_S_empty_spec, __ss.count());
1180 __hms.fractional_width);
1189 template<
typename _Tp,
typename _FormatContext>
1190 typename _FormatContext::iterator
1191 _M_u_w(
const _Tp& __t,
typename _FormatContext::iterator __out,
1192 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
1199 chrono::weekday __wd = _S_weekday(__t);
1201 if (__mod) [[unlikely]]
1204 __tm.tm_wday = __wd.c_encoding();
1205 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
1209 unsigned __wdi = __conv ==
'u' ? __wd.iso_encoding()
1210 : __wd.c_encoding();
1211 const _CharT __d = _S_digit(__wdi);
1212 return __format::__write(
std::move(__out), __string_view(&__d, 1));
1215 template<
typename _Tp,
typename _FormatContext>
1216 typename _FormatContext::iterator
1217 _M_U_V_W(
const _Tp& __t,
typename _FormatContext::iterator __out,
1218 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
1226 using namespace chrono;
1227 auto __d = _S_days(__t);
1228 using _TDays =
decltype(__d);
1230 if (__mod) [[unlikely]]
1232 const year_month_day __ymd(__d);
1233 const year __y = __ymd.year();
1235 __tm.tm_year = (int)__y - 1900;
1236 __tm.tm_yday = (__d - _TDays(__y/January/1)).count();
1237 __tm.tm_wday = weekday(__d).c_encoding();
1238 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
1246 __d -= (weekday(__d) - Monday) -
days(3);
1249 __first = _TDays(year_month_day(__d).year()/January/1);
1254 if constexpr (
requires { __t.year(); })
1257 __y = year_month_day(__d).year();
1258 const weekday __weekstart = __conv ==
'U' ? Sunday : Monday;
1259 __first = _TDays(__y/January/__weekstart[1]);
1261 auto __weeks = chrono::floor<weeks>(__d - __first);
1262 __string_view __sv = _S_two_digits(__weeks.count() + 1);
1263 return __format::__write(
std::move(__out), __sv);
1266 template<
typename _Tp,
typename _FormatContext>
1267 typename _FormatContext::iterator
1268 _M_x(
const _Tp& __t,
typename _FormatContext::iterator __out,
1269 _FormatContext& __ctx,
bool __mod =
false)
const
1273 locale __loc = _M_locale(__ctx);
1274 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1275 const _CharT* __date_reps[2];
1276 __tp._M_date_formats(__date_reps);
1277 const _CharT* __rep = __date_reps[__mod];
1279 return _M_D(__t,
std::move(__out), __ctx);
1281 basic_string<_CharT> __fmt(_S_empty_spec);
1282 __fmt.insert(1u, 1u, _S_colon);
1283 __fmt.insert(2u, __rep);
1288 template<
typename _Tp,
typename _FormatContext>
1289 typename _FormatContext::iterator
1290 _M_X(
const _Tp& __tt,
typename _FormatContext::iterator __out,
1291 _FormatContext& __ctx,
bool __mod =
false)
const
1295 auto __t = _S_floor_seconds(__tt);
1296 locale __loc = _M_locale(__ctx);
1297 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1298 const _CharT* __time_reps[2];
1299 __tp._M_time_formats(__time_reps);
1300 const _CharT* __rep = __time_reps[__mod];
1302 return _M_R_T(__t,
std::move(__out), __ctx,
true);
1304 basic_string<_CharT> __fmt(_S_empty_spec);
1305 __fmt.insert(1u, 1u, _S_colon);
1306 __fmt.insert(2u, __rep);
1311 template<
typename _Tp,
typename _FormatContext>
1312 typename _FormatContext::iterator
1313 _M_z(
const _Tp& __t,
typename _FormatContext::iterator __out,
1314 _FormatContext&,
bool __mod =
false)
const
1316 using ::std::chrono::__detail::__utc_leap_second;
1317 using ::std::chrono::__detail::__local_time_fmt;
1319 auto __utc = __mod ? __string_view(_GLIBCXX_WIDEN(
"+00:00"), 6)
1320 : __string_view(_GLIBCXX_WIDEN(
"+0000"), 5);
1322 if constexpr (chrono::__is_time_point_v<_Tp>)
1324 if constexpr (is_same_v<
typename _Tp::clock,
1325 chrono::system_clock>)
1326 return __format::__write(
std::move(__out), __utc);
1328 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1330 if (__t._M_offset_sec)
1333 basic_string<_CharT> __s;
1334 if (*__t._M_offset_sec != 0s)
1336 chrono:: hh_mm_ss __hms(*__t._M_offset_sec);
1337 __s = _S_plus_minus[__hms.is_negative()];
1338 __s += _S_two_digits(__hms.hours().count());
1341 __s += _S_two_digits(__hms.minutes().count());
1344 return __format::__write(
std::move(__out), __sv);
1347 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1348 return __format::__write(
std::move(__out), __utc);
1350 __no_timezone_available();
1353 template<
typename _Tp,
typename _FormatContext>
1354 typename _FormatContext::iterator
1355 _M_Z(
const _Tp& __t,
typename _FormatContext::iterator __out,
1356 _FormatContext& __ctx)
const
1358 using ::std::chrono::__detail::__utc_leap_second;
1359 using ::std::chrono::__detail::__local_time_fmt;
1361 __string_view __utc(_GLIBCXX_WIDEN(
"UTC"), 3);
1362 if constexpr (chrono::__is_time_point_v<_Tp>)
1364 if constexpr (is_same_v<
typename _Tp::clock,
1365 chrono::system_clock>)
1366 return __format::__write(
std::move(__out), __utc);
1368 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1372 string_view __sv = *__t._M_abbrev;
1373 if constexpr (is_same_v<_CharT, char>)
1374 return __format::__write(
std::move(__out), __sv);
1378 basic_string<_CharT> __ws(__sv.size(), _CharT());
1379 auto& __ct = use_facet<ctype<_CharT>>(_M_locale(__ctx));
1380 __ct.widen(__sv.begin(), __sv.end(), __ws.data());
1381 __string_view __wsv = __ws;
1382 return __format::__write(
std::move(__out), __wsv);
1386 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1387 return __format::__write(
std::move(__out), __utc);
1389 __no_timezone_available();
1396 _S_digit(
int __n)
noexcept
1399 return _GLIBCXX_WIDEN(
"0123456789999999")[__n & 0xf];
1403 static basic_string_view<_CharT>
1404 _S_two_digits(
int __n)
noexcept
1407 _GLIBCXX_WIDEN(
"0001020304050607080910111213141516171819"
1408 "2021222324252627282930313233343536373839"
1409 "4041424344454647484950515253545556575859"
1410 "6061626364656667686970717273747576777879"
1411 "8081828384858687888990919293949596979899"
1412 "9999999999999999999999999999999999999999"
1413 "9999999999999999") + 2 * (__n & 0x7f),
1421 template<
typename _Tp>
1422 static decltype(
auto)
1423 _S_hms(
const _Tp& __t)
1425 using ::std::chrono::__detail::__utc_leap_second;
1426 using ::std::chrono::__detail::__local_time_fmt;
1428 if constexpr (__is_specialization_of<_Tp, chrono::hh_mm_ss>)
1430 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1432 else if constexpr (chrono::__is_duration_v<_Tp>)
1433 return chrono::hh_mm_ss<_Tp>(__t);
1434 else if constexpr (chrono::__is_time_point_v<_Tp>)
1435 return chrono::hh_mm_ss(__t - chrono::floor<chrono::days>(__t));
1436 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1437 return _S_hms(__t._M_time);
1440 __invalid_chrono_spec();
1441 return chrono::hh_mm_ss<chrono::seconds>();
1446 template<
typename _Tp>
1448 _S_days(
const _Tp& __t)
1450 using namespace chrono;
1451 using ::std::chrono::__detail::__utc_leap_second;
1452 using ::std::chrono::__detail::__local_time_fmt;
1454 if constexpr (__is_time_point_v<_Tp>)
1455 return chrono::floor<days>(__t);
1456 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1458 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1459 return chrono::floor<days>(__t._M_time);
1460 else if constexpr (is_same_v<_Tp, year_month_day>
1461 || is_same_v<_Tp, year_month_day_last>
1462 || is_same_v<_Tp, year_month_weekday>
1463 || is_same_v<_Tp, year_month_weekday_last>)
1464 return sys_days(__t);
1467 if constexpr (__is_duration_v<_Tp>)
1468 __not_valid_for_duration();
1470 __invalid_chrono_spec();
1471 return chrono::sys_days();
1476 template<
typename _Tp>
1477 static chrono::year_month_day
1478 _S_date(
const _Tp& __t)
1480 if constexpr (is_same_v<_Tp, chrono::year_month_day>)
1483 return chrono::year_month_day(_S_days(__t));
1486 template<
typename _Tp>
1488 _S_day(
const _Tp& __t)
1490 using namespace chrono;
1492 if constexpr (is_same_v<_Tp, day>)
1494 else if constexpr (
requires { __t.day(); })
1497 return _S_date(__t).day();
1500 template<
typename _Tp>
1501 static chrono::month
1502 _S_month(
const _Tp& __t)
1504 using namespace chrono;
1506 if constexpr (is_same_v<_Tp, month>)
1508 else if constexpr (
requires { __t.month(); })
1511 return _S_date(__t).month();
1514 template<
typename _Tp>
1516 _S_year(
const _Tp& __t)
1518 using namespace chrono;
1520 if constexpr (is_same_v<_Tp, year>)
1522 else if constexpr (
requires { __t.year(); })
1525 return _S_date(__t).year();
1528 template<
typename _Tp>
1529 static chrono::weekday
1530 _S_weekday(
const _Tp& __t)
1533 using ::std::chrono::__detail::__local_time_fmt;
1535 if constexpr (is_same_v<_Tp, weekday>)
1537 else if constexpr (
requires { __t.weekday(); })
1539 else if constexpr (is_same_v<_Tp, month_weekday>)
1540 return __t.weekday_indexed().weekday();
1541 else if constexpr (is_same_v<_Tp, month_weekday_last>)
1542 return __t.weekday_last().weekday();
1544 return weekday(_S_days(__t));
1548 template<
typename _Tp>
1550 _S_floor_seconds(
const _Tp& __t)
1552 using chrono::__detail::__local_time_fmt;
1553 if constexpr (chrono::__is_time_point_v<_Tp>
1554 || chrono::__is_duration_v<_Tp>)
1556 if constexpr (_Tp::period::den != 1)
1557 return chrono::floor<chrono::seconds>(__t);
1561 else if constexpr (__is_specialization_of<_Tp, chrono::hh_mm_ss>)
1563 if constexpr (_Tp::fractional_width != 0)
1564 return chrono::floor<chrono::seconds>(__t.to_duration());
1568 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1569 return _S_floor_seconds(__t._M_time);
1576 template<
typename _Iter>
1578 _M_locale_fmt(_Iter __out,
const locale& __loc,
const struct tm& __tm,
1579 char __fmt,
char __mod)
const
1581 basic_ostringstream<_CharT> __os;
1582 const auto& __tp = use_facet<time_put<_CharT>>(__loc);
1583 __tp.put(__os, __os, _S_space, &__tm, __fmt, __mod);
1585 __out = __format::__write(
std::move(__out), __os.view());
1593 template<
typename _Rep,
typename _Period,
typename _CharT>
1594 struct formatter<chrono::duration<_Rep, _Period>, _CharT>
1596 constexpr typename basic_format_parse_context<_CharT>::iterator
1597 parse(basic_format_parse_context<_CharT>& __pc)
1599 using namespace __format;
1600 auto __it = _M_f._M_parse(__pc, _Duration|_TimeOfDay);
1601 if constexpr (!is_floating_point_v<_Rep>)
1602 if (_M_f._M_spec._M_prec_kind != __format::_WP_none)
1603 __throw_format_error(
"format error: invalid precision for duration");
1607 template<
typename _Out>
1608 typename basic_format_context<_Out, _CharT>::iterator
1609 format(
const chrono::duration<_Rep, _Period>& __d,
1610 basic_format_context<_Out, _CharT>& __fc)
const
1613 if (__d < __d.zero()) [[unlikely]]
1615 if constexpr (is_integral_v<_Rep>)
1619 using _URep = make_unsigned_t<_Rep>;
1620 auto __ucnt = -
static_cast<_URep
>(__d.count());
1621 auto __ud = chrono::duration<_URep, _Period>(__ucnt);
1622 return _M_f._M_format(__ud, __fc,
true);
1625 return _M_f._M_format(-__d, __fc,
true);
1627 return _M_f._M_format(__d, __fc,
false);
1631 __format::__formatter_chrono<_CharT> _M_f;
1634 template<
typename _CharT>
1635 struct formatter<chrono::day, _CharT>
1637 template<
typename _ParseContext>
1638 constexpr typename _ParseContext::iterator
1639 parse(_ParseContext& __pc)
1640 {
return _M_f._M_parse(__pc, __format::_Day); }
1642 template<
typename _FormatContext>
1643 typename _FormatContext::iterator
1644 format(
const chrono::day& __t, _FormatContext& __fc)
const
1645 {
return _M_f._M_format(__t, __fc); }
1648 __format::__formatter_chrono<_CharT> _M_f;
1651 template<
typename _CharT>
1652 struct formatter<chrono::month, _CharT>
1654 template<
typename _ParseContext>
1655 constexpr typename _ParseContext::iterator
1656 parse(_ParseContext& __pc)
1657 {
return _M_f._M_parse(__pc, __format::_Month); }
1659 template<
typename _FormatContext>
1660 typename _FormatContext::iterator
1661 format(
const chrono::month& __t, _FormatContext& __fc)
const
1662 {
return _M_f._M_format(__t, __fc); }
1665 __format::__formatter_chrono<_CharT> _M_f;
1668 template<
typename _CharT>
1669 struct formatter<chrono::year, _CharT>
1671 template<
typename _ParseContext>
1672 constexpr typename _ParseContext::iterator
1673 parse(_ParseContext& __pc)
1674 {
return _M_f._M_parse(__pc, __format::_Year); }
1676 template<
typename _FormatContext>
1677 typename _FormatContext::iterator
1678 format(
const chrono::year& __t, _FormatContext& __fc)
const
1679 {
return _M_f._M_format(__t, __fc); }
1682 __format::__formatter_chrono<_CharT> _M_f;
1685 template<
typename _CharT>
1686 struct formatter<chrono::weekday, _CharT>
1688 template<
typename _ParseContext>
1689 constexpr typename _ParseContext::iterator
1690 parse(_ParseContext& __pc)
1691 {
return _M_f._M_parse(__pc, __format::_Weekday); }
1693 template<
typename _FormatContext>
1694 typename _FormatContext::iterator
1695 format(
const chrono::weekday& __t, _FormatContext& __fc)
const
1696 {
return _M_f._M_format(__t, __fc); }
1699 __format::__formatter_chrono<_CharT> _M_f;
1702 template<
typename _CharT>
1703 struct formatter<chrono::weekday_indexed, _CharT>
1705 template<
typename _ParseContext>
1706 constexpr typename _ParseContext::iterator
1707 parse(_ParseContext& __pc)
1708 {
return _M_f._M_parse(__pc, __format::_Weekday); }
1710 template<
typename _FormatContext>
1711 typename _FormatContext::iterator
1712 format(
const chrono::weekday_indexed& __t, _FormatContext& __fc)
const
1713 {
return _M_f._M_format(__t, __fc); }
1716 __format::__formatter_chrono<_CharT> _M_f;
1719 template<
typename _CharT>
1720 struct formatter<chrono::weekday_last, _CharT>
1722 template<
typename _ParseContext>
1723 constexpr typename _ParseContext::iterator
1724 parse(_ParseContext& __pc)
1725 {
return _M_f._M_parse(__pc, __format::_Weekday); }
1727 template<
typename _FormatContext>
1728 typename _FormatContext::iterator
1729 format(
const chrono::weekday_last& __t, _FormatContext& __fc)
const
1730 {
return _M_f._M_format(__t, __fc); }
1733 __format::__formatter_chrono<_CharT> _M_f;
1736 template<
typename _CharT>
1737 struct formatter<chrono::month_day, _CharT>
1739 template<
typename _ParseContext>
1740 constexpr typename _ParseContext::iterator
1741 parse(_ParseContext& __pc)
1742 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Day); }
1744 template<
typename _FormatContext>
1745 typename _FormatContext::iterator
1746 format(
const chrono::month_day& __t, _FormatContext& __fc)
const
1747 {
return _M_f._M_format(__t, __fc); }
1750 __format::__formatter_chrono<_CharT> _M_f;
1753 template<
typename _CharT>
1754 struct formatter<chrono::month_day_last, _CharT>
1756 template<
typename _ParseContext>
1757 constexpr typename _ParseContext::iterator
1758 parse(_ParseContext& __pc)
1759 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Day); }
1761 template<
typename _FormatContext>
1762 typename _FormatContext::iterator
1763 format(
const chrono::month_day_last& __t, _FormatContext& __fc)
const
1764 {
return _M_f._M_format(__t, __fc); }
1767 __format::__formatter_chrono<_CharT> _M_f;
1770 template<
typename _CharT>
1771 struct formatter<chrono::month_weekday, _CharT>
1773 template<
typename _ParseContext>
1774 constexpr typename _ParseContext::iterator
1775 parse(_ParseContext& __pc)
1776 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Weekday); }
1778 template<
typename _FormatContext>
1779 typename _FormatContext::iterator
1780 format(
const chrono::month_weekday& __t, _FormatContext& __fc)
const
1781 {
return _M_f._M_format(__t, __fc); }
1784 __format::__formatter_chrono<_CharT> _M_f;
1787 template<
typename _CharT>
1788 struct formatter<chrono::month_weekday_last, _CharT>
1790 template<
typename _ParseContext>
1791 constexpr typename _ParseContext::iterator
1792 parse(_ParseContext& __pc)
1793 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Weekday); }
1795 template<
typename _FormatContext>
1796 typename _FormatContext::iterator
1797 format(
const chrono::month_weekday_last& __t,
1798 _FormatContext& __fc)
const
1799 {
return _M_f._M_format(__t, __fc); }
1802 __format::__formatter_chrono<_CharT> _M_f;
1805 template<
typename _CharT>
1806 struct formatter<chrono::year_month, _CharT>
1808 template<
typename _ParseContext>
1809 constexpr typename _ParseContext::iterator
1810 parse(_ParseContext& __pc)
1811 {
return _M_f._M_parse(__pc, __format::_Year|__format::_Month); }
1813 template<
typename _FormatContext>
1814 typename _FormatContext::iterator
1815 format(
const chrono::year_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_month_day, _CharT>
1825 template<
typename _ParseContext>
1826 constexpr typename _ParseContext::iterator
1827 parse(_ParseContext& __pc)
1828 {
return _M_f._M_parse(__pc, __format::_Date); }
1830 template<
typename _FormatContext>
1831 typename _FormatContext::iterator
1832 format(
const chrono::year_month_day& __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::year_month_day_last, _CharT>
1842 template<
typename _ParseContext>
1843 constexpr typename _ParseContext::iterator
1844 parse(_ParseContext& __pc)
1845 {
return _M_f._M_parse(__pc, __format::_Date); }
1847 template<
typename _FormatContext>
1848 typename _FormatContext::iterator
1849 format(
const chrono::year_month_day_last& __t,
1850 _FormatContext& __fc)
const
1851 {
return _M_f._M_format(__t, __fc); }
1854 __format::__formatter_chrono<_CharT> _M_f;
1857 template<
typename _CharT>
1858 struct formatter<chrono::year_month_weekday, _CharT>
1860 template<
typename _ParseContext>
1861 constexpr typename _ParseContext::iterator
1862 parse(_ParseContext& __pc)
1863 {
return _M_f._M_parse(__pc, __format::_Date); }
1865 template<
typename _FormatContext>
1866 typename _FormatContext::iterator
1867 format(
const chrono::year_month_weekday& __t,
1868 _FormatContext& __fc)
const
1869 {
return _M_f._M_format(__t, __fc); }
1872 __format::__formatter_chrono<_CharT> _M_f;
1875 template<
typename _CharT>
1876 struct formatter<chrono::year_month_weekday_last, _CharT>
1878 template<
typename _ParseContext>
1879 constexpr typename _ParseContext::iterator
1880 parse(_ParseContext& __pc)
1881 {
return _M_f._M_parse(__pc, __format::_Date); }
1883 template<
typename _FormatContext>
1884 typename _FormatContext::iterator
1885 format(
const chrono::year_month_weekday_last& __t,
1886 _FormatContext& __fc)
const
1887 {
return _M_f._M_format(__t, __fc); }
1890 __format::__formatter_chrono<_CharT> _M_f;
1893 template<
typename _Rep,
typename _Period,
typename _CharT>
1894 struct formatter<chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>, _CharT>
1896 template<
typename _ParseContext>
1897 constexpr typename _ParseContext::iterator
1898 parse(_ParseContext& __pc)
1899 {
return _M_f._M_parse(__pc, __format::_TimeOfDay); }
1901 template<
typename _FormatContext>
1902 typename _FormatContext::iterator
1903 format(
const chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>& __t,
1904 _FormatContext& __fc)
const
1905 {
return _M_f._M_format(__t, __fc); }
1908 __format::__formatter_chrono<_CharT> _M_f;
1911#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
1912 template<
typename _CharT>
1913 struct formatter<chrono::sys_info, _CharT>
1915 template<
typename _ParseContext>
1916 constexpr typename _ParseContext::iterator
1917 parse(_ParseContext& __pc)
1918 {
return _M_f._M_parse(__pc, __format::_ChronoParts{}); }
1920 template<
typename _FormatContext>
1921 typename _FormatContext::iterator
1922 format(
const chrono::sys_info& __i, _FormatContext& __fc)
const
1923 {
return _M_f._M_format(__i, __fc); }
1926 __format::__formatter_chrono<_CharT> _M_f;
1929 template<
typename _CharT>
1930 struct formatter<chrono::local_info, _CharT>
1932 template<
typename _ParseContext>
1933 constexpr typename _ParseContext::iterator
1934 parse(_ParseContext& __pc)
1935 {
return _M_f._M_parse(__pc, __format::_ChronoParts{}); }
1937 template<
typename _FormatContext>
1938 typename _FormatContext::iterator
1939 format(
const chrono::local_info& __i, _FormatContext& __fc)
const
1940 {
return _M_f._M_format(__i, __fc); }
1943 __format::__formatter_chrono<_CharT> _M_f;
1947 template<
typename _Duration,
typename _CharT>
1948 struct formatter<chrono::sys_time<_Duration>, _CharT>
1950 template<
typename _ParseContext>
1951 constexpr typename _ParseContext::iterator
1952 parse(_ParseContext& __pc)
1954 auto __next = _M_f._M_parse(__pc, __format::_ZonedDateTime);
1955 if constexpr (!__stream_insertable)
1956 if (_M_f._M_spec._M_chrono_specs.empty())
1957 __format::__invalid_chrono_spec();
1961 template<
typename _FormatContext>
1962 typename _FormatContext::iterator
1963 format(
const chrono::sys_time<_Duration>& __t,
1964 _FormatContext& __fc)
const
1965 {
return _M_f._M_format(__t, __fc); }
1968 static constexpr bool __stream_insertable
1969 =
requires (basic_ostream<_CharT>& __os,
1970 chrono::sys_time<_Duration> __t) { __os << __t; };
1972 __format::__formatter_chrono<_CharT> _M_f;
1975 template<
typename _Duration,
typename _CharT>
1976 struct formatter<chrono::utc_time<_Duration>, _CharT>
1977 : __format::__formatter_chrono<_CharT>
1979 template<
typename _ParseContext>
1980 constexpr typename _ParseContext::iterator
1981 parse(_ParseContext& __pc)
1982 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
1984 template<
typename _FormatContext>
1985 typename _FormatContext::iterator
1986 format(
const chrono::utc_time<_Duration>& __t,
1987 _FormatContext& __fc)
const
1992 using chrono::__detail::__utc_leap_second;
1994 using chrono::sys_time;
1995 using _CDur = common_type_t<_Duration, seconds>;
1996 const auto __li = chrono::get_leap_second_info(__t);
1997 sys_time<_CDur> __s{__t.time_since_epoch() - __li.elapsed};
1998 if (!__li.is_leap_second) [[likely]]
1999 return _M_f._M_format(__s, __fc);
2001 return _M_f._M_format(__utc_leap_second(__s), __fc);
2005 friend formatter<chrono::__detail::__utc_leap_second<_Duration>, _CharT>;
2007 __format::__formatter_chrono<_CharT> _M_f;
2010 template<
typename _Duration,
typename _CharT>
2011 struct formatter<chrono::tai_time<_Duration>, _CharT>
2012 : __format::__formatter_chrono<_CharT>
2014 template<
typename _ParseContext>
2015 constexpr typename _ParseContext::iterator
2016 parse(_ParseContext& __pc)
2017 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2019 template<
typename _FormatContext>
2020 typename _FormatContext::iterator
2021 format(
const chrono::tai_time<_Duration>& __t,
2022 _FormatContext& __fc)
const
2028 using _CDur = common_type_t<_Duration, chrono::days>;
2029 chrono::local_time<_CDur> __lt(__t.time_since_epoch() - __tai_offset);
2030 const string __abbrev(
"TAI", 3);
2033 return _M_f._M_format(__lf, __fc);
2037 __format::__formatter_chrono<_CharT> _M_f;
2040 template<
typename _Duration,
typename _CharT>
2041 struct formatter<chrono::gps_time<_Duration>, _CharT>
2042 : __format::__formatter_chrono<_CharT>
2044 template<
typename _ParseContext>
2045 constexpr typename _ParseContext::iterator
2046 parse(_ParseContext& __pc)
2047 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2049 template<
typename _FormatContext>
2050 typename _FormatContext::iterator
2051 format(
const chrono::gps_time<_Duration>& __t,
2052 _FormatContext& __fc)
const
2058 using _CDur = common_type_t<_Duration, chrono::days>;
2059 chrono::local_time<_CDur> __lt(__t.time_since_epoch() + __gps_offset);
2060 const string __abbrev(
"GPS", 3);
2063 return _M_f._M_format(__lf, __fc);
2067 __format::__formatter_chrono<_CharT> _M_f;
2070 template<
typename _Duration,
typename _CharT>
2071 struct formatter<chrono::file_time<_Duration>, _CharT>
2073 template<
typename _ParseContext>
2074 constexpr typename _ParseContext::iterator
2075 parse(_ParseContext& __pc)
2076 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2078 template<
typename _FormatContext>
2079 typename _FormatContext::iterator
2080 format(
const chrono::file_time<_Duration>& __t,
2081 _FormatContext& __ctx)
const
2083 using namespace chrono;
2084 return _M_f._M_format(chrono::clock_cast<system_clock>(__t), __ctx);
2088 __format::__formatter_chrono<_CharT> _M_f;
2091 template<
typename _Duration,
typename _CharT>
2092 struct formatter<chrono::local_time<_Duration>, _CharT>
2094 template<
typename _ParseContext>
2095 constexpr typename _ParseContext::iterator
2096 parse(_ParseContext& __pc)
2097 {
return _M_f._M_parse(__pc, __format::_DateTime); }
2099 template<
typename _FormatContext>
2100 typename _FormatContext::iterator
2101 format(
const chrono::local_time<_Duration>& __t,
2102 _FormatContext& __ctx)
const
2103 {
return _M_f._M_format(__t, __ctx); }
2106 __format::__formatter_chrono<_CharT> _M_f;
2109 template<
typename _Duration,
typename _CharT>
2110 struct formatter<chrono::__detail::__local_time_fmt<_Duration>, _CharT>
2112 template<
typename _ParseContext>
2113 constexpr typename _ParseContext::iterator
2114 parse(_ParseContext& __pc)
2115 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2117 template<
typename _FormatContext>
2118 typename _FormatContext::iterator
2119 format(
const chrono::__detail::__local_time_fmt<_Duration>& __t,
2120 _FormatContext& __ctx)
const
2121 {
return _M_f._M_format(__t, __ctx); }
2124 __format::__formatter_chrono<_CharT> _M_f;
2127#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2128 template<
typename _Duration,
typename _TimeZonePtr,
typename _CharT>
2129 struct formatter<chrono::zoned_time<_Duration, _TimeZonePtr>, _CharT>
2130 : formatter<chrono::__detail::__local_time_fmt<_Duration>, _CharT>
2132 template<
typename _FormatContext>
2133 typename _FormatContext::iterator
2134 format(
const chrono::zoned_time<_Duration, _TimeZonePtr>& __tp,
2135 _FormatContext& __ctx)
const
2137 using chrono::__detail::__local_time_fmt;
2138 using _Base = formatter<__local_time_fmt<_Duration>, _CharT>;
2139 const chrono::sys_info __info = __tp.get_info();
2143 return _Base::format(__lf, __ctx);
2149 template<
typename _Duration,
typename _CharT>
2150 struct formatter<chrono::__detail::__utc_leap_second<_Duration>, _CharT>
2151 : formatter<chrono::utc_time<_Duration>, _CharT>
2153 template<
typename _FormatContext>
2154 typename _FormatContext::iterator
2155 format(
const chrono::__detail::__utc_leap_second<_Duration>& __t,
2156 _FormatContext& __fc)
const
2157 {
return this->_M_f._M_format(__t, __fc); }
2168 template<
typename _Duration = seconds>
2171 static_assert(is_same_v<common_type_t<_Duration, seconds>, _Duration>);
2174 _Parser(__format::_ChronoParts __need) : _M_need(__need) { }
2176 _Parser(_Parser&&) =
delete;
2177 void operator=(_Parser&&) =
delete;
2179 _Duration _M_time{};
2180 sys_days _M_sys_days{};
2181 year_month_day _M_ymd{};
2183 __format::_ChronoParts _M_need;
2184 unsigned _M_is_leap_second : 1 {};
2185 unsigned _M_reserved : 15 {};
2187 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2188 basic_istream<_CharT, _Traits>&
2189 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2190 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2191 minutes* __offset =
nullptr);
2196 template<
typename _CharT,
typename _Traits>
2197 static int_least32_t
2198 _S_read_unsigned(basic_istream<_CharT, _Traits>& __is,
2199 ios_base::iostate& __err,
int __n)
2201 int_least32_t __val = _S_try_read_digit(__is, __err);
2202 if (__val == -1) [[unlikely]]
2203 __err |= ios_base::failbit;
2208 for (
int __i = 1; __i < __n1; ++__i)
2209 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
2215 while (__n1++ < __n) [[unlikely]]
2216 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
2218 if (__builtin_mul_overflow(__val, 10, &__val)
2219 || __builtin_add_overflow(__val, __dig, &__val))
2221 __err |= ios_base::failbit;
2231 template<
typename _CharT,
typename _Traits>
2232 static int_least32_t
2233 _S_read_signed(basic_istream<_CharT, _Traits>& __is,
2234 ios_base::iostate& __err,
int __n)
2236 auto __sign = __is.peek();
2237 if (__sign ==
'-' || __sign ==
'+')
2239 int_least32_t __val = _S_read_unsigned(__is, __err, __n);
2240 if (__err & ios_base::failbit)
2242 if (__sign ==
'-') [[unlikely]]
2250 template<
typename _CharT,
typename _Traits>
2251 static int_least32_t
2252 _S_try_read_digit(basic_istream<_CharT, _Traits>& __is,
2253 ios_base::iostate& __err)
2255 int_least32_t __val = -1;
2256 auto __i = __is.peek();
2257 if (!_Traits::eq_int_type(__i, _Traits::eof())) [[likely]]
2259 _CharT __c = _Traits::to_char_type(__i);
2260 if (_CharT(
'0') <= __c && __c <= _CharT(
'9')) [[likely]]
2263 __val = __c - _CharT(
'0');
2267 __err |= ios_base::eofbit;
2273 template<
typename _CharT,
typename _Traits>
2275 _S_read_chr(basic_istream<_CharT, _Traits>& __is,
2276 ios_base::iostate& __err, _CharT __c)
2278 auto __i = __is.peek();
2279 if (_Traits::eq_int_type(__i, _Traits::eof()))
2280 __err |= ios_base::eofbit;
2281 else if (_Traits::to_char_type(__i) == __c) [[likely]]
2286 __err |= ios_base::failbit;
2291 template<
typename _Duration>
2292 using _Parser_t = _Parser<common_type_t<_Duration, seconds>>;
2297 template<
typename _CharT,
typename _Traits,
typename _Rep,
typename _Period,
2298 typename _Alloc = allocator<_CharT>>
2299 inline basic_istream<_CharT, _Traits>&
2300 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2301 duration<_Rep, _Period>& __d,
2302 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2305 auto __need = __format::_ChronoParts::_TimeOfDay;
2306 __detail::_Parser_t<duration<_Rep, _Period>> __p(__need);
2307 if (__p(__is, __fmt, __abbrev, __offset))
2308 __d = chrono::duration_cast<duration<_Rep, _Period>>(__p._M_time);
2312 template<
typename _CharT,
typename _Traits>
2313 inline basic_ostream<_CharT, _Traits>&
2314 operator<<(basic_ostream<_CharT, _Traits>& __os,
const day& __d)
2316 using _Ctx = __format::__format_context<_CharT>;
2317 using _Str = basic_string_view<_CharT>;
2318 _Str __s = _GLIBCXX_WIDEN(
"{:02d} is not a valid day");
2320 __s = __s.substr(0, 6);
2321 auto __u = (unsigned)__d;
2322 __os << std::vformat(__s, make_format_args<_Ctx>(__u));
2326 template<
typename _CharT,
typename _Traits,
2327 typename _Alloc = allocator<_CharT>>
2328 inline basic_istream<_CharT, _Traits>&
2329 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2331 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2334 __detail::_Parser<> __p(__format::_ChronoParts::_Day);
2335 if (__p(__is, __fmt, __abbrev, __offset))
2336 __d = __p._M_ymd.day();
2340 template<
typename _CharT,
typename _Traits>
2341 inline basic_ostream<_CharT, _Traits>&
2342 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month& __m)
2344 using _Ctx = __format::__format_context<_CharT>;
2345 using _Str = basic_string_view<_CharT>;
2346 _Str __s = _GLIBCXX_WIDEN(
"{:L%b}{} is not a valid month");
2349 make_format_args<_Ctx>(__m));
2352 auto __u = (unsigned)__m;
2353 __os <<
std::vformat(__s.substr(6), make_format_args<_Ctx>(__u));
2358 template<
typename _CharT,
typename _Traits,
2359 typename _Alloc = allocator<_CharT>>
2360 inline basic_istream<_CharT, _Traits>&
2361 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2363 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2366 __detail::_Parser<> __p(__format::_ChronoParts::_Month);
2367 if (__p(__is, __fmt, __abbrev, __offset))
2368 __m = __p._M_ymd.month();
2372 template<
typename _CharT,
typename _Traits>
2373 inline basic_ostream<_CharT, _Traits>&
2374 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year& __y)
2376 using _Ctx = __format::__format_context<_CharT>;
2377 using _Str = basic_string_view<_CharT>;
2378 _Str __s = _GLIBCXX_WIDEN(
"-{:04d} is not a valid year");
2380 __s = __s.substr(0, 7);
2382 if (__i >= 0) [[likely]]
2383 __s.remove_prefix(1);
2386 __os << std::vformat(__s, make_format_args<_Ctx>(__i));
2390 template<
typename _CharT,
typename _Traits,
2391 typename _Alloc = allocator<_CharT>>
2392 inline basic_istream<_CharT, _Traits>&
2393 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2395 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2398 __detail::_Parser<> __p(__format::_ChronoParts::_Year);
2399 if (__p(__is, __fmt, __abbrev, __offset))
2400 __y = __p._M_ymd.year();
2404 template<
typename _CharT,
typename _Traits>
2405 inline basic_ostream<_CharT, _Traits>&
2406 operator<<(basic_ostream<_CharT, _Traits>& __os,
const weekday& __wd)
2408 using _Ctx = __format::__format_context<_CharT>;
2409 using _Str = basic_string_view<_CharT>;
2410 _Str __s = _GLIBCXX_WIDEN(
"{:L%a}{} is not a valid weekday");
2413 make_format_args<_Ctx>(__wd));
2416 auto __c = __wd.c_encoding();
2417 __os <<
std::vformat(__s.substr(6), make_format_args<_Ctx>(__c));
2422 template<
typename _CharT,
typename _Traits,
2423 typename _Alloc = allocator<_CharT>>
2424 inline basic_istream<_CharT, _Traits>&
2425 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2427 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2430 __detail::_Parser<> __p(__format::_ChronoParts::_Weekday);
2431 if (__p(__is, __fmt, __abbrev, __offset))
2436 template<
typename _CharT,
typename _Traits>
2437 inline basic_ostream<_CharT, _Traits>&
2438 operator<<(basic_ostream<_CharT, _Traits>& __os,
2439 const weekday_indexed& __wdi)
2444 basic_stringstream<_CharT> __os2;
2445 __os2.imbue(__os.getloc());
2446 __os2 << __wdi.weekday();
2447 const auto __i = __wdi.index();
2448 basic_string_view<_CharT> __s
2449 = _GLIBCXX_WIDEN(
"[ is not a valid index]");
2451 __os2 << std::format(_GLIBCXX_WIDEN(
"{}"), __i);
2452 if (__i >= 1 && __i <= 5)
2453 __os2 << __s.back();
2455 __os2 << __s.substr(1);
2456 __os << __os2.view();
2460 template<
typename _CharT,
typename _Traits>
2461 inline basic_ostream<_CharT, _Traits>&
2462 operator<<(basic_ostream<_CharT, _Traits>& __os,
2463 const weekday_last& __wdl)
2466 basic_stringstream<_CharT> __os2;
2467 __os2.imbue(__os.getloc());
2468 __os2 << __wdl.weekday() << _GLIBCXX_WIDEN(
"[last]");
2469 __os << __os2.view();
2473 template<
typename _CharT,
typename _Traits>
2474 inline basic_ostream<_CharT, _Traits>&
2475 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month_day& __md)
2478 basic_stringstream<_CharT> __os2;
2479 __os2.imbue(__os.getloc());
2480 __os2 << __md.month();
2481 if constexpr (is_same_v<_CharT, char>)
2485 __os2 << __md.day();
2486 __os << __os2.view();
2490 template<
typename _CharT,
typename _Traits,
2491 typename _Alloc = allocator<_CharT>>
2492 inline basic_istream<_CharT, _Traits>&
2493 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2495 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2498 using __format::_ChronoParts;
2499 auto __need = _ChronoParts::_Month | _ChronoParts::_Day;
2500 __detail::_Parser<> __p(__need);
2501 if (__p(__is, __fmt, __abbrev, __offset))
2502 __md = month_day(__p._M_ymd.month(), __p._M_ymd.day());
2506 template<
typename _CharT,
typename _Traits>
2507 inline basic_ostream<_CharT, _Traits>&
2508 operator<<(basic_ostream<_CharT, _Traits>& __os,
2509 const month_day_last& __mdl)
2512 basic_stringstream<_CharT> __os2;
2513 __os2.imbue(__os.getloc());
2514 __os2 << __mdl.month() << _GLIBCXX_WIDEN(
"/last");
2515 __os << __os2.view();
2519 template<
typename _CharT,
typename _Traits>
2520 inline basic_ostream<_CharT, _Traits>&
2521 operator<<(basic_ostream<_CharT, _Traits>& __os,
2522 const month_weekday& __mwd)
2525 basic_stringstream<_CharT> __os2;
2526 __os2.imbue(__os.getloc());
2527 __os2 << __mwd.month();
2528 if constexpr (is_same_v<_CharT, char>)
2532 __os2 << __mwd.weekday_indexed();
2533 __os << __os2.view();
2537 template<
typename _CharT,
typename _Traits>
2538 inline basic_ostream<_CharT, _Traits>&
2539 operator<<(basic_ostream<_CharT, _Traits>& __os,
2540 const month_weekday_last& __mwdl)
2543 basic_stringstream<_CharT> __os2;
2544 __os2.imbue(__os.getloc());
2545 __os2 << __mwdl.month();
2546 if constexpr (is_same_v<_CharT, char>)
2550 __os2 << __mwdl.weekday_last();
2551 __os << __os2.view();
2555 template<
typename _CharT,
typename _Traits>
2556 inline basic_ostream<_CharT, _Traits>&
2557 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year_month& __ym)
2560 basic_stringstream<_CharT> __os2;
2561 __os2.imbue(__os.getloc());
2562 __os2 << __ym.year();
2563 if constexpr (is_same_v<_CharT, char>)
2567 __os2 << __ym.month();
2568 __os << __os2.view();
2572 template<
typename _CharT,
typename _Traits,
2573 typename _Alloc = allocator<_CharT>>
2574 inline basic_istream<_CharT, _Traits>&
2575 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2577 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2580 using __format::_ChronoParts;
2581 auto __need = _ChronoParts::_Year | _ChronoParts::_Month;
2582 __detail::_Parser<> __p(__need);
2583 if (__p(__is, __fmt, __abbrev, __offset))
2584 __ym = year_month(__p._M_ymd.year(), __p._M_ymd.month());
2588 template<
typename _CharT,
typename _Traits>
2589 inline basic_ostream<_CharT, _Traits>&
2590 operator<<(basic_ostream<_CharT, _Traits>& __os,
2591 const year_month_day& __ymd)
2593 using _Ctx = __format::__format_context<_CharT>;
2594 using _Str = basic_string_view<_CharT>;
2595 _Str __s = _GLIBCXX_WIDEN(
"{:%F} is not a valid date");
2596 __os <<
std::vformat(__ymd.ok() ? __s.substr(0, 5) : __s,
2597 make_format_args<_Ctx>(__ymd));
2601 template<
typename _CharT,
typename _Traits,
2602 typename _Alloc = allocator<_CharT>>
2603 inline basic_istream<_CharT, _Traits>&
2605 year_month_day&
__ymd,
2609 using __format::_ChronoParts;
2610 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2611 | _ChronoParts::_Day;
2612 __detail::_Parser<> __p(
__need);
2618 template<
typename _CharT,
typename _Traits>
2621 const year_month_day_last&
__ymdl)
2636 template<
typename _CharT,
typename _Traits>
2637 inline basic_ostream<_CharT, _Traits>&
2638 operator<<(basic_ostream<_CharT, _Traits>& __os,
2639 const year_month_weekday& __ymwd)
2643 basic_stringstream<_CharT> __os2;
2644 __os2.imbue(__os.getloc());
2646 if constexpr (is_same_v<_CharT, char>)
2650 __os2 << __ymwd.year() << __slash << __ymwd.month() << __slash
2651 << __ymwd.weekday_indexed();
2652 __os << __os2.view();
2656 template<
typename _CharT,
typename _Traits>
2657 inline basic_ostream<_CharT, _Traits>&
2658 operator<<(basic_ostream<_CharT, _Traits>& __os,
2659 const year_month_weekday_last& __ymwdl)
2663 basic_stringstream<_CharT> __os2;
2664 __os2.imbue(__os.getloc());
2666 if constexpr (is_same_v<_CharT, char>)
2670 __os2 << __ymwdl.year() << __slash << __ymwdl.month() << __slash
2671 << __ymwdl.weekday_last();
2672 __os << __os2.view();
2676 template<
typename _CharT,
typename _Traits,
typename _Duration>
2677 inline basic_ostream<_CharT, _Traits>&
2678 operator<<(basic_ostream<_CharT, _Traits>& __os,
2679 const hh_mm_ss<_Duration>& __hms)
2681 return __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%T}"), __hms);
2684#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2686 template<
typename _CharT,
typename _Traits>
2687 basic_ostream<_CharT, _Traits>&
2688 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_info& __i)
2690 __os <<
'[' << __i.begin <<
',' << __i.end
2691 <<
',' << hh_mm_ss(__i.offset) <<
',' << __i.save
2692 <<
',' << __i.abbrev <<
']';
2697 template<
typename _CharT,
typename _Traits>
2698 basic_ostream<_CharT, _Traits>&
2699 operator<<(basic_ostream<_CharT, _Traits>& __os,
const local_info& __li)
2702 if (__li.result == local_info::unique)
2706 if (__li.result == local_info::nonexistent)
2707 __os <<
"nonexistent";
2709 __os <<
"ambiguous";
2710 __os <<
" local time between " << __li.first;
2711 __os <<
" and " << __li.second;
2717 template<
typename _CharT,
typename _Traits,
typename _Duration,
2718 typename _TimeZonePtr>
2719 inline basic_ostream<_CharT, _Traits>&
2720 operator<<(basic_ostream<_CharT, _Traits>& __os,
2721 const zoned_time<_Duration, _TimeZonePtr>& __t)
2723 __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T %Z}"), __t);
2728 template<
typename _CharT,
typename _Traits,
typename _Duration>
2729 requires (!treat_as_floating_point_v<typename _Duration::rep>)
2730 && ratio_less_v<typename _Duration::period, days::period>
2731 inline basic_ostream<_CharT, _Traits>&
2732 operator<<(basic_ostream<_CharT, _Traits>& __os,
2733 const sys_time<_Duration>& __tp)
2735 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __tp);
2739 template<
typename _CharT,
typename _Traits>
2740 inline basic_ostream<_CharT, _Traits>&
2741 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_days& __dp)
2743 __os << year_month_day{__dp};
2747 template<
typename _CharT,
typename _Traits,
typename _Duration,
2748 typename _Alloc = allocator<_CharT>>
2749 basic_istream<_CharT, _Traits>&
2750 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2751 sys_time<_Duration>& __tp,
2752 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2758 using __format::_ChronoParts;
2759 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2760 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2761 __detail::_Parser_t<_Duration> __p(__need);
2762 if (__p(__is, __fmt, __abbrev, __offset))
2764 if (__p._M_is_leap_second)
2768 auto __st = __p._M_sys_days + __p._M_time - *__offset;
2769 __tp = chrono::time_point_cast<_Duration>(__st);
2775 template<
typename _CharT,
typename _Traits,
typename _Duration>
2776 inline basic_ostream<_CharT, _Traits>&
2777 operator<<(basic_ostream<_CharT, _Traits>& __os,
2778 const utc_time<_Duration>& __t)
2780 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
2784 template<
typename _CharT,
typename _Traits,
typename _Duration,
2785 typename _Alloc = allocator<_CharT>>
2786 inline basic_istream<_CharT, _Traits>&
2787 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2788 utc_time<_Duration>& __tp,
2789 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2795 using __format::_ChronoParts;
2796 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2797 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2798 __detail::_Parser_t<_Duration> __p(__need);
2799 if (__p(__is, __fmt, __abbrev, __offset))
2803 auto __ut = utc_clock::from_sys(__p._M_sys_days) + __p._M_time
2805 __tp = chrono::time_point_cast<_Duration>(__ut);
2810 template<
typename _CharT,
typename _Traits,
typename _Duration>
2811 inline basic_ostream<_CharT, _Traits>&
2812 operator<<(basic_ostream<_CharT, _Traits>& __os,
2813 const tai_time<_Duration>& __t)
2815 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
2819 template<
typename _CharT,
typename _Traits,
typename _Duration,
2820 typename _Alloc = allocator<_CharT>>
2821 inline basic_istream<_CharT, _Traits>&
2822 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2823 tai_time<_Duration>& __tp,
2824 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2830 using __format::_ChronoParts;
2831 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2832 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2833 __detail::_Parser_t<_Duration> __p(__need);
2834 if (__p(__is, __fmt, __abbrev, __offset))
2836 if (__p._M_is_leap_second)
2840 auto __st = __p._M_sys_days + __p._M_time - *__offset;
2841 auto __tt = tai_clock::from_utc(utc_clock::from_sys(__st));
2842 __tp = chrono::time_point_cast<_Duration>(__tt);
2848 template<
typename _CharT,
typename _Traits,
typename _Duration>
2849 inline basic_ostream<_CharT, _Traits>&
2850 operator<<(basic_ostream<_CharT, _Traits>& __os,
2851 const gps_time<_Duration>& __t)
2853 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
2857 template<
typename _CharT,
typename _Traits,
typename _Duration,
2858 typename _Alloc = allocator<_CharT>>
2859 inline basic_istream<_CharT, _Traits>&
2860 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2861 gps_time<_Duration>& __tp,
2862 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2868 using __format::_ChronoParts;
2869 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2870 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2871 __detail::_Parser_t<_Duration> __p(__need);
2872 if (__p(__is, __fmt, __abbrev, __offset))
2874 if (__p._M_is_leap_second)
2878 auto __st = __p._M_sys_days + __p._M_time - *__offset;
2879 auto __tt = gps_clock::from_utc(utc_clock::from_sys(__st));
2880 __tp = chrono::time_point_cast<_Duration>(__tt);
2886 template<
typename _CharT,
typename _Traits,
typename _Duration>
2887 inline basic_ostream<_CharT, _Traits>&
2888 operator<<(basic_ostream<_CharT, _Traits>& __os,
2889 const file_time<_Duration>& __t)
2891 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
2895 template<
typename _CharT,
typename _Traits,
typename _Duration,
2896 typename _Alloc = allocator<_CharT>>
2897 inline basic_istream<_CharT, _Traits>&
2898 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2899 file_time<_Duration>& __tp,
2900 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2903 sys_time<_Duration> __st;
2904 if (chrono::from_stream(__is, __fmt, __st, __abbrev, __offset))
2905 __tp = chrono::time_point_cast<_Duration>(file_clock::from_sys(__st));
2909 template<
typename _CharT,
typename _Traits,
typename _Duration>
2910 inline basic_ostream<_CharT, _Traits>&
2911 operator<<(basic_ostream<_CharT, _Traits>& __os,
2912 const local_time<_Duration>& __lt)
2914 __os << sys_time<_Duration>{__lt.time_since_epoch()};
2918 template<
typename _CharT,
typename _Traits,
typename _Duration,
2919 typename _Alloc = allocator<_CharT>>
2920 basic_istream<_CharT, _Traits>&
2921 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2922 local_time<_Duration>& __tp,
2923 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2926 using __format::_ChronoParts;
2927 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2928 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2929 __detail::_Parser_t<_Duration> __p(__need);
2930 if (__p(__is, __fmt, __abbrev, __offset))
2932 days __d = __p._M_sys_days.time_since_epoch();
2933 auto __t = local_days(__d) + __p._M_time;
2934 __tp = chrono::time_point_cast<_Duration>(__t);
2943 template<
typename _Parsable,
typename _CharT,
2945 typename... _OptArgs>
2946 concept __parsable =
requires (basic_istream<_CharT, _Traits>& __is,
2947 const _CharT* __fmt, _Parsable& __tp,
2948 _OptArgs*... __args)
2949 { from_stream(__is, __fmt, __tp, __args...); };
2951 template<
typename _Parsable,
typename _CharT,
2952 typename _Traits = char_traits<_CharT>,
2953 typename _Alloc = allocator<_CharT>>
2957 using __string_type = basic_string<_CharT, _Traits, _Alloc>;
2960 _Parse(
const _CharT* __fmt, _Parsable& __tp,
2961 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2964 _M_abbrev(__abbrev), _M_offset(__offset)
2967 _Parse(_Parse&&) =
delete;
2968 _Parse& operator=(_Parse&&) =
delete;
2971 using __stream_type = basic_istream<_CharT, _Traits>;
2973 const _CharT*
const _M_fmt;
2974 _Parsable*
const _M_tp;
2975 __string_type*
const _M_abbrev;
2978 friend __stream_type&
2979 operator>>(__stream_type& __is, _Parse&& __p)
2982 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev,
2984 else if (__p._M_abbrev)
2985 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev);
2987 from_stream(__is, __p._M_fmt, *__p._M_tp);
2991 friend void operator>>(__stream_type&, _Parse&) =
delete;
2992 friend void operator>>(__stream_type&,
const _Parse&) =
delete;
2996 template<
typename _CharT, __detail::__parsable<_CharT> _Parsable>
2997 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
2999 parse(
const _CharT* __fmt, _Parsable& __tp)
3000 {
return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp); }
3002 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3003 __detail::__parsable<_CharT, _Traits> _Parsable>
3006 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp)
3008 return __detail::_Parse<_Parsable, _CharT, _Traits>(__fmt.c_str(), __tp);
3011 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3012 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
3013 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
3014 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
3016 parse(
const _CharT* __fmt, _Parsable& __tp,
3017 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
3020 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
3024 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3025 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
3026 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
3029 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
3030 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
3033 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
3037 template<
typename _CharT,
typename _Traits =
char_traits<_CharT>,
3038 typename _StrT = basic_
string<_CharT, _Traits>,
3039 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
3040 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
3042 parse(
const _CharT* __fmt, _Parsable& __tp,
minutes& __offset)
3044 return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp,
nullptr,
3048 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3049 typename _StrT = basic_string<_CharT, _Traits>,
3050 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
3053 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
3056 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
3061 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3062 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
3063 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
3064 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
3066 parse(
const _CharT* __fmt, _Parsable& __tp,
3067 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
3070 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
3075 template<
typename _CharT,
typename _Traits,
typename _Alloc,
3076 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
3077 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
3080 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
3081 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
3084 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
3090 template<
typename _Duration>
3091 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3092 basic_istream<_CharT, _Traits>&
3093 __detail::_Parser<_Duration>::
3094 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3095 basic_string<_CharT, _Traits, _Alloc>* __abbrev,
3098 using sentry =
typename basic_istream<_CharT, _Traits>::sentry;
3100 if (sentry __cerb(__is,
true); __cerb)
3102 locale __loc = __is.getloc();
3107 struct _Stream_state
3110 _Stream_state(basic_istream<_CharT, _Traits>& __i)
3112 _M_flags(__i.flags(ios_base::
skipws | ios_base::
dec)),
3118 _M_is.flags(_M_flags);
3122 _Stream_state(_Stream_state&&) =
delete;
3124 basic_istream<_CharT, _Traits>& _M_is;
3125 ios_base::fmtflags _M_flags;
3135 auto __read_unsigned = [&] (
int __n) {
3136 return _S_read_unsigned(__is, __err, __n);
3141 auto __read_signed = [&] (
int __n) {
3142 return _S_read_signed(__is, __err, __n);
3146 auto __read_chr = [&__is, &__err] (_CharT __c) {
3147 return _S_read_chr(__is, __err, __c);
3150 using __format::_ChronoParts;
3151 _ChronoParts __parts{};
3153 const year __bad_y = --year::min();
3154 const month __bad_mon(255);
3155 const day __bad_day(255);
3156 const weekday __bad_wday(255);
3157 const hours __bad_h(-1);
3158 const minutes __bad_min(-9999);
3161 year __y = __bad_y, __yy = __bad_y;
3162 year __iso_y = __bad_y, __iso_yy = __bad_y;
3163 month __m = __bad_mon;
3164 day __d = __bad_day;
3165 weekday __wday = __bad_wday;
3166 hours __h = __bad_h, __h12 = __bad_h;
3168 _Duration __s = __bad_sec;
3170 int __iso_wk = -1, __sunday_wk = -1, __monday_wk = -1;
3172 int __dayofyear = -1;
3174 minutes __tz_offset = __bad_min;
3175 basic_string<_CharT, _Traits> __tz_abbr;
3177 if ((_M_need & _ChronoParts::_TimeOfDay)
3178 && (_M_need & _ChronoParts::_Year))
3184 __parts = _ChronoParts::_TimeOfDay;
3191 bool __is_flag =
false;
3193 constexpr bool __is_floating
3194 = treat_as_floating_point_v<typename _Duration::rep>;
3213 _CharT __c = *__fmt++;
3220 else if (!__read_chr(__c)) [[unlikely]]
3231 if (__mod || __num) [[unlikely]]
3236 __tmget.get(__is, {}, __is, __err, &__tm,
3238 if (!__is_failed(__err))
3239 __wday = weekday(__tm.tm_wday);
3241 __parts |= _ChronoParts::_Weekday;
3247 if (__mod || __num) [[unlikely]]
3255 __tmget.get(__is, {}, __is, __err, &__tm,
3257 if (!__is_failed(__err))
3258 __m = month(__tm.tm_mon + 1);
3260 __parts |= _ChronoParts::_Month;
3264 if (__mod ==
'O' || __num) [[unlikely]]
3269 __tmget.get(__is, {}, __is, __err, &__tm,
3270 __fmt - 2 - (__mod ==
'E'), __fmt);
3271 if (!__is_failed(__err))
3273 __y = year(__tm.tm_year + 1900);
3274 __m = month(__tm.tm_mon + 1);
3275 __d = day(__tm.tm_mday);
3276 __h =
hours(__tm.tm_hour);
3281 __parts |= _ChronoParts::_DateTime;
3285 if (!__mod) [[likely]]
3287 auto __v = __read_signed(__num ? __num : 2);
3288 if (!__is_failed(__err))
3290 int __cmin = (int)year::min() / 100;
3291 int __cmax = (int)year::max() / 100;
3292 if (__cmin <= __v && __v <= __cmax)
3293 __century = __v * 100;
3298 else if (__mod ==
'E')
3301 __tmget.get(__is, {}, __is, __err, &__tm,
3303 if (!__is_failed(__err))
3304 __century = __tm.tm_year;
3313 if (!__mod) [[likely]]
3315 auto __v = __read_unsigned(__num ? __num : 2);
3316 if (!__is_failed(__err))
3319 else if (__mod ==
'O')
3322 __tmget.get(__is, {}, __is, __err, &__tm,
3324 if (!__is_failed(__err))
3325 __d = day(__tm.tm_mday);
3329 __parts |= _ChronoParts::_Day;
3333 if (__mod || __num) [[unlikely]]
3337 auto __month = __read_unsigned(2);
3339 auto __day = __read_unsigned(2);
3341 auto __year = __read_unsigned(2);
3342 if (__is_failed(__err))
3344 __y = year(__year + 1900 + 100 *
int(__year < 69));
3345 __m = month(__month);
3347 if (!year_month_day(__y, __m, __d).ok())
3349 __y = __yy = __iso_y = __iso_yy = __bad_y;
3355 __parts |= _ChronoParts::_Date;
3359 if (__mod) [[unlikely]]
3363 auto __year = __read_signed(__num ? __num : 4);
3365 auto __month = __read_unsigned(2);
3367 auto __day = __read_unsigned(2);
3368 if (__is_failed(__err))
3371 __m = month(__month);
3373 if (!year_month_day(__y, __m, __d).ok())
3375 __y = __yy = __iso_y = __iso_yy = __bad_y;
3381 __parts |= _ChronoParts::_Date;
3385 if (__mod) [[unlikely]]
3389 auto __val = __read_unsigned(__num ? __num : 2);
3390 if (__val >= 0 && __val <= 99)
3392 __iso_yy = year(__val);
3393 if (__century == -1)
3397 __iso_yy = __iso_y = __y = __yy = __bad_y;
3399 __parts |= _ChronoParts::_Year;
3403 if (__mod) [[unlikely]]
3406 __iso_y = year(__read_unsigned(__num ? __num : 4));
3407 __parts |= _ChronoParts::_Year;
3412 if (__mod ==
'E') [[unlikely]]
3414 else if (__mod ==
'O')
3419 __tmget.get(__is, {}, __is, __err, &__tm,
3421 if (!__is_failed(__err))
3425 __h12 =
hours(__tm.tm_hour);
3429 __h =
hours(__tm.tm_hour);
3438 auto __val = __read_unsigned(__num ? __num : 2);
3439 if (__c ==
'I' && __val >= 1 && __val <= 12)
3441 __h12 =
hours(__val);
3444 else if (__c ==
'H' && __val >= 0 && __val <= 23)
3451 if (_M_need & _ChronoParts::_TimeOfDay)
3456 __parts |= _ChronoParts::_TimeOfDay;
3460 if (__mod) [[unlikely]]
3462 else if (_M_need == _ChronoParts::_TimeOfDay)
3464 auto __val = __read_signed(__num ? __num : 3);
3465 if (!__is_failed(__err))
3468 __parts |= _ChronoParts::_TimeOfDay;
3473 __dayofyear = __read_unsigned(__num ? __num : 3);
3480 if (__mod ==
'E') [[unlikely]]
3482 else if (__mod ==
'O')
3485 __tmget.get(__is, {}, __is, __err, &__tm,
3487 if (!__is_failed(__err))
3488 __m = month(__tm.tm_mon + 1);
3492 auto __val = __read_unsigned(__num ? __num : 2);
3493 if (__val >= 1 && __val <= 12)
3498 __parts |= _ChronoParts::_Month;
3502 if (__mod ==
'E') [[unlikely]]
3504 else if (__mod ==
'O')
3507 __tmget.get(__is, {}, __is, __err, &__tm,
3509 if (!__is_failed(__err))
3514 auto __val = __read_unsigned(__num ? __num : 2);
3515 if (0 <= __val && __val < 60)
3519 if (_M_need & _ChronoParts::_TimeOfDay)
3524 __parts |= _ChronoParts::_TimeOfDay;
3534 const _CharT* __ampms[2];
3535 __tmpunct._M_am_pm(__ampms);
3536 int __n = 0, __which = 3;
3537 while (__which != 0)
3539 auto __i = __is.peek();
3540 if (_Traits::eq_int_type(__i, _Traits::eof()))
3550 else if (__ampms[0][__n + 1] == _CharT())
3561 else if (__ampms[1][__n + 1] == _CharT())
3572 if (__which == 0 || __which == 3)
3585 __tmget.get(__is, {}, __is, __err, &__tm,
3587 if (!__is_failed(__err))
3589 __h =
hours(__tm.tm_hour);
3594 __parts |= _ChronoParts::_TimeOfDay;
3599 if (__mod || __num) [[unlikely]]
3606 auto __val = __read_unsigned(2);
3607 if (__val == -1 || __val > 23) [[unlikely]]
3609 if (_M_need & _ChronoParts::_TimeOfDay)
3613 if (!__read_chr(
':')) [[unlikely]]
3617 __val = __read_unsigned(2);
3618 if (__val == -1 || __val > 60) [[unlikely]]
3620 if (_M_need & _ChronoParts::_TimeOfDay)
3628 __parts |= _ChronoParts::_TimeOfDay;
3631 else if (!__read_chr(
':')) [[unlikely]]
3637 if (__mod ==
'E') [[unlikely]]
3639 else if (__mod ==
'O')
3642 __tmget.get(__is, {}, __is, __err, &__tm,
3644 if (!__is_failed(__err))
3647 else if constexpr (_Duration::period::den == 1
3650 auto __val = __read_unsigned(__num ? __num : 2);
3651 if (0 <= __val && __val <= 59) [[likely]]
3655 if (_M_need & _ChronoParts::_TimeOfDay)
3662 basic_stringstream<_CharT> __buf;
3663 auto __digit = _S_try_read_digit(__is, __err);
3666 __buf.put(_CharT(
'0') + __digit);
3667 __digit = _S_try_read_digit(__is, __err);
3669 __buf.put(_CharT(
'0') + __digit);
3672 auto __i = __is.peek();
3673 if (_Traits::eq_int_type(__i, _Traits::eof()))
3680 auto& __np = use_facet<numpunct<_CharT>>(__loc);
3681 __dp = __np.decimal_point();
3683 _CharT __c = _Traits::to_char_type(__i);
3689 = hh_mm_ss<_Duration>::fractional_width;
3692 __digit = _S_try_read_digit(__is, __err);
3694 __buf.put(_CharT(
'0') + __digit);
3702 if (!__is_failed(__err)) [[likely]]
3704 long double __val{};
3705#if __cpp_lib_to_chars
3707 auto __first = __str.data();
3708 auto __last = __first + __str.size();
3712 if ((
bool)ec || ptr != __last) [[unlikely]]
3719 duration<long double> __fs(__val);
3720 if constexpr (__is_floating)
3723 __s = chrono::round<_Duration>(__fs);
3727 __parts |= _ChronoParts::_TimeOfDay;
3732 if (__mod ==
'E') [[unlikely]]
3734 else if (__mod ==
'O')
3739 __tmget.get(__is, {}, __is, __err, &__tm,
3741 if (!__is_failed(__err))
3742 __wday = weekday(__tm.tm_wday);
3749 const int __lo = __c ==
'u' ? 1 : 0;
3750 const int __hi = __lo + 6;
3751 auto __val = __read_unsigned(__num ? __num : 1);
3752 if (__lo <= __val && __val <= __hi)
3753 __wday = weekday(__val);
3756 __wday = __bad_wday;
3760 __parts |= _ChronoParts::_Weekday;
3766 if (__mod ==
'E') [[unlikely]]
3768 else if (__mod ==
'O')
3770 if (__c ==
'V') [[unlikely]]
3780 const int __lo = __c ==
'V' ? 1 : 0;
3781 const int __hi = 53;
3782 auto __val = __read_unsigned(__num ? __num : 2);
3783 if (__lo <= __val && __val <= __hi)
3788 __sunday_wk = __val;
3794 __monday_wk = __val;
3799 __iso_wk = __sunday_wk = __monday_wk = -1;
3805 if (__mod ==
'O' || __num) [[unlikely]]
3810 __tmget.get(__is, {}, __is, __err, &__tm,
3811 __fmt - 2 - (__mod ==
'E'), __fmt);
3812 if (!__is_failed(__err))
3814 __y = year(__tm.tm_year + 1900);
3815 __m = month(__tm.tm_mon + 1);
3816 __d = day(__tm.tm_mday);
3819 __parts |= _ChronoParts::_Date;
3823 if (__mod ==
'O' || __num) [[unlikely]]
3828 __tmget.get(__is, {}, __is, __err, &__tm,
3829 __fmt - 2 - (__mod ==
'E'), __fmt);
3830 if (!__is_failed(__err))
3832 __h =
hours(__tm.tm_hour);
3837 __parts |= _ChronoParts::_TimeOfDay;
3841 if (__mod) [[unlikely]]
3844 __tmget.get(__is, {}, __is, __err, &__tm,
3846 if (!__is_failed(__err))
3848 int __cent = __tm.tm_year < 2000 ? 1900 : 2000;
3849 __yy = year(__tm.tm_year - __cent);
3850 if (__century == -1)
3856 auto __val = __read_unsigned(__num ? __num : 2);
3857 if (__val >= 0 && __val <= 99)
3860 if (__century == -1)
3861 __century = __val < 69 ? 2000 : 1900;
3864 __y = __yy = __iso_yy = __iso_y = __bad_y;
3866 __parts |= _ChronoParts::_Year;
3870 if (__mod ==
'O') [[unlikely]]
3872 else if (__mod ==
'E')
3875 __tmget.get(__is, {}, __is, __err, &__tm,
3877 if (!__is_failed(__err))
3878 __y = year(__tm.tm_year);
3882 auto __val = __read_unsigned(__num ? __num : 4);
3883 if (!__is_failed(__err))
3886 __parts |= _ChronoParts::_Year;
3890 if (__num) [[unlikely]]
3897 auto __i = __is.peek();
3898 if (_Traits::eq_int_type(__i, _Traits::eof()))
3903 _CharT __ic = _Traits::to_char_type(__i);
3904 const bool __neg = __ic == _CharT(
'-');
3905 if (__ic == _CharT(
'-') || __ic == _CharT(
'+'))
3912 __hh = __read_unsigned(2);
3917 __hh = 10 * _S_try_read_digit(__is, __err);
3918 __hh += _S_try_read_digit(__is, __err);
3921 if (__is_failed(__err))
3925 if (_Traits::eq_int_type(__i, _Traits::eof()))
3928 __tz_offset =
minutes(__hh * (__neg ? -60 : 60));
3931 __ic = _Traits::to_char_type(__i);
3933 bool __read_mm =
false;
3936 if (__ic == _GLIBCXX_WIDEN(
":")[0])
3943 else if (_CharT(
'0') <= __ic && __ic <= _CharT(
'9'))
3949 int_least32_t __mm = 0;
3952 __mm = 10 * _S_try_read_digit(__is, __err);
3953 __mm += _S_try_read_digit(__is, __err);
3956 if (!__is_failed(__err))
3958 auto __z = __hh * 60 + __mm;
3959 __tz_offset =
minutes(__neg ? -__z : __z);
3965 if (__mod || __num) [[unlikely]]
3969 basic_string_view<_CharT> __x = _GLIBCXX_WIDEN(
"_/-+");
3973 auto __i = __is.peek();
3974 if (!_Traits::eq_int_type(__i, _Traits::eof()))
3976 _CharT __a = _Traits::to_char_type(__i);
3978 || __x.find(__a) != __x.npos)
3980 __tz_abbr.push_back(__a);
3989 if (__tz_abbr.empty())
3995 if (__mod || __num) [[unlikely]]
3999 _CharT __i = __is.peek();
4000 if (_Traits::eq_int_type(__i, _Traits::eof()))
4002 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
4010 if (__mod || __num) [[unlikely]]
4014 _CharT __i = __is.peek();
4015 if (_Traits::eq_int_type(__i, _Traits::eof()))
4017 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
4023 if (__mod || __num) [[unlikely]]
4031 if (__mod || __num) [[unlikely]]
4040 if (_CharT(
'1') <= __c && __c <= _CharT(
'9'))
4042 if (!__mod) [[likely]]
4045 auto __end = __fmt + _Traits::length(__fmt);
4047 = __format::__parse_integer(__fmt - 1, __end);
4048 if (__ptr) [[likely]]
4059 if (__is_failed(__err)) [[unlikely]]
4069 if (__yy != __bad_y && __y == __bad_y)
4070 __y =
years(__century) + __yy;
4071 if (__iso_yy != __bad_y && __iso_y == __bad_y)
4072 __iso_y =
years(__century) + __iso_yy;
4075 bool __can_use_doy =
false;
4076 bool __can_use_iso_wk =
false;
4077 bool __can_use_sun_wk =
false;
4078 bool __can_use_mon_wk =
false;
4081 if (__y != __bad_y && __dayofyear >= 0)
4083 __can_use_doy =
true;
4084 __parts |= _ChronoParts::_Date;
4086 else if (__y != __bad_y && __wday != __bad_wday && __sunday_wk >= 0)
4088 __can_use_sun_wk =
true;
4089 __parts |= _ChronoParts::_Date;
4091 else if (__y != __bad_y && __wday != __bad_wday && __monday_wk >= 0)
4093 __can_use_mon_wk =
true;
4094 __parts |= _ChronoParts::_Date;
4096 else if (__iso_y != __bad_y && __wday != __bad_wday && __iso_wk > 0)
4099 __can_use_iso_wk =
true;
4100 __parts |= _ChronoParts::_Date;
4103 if (__is_failed(__err)) [[unlikely]]
4105 else if (__is_flag) [[unlikely]]
4107 else if ((_M_need & __parts) == _M_need) [[likely]]
4129 const bool __need_wday = _M_need & _ChronoParts::_Weekday;
4133 const bool __need_time = _M_need & _ChronoParts::_TimeOfDay;
4135 if (__need_wday && __wday != __bad_wday)
4137 else if (_M_need & _ChronoParts::_Date)
4141 const bool __need_ymd = !__need_wday && !__need_time;
4143 if ((_M_need & _ChronoParts::_Year && __y == __bad_y)
4144 || (_M_need & _ChronoParts::_Month && __m == __bad_mon)
4145 || (_M_need & _ChronoParts::_Day && __d == __bad_day))
4152 if ((0 < __dayofyear && __dayofyear <= 365)
4153 || (__dayofyear == 366 && __y.is_leap()))
4156 _M_sys_days = sys_days(__y/January/1)
4157 +
days(__dayofyear - 1);
4159 _M_ymd = year_month_day(_M_sys_days);
4164 else if (__can_use_iso_wk)
4172 const sys_days __jan4(__iso_y/January/4);
4173 weekday __wd1(__jan4 -
days(3));
4174 if (__wd1 != Thursday)
4175 if (__wd1 != Wednesday || !__iso_y.is_leap())
4179 if (!__is_failed(__err)) [[likely]]
4182 sys_days __w(Thursday[1]/January/__iso_y);
4184 __w -= Thursday - Monday;
4186 __w += __wday - Monday;
4190 _M_ymd = year_month_day(_M_sys_days);
4193 else if (__can_use_sun_wk)
4196 sys_days __wk1(__y/January/Sunday[1]);
4197 _M_sys_days = __wk1 +
weeks(__sunday_wk - 1)
4198 +
days(__wday.c_encoding());
4199 _M_ymd = year_month_day(_M_sys_days);
4200 if (_M_ymd.year() != __y) [[unlikely]]
4203 else if (__can_use_mon_wk)
4206 sys_days __wk1(__y/January/Monday[1]);
4207 _M_sys_days = __wk1 +
weeks(__monday_wk - 1)
4208 +
days(__wday.c_encoding() - 1);
4209 _M_ymd = year_month_day(_M_sys_days);
4210 if (_M_ymd.year() != __y) [[unlikely]]
4222 if (_M_need & _ChronoParts::_Year)
4224 if (!__y.ok()) [[unlikely]]
4227 else if (__y == __bad_y)
4230 if (_M_need & _ChronoParts::_Month)
4232 if (!__m.ok()) [[unlikely]]
4235 else if (__m == __bad_mon)
4238 if (_M_need & _ChronoParts::_Day)
4240 if (__d < day(1) || __d > (__y/__m/last).day())
4243 else if (__d == __bad_day)
4246 if (year_month_day __ymd(__y, __m, __d); __ymd.ok())
4249 if (__need_wday || __need_time)
4250 _M_sys_days = sys_days(_M_ymd);
4257 _M_wd = weekday(_M_sys_days);
4263 if (__h == __bad_h && __h12 != __bad_h)
4267 else if (__ampm == 2)
4268 __h = __h12 ==
hours(12) ? __h12 : __h12 +
hours(12);
4273 auto __t = _M_time.zero();
4282 if (__min != __bad_min)
4288 if (__s != __bad_sec)
4292 _M_is_leap_second = __s >=
seconds(60);
4301 if (!__is_failed(__err)) [[likely]]
4303 if (__offset && __tz_offset != __bad_min)
4304 *__offset = __tz_offset;
4305 if (__abbrev && !__tz_abbr.empty())
4313 __is.setstate(__err);
4317#undef _GLIBCXX_WIDEN
4322_GLIBCXX_END_NAMESPACE_VERSION
__detail::__local_time_fmt< _Duration > local_time_format(local_time< _Duration > __time, const string *__abbrev=nullptr, const seconds *__offset_sec=nullptr)
duration< int64_t > seconds
seconds
duration< int64_t, ratio< 604800 > > weeks
weeks
duration< int64_t, ratio< 3600 > > hours
hours
duration< int64_t, ratio< 86400 > > days
days
basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const duration< _Rep, _Period > &__d)
duration< int64_t, ratio< 60 > > minutes
minutes
duration< int64_t, ratio< 31556952 > > years
years
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
ISO C++ entities toplevel namespace is std.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
chars_format
floating-point format for primitive numerical conversion
bool isspace(_CharT __c, const locale &__loc)
Convenience interface to ctype.is(ctype_base::space, __c).
_CharT toupper(_CharT __c, const locale &__loc)
Convenience interface to ctype.toupper(__c).
bool isalnum(_CharT __c, const locale &__loc)
Convenience interface to ctype.is(ctype_base::alnum, __c).
ios_base & dec(ios_base &__base)
Calls base.setf(ios_base::dec, ios_base::basefield).
ios_base & skipws(ios_base &__base)
Calls base.setf(ios_base::skipws).
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
constexpr bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
basic_istream< _CharT, _Traits > & ws(basic_istream< _CharT, _Traits > &__is)
Quick and easy way to eat whitespace.
constexpr from_chars_result from_chars(const char *__first, const char *__last, _Tp &__value, int __base=10)
std::from_chars for integral types.
ISO C++ 2011 namespace for date and time utilities.
static constexpr bool is_signed
_Ios_Iostate iostate
This is a bitmask type.
static const iostate eofbit
Indicates that an input operation reached the end of an input sequence.
static const iostate goodbit
Indicates all is well.
static const iostate failbit
Indicates that an input operation failed to read the expected characters, or that an output operation...
Container class for localization functionality.
static const locale & classic()
Return reference to the C locale.