30#ifndef _GLIBCXX_CHRONO_IO_H
31#define _GLIBCXX_CHRONO_IO_H 1
33#pragma GCC system_header
35#if __cplusplus >= 202002L
45_GLIBCXX_BEGIN_NAMESPACE_VERSION
60 template<
typename _CharT>
69#define _GLIBCXX_WIDEN_(C, S) ::std::chrono::__detail::_Widen<C>(S, L##S)
70#define _GLIBCXX_WIDEN(S) _GLIBCXX_WIDEN_(_CharT, S)
72 template<
typename _Period,
typename _CharT>
79#define _GLIBCXX_UNITS_SUFFIX(period, suffix) \
80 if constexpr (is_same_v<_Period, period>) \
81 return _GLIBCXX_WIDEN(suffix); \
89#if _GLIBCXX_USE_ALT_MICROSECONDS_SUFFIX
111#undef _GLIBCXX_UNITS_SUFFIX
115 template<
typename _Period,
typename _CharT,
typename _Out>
119 if (
auto __s = __detail::__units_suffix<_Period, _CharT>();
__s.size())
121 else if constexpr (_Period::den == 1)
123 (uintmax_t)_Period::num);
126 (uintmax_t)_Period::num,
127 (uintmax_t)_Period::den);
136 template<
typename _CharT,
typename _Traits,
137 typename _Rep,
typename _Period>
143 using period =
typename _Period::type;
147 __s.precision(
__os.precision());
149 __detail::__fmt_units_suffix<period, _CharT>(_Out(
__s));
158 template<
typename _Duration>
162 const string* _M_abbrev;
179 template<
typename _Duration>
180 inline __detail::__local_time_fmt<_Duration>
192 [[noreturn,__gnu__::__always_inline__]]
194 __no_timezone_available()
195 { __throw_format_error(
"format error: no timezone available for %Z or %z"); }
197 [[noreturn,__gnu__::__always_inline__]]
199 __not_valid_for_duration()
200 { __throw_format_error(
"format error: chrono-format-spec not valid for "
201 "chrono::duration"); }
203 [[noreturn,__gnu__::__always_inline__]]
205 __invalid_chrono_spec()
206 { __throw_format_error(
"format error: chrono-format-spec not valid for "
209 template<
typename _CharT>
210 struct _ChronoSpec : _Spec<_CharT>
212 basic_string_view<_CharT> _M_chrono_specs;
219 _Year = 1, _Month = 2, _Day = 4, _Weekday = 8, _TimeOfDay = 16,
221 _Date = _Year | _Month | _Day | _Weekday,
222 _DateTime = _Date | _TimeOfDay,
223 _ZonedDateTime = _DateTime | _TimeZone,
227 constexpr _ChronoParts
228 operator|(_ChronoParts __x, _ChronoParts __y)
noexcept
229 {
return static_cast<_ChronoParts
>((int)__x | (
int)__y); }
231 constexpr _ChronoParts&
232 operator|=(_ChronoParts& __x, _ChronoParts __y)
noexcept
233 {
return __x = __x | __y; }
236 template<
typename _CharT>
237 struct __formatter_chrono
239 using __string_view = basic_string_view<_CharT>;
240 using __string = basic_string<_CharT>;
242 template<
typename _ParseContext>
243 constexpr typename _ParseContext::iterator
244 _M_parse(_ParseContext& __pc, _ChronoParts __parts)
246 auto __first = __pc.
begin();
247 auto __last = __pc.end();
249 _ChronoSpec<_CharT> __spec{};
251 auto __finalize = [
this, &__spec] {
255 auto __finished = [&] {
256 if (__first == __last || *__first ==
'}')
267 __first = __spec._M_parse_fill_and_align(__first, __last);
271 __first = __spec._M_parse_width(__first, __last, __pc);
275 if (__parts & _ChronoParts::_Duration)
277 __first = __spec._M_parse_precision(__first, __last, __pc);
282 __first = __spec._M_parse_locale(__first, __last);
289 __string_view __str(__first, __last - __first);
290 auto __end = __str.find(
'}');
291 if (__end != __str.npos)
293 __str.remove_suffix(__str.length() - __end);
294 __last = __first + __end;
296 if (__str.find(
'{') != __str.npos)
297 __throw_format_error(
"chrono format error: '{' in chrono-specs");
304 const auto __chrono_specs = __first++;
305 if (*__chrono_specs !=
'%')
306 __throw_format_error(
"chrono format error: no '%' at start of "
313 while (__first != __last)
315 enum _Mods { _Mod_none, _Mod_E, _Mod_O, _Mod_E_O };
316 _Mods __allowed_mods = _Mod_none;
318 _CharT __c = *__first++;
331 __needed = _DateTime;
332 __allowed_mods = _Mod_E;
336 __allowed_mods = _Mod_E;
341 __allowed_mods = _Mod_O;
353 __needed = _TimeOfDay;
354 __allowed_mods = _Mod_O;
357 if (!(__parts & _Duration))
362 __allowed_mods = _Mod_O;
365 __needed = _TimeOfDay;
366 __allowed_mods = _Mod_O;
372 __needed = _TimeOfDay;
376 __needed = _Duration;
379 __needed = _TimeOfDay;
380 __allowed_mods = _Mod_O;
385 __allowed_mods = _Mod_O;
391 __allowed_mods = _Mod_O;
395 __allowed_mods = _Mod_E;
398 __needed = _TimeOfDay;
399 __allowed_mods = _Mod_E;
403 __allowed_mods = _Mod_E_O;
407 __allowed_mods = _Mod_E;
410 __needed = _TimeZone;
411 __allowed_mods = _Mod_E_O;
414 __needed = _TimeZone;
422 if (__mod) [[unlikely]]
424 __allowed_mods = _Mod_none;
430 __throw_format_error(
"chrono format error: invalid "
431 " specifier in chrono-specs");
434 if ((__mod ==
'E' && !(__allowed_mods & _Mod_E))
435 || (__mod ==
'O' && !(__allowed_mods & _Mod_O)))
436 __throw_format_error(
"chrono format error: invalid "
437 " modifier in chrono-specs");
440 if ((__parts & __needed) != __needed)
441 __throw_format_error(
"chrono format error: format argument "
442 "does not contain the information "
443 "required by the chrono-specs");
446 size_t __pos = __string_view(__first, __last - __first).find(
'%');
451 if (__pos == __string_view::npos)
457 __first += __pos + 1;
462 if (__conv || __mod != _CharT())
463 __throw_format_error(
"chrono format error: unescaped '%' in "
467 _M_spec._M_chrono_specs
468 = __string_view(__chrono_specs, __first - __chrono_specs);
478 template<
typename _Tp,
typename _FormatContext>
479 typename _FormatContext::iterator
480 _M_format(
const _Tp& __t, _FormatContext& __fc,
481 bool __is_neg =
false)
const
483 auto __first = _M_spec._M_chrono_specs.begin();
484 const auto __last = _M_spec._M_chrono_specs.end();
485 if (__first == __last)
486 return _M_format_to_ostream(__t, __fc, __is_neg);
488 _Sink_iter<_CharT> __out;
489 __format::_Str_sink<_CharT> __sink;
490 bool __write_direct =
false;
491 if constexpr (is_same_v<
typename _FormatContext::iterator,
494 if (_M_spec._M_width_kind == __format::_WP_none)
497 __write_direct =
true;
500 __out = __sink.out();
503 __out = __sink.out();
507 if constexpr (__is_specialization_of<_Tp, chrono::hh_mm_ss>)
508 __is_neg = __t.is_negative();
510 auto __print_sign = [&__is_neg, &__out] {
511 if constexpr (chrono::__is_duration_v<_Tp>
512 || __is_specialization_of<_Tp, chrono::hh_mm_ss>)
515 *__out++ = _S_plus_minus[1];
522 constexpr const _CharT* __literals = _GLIBCXX_WIDEN(
"\n\t%");
529 _CharT __c = *__first++;
534 __out = _M_a_A(__t,
std::move(__out), __fc, __c ==
'A');
539 __out = _M_b_B(__t,
std::move(__out), __fc, __c ==
'B');
542 __out = _M_c(__t,
std::move(__out), __fc, __mod ==
'E');
547 __out = _M_C_y_Y(__t,
std::move(__out), __fc, __c, __mod);
551 __out = _M_d_e(__t,
std::move(__out), __fc, __c, __mod ==
'O');
554 __out = _M_D(__t,
std::move(__out), __fc);
557 __out = _M_F(__t,
std::move(__out), __fc);
561 __out = _M_g_G(__t,
std::move(__out), __fc, __c ==
'G');
565 __out = _M_H_I(__t, __print_sign(), __fc, __c, __mod ==
'O');
568 __out = _M_j(__t, __print_sign(), __fc);
571 __out = _M_m(__t,
std::move(__out), __fc, __mod ==
'O');
574 __out = _M_M(__t, __print_sign(), __fc, __mod ==
'O');
577 __out = _M_p(__t,
std::move(__out), __fc);
580 __out = _M_q(__t,
std::move(__out), __fc);
584 if constexpr (chrono::__is_duration_v<_Tp>)
588 __throw_format_error(
"chrono format error: argument is "
592 __out = _M_r(__t, __print_sign(), __fc);
596 __out = _M_R_T(__t, __print_sign(), __fc, __c ==
'T');
599 __out = _M_S(__t, __print_sign(), __fc, __mod ==
'O');
603 __out = _M_u_w(__t,
std::move(__out), __fc, __c, __mod ==
'O');
608 __out = _M_U_V_W(__t,
std::move(__out), __fc, __c,
612 __out = _M_x(__t,
std::move(__out), __fc, __mod ==
'E');
615 __out = _M_X(__t, __print_sign(), __fc, __mod ==
'E');
618 __out = _M_z(__t,
std::move(__out), __fc, (
bool)__mod);
621 __out = _M_Z(__t,
std::move(__out), __fc);
624 *__out++ = __literals[0];
627 *__out++ = __literals[1];
630 *__out++ = __literals[2];
642 __string_view __str(__first, __last - __first);
643 size_t __pos = __str.find(
'%');
648 if (__pos == __str.npos)
652 __str.remove_suffix(__str.length() - __pos);
653 __first += __pos + 1;
655 __out = __format::__write(
std::move(__out), __str);
658 while (__first != __last);
660 if constexpr (is_same_v<
typename _FormatContext::iterator,
666 return __format::__write_padded_as_spec(__str, __str.size(),
670 _ChronoSpec<_CharT> _M_spec;
674 template<
typename _FormatContext>
676 _M_locale(_FormatContext& __fc)
const
678 if (!_M_spec._M_localized)
681 return __fc.locale();
688 template<
typename _Tp,
typename _FormatContext>
689 typename _FormatContext::iterator
690 _M_format_to_ostream(
const _Tp& __t, _FormatContext& __fc,
693 using ::std::chrono::__detail::__utc_leap_second;
694 using ::std::chrono::__detail::__local_time_fmt;
696 if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
697 return _M_format_to_ostream(__t._M_time, __fc,
false);
700 basic_ostringstream<_CharT> __os;
701 __os.imbue(_M_locale(__fc));
703 if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
704 __os << __t._M_date <<
' ' << __t._M_time;
707 if constexpr (chrono::__is_duration_v<_Tp>)
708 if (__is_neg) [[unlikely]]
709 __os << _S_plus_minus[1];
714 return __format::__write_padded_as_spec(__str, __str.size(),
719 static constexpr const _CharT* _S_chars
720 = _GLIBCXX_WIDEN(
"0123456789+-:/ {}");
721 static constexpr const _CharT* _S_plus_minus = _S_chars + 10;
722 static constexpr _CharT _S_colon = _S_chars[12];
723 static constexpr _CharT _S_slash = _S_chars[13];
724 static constexpr _CharT _S_space = _S_chars[14];
725 static constexpr const _CharT* _S_empty_spec = _S_chars + 15;
727 template<
typename _Tp,
typename _FormatContext>
728 typename _FormatContext::iterator
729 _M_a_A(
const _Tp& __t,
typename _FormatContext::iterator __out,
730 _FormatContext& __ctx,
bool __full)
const
734 chrono::weekday __wd = _S_weekday(__t);
736 __throw_format_error(
"format error: invalid weekday");
738 locale __loc = _M_locale(__ctx);
739 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
740 const _CharT* __days[7];
742 __tp._M_days(__days);
744 __tp._M_days_abbreviated(__days);
745 __string_view __str(__days[__wd.c_encoding()]);
746 return __format::__write(
std::move(__out), __str);
749 template<
typename _Tp,
typename _FormatContext>
750 typename _FormatContext::iterator
751 _M_b_B(
const _Tp& __t,
typename _FormatContext::iterator __out,
752 _FormatContext& __ctx,
bool __full)
const
756 chrono::month __m = _S_month(__t);
758 __throw_format_error(
"format error: invalid month");
759 locale __loc = _M_locale(__ctx);
760 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
761 const _CharT* __months[12];
763 __tp._M_months(__months);
765 __tp._M_months_abbreviated(__months);
766 __string_view __str(__months[(
unsigned)__m - 1]);
767 return __format::__write(
std::move(__out), __str);
770 template<
typename _Tp,
typename _FormatContext>
771 typename _FormatContext::iterator
772 _M_c(
const _Tp& __tt,
typename _FormatContext::iterator __out,
773 _FormatContext& __ctx,
bool __mod =
false)
const
778 auto __t = _S_floor_seconds(__tt);
779 locale __loc = _M_locale(__ctx);
780 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
781 const _CharT* __formats[2];
782 __tp._M_date_time_formats(__formats);
783 const _CharT* __rep = __formats[__mod];
785 __rep = _GLIBCXX_WIDEN(
"%a %b %e %H:%M:%S %Y");
786 basic_string<_CharT> __fmt(_S_empty_spec);
787 __fmt.insert(1u, 1u, _S_colon);
788 __fmt.insert(2u, __rep);
793 template<
typename _Tp,
typename _FormatContext>
794 typename _FormatContext::iterator
795 _M_C_y_Y(
const _Tp& __t,
typename _FormatContext::iterator __out,
796 _FormatContext& __ctx, _CharT __conv, _CharT __mod = 0)
const
806 chrono::year __y = _S_year(__t);
808 if (__mod) [[unlikely]]
811 __tm.tm_year = (int)__y - 1900;
812 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
816 basic_string<_CharT> __s;
818 const bool __is_neg = __yi < 0;
819 __yi = __builtin_abs(__yi);
821 if (__conv ==
'Y' || __conv ==
'C')
823 int __ci = __yi / 100;
824 if (__is_neg) [[unlikely]]
826 __s.assign(1, _S_plus_minus[1]);
828 if (__conv ==
'C' && (__ci * 100) != __yi)
831 if (__ci >= 100) [[unlikely]]
833 __s += std::format(_S_empty_spec, __ci / 100);
836 __s += _S_two_digits(__ci);
839 if (__conv ==
'Y' || __conv ==
'y')
840 __s += _S_two_digits(__yi % 100);
842 return __format::__write(
std::move(__out), __string_view(__s));
845 template<
typename _Tp,
typename _FormatContext>
846 typename _FormatContext::iterator
847 _M_D(
const _Tp& __t,
typename _FormatContext::iterator __out,
848 _FormatContext&)
const
850 auto __ymd = _S_date(__t);
851 basic_string<_CharT> __s;
852#if ! _GLIBCXX_USE_CXX11_ABI
855 __s = _S_two_digits((
unsigned)__ymd.month());
857 __s += _S_two_digits((
unsigned)__ymd.day());
859 __s += _S_two_digits(__builtin_abs((
int)__ymd.year()) % 100);
860 return __format::__write(
std::move(__out), __string_view(__s));
863 template<
typename _Tp,
typename _FormatContext>
864 typename _FormatContext::iterator
865 _M_d_e(
const _Tp& __t,
typename _FormatContext::iterator __out,
866 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
873 chrono::day __d = _S_day(__t);
874 unsigned __i = (unsigned)__d;
876 if (__mod) [[unlikely]]
880 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
884 auto __sv = _S_two_digits(__i);
886 if (__conv == _CharT(
'e') && __i < 10)
892 return __format::__write(
std::move(__out), __sv);
895 template<
typename _Tp,
typename _FormatContext>
896 typename _FormatContext::iterator
897 _M_F(
const _Tp& __t,
typename _FormatContext::iterator __out,
898 _FormatContext&)
const
900 auto __ymd = _S_date(__t);
901 auto __s = std::format(_GLIBCXX_WIDEN(
"{:04d}- - "),
903 auto __sv = _S_two_digits((
unsigned)__ymd.month());
904 __s[__s.size() - 5] = __sv[0];
905 __s[__s.size() - 4] = __sv[1];
906 __sv = _S_two_digits((
unsigned)__ymd.day());
907 __s[__s.size() - 2] = __sv[0];
908 __s[__s.size() - 1] = __sv[1];
910 return __format::__write(
std::move(__out), __sv);
913 template<
typename _Tp,
typename _FormatContext>
914 typename _FormatContext::iterator
915 _M_g_G(
const _Tp& __t,
typename _FormatContext::iterator __out,
916 _FormatContext& __ctx,
bool __full)
const
920 using namespace chrono;
921 auto __d = _S_days(__t);
923 __d -= (weekday(__d) - Monday) -
days(3);
925 year __y = year_month_day(__d).year();
926 return _M_C_y_Y(__y,
std::move(__out), __ctx,
"yY"[__full]);
929 template<
typename _Tp,
typename _FormatContext>
930 typename _FormatContext::iterator
931 _M_H_I(
const _Tp& __t,
typename _FormatContext::iterator __out,
932 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
939 const auto __hms = _S_hms(__t);
940 int __i = __hms.hours().count();
942 if (__mod) [[unlikely]]
946 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
950 if (__conv == _CharT(
'I'))
957 return __format::__write(
std::move(__out), _S_two_digits(__i));
960 template<
typename _Tp,
typename _FormatContext>
961 typename _FormatContext::iterator
962 _M_j(
const _Tp& __t,
typename _FormatContext::iterator __out,
963 _FormatContext&)
const
965 if constexpr (chrono::__is_duration_v<_Tp>)
968 unsigned __d = chrono::duration_cast<chrono::days>(__t).count();
974 using namespace chrono;
975 auto __day = _S_days(__t);
976 auto __ymd = _S_date(__t);
980 if constexpr (is_same_v<
typename decltype(__day)::clock, local_t>)
981 __d = __day - local_days(__ymd.year()/January/0);
983 __d = __day - sys_days(__ymd.year()/January/0);
989 template<
typename _Tp,
typename _FormatContext>
990 typename _FormatContext::iterator
991 _M_m(
const _Tp& __t,
typename _FormatContext::iterator __out,
992 _FormatContext& __ctx,
bool __mod)
const
997 auto __m = _S_month(__t);
998 auto __i = (unsigned)__m;
1000 if (__mod) [[unlikely]]
1003 __tm.tm_mon = __i - 1;
1004 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
1008 return __format::__write(
std::move(__out), _S_two_digits(__i));
1011 template<
typename _Tp,
typename _FormatContext>
1012 typename _FormatContext::iterator
1013 _M_M(
const _Tp& __t,
typename _FormatContext::iterator __out,
1014 _FormatContext& __ctx,
bool __mod)
const
1019 auto __m = _S_hms(__t).minutes();
1020 auto __i = __m.count();
1022 if (__mod) [[unlikely]]
1026 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
1030 return __format::__write(
std::move(__out), _S_two_digits(__i));
1033 template<
typename _Tp,
typename _FormatContext>
1034 typename _FormatContext::iterator
1035 _M_p(
const _Tp& __t,
typename _FormatContext::iterator __out,
1036 _FormatContext& __ctx)
const
1039 auto __hms = _S_hms(__t);
1040 locale __loc = _M_locale(__ctx);
1041 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1042 const _CharT* __ampm[2];
1043 __tp._M_am_pm(__ampm);
1045 __ampm[__hms.hours().count() >= 12]);
1048 template<
typename _Tp,
typename _FormatContext>
1049 typename _FormatContext::iterator
1050 _M_q(
const _Tp&,
typename _FormatContext::iterator __out,
1051 _FormatContext&)
const
1054 if constexpr (!chrono::__is_duration_v<_Tp>)
1055 __throw_format_error(
"format error: argument is not a duration");
1058 namespace __d = chrono::__detail;
1059 using period =
typename _Tp::period;
1060 return __d::__fmt_units_suffix<period, _CharT>(
std::move(__out));
1066 template<
typename _Tp,
typename _FormatContext>
1067 typename _FormatContext::iterator
1068 _M_r(
const _Tp& __tt,
typename _FormatContext::iterator __out,
1069 _FormatContext& __ctx)
const
1072 auto __t = _S_floor_seconds(__tt);
1073 locale __loc = _M_locale(__ctx);
1074 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1075 const _CharT* __ampm_fmt;
1076 __tp._M_am_pm_format(&__ampm_fmt);
1077 basic_string<_CharT> __fmt(_S_empty_spec);
1078 __fmt.insert(1u, 1u, _S_colon);
1079 __fmt.insert(2u, __ampm_fmt);
1084 template<
typename _Tp,
typename _FormatContext>
1085 typename _FormatContext::iterator
1086 _M_R_T(
const _Tp& __t,
typename _FormatContext::iterator __out,
1087 _FormatContext& __ctx,
bool __secs)
const
1091 auto __hms = _S_hms(__t);
1093 auto __s = std::format(_GLIBCXX_WIDEN(
"{:02d}:00"),
1094 __hms.hours().count());
1095 auto __sv = _S_two_digits(__hms.minutes().count());
1096 __s[__s.size() - 2] = __sv[0];
1097 __s[__s.size() - 1] = __sv[1];
1099 __out = __format::__write(
std::move(__out), __sv);
1102 *__out++ = _S_colon;
1103 __out = _M_S(__hms,
std::move(__out), __ctx);
1108 template<
typename _Tp,
typename _FormatContext>
1109 typename _FormatContext::iterator
1110 _M_S(
const _Tp& __t,
typename _FormatContext::iterator __out,
1111 _FormatContext& __ctx,
bool __mod =
false)
const
1115 auto __hms = _S_hms(__t);
1117 if (__mod) [[unlikely]]
1120 __tm.tm_sec = (int)__hms.seconds().count();
1121 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
1125 __out = __format::__write(
std::move(__out),
1126 _S_two_digits(__hms.seconds().count()));
1127 if constexpr (__hms.fractional_width != 0)
1129 locale __loc = _M_locale(__ctx);
1130 auto __ss = __hms.subseconds();
1131 using rep =
typename decltype(__ss)::rep;
1132 if constexpr (is_floating_point_v<rep>)
1135 _GLIBCXX_WIDEN(
"{:.{}Lg}"),
1137 __hms.fractional_width);
1139 else if constexpr (is_integral_v<rep>)
1142 = use_facet<numpunct<_CharT>>(__loc);
1144 _GLIBCXX_WIDEN(
"{}{:0{}}"),
1145 __np.decimal_point(),
1147 __hms.fractional_width);
1152 = use_facet<numpunct<_CharT>>(__loc);
1153 *__out++ = __np.decimal_point();
1154 auto __str = std::format(_S_empty_spec, __ss.count());
1157 __hms.fractional_width);
1165 template<
typename _Tp,
typename _FormatContext>
1166 typename _FormatContext::iterator
1167 _M_u_w(
const _Tp& __t,
typename _FormatContext::iterator __out,
1168 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
1175 chrono::weekday __wd = _S_weekday(__t);
1177 if (__mod) [[unlikely]]
1180 __tm.tm_wday = __wd.c_encoding();
1181 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
1185 unsigned __wdi = __conv ==
'u' ? __wd.iso_encoding()
1186 : __wd.c_encoding();
1187 const _CharT __d = _S_digit(__wdi);
1188 return __format::__write(
std::move(__out), __string_view(&__d, 1));
1191 template<
typename _Tp,
typename _FormatContext>
1192 typename _FormatContext::iterator
1193 _M_U_V_W(
const _Tp& __t,
typename _FormatContext::iterator __out,
1194 _FormatContext& __ctx, _CharT __conv,
bool __mod =
false)
const
1202 using namespace chrono;
1203 auto __d = _S_days(__t);
1204 using _TDays =
decltype(__d);
1206 if (__mod) [[unlikely]]
1208 const year_month_day __ymd(__d);
1209 const year __y = __ymd.year();
1211 __tm.tm_year = (int)__y - 1900;
1212 __tm.tm_yday = (__d - _TDays(__y/January/1)).count();
1213 __tm.tm_wday = weekday(__d).c_encoding();
1214 return _M_locale_fmt(
std::move(__out), _M_locale(__ctx), __tm,
1222 __d -= (weekday(__d) - Monday) -
days(3);
1225 __first = _TDays(year_month_day(__d).year()/January/1);
1230 if constexpr (
requires { __t.year(); })
1233 __y = year_month_day(__d).year();
1234 const weekday __weekstart = __conv ==
'U' ? Sunday : Monday;
1235 __first = _TDays(__y/January/__weekstart[1]);
1237 auto __weeks = chrono::floor<weeks>(__d - __first);
1238 __string_view __sv = _S_two_digits(__weeks.count() + 1);
1239 return __format::__write(
std::move(__out), __sv);
1242 template<
typename _Tp,
typename _FormatContext>
1243 typename _FormatContext::iterator
1244 _M_x(
const _Tp& __t,
typename _FormatContext::iterator __out,
1245 _FormatContext& __ctx,
bool __mod =
false)
const
1249 locale __loc = _M_locale(__ctx);
1250 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1251 const _CharT* __date_reps[2];
1252 __tp._M_date_formats(__date_reps);
1253 const _CharT* __rep = __date_reps[__mod];
1255 return _M_D(__t,
std::move(__out), __ctx);
1257 basic_string<_CharT> __fmt(_S_empty_spec);
1258 __fmt.insert(1u, 1u, _S_colon);
1259 __fmt.insert(2u, __rep);
1264 template<
typename _Tp,
typename _FormatContext>
1265 typename _FormatContext::iterator
1266 _M_X(
const _Tp& __tt,
typename _FormatContext::iterator __out,
1267 _FormatContext& __ctx,
bool __mod =
false)
const
1271 auto __t = _S_floor_seconds(__tt);
1272 locale __loc = _M_locale(__ctx);
1273 const auto& __tp = use_facet<__timepunct<_CharT>>(__loc);
1274 const _CharT* __time_reps[2];
1275 __tp._M_time_formats(__time_reps);
1276 const _CharT* __rep = __time_reps[__mod];
1278 return _M_R_T(__t,
std::move(__out), __ctx,
true);
1280 basic_string<_CharT> __fmt(_S_empty_spec);
1281 __fmt.insert(1u, 1u, _S_colon);
1282 __fmt.insert(2u, __rep);
1287 template<
typename _Tp,
typename _FormatContext>
1288 typename _FormatContext::iterator
1289 _M_z(
const _Tp& __t,
typename _FormatContext::iterator __out,
1290 _FormatContext&,
bool __mod =
false)
const
1292 using ::std::chrono::__detail::__utc_leap_second;
1293 using ::std::chrono::__detail::__local_time_fmt;
1295 auto __utc = __mod ? __string_view(_GLIBCXX_WIDEN(
"+00:00"), 6)
1296 : __string_view(_GLIBCXX_WIDEN(
"+0000"), 5);
1298 if constexpr (chrono::__is_time_point_v<_Tp>)
1300 if constexpr (is_same_v<
typename _Tp::clock,
1301 chrono::system_clock>)
1302 return __format::__write(
std::move(__out), __utc);
1304 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1306 if (__t._M_offset_sec)
1309 basic_string<_CharT> __s;
1310 if (*__t._M_offset_sec != 0s)
1312 chrono:: hh_mm_ss __hms(*__t._M_offset_sec);
1313 __s = _S_plus_minus[__hms.is_negative()];
1314 __s += _S_two_digits(__hms.hours().count());
1317 __s += _S_two_digits(__hms.minutes().count());
1320 return __format::__write(
std::move(__out), __sv);
1323 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1324 return __format::__write(
std::move(__out), __utc);
1326 __no_timezone_available();
1329 template<
typename _Tp,
typename _FormatContext>
1330 typename _FormatContext::iterator
1331 _M_Z(
const _Tp& __t,
typename _FormatContext::iterator __out,
1332 _FormatContext& __ctx)
const
1334 using ::std::chrono::__detail::__utc_leap_second;
1335 using ::std::chrono::__detail::__local_time_fmt;
1337 __string_view __utc(_GLIBCXX_WIDEN(
"UTC"), 3);
1338 if constexpr (chrono::__is_time_point_v<_Tp>)
1340 if constexpr (is_same_v<
typename _Tp::clock,
1341 chrono::system_clock>)
1342 return __format::__write(
std::move(__out), __utc);
1344 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1348 string_view __sv = *__t._M_abbrev;
1349 if constexpr (is_same_v<_CharT, char>)
1350 return __format::__write(
std::move(__out), __sv);
1354 basic_string<_CharT> __ws(__sv.size(), _CharT());
1355 auto& __ct = use_facet<ctype<_CharT>>(_M_locale(__ctx));
1356 __ct.widen(__sv.begin(), __sv.end(), __ws.data());
1357 __string_view __wsv = __ws;
1358 return __format::__write(
std::move(__out), __wsv);
1362 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1363 return __format::__write(
std::move(__out), __utc);
1365 __no_timezone_available();
1372 _S_digit(
int __n)
noexcept
1375 return _GLIBCXX_WIDEN(
"0123456789999999")[__n & 0xf];
1379 static basic_string_view<_CharT>
1380 _S_two_digits(
int __n)
noexcept
1383 _GLIBCXX_WIDEN(
"0001020304050607080910111213141516171819"
1384 "2021222324252627282930313233343536373839"
1385 "4041424344454647484950515253545556575859"
1386 "6061626364656667686970717273747576777879"
1387 "8081828384858687888990919293949596979899"
1388 "9999999999999999999999999999999999999999"
1389 "9999999999999999") + 2 * (__n & 0x7f),
1397 template<
typename _Tp>
1398 static decltype(
auto)
1399 _S_hms(
const _Tp& __t)
1401 using ::std::chrono::__detail::__utc_leap_second;
1402 using ::std::chrono::__detail::__local_time_fmt;
1404 if constexpr (__is_specialization_of<_Tp, chrono::hh_mm_ss>)
1406 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1408 else if constexpr (chrono::__is_duration_v<_Tp>)
1409 return chrono::hh_mm_ss<_Tp>(__t);
1410 else if constexpr (chrono::__is_time_point_v<_Tp>)
1411 return chrono::hh_mm_ss(__t - chrono::floor<chrono::days>(__t));
1412 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1413 return _S_hms(__t._M_time);
1416 __invalid_chrono_spec();
1417 return chrono::hh_mm_ss<chrono::seconds>();
1422 template<
typename _Tp>
1424 _S_days(
const _Tp& __t)
1426 using namespace chrono;
1427 using ::std::chrono::__detail::__utc_leap_second;
1428 using ::std::chrono::__detail::__local_time_fmt;
1430 if constexpr (__is_time_point_v<_Tp>)
1431 return chrono::floor<days>(__t);
1432 else if constexpr (__is_specialization_of<_Tp, __utc_leap_second>)
1434 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1435 return chrono::floor<days>(__t._M_time);
1436 else if constexpr (is_same_v<_Tp, year_month_day>
1437 || is_same_v<_Tp, year_month_day_last>
1438 || is_same_v<_Tp, year_month_weekday>
1439 || is_same_v<_Tp, year_month_weekday_last>)
1440 return sys_days(__t);
1443 if constexpr (__is_duration_v<_Tp>)
1444 __not_valid_for_duration();
1446 __invalid_chrono_spec();
1447 return chrono::sys_days();
1452 template<
typename _Tp>
1453 static chrono::year_month_day
1454 _S_date(
const _Tp& __t)
1456 if constexpr (is_same_v<_Tp, chrono::year_month_day>)
1459 return chrono::year_month_day(_S_days(__t));
1462 template<
typename _Tp>
1464 _S_day(
const _Tp& __t)
1466 using namespace chrono;
1468 if constexpr (is_same_v<_Tp, day>)
1470 else if constexpr (
requires { __t.day(); })
1473 return _S_date(__t).day();
1476 template<
typename _Tp>
1477 static chrono::month
1478 _S_month(
const _Tp& __t)
1480 using namespace chrono;
1482 if constexpr (is_same_v<_Tp, month>)
1484 else if constexpr (
requires { __t.month(); })
1487 return _S_date(__t).month();
1490 template<
typename _Tp>
1492 _S_year(
const _Tp& __t)
1494 using namespace chrono;
1496 if constexpr (is_same_v<_Tp, year>)
1498 else if constexpr (
requires { __t.year(); })
1501 return _S_date(__t).year();
1504 template<
typename _Tp>
1505 static chrono::weekday
1506 _S_weekday(
const _Tp& __t)
1509 using ::std::chrono::__detail::__local_time_fmt;
1511 if constexpr (is_same_v<_Tp, weekday>)
1513 else if constexpr (
requires { __t.weekday(); })
1514 return __t.weekday();
1515 else if constexpr (is_same_v<_Tp, month_weekday>)
1516 return __t.weekday_indexed().weekday();
1517 else if constexpr (is_same_v<_Tp, month_weekday_last>)
1518 return __t.weekday_last().weekday();
1520 return weekday(_S_days(__t));
1524 template<
typename _Tp>
1526 _S_floor_seconds(
const _Tp& __t)
1528 using chrono::__detail::__local_time_fmt;
1529 if constexpr (chrono::__is_time_point_v<_Tp>
1530 || chrono::__is_duration_v<_Tp>)
1532 if constexpr (_Tp::period::den != 1)
1533 return chrono::floor<chrono::seconds>(__t);
1537 else if constexpr (__is_specialization_of<_Tp, chrono::hh_mm_ss>)
1539 if constexpr (_Tp::fractional_width != 0)
1540 return chrono::floor<chrono::seconds>(__t.to_duration());
1544 else if constexpr (__is_specialization_of<_Tp, __local_time_fmt>)
1545 return _S_floor_seconds(__t._M_time);
1552 template<
typename _Iter>
1554 _M_locale_fmt(_Iter __out,
const locale& __loc,
const struct tm& __tm,
1555 char __fmt,
char __mod)
const
1557 basic_ostringstream<_CharT> __os;
1558 const auto& __tp = use_facet<time_put<_CharT>>(__loc);
1559 __tp.put(__os, __os, _S_space, &__tm, __fmt, __mod);
1561 __out = __format::__write(
std::move(__out), __os.view());
1569 template<
typename _Rep,
typename _Period,
typename _CharT>
1570 struct formatter<chrono::duration<_Rep, _Period>, _CharT>
1572 constexpr typename basic_format_parse_context<_CharT>::iterator
1573 parse(basic_format_parse_context<_CharT>& __pc)
1575 using namespace __format;
1576 auto __it = _M_f._M_parse(__pc, _Duration|_TimeOfDay);
1577 if constexpr (!is_floating_point_v<_Rep>)
1578 if (_M_f._M_spec._M_prec_kind != __format::_WP_none)
1579 __throw_format_error(
"format error: invalid precision for duration");
1583 template<
typename _Out>
1584 typename basic_format_context<_Out, _CharT>::iterator
1585 format(
const chrono::duration<_Rep, _Period>& __d,
1586 basic_format_context<_Out, _CharT>& __fc)
const
1588 return _M_f._M_format(
chrono::abs(__d), __fc, __d < __d.zero());
1592 __format::__formatter_chrono<_CharT> _M_f;
1595 template<
typename _CharT>
1596 struct formatter<chrono::day, _CharT>
1598 template<
typename _ParseContext>
1599 constexpr typename _ParseContext::iterator
1600 parse(_ParseContext& __pc)
1601 {
return _M_f._M_parse(__pc, __format::_Day); }
1603 template<
typename _FormatContext>
1604 typename _FormatContext::iterator
1605 format(
const chrono::day& __t, _FormatContext& __fc)
const
1606 {
return _M_f._M_format(__t, __fc); }
1609 __format::__formatter_chrono<_CharT> _M_f;
1612 template<
typename _CharT>
1613 struct formatter<chrono::month, _CharT>
1615 template<
typename _ParseContext>
1616 constexpr typename _ParseContext::iterator
1617 parse(_ParseContext& __pc)
1618 {
return _M_f._M_parse(__pc, __format::_Month); }
1620 template<
typename _FormatContext>
1621 typename _FormatContext::iterator
1622 format(
const chrono::month& __t, _FormatContext& __fc)
const
1623 {
return _M_f._M_format(__t, __fc); }
1626 __format::__formatter_chrono<_CharT> _M_f;
1629 template<
typename _CharT>
1630 struct formatter<chrono::year, _CharT>
1632 template<
typename _ParseContext>
1633 constexpr typename _ParseContext::iterator
1634 parse(_ParseContext& __pc)
1635 {
return _M_f._M_parse(__pc, __format::_Year); }
1637 template<
typename _FormatContext>
1638 typename _FormatContext::iterator
1639 format(
const chrono::year& __t, _FormatContext& __fc)
const
1640 {
return _M_f._M_format(__t, __fc); }
1643 __format::__formatter_chrono<_CharT> _M_f;
1646 template<
typename _CharT>
1647 struct formatter<chrono::weekday, _CharT>
1649 template<
typename _ParseContext>
1650 constexpr typename _ParseContext::iterator
1651 parse(_ParseContext& __pc)
1652 {
return _M_f._M_parse(__pc, __format::_Weekday); }
1654 template<
typename _FormatContext>
1655 typename _FormatContext::iterator
1656 format(
const chrono::weekday& __t, _FormatContext& __fc)
const
1657 {
return _M_f._M_format(__t, __fc); }
1660 __format::__formatter_chrono<_CharT> _M_f;
1663 template<
typename _CharT>
1664 struct formatter<chrono::weekday_indexed, _CharT>
1666 template<
typename _ParseContext>
1667 constexpr typename _ParseContext::iterator
1668 parse(_ParseContext& __pc)
1669 {
return _M_f._M_parse(__pc, __format::_Weekday); }
1671 template<
typename _FormatContext>
1672 typename _FormatContext::iterator
1673 format(
const chrono::weekday_indexed& __t, _FormatContext& __fc)
const
1674 {
return _M_f._M_format(__t, __fc); }
1677 __format::__formatter_chrono<_CharT> _M_f;
1680 template<
typename _CharT>
1681 struct formatter<chrono::weekday_last, _CharT>
1683 template<
typename _ParseContext>
1684 constexpr typename _ParseContext::iterator
1685 parse(_ParseContext& __pc)
1686 {
return _M_f._M_parse(__pc, __format::_Weekday); }
1688 template<
typename _FormatContext>
1689 typename _FormatContext::iterator
1690 format(
const chrono::weekday_last& __t, _FormatContext& __fc)
const
1691 {
return _M_f._M_format(__t, __fc); }
1694 __format::__formatter_chrono<_CharT> _M_f;
1697 template<
typename _CharT>
1698 struct formatter<chrono::month_day, _CharT>
1700 template<
typename _ParseContext>
1701 constexpr typename _ParseContext::iterator
1702 parse(_ParseContext& __pc)
1703 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Day); }
1705 template<
typename _FormatContext>
1706 typename _FormatContext::iterator
1707 format(
const chrono::month_day& __t, _FormatContext& __fc)
const
1708 {
return _M_f._M_format(__t, __fc); }
1711 __format::__formatter_chrono<_CharT> _M_f;
1714 template<
typename _CharT>
1715 struct formatter<chrono::month_day_last, _CharT>
1717 template<
typename _ParseContext>
1718 constexpr typename _ParseContext::iterator
1719 parse(_ParseContext& __pc)
1720 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Day); }
1722 template<
typename _FormatContext>
1723 typename _FormatContext::iterator
1724 format(
const chrono::month_day_last& __t, _FormatContext& __fc)
const
1725 {
return _M_f._M_format(__t, __fc); }
1728 __format::__formatter_chrono<_CharT> _M_f;
1731 template<
typename _CharT>
1732 struct formatter<chrono::month_weekday, _CharT>
1734 template<
typename _ParseContext>
1735 constexpr typename _ParseContext::iterator
1736 parse(_ParseContext& __pc)
1737 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Weekday); }
1739 template<
typename _FormatContext>
1740 typename _FormatContext::iterator
1741 format(
const chrono::month_weekday& __t, _FormatContext& __fc)
const
1742 {
return _M_f._M_format(__t, __fc); }
1745 __format::__formatter_chrono<_CharT> _M_f;
1748 template<
typename _CharT>
1749 struct formatter<chrono::month_weekday_last, _CharT>
1751 template<
typename _ParseContext>
1752 constexpr typename _ParseContext::iterator
1753 parse(_ParseContext& __pc)
1754 {
return _M_f._M_parse(__pc, __format::_Month|__format::_Weekday); }
1756 template<
typename _FormatContext>
1757 typename _FormatContext::iterator
1758 format(
const chrono::month_weekday_last& __t,
1759 _FormatContext& __fc)
const
1760 {
return _M_f._M_format(__t, __fc); }
1763 __format::__formatter_chrono<_CharT> _M_f;
1766 template<
typename _CharT>
1767 struct formatter<chrono::year_month, _CharT>
1769 template<
typename _ParseContext>
1770 constexpr typename _ParseContext::iterator
1771 parse(_ParseContext& __pc)
1772 {
return _M_f._M_parse(__pc, __format::_Year|__format::_Month); }
1774 template<
typename _FormatContext>
1775 typename _FormatContext::iterator
1776 format(
const chrono::year_month& __t, _FormatContext& __fc)
const
1777 {
return _M_f._M_format(__t, __fc); }
1780 __format::__formatter_chrono<_CharT> _M_f;
1783 template<
typename _CharT>
1784 struct formatter<chrono::year_month_day, _CharT>
1786 template<
typename _ParseContext>
1787 constexpr typename _ParseContext::iterator
1788 parse(_ParseContext& __pc)
1789 {
return _M_f._M_parse(__pc, __format::_Date); }
1791 template<
typename _FormatContext>
1792 typename _FormatContext::iterator
1793 format(
const chrono::year_month_day& __t, _FormatContext& __fc)
const
1794 {
return _M_f._M_format(__t, __fc); }
1797 __format::__formatter_chrono<_CharT> _M_f;
1800 template<
typename _CharT>
1801 struct formatter<chrono::year_month_day_last, _CharT>
1803 template<
typename _ParseContext>
1804 constexpr typename _ParseContext::iterator
1805 parse(_ParseContext& __pc)
1806 {
return _M_f._M_parse(__pc, __format::_Date); }
1808 template<
typename _FormatContext>
1809 typename _FormatContext::iterator
1810 format(
const chrono::year_month_day_last& __t,
1811 _FormatContext& __fc)
const
1812 {
return _M_f._M_format(__t, __fc); }
1815 __format::__formatter_chrono<_CharT> _M_f;
1818 template<
typename _CharT>
1819 struct formatter<chrono::year_month_weekday, _CharT>
1821 template<
typename _ParseContext>
1822 constexpr typename _ParseContext::iterator
1823 parse(_ParseContext& __pc)
1824 {
return _M_f._M_parse(__pc, __format::_Date); }
1826 template<
typename _FormatContext>
1827 typename _FormatContext::iterator
1828 format(
const chrono::year_month_weekday& __t,
1829 _FormatContext& __fc)
const
1830 {
return _M_f._M_format(__t, __fc); }
1833 __format::__formatter_chrono<_CharT> _M_f;
1836 template<
typename _CharT>
1837 struct formatter<chrono::year_month_weekday_last, _CharT>
1839 template<
typename _ParseContext>
1840 constexpr typename _ParseContext::iterator
1841 parse(_ParseContext& __pc)
1842 {
return _M_f._M_parse(__pc, __format::_Date); }
1844 template<
typename _FormatContext>
1845 typename _FormatContext::iterator
1846 format(
const chrono::year_month_weekday_last& __t,
1847 _FormatContext& __fc)
const
1848 {
return _M_f._M_format(__t, __fc); }
1851 __format::__formatter_chrono<_CharT> _M_f;
1854 template<
typename _Rep,
typename _Period,
typename _CharT>
1855 struct formatter<chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>, _CharT>
1857 template<
typename _ParseContext>
1858 constexpr typename _ParseContext::iterator
1859 parse(_ParseContext& __pc)
1860 {
return _M_f._M_parse(__pc, __format::_TimeOfDay); }
1862 template<
typename _FormatContext>
1863 typename _FormatContext::iterator
1864 format(
const chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>& __t,
1865 _FormatContext& __fc)
const
1866 {
return _M_f._M_format(__t, __fc); }
1869 __format::__formatter_chrono<_CharT> _M_f;
1872#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
1873 template<
typename _CharT>
1874 struct formatter<chrono::sys_info, _CharT>
1876 template<
typename _ParseContext>
1877 constexpr typename _ParseContext::iterator
1878 parse(_ParseContext& __pc)
1879 {
return _M_f._M_parse(__pc, __format::_ChronoParts{}); }
1881 template<
typename _FormatContext>
1882 typename _FormatContext::iterator
1883 format(
const chrono::sys_info& __i, _FormatContext& __fc)
const
1884 {
return _M_f._M_format(__i, __fc); }
1887 __format::__formatter_chrono<_CharT> _M_f;
1890 template<
typename _CharT>
1891 struct formatter<chrono::local_info, _CharT>
1893 template<
typename _ParseContext>
1894 constexpr typename _ParseContext::iterator
1895 parse(_ParseContext& __pc)
1896 {
return _M_f._M_parse(__pc, __format::_ChronoParts{}); }
1898 template<
typename _FormatContext>
1899 typename _FormatContext::iterator
1900 format(
const chrono::local_info& __i, _FormatContext& __fc)
const
1901 {
return _M_f._M_format(__i, __fc); }
1904 __format::__formatter_chrono<_CharT> _M_f;
1908 template<
typename _Duration,
typename _CharT>
1909 struct formatter<chrono::sys_time<_Duration>, _CharT>
1911 template<
typename _ParseContext>
1912 constexpr typename _ParseContext::iterator
1913 parse(_ParseContext& __pc)
1914 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
1916 template<
typename _FormatContext>
1917 typename _FormatContext::iterator
1918 format(
const chrono::sys_time<_Duration>& __t,
1919 _FormatContext& __fc)
const
1920 {
return _M_f._M_format(__t, __fc); }
1923 __format::__formatter_chrono<_CharT> _M_f;
1926 template<
typename _Duration,
typename _CharT>
1927 struct formatter<chrono::utc_time<_Duration>, _CharT>
1928 : __format::__formatter_chrono<_CharT>
1930 template<
typename _ParseContext>
1931 constexpr typename _ParseContext::iterator
1932 parse(_ParseContext& __pc)
1933 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
1935 template<
typename _FormatContext>
1936 typename _FormatContext::iterator
1937 format(
const chrono::utc_time<_Duration>& __t,
1938 _FormatContext& __fc)
const
1943 using chrono::__detail::__utc_leap_second;
1945 using chrono::sys_time;
1946 using _CDur = common_type_t<_Duration, seconds>;
1947 const auto __li = chrono::get_leap_second_info(__t);
1948 sys_time<_CDur> __s{__t.time_since_epoch() - __li.elapsed};
1949 if (!__li.is_leap_second) [[likely]]
1950 return _M_f._M_format(__s, __fc);
1952 return _M_f._M_format(__utc_leap_second(__s), __fc);
1956 friend formatter<chrono::__detail::__utc_leap_second<_Duration>, _CharT>;
1958 __format::__formatter_chrono<_CharT> _M_f;
1961 template<
typename _Duration,
typename _CharT>
1962 struct formatter<chrono::tai_time<_Duration>, _CharT>
1963 : __format::__formatter_chrono<_CharT>
1965 template<
typename _ParseContext>
1966 constexpr typename _ParseContext::iterator
1967 parse(_ParseContext& __pc)
1968 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
1970 template<
typename _FormatContext>
1971 typename _FormatContext::iterator
1972 format(
const chrono::tai_time<_Duration>& __t,
1973 _FormatContext& __fc)
const
1979 using _CDur = common_type_t<_Duration, chrono::days>;
1980 chrono::local_time<_CDur> __lt(__t.time_since_epoch() - __tai_offset);
1981 const string __abbrev(
"TAI", 3);
1984 return _M_f._M_format(__lf, __fc);
1988 __format::__formatter_chrono<_CharT> _M_f;
1991 template<
typename _Duration,
typename _CharT>
1992 struct formatter<chrono::gps_time<_Duration>, _CharT>
1993 : __format::__formatter_chrono<_CharT>
1995 template<
typename _ParseContext>
1996 constexpr typename _ParseContext::iterator
1997 parse(_ParseContext& __pc)
1998 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2000 template<
typename _FormatContext>
2001 typename _FormatContext::iterator
2002 format(
const chrono::gps_time<_Duration>& __t,
2003 _FormatContext& __fc)
const
2009 using _CDur = common_type_t<_Duration, chrono::days>;
2010 chrono::local_time<_CDur> __lt(__t.time_since_epoch() + __gps_offset);
2011 const string __abbrev(
"GPS", 3);
2014 return _M_f._M_format(__lf, __fc);
2018 __format::__formatter_chrono<_CharT> _M_f;
2021 template<
typename _Duration,
typename _CharT>
2022 struct formatter<chrono::file_time<_Duration>, _CharT>
2024 template<
typename _ParseContext>
2025 constexpr typename _ParseContext::iterator
2026 parse(_ParseContext& __pc)
2027 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2029 template<
typename _FormatContext>
2030 typename _FormatContext::iterator
2031 format(
const chrono::file_time<_Duration>& __t,
2032 _FormatContext& __ctx)
const
2034 using namespace chrono;
2035 return _M_f._M_format(chrono::clock_cast<system_clock>(__t), __ctx);
2039 __format::__formatter_chrono<_CharT> _M_f;
2042 template<
typename _Duration,
typename _CharT>
2043 struct formatter<chrono::local_time<_Duration>, _CharT>
2045 template<
typename _ParseContext>
2046 constexpr typename _ParseContext::iterator
2047 parse(_ParseContext& __pc)
2048 {
return _M_f._M_parse(__pc, __format::_DateTime); }
2050 template<
typename _FormatContext>
2051 typename _FormatContext::iterator
2052 format(
const chrono::local_time<_Duration>& __t,
2053 _FormatContext& __ctx)
const
2054 {
return _M_f._M_format(__t, __ctx); }
2057 __format::__formatter_chrono<_CharT> _M_f;
2060 template<
typename _Duration,
typename _CharT>
2061 struct formatter<chrono::__detail::__local_time_fmt<_Duration>, _CharT>
2063 template<
typename _ParseContext>
2064 constexpr typename _ParseContext::iterator
2065 parse(_ParseContext& __pc)
2066 {
return _M_f._M_parse(__pc, __format::_ZonedDateTime); }
2068 template<
typename _FormatContext>
2069 typename _FormatContext::iterator
2070 format(
const chrono::__detail::__local_time_fmt<_Duration>& __t,
2071 _FormatContext& __ctx)
const
2072 {
return _M_f._M_format(__t, __ctx); }
2075 __format::__formatter_chrono<_CharT> _M_f;
2078#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2079 template<
typename _Duration,
typename _TimeZonePtr,
typename _CharT>
2080 struct formatter<chrono::zoned_time<_Duration, _TimeZonePtr>, _CharT>
2081 : formatter<chrono::__detail::__local_time_fmt<_Duration>, _CharT>
2083 template<
typename _FormatContext>
2084 typename _FormatContext::iterator
2085 format(
const chrono::zoned_time<_Duration, _TimeZonePtr>& __tp,
2086 _FormatContext& __ctx)
const
2088 using chrono::__detail::__local_time_fmt;
2089 using _Base = formatter<__local_time_fmt<_Duration>, _CharT>;
2090 const chrono::sys_info __info = __tp.get_info();
2094 return _Base::format(__lf, __ctx);
2100 template<
typename _Duration,
typename _CharT>
2101 struct formatter<chrono::__detail::__utc_leap_second<_Duration>, _CharT>
2102 : formatter<chrono::utc_time<_Duration>, _CharT>
2104 template<
typename _FormatContext>
2105 typename _FormatContext::iterator
2106 format(
const chrono::__detail::__utc_leap_second<_Duration>& __t,
2107 _FormatContext& __fc)
const
2108 {
return this->_M_f._M_format(__t, __fc); }
2119 template<
typename _Duration = seconds>
2122 static_assert(is_same_v<common_type_t<_Duration, seconds>, _Duration>);
2125 _Parser(__format::_ChronoParts __need) : _M_need(__need) { }
2127 _Parser(_Parser&&) =
delete;
2128 void operator=(_Parser&&) =
delete;
2130 _Duration _M_time{};
2131 sys_days _M_sys_days{};
2132 year_month_day _M_ymd{};
2134 __format::_ChronoParts _M_need;
2136 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2137 basic_istream<_CharT, _Traits>&
2138 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2139 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2140 minutes* __offset =
nullptr);
2145 template<
typename _CharT,
typename _Traits>
2146 static int_least32_t
2147 _S_read_unsigned(basic_istream<_CharT, _Traits>& __is,
2148 ios_base::iostate& __err,
int __n)
2150 int_least32_t __val = _S_try_read_digit(__is, __err);
2151 if (__val == -1) [[unlikely]]
2152 __err |= ios_base::failbit;
2157 for (
int __i = 1; __i < __n1; ++__i)
2158 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
2164 while (__n1++ < __n) [[unlikely]]
2165 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
2167 if (__builtin_mul_overflow(__val, 10, &__val)
2168 || __builtin_add_overflow(__val, __dig, &__val))
2170 __err |= ios_base::failbit;
2180 template<
typename _CharT,
typename _Traits>
2181 static int_least32_t
2182 _S_read_signed(basic_istream<_CharT, _Traits>& __is,
2183 ios_base::iostate& __err,
int __n)
2185 auto __sign = __is.peek();
2186 if (__sign ==
'-' || __sign ==
'+')
2188 int_least32_t __val = _S_read_unsigned(__is, __err, __n);
2189 if (__err & ios_base::failbit)
2191 if (__sign ==
'-') [[unlikely]]
2199 template<
typename _CharT,
typename _Traits>
2200 static int_least32_t
2201 _S_try_read_digit(basic_istream<_CharT, _Traits>& __is,
2202 ios_base::iostate& __err)
2204 int_least32_t __val = -1;
2205 auto __i = __is.peek();
2206 if (!_Traits::eq_int_type(__i, _Traits::eof())) [[likely]]
2208 _CharT __c = _Traits::to_char_type(__i);
2209 if (_CharT(
'0') <= __c && __c <= _CharT(
'9')) [[likely]]
2212 __val = __c - _CharT(
'0');
2216 __err |= ios_base::eofbit;
2222 template<
typename _CharT,
typename _Traits>
2224 _S_read_chr(basic_istream<_CharT, _Traits>& __is,
2225 ios_base::iostate& __err, _CharT __c)
2227 auto __i = __is.peek();
2228 if (_Traits::eq_int_type(__i, _Traits::eof()))
2229 __err |= ios_base::eofbit;
2230 else if (_Traits::to_char_type(__i) == __c) [[likely]]
2235 __err |= ios_base::failbit;
2240 template<
typename _Duration>
2241 using _Parser_t = _Parser<common_type_t<_Duration, seconds>>;
2246 template<
typename _CharT,
typename _Traits,
typename _Rep,
typename _Period,
2247 typename _Alloc = allocator<_CharT>>
2248 inline basic_istream<_CharT, _Traits>&
2249 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2250 duration<_Rep, _Period>& __d,
2251 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2254 auto __need = __format::_ChronoParts::_TimeOfDay;
2255 __detail::_Parser_t<duration<_Rep, _Period>> __p(__need);
2256 if (__p(__is, __fmt, __abbrev, __offset))
2257 __d = chrono::duration_cast<duration<_Rep, _Period>>(__p._M_time);
2261 template<
typename _CharT,
typename _Traits>
2262 inline basic_ostream<_CharT, _Traits>&
2263 operator<<(basic_ostream<_CharT, _Traits>& __os,
const day& __d)
2265 using _Ctx = __format::__format_context<_CharT>;
2266 using _Str = basic_string_view<_CharT>;
2267 _Str __s = _GLIBCXX_WIDEN(
"{:02d} is not a valid day");
2269 __s = __s.substr(0, 6);
2270 auto __u = (unsigned)__d;
2271 __os << std::vformat(__s, make_format_args<_Ctx>(__u));
2275 template<
typename _CharT,
typename _Traits,
2276 typename _Alloc = allocator<_CharT>>
2277 inline basic_istream<_CharT, _Traits>&
2278 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2280 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2283 __detail::_Parser<> __p(__format::_ChronoParts::_Day);
2284 if (__p(__is, __fmt, __abbrev, __offset))
2285 __d = __p._M_ymd.day();
2289 template<
typename _CharT,
typename _Traits>
2290 inline basic_ostream<_CharT, _Traits>&
2291 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month& __m)
2293 using _Ctx = __format::__format_context<_CharT>;
2294 using _Str = basic_string_view<_CharT>;
2295 _Str __s = _GLIBCXX_WIDEN(
"{:L%b}{} is not a valid month");
2298 make_format_args<_Ctx>(__m));
2301 auto __u = (unsigned)__m;
2302 __os <<
std::vformat(__s.substr(6), make_format_args<_Ctx>(__u));
2307 template<
typename _CharT,
typename _Traits,
2308 typename _Alloc = allocator<_CharT>>
2309 inline basic_istream<_CharT, _Traits>&
2310 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2312 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2315 __detail::_Parser<> __p(__format::_ChronoParts::_Month);
2316 if (__p(__is, __fmt, __abbrev, __offset))
2317 __m = __p._M_ymd.month();
2321 template<
typename _CharT,
typename _Traits>
2322 inline basic_ostream<_CharT, _Traits>&
2323 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year& __y)
2325 using _Ctx = __format::__format_context<_CharT>;
2326 using _Str = basic_string_view<_CharT>;
2327 _Str __s = _GLIBCXX_WIDEN(
"-{:04d} is not a valid year");
2329 __s = __s.substr(0, 7);
2331 if (__i >= 0) [[likely]]
2332 __s.remove_prefix(1);
2335 __os << std::vformat(__s, make_format_args<_Ctx>(__i));
2339 template<
typename _CharT,
typename _Traits,
2340 typename _Alloc = allocator<_CharT>>
2341 inline basic_istream<_CharT, _Traits>&
2342 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2344 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2347 __detail::_Parser<> __p(__format::_ChronoParts::_Year);
2348 if (__p(__is, __fmt, __abbrev, __offset))
2349 __y = __p._M_ymd.year();
2353 template<
typename _CharT,
typename _Traits>
2354 inline basic_ostream<_CharT, _Traits>&
2355 operator<<(basic_ostream<_CharT, _Traits>& __os,
const weekday& __wd)
2357 using _Ctx = __format::__format_context<_CharT>;
2358 using _Str = basic_string_view<_CharT>;
2359 _Str __s = _GLIBCXX_WIDEN(
"{:L%a}{} is not a valid weekday");
2362 make_format_args<_Ctx>(__wd));
2365 auto __c = __wd.c_encoding();
2366 __os <<
std::vformat(__s.substr(6), make_format_args<_Ctx>(__c));
2371 template<
typename _CharT,
typename _Traits,
2372 typename _Alloc = allocator<_CharT>>
2373 inline basic_istream<_CharT, _Traits>&
2374 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2376 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2379 __detail::_Parser<> __p(__format::_ChronoParts::_Weekday);
2380 if (__p(__is, __fmt, __abbrev, __offset))
2385 template<
typename _CharT,
typename _Traits>
2386 inline basic_ostream<_CharT, _Traits>&
2387 operator<<(basic_ostream<_CharT, _Traits>& __os,
2388 const weekday_indexed& __wdi)
2393 basic_stringstream<_CharT> __os2;
2394 __os2.imbue(__os.getloc());
2395 __os2 << __wdi.weekday();
2396 const auto __i = __wdi.index();
2397 basic_string_view<_CharT> __s
2398 = _GLIBCXX_WIDEN(
"[ is not a valid index]");
2400 __os2 << std::format(_GLIBCXX_WIDEN(
"{}"), __i);
2401 if (__i >= 1 && __i <= 5)
2402 __os2 << __s.back();
2404 __os2 << __s.substr(1);
2405 __os << __os2.view();
2409 template<
typename _CharT,
typename _Traits>
2410 inline basic_ostream<_CharT, _Traits>&
2411 operator<<(basic_ostream<_CharT, _Traits>& __os,
2412 const weekday_last& __wdl)
2415 basic_stringstream<_CharT> __os2;
2416 __os2.imbue(__os.getloc());
2417 __os2 << __wdl.weekday() << _GLIBCXX_WIDEN(
"[last]");
2418 __os << __os2.view();
2422 template<
typename _CharT,
typename _Traits>
2423 inline basic_ostream<_CharT, _Traits>&
2424 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month_day& __md)
2427 basic_stringstream<_CharT> __os2;
2428 __os2.imbue(__os.getloc());
2429 __os2 << __md.month();
2430 if constexpr (is_same_v<_CharT, char>)
2434 __os2 << __md.day();
2435 __os << __os2.view();
2439 template<
typename _CharT,
typename _Traits,
2440 typename _Alloc = allocator<_CharT>>
2441 inline basic_istream<_CharT, _Traits>&
2442 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2444 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2447 using __format::_ChronoParts;
2448 auto __need = _ChronoParts::_Month | _ChronoParts::_Day;
2449 __detail::_Parser<> __p(__need);
2450 if (__p(__is, __fmt, __abbrev, __offset))
2451 __md = month_day(__p._M_ymd.month(), __p._M_ymd.day());
2455 template<
typename _CharT,
typename _Traits>
2456 inline basic_ostream<_CharT, _Traits>&
2457 operator<<(basic_ostream<_CharT, _Traits>& __os,
2458 const month_day_last& __mdl)
2461 basic_stringstream<_CharT> __os2;
2462 __os2.imbue(__os.getloc());
2463 __os2 << __mdl.month() << _GLIBCXX_WIDEN(
"/last");
2464 __os << __os2.view();
2468 template<
typename _CharT,
typename _Traits>
2469 inline basic_ostream<_CharT, _Traits>&
2470 operator<<(basic_ostream<_CharT, _Traits>& __os,
2471 const month_weekday& __mwd)
2474 basic_stringstream<_CharT> __os2;
2475 __os2.imbue(__os.getloc());
2476 __os2 << __mwd.month();
2477 if constexpr (is_same_v<_CharT, char>)
2481 __os2 << __mwd.weekday_indexed();
2482 __os << __os2.view();
2486 template<
typename _CharT,
typename _Traits>
2487 inline basic_ostream<_CharT, _Traits>&
2488 operator<<(basic_ostream<_CharT, _Traits>& __os,
2489 const month_weekday_last& __mwdl)
2492 basic_stringstream<_CharT> __os2;
2493 __os2.imbue(__os.getloc());
2494 __os2 << __mwdl.month();
2495 if constexpr (is_same_v<_CharT, char>)
2499 __os2 << __mwdl.weekday_last();
2500 __os << __os2.view();
2504 template<
typename _CharT,
typename _Traits>
2505 inline basic_ostream<_CharT, _Traits>&
2506 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year_month& __ym)
2509 basic_stringstream<_CharT> __os2;
2510 __os2.imbue(__os.getloc());
2511 __os2 << __ym.year();
2512 if constexpr (is_same_v<_CharT, char>)
2516 __os2 << __ym.month();
2517 __os << __os2.view();
2521 template<
typename _CharT,
typename _Traits,
2522 typename _Alloc = allocator<_CharT>>
2523 inline basic_istream<_CharT, _Traits>&
2524 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2526 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2529 using __format::_ChronoParts;
2530 auto __need = _ChronoParts::_Year | _ChronoParts::_Month;
2531 __detail::_Parser<> __p(__need);
2532 if (__p(__is, __fmt, __abbrev, __offset))
2533 __ym = year_month(__p._M_ymd.year(), __p._M_ymd.month());
2537 template<
typename _CharT,
typename _Traits>
2538 inline basic_ostream<_CharT, _Traits>&
2539 operator<<(basic_ostream<_CharT, _Traits>& __os,
2540 const year_month_day& __ymd)
2542 using _Ctx = __format::__format_context<_CharT>;
2543 using _Str = basic_string_view<_CharT>;
2544 _Str __s = _GLIBCXX_WIDEN(
"{:%F} is not a valid date");
2545 __os <<
std::vformat(__ymd.ok() ? __s.substr(0, 5) : __s,
2546 make_format_args<_Ctx>(__ymd));
2550 template<
typename _CharT,
typename _Traits,
2551 typename _Alloc = allocator<_CharT>>
2552 inline basic_istream<_CharT, _Traits>&
2554 year_month_day&
__ymd,
2558 using __format::_ChronoParts;
2559 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2560 | _ChronoParts::_Day;
2561 __detail::_Parser<> __p(
__need);
2567 template<
typename _CharT,
typename _Traits>
2570 const year_month_day_last&
__ymdl)
2585 template<
typename _CharT,
typename _Traits>
2586 inline basic_ostream<_CharT, _Traits>&
2587 operator<<(basic_ostream<_CharT, _Traits>& __os,
2588 const year_month_weekday& __ymwd)
2592 basic_stringstream<_CharT> __os2;
2593 __os2.imbue(__os.getloc());
2595 if constexpr (is_same_v<_CharT, char>)
2599 __os2 << __ymwd.year() << __slash << __ymwd.month() << __slash
2600 << __ymwd.weekday_indexed();
2601 __os << __os2.view();
2605 template<
typename _CharT,
typename _Traits>
2606 inline basic_ostream<_CharT, _Traits>&
2607 operator<<(basic_ostream<_CharT, _Traits>& __os,
2608 const year_month_weekday_last& __ymwdl)
2612 basic_stringstream<_CharT> __os2;
2613 __os2.imbue(__os.getloc());
2615 if constexpr (is_same_v<_CharT, char>)
2619 __os2 << __ymwdl.year() << __slash << __ymwdl.month() << __slash
2620 << __ymwdl.weekday_last();
2621 __os << __os2.view();
2625 template<
typename _CharT,
typename _Traits,
typename _Duration>
2626 inline basic_ostream<_CharT, _Traits>&
2627 operator<<(basic_ostream<_CharT, _Traits>& __os,
2628 const hh_mm_ss<_Duration>& __hms)
2630 return __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%T}"), __hms);
2633#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2635 template<
typename _CharT,
typename _Traits>
2636 basic_ostream<_CharT, _Traits>&
2637 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_info& __i)
2639 __os <<
'[' << __i.begin <<
',' << __i.end
2640 <<
',' << hh_mm_ss(__i.offset) <<
',' << __i.save
2641 <<
',' << __i.abbrev <<
']';
2646 template<
typename _CharT,
typename _Traits>
2647 basic_ostream<_CharT, _Traits>&
2648 operator<<(basic_ostream<_CharT, _Traits>& __os,
const local_info& __li)
2651 if (__li.result == local_info::unique)
2655 if (__li.result == local_info::nonexistent)
2656 __os <<
"nonexistent";
2658 __os <<
"ambiguous";
2659 __os <<
" local time between " << __li.first;
2660 __os <<
" and " << __li.second;
2666 template<
typename _CharT,
typename _Traits,
typename _Duration,
2667 typename _TimeZonePtr>
2668 inline basic_ostream<_CharT, _Traits>&
2669 operator<<(basic_ostream<_CharT, _Traits>& __os,
2670 const zoned_time<_Duration, _TimeZonePtr>& __t)
2672 __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T %Z}"), __t);
2677 template<
typename _CharT,
typename _Traits,
typename _Duration>
2678 requires (!treat_as_floating_point_v<typename _Duration::rep>)
2679 && ratio_less_v<typename _Duration::period, days::period>
2680 inline basic_ostream<_CharT, _Traits>&
2681 operator<<(basic_ostream<_CharT, _Traits>& __os,
2682 const sys_time<_Duration>& __tp)
2684 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __tp);
2688 template<
typename _CharT,
typename _Traits>
2689 inline basic_ostream<_CharT, _Traits>&
2690 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_days& __dp)
2692 __os << year_month_day{__dp};
2696 template<
typename _CharT,
typename _Traits,
typename _Duration,
2697 typename _Alloc = allocator<_CharT>>
2698 basic_istream<_CharT, _Traits>&
2699 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2700 sys_time<_Duration>& __tp,
2701 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2707 using __format::_ChronoParts;
2708 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2709 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2710 __detail::_Parser_t<_Duration> __p(__need);
2711 if (__p(__is, __fmt, __abbrev, __offset))
2713 auto __st = __p._M_sys_days + __p._M_time - *__offset;
2714 __tp = chrono::time_point_cast<_Duration>(__st);
2719 template<
typename _CharT,
typename _Traits,
typename _Duration>
2720 inline basic_ostream<_CharT, _Traits>&
2721 operator<<(basic_ostream<_CharT, _Traits>& __os,
2722 const utc_time<_Duration>& __t)
2724 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
2728 template<
typename _CharT,
typename _Traits,
typename _Duration,
2729 typename _Alloc = allocator<_CharT>>
2730 inline basic_istream<_CharT, _Traits>&
2731 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2732 utc_time<_Duration>& __tp,
2733 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2736 sys_time<_Duration> __st;
2737 if (chrono::from_stream(__is, __fmt, __st, __abbrev, __offset))
2738 __tp = utc_clock::from_sys(__st);
2742 template<
typename _CharT,
typename _Traits,
typename _Duration>
2743 inline basic_ostream<_CharT, _Traits>&
2744 operator<<(basic_ostream<_CharT, _Traits>& __os,
2745 const tai_time<_Duration>& __t)
2747 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
2751 template<
typename _CharT,
typename _Traits,
typename _Duration,
2752 typename _Alloc = allocator<_CharT>>
2753 inline basic_istream<_CharT, _Traits>&
2754 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2755 tai_time<_Duration>& __tp,
2756 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2759 utc_time<_Duration> __ut;
2760 if (chrono::from_stream(__is, __fmt, __ut, __abbrev, __offset))
2761 __tp = tai_clock::from_utc(__ut);
2765 template<
typename _CharT,
typename _Traits,
typename _Duration>
2766 inline basic_ostream<_CharT, _Traits>&
2767 operator<<(basic_ostream<_CharT, _Traits>& __os,
2768 const gps_time<_Duration>& __t)
2770 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
2774 template<
typename _CharT,
typename _Traits,
typename _Duration,
2775 typename _Alloc = allocator<_CharT>>
2776 inline basic_istream<_CharT, _Traits>&
2777 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2778 gps_time<_Duration>& __tp,
2779 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2782 utc_time<_Duration> __ut;
2783 if (chrono::from_stream(__is, __fmt, __ut, __abbrev, __offset))
2784 __tp = gps_clock::from_utc(__ut);
2788 template<
typename _CharT,
typename _Traits,
typename _Duration>
2789 inline basic_ostream<_CharT, _Traits>&
2790 operator<<(basic_ostream<_CharT, _Traits>& __os,
2791 const file_time<_Duration>& __t)
2793 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
2797 template<
typename _CharT,
typename _Traits,
typename _Duration,
2798 typename _Alloc = allocator<_CharT>>
2799 inline basic_istream<_CharT, _Traits>&
2800 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2801 file_time<_Duration>& __tp,
2802 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2805 sys_time<_Duration> __st;
2806 if (chrono::from_stream(__is, __fmt, __st, __abbrev, __offset))
2807 __tp = file_clock::from_sys(__st);
2811 template<
typename _CharT,
typename _Traits,
typename _Duration>
2812 inline basic_ostream<_CharT, _Traits>&
2813 operator<<(basic_ostream<_CharT, _Traits>& __os,
2814 const local_time<_Duration>& __lt)
2816 __os << sys_time<_Duration>{__lt.time_since_epoch()};
2820 template<
typename _CharT,
typename _Traits,
typename _Duration,
2821 typename _Alloc = allocator<_CharT>>
2822 basic_istream<_CharT, _Traits>&
2823 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2824 local_time<_Duration>& __tp,
2825 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2828 using __format::_ChronoParts;
2829 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
2830 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
2831 __detail::_Parser_t<_Duration> __p(__need);
2832 if (__p(__is, __fmt, __abbrev, __offset))
2834 days __d = __p._M_sys_days.time_since_epoch();
2835 auto __t = local_days(__d) + __p._M_time;
2836 __tp = chrono::time_point_cast<_Duration>(__t);
2845 template<
typename _Parsable,
typename _CharT,
2847 typename... _OptArgs>
2848 concept __parsable =
requires (basic_istream<_CharT, _Traits>& __is,
2849 const _CharT* __fmt, _Parsable& __tp,
2850 _OptArgs*... __args)
2851 { from_stream(__is, __fmt, __tp, __args...); };
2853 template<
typename _Parsable,
typename _CharT,
2854 typename _Traits = char_traits<_CharT>,
2855 typename _Alloc = allocator<_CharT>>
2859 using __string_type = basic_string<_CharT, _Traits, _Alloc>;
2862 _Parse(
const _CharT* __fmt, _Parsable& __tp,
2863 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
2866 _M_abbrev(__abbrev), _M_offset(__offset)
2869 _Parse(_Parse&&) =
delete;
2870 _Parse& operator=(_Parse&&) =
delete;
2873 using __stream_type = basic_istream<_CharT, _Traits>;
2875 const _CharT*
const _M_fmt;
2876 _Parsable*
const _M_tp;
2877 __string_type*
const _M_abbrev;
2880 friend __stream_type&
2881 operator>>(__stream_type& __is, _Parse&& __p)
2884 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev,
2886 else if (__p._M_abbrev)
2887 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev);
2889 from_stream(__is, __p._M_fmt, *__p._M_tp);
2893 friend void operator>>(__stream_type&, _Parse&) =
delete;
2894 friend void operator>>(__stream_type&,
const _Parse&) =
delete;
2898 template<
typename _CharT, __detail::__parsable<_CharT> _Parsable>
2899 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
2901 parse(
const _CharT* __fmt, _Parsable& __tp)
2902 {
return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp); }
2904 template<
typename _CharT,
typename _Traits,
typename _Alloc,
2905 __detail::__parsable<_CharT, _Traits> _Parsable>
2908 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp)
2910 return __detail::_Parse<_Parsable, _CharT, _Traits>(__fmt.c_str(), __tp);
2913 template<
typename _CharT,
typename _Traits,
typename _Alloc,
2914 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
2915 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
2916 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
2918 parse(
const _CharT* __fmt, _Parsable& __tp,
2919 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
2922 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
2926 template<
typename _CharT,
typename _Traits,
typename _Alloc,
2927 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
2928 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
2931 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
2932 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
2935 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
2939 template<
typename _CharT,
typename _Traits =
char_traits<_CharT>,
2940 typename _StrT = basic_
string<_CharT, _Traits>,
2941 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
2942 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
2944 parse(
const _CharT* __fmt, _Parsable& __tp,
minutes& __offset)
2946 return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp,
nullptr,
2950 template<
typename _CharT,
typename _Traits,
typename _Alloc,
2951 typename _StrT = basic_string<_CharT, _Traits>,
2952 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
2955 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
2958 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
2963 template<
typename _CharT,
typename _Traits,
typename _Alloc,
2964 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
2965 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
2966 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
2968 parse(
const _CharT* __fmt, _Parsable& __tp,
2969 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
2972 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
2977 template<
typename _CharT,
typename _Traits,
typename _Alloc,
2978 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
2979 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
2982 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
2983 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
2986 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
2992 template<
typename _Duration>
2993 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2994 basic_istream<_CharT, _Traits>&
2995 __detail::_Parser<_Duration>::
2996 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
2997 basic_string<_CharT, _Traits, _Alloc>* __abbrev,
3000 using sentry =
typename basic_istream<_CharT, _Traits>::sentry;
3002 if (sentry __cerb(__is,
true); __cerb)
3004 locale __loc = __is.getloc();
3009 struct _Stream_state
3012 _Stream_state(basic_istream<_CharT, _Traits>& __i)
3014 _M_flags(__i.flags(ios_base::
skipws | ios_base::
dec)),
3020 _M_is.flags(_M_flags);
3024 _Stream_state(_Stream_state&&) =
delete;
3026 basic_istream<_CharT, _Traits>& _M_is;
3027 ios_base::fmtflags _M_flags;
3037 auto __read_unsigned = [&] (
int __n) {
3038 return _S_read_unsigned(__is, __err, __n);
3043 auto __read_signed = [&] (
int __n) {
3044 return _S_read_signed(__is, __err, __n);
3048 auto __read_chr = [&__is, &__err] (_CharT __c) {
3049 return _S_read_chr(__is, __err, __c);
3052 using __format::_ChronoParts;
3053 _ChronoParts __parts{};
3055 const year __bad_y = --year::min();
3056 const month __bad_mon(255);
3057 const day __bad_day(255);
3058 const weekday __bad_wday(255);
3059 const hours __bad_h(-1);
3060 const minutes __bad_min(-9999);
3063 year __y = __bad_y, __yy = __bad_y;
3064 year __iso_y = __bad_y, __iso_yy = __bad_y;
3065 month __m = __bad_mon;
3066 day __d = __bad_day;
3067 weekday __wday = __bad_wday;
3068 hours __h = __bad_h, __h12 = __bad_h;
3070 _Duration __s = __bad_sec;
3072 int __iso_wk = -1, __sunday_wk = -1, __monday_wk = -1;
3074 int __dayofyear = -1;
3076 minutes __tz_offset = __bad_min;
3077 basic_string<_CharT, _Traits> __tz_abbr;
3083 bool __is_flag =
false;
3102 _CharT __c = *__fmt++;
3109 else if (!__read_chr(__c)) [[unlikely]]
3120 if (__mod || __num) [[unlikely]]
3125 __tmget.get(__is, {}, __is, __err, &__tm,
3127 if (!__is_failed(__err))
3128 __wday = weekday(__tm.tm_wday);
3130 __parts |= _ChronoParts::_Weekday;
3136 if (__mod || __num) [[unlikely]]
3144 __tmget.get(__is, {}, __is, __err, &__tm,
3146 if (!__is_failed(__err))
3147 __m = month(__tm.tm_mon + 1);
3149 __parts |= _ChronoParts::_Month;
3153 if (__mod ==
'O' || __num) [[unlikely]]
3158 __tmget.get(__is, {}, __is, __err, &__tm,
3159 __fmt - 2 - (__mod ==
'E'), __fmt);
3160 if (!__is_failed(__err))
3162 __y = year(__tm.tm_year + 1900);
3163 __m = month(__tm.tm_mon + 1);
3164 __d = day(__tm.tm_mday);
3165 __h =
hours(__tm.tm_hour);
3167 __s = duration_cast<_Duration>(
seconds(__tm.tm_sec));
3170 __parts |= _ChronoParts::_DateTime;
3174 if (!__mod) [[likely]]
3176 auto __v = __read_signed(__num ? __num : 2);
3177 if (!__is_failed(__err))
3179 int __cmin = (int)year::min() / 100;
3180 int __cmax = (int)year::max() / 100;
3181 if (__cmin <= __v && __v <= __cmax)
3182 __century = __v * 100;
3187 else if (__mod ==
'E')
3190 __tmget.get(__is, {}, __is, __err, &__tm,
3192 if (!__is_failed(__err))
3193 __century = __tm.tm_year;
3202 if (!__mod) [[likely]]
3204 auto __v = __read_unsigned(__num ? __num : 2);
3205 if (!__is_failed(__err))
3208 else if (__mod ==
'O')
3211 __tmget.get(__is, {}, __is, __err, &__tm,
3213 if (!__is_failed(__err))
3214 __d = day(__tm.tm_mday);
3218 __parts |= _ChronoParts::_Day;
3222 if (__mod || __num) [[unlikely]]
3226 auto __month = __read_unsigned(2);
3228 auto __day = __read_unsigned(2);
3230 auto __year = __read_unsigned(2);
3231 if (__is_failed(__err))
3233 __y = year(__year + 1900 + 100 *
int(__year < 69));
3234 __m = month(__month);
3236 if (!year_month_day(__y, __m, __d).ok())
3238 __y = __yy = __iso_y = __iso_yy = __bad_y;
3244 __parts |= _ChronoParts::_Date;
3248 if (__mod) [[unlikely]]
3252 auto __year = __read_signed(__num ? __num : 4);
3254 auto __month = __read_unsigned(2);
3256 auto __day = __read_unsigned(2);
3257 if (__is_failed(__err))
3260 __m = month(__month);
3262 if (!year_month_day(__y, __m, __d).ok())
3264 __y = __yy = __iso_y = __iso_yy = __bad_y;
3270 __parts |= _ChronoParts::_Date;
3274 if (__mod) [[unlikely]]
3278 auto __val = __read_unsigned(__num ? __num : 2);
3279 if (__val >= 0 && __val <= 99)
3281 __iso_yy = year(__val);
3282 if (__century == -1)
3286 __iso_yy = __iso_y = __y = __yy = __bad_y;
3288 __parts |= _ChronoParts::_Year;
3292 if (__mod) [[unlikely]]
3295 __iso_y = year(__read_unsigned(__num ? __num : 4));
3296 __parts |= _ChronoParts::_Year;
3301 if (__mod ==
'E') [[unlikely]]
3303 else if (__mod ==
'O')
3308 __tmget.get(__is, {}, __is, __err, &__tm,
3310 if (!__is_failed(__err))
3314 __h12 =
hours(__tm.tm_hour);
3318 __h =
hours(__tm.tm_hour);
3327 auto __val = __read_unsigned(__num ? __num : 2);
3328 if (__c ==
'I' && __val >= 1 && __val <= 12)
3330 __h12 =
hours(__val);
3333 else if (__c ==
'H' && __val >= 0 && __val <= 23)
3340 if (_M_need & _ChronoParts::_TimeOfDay)
3345 __parts |= _ChronoParts::_TimeOfDay;
3349 if (__mod) [[unlikely]]
3351 else if (_M_need == _ChronoParts::_TimeOfDay)
3353 auto __val = __read_signed(__num ? __num : 3);
3354 if (!__is_failed(__err))
3357 __parts |= _ChronoParts::_TimeOfDay;
3362 __dayofyear = __read_unsigned(__num ? __num : 3);
3369 if (__mod ==
'E') [[unlikely]]
3371 else if (__mod ==
'O')
3374 __tmget.get(__is, {}, __is, __err, &__tm,
3376 if (!__is_failed(__err))
3377 __m = month(__tm.tm_mon + 1);
3381 auto __val = __read_unsigned(__num ? __num : 2);
3382 if (__val >= 1 && __val <= 12)
3387 __parts |= _ChronoParts::_Month;
3391 if (__mod ==
'E') [[unlikely]]
3393 else if (__mod ==
'O')
3396 __tmget.get(__is, {}, __is, __err, &__tm,
3398 if (!__is_failed(__err))
3403 auto __val = __read_unsigned(__num ? __num : 2);
3404 if (0 <= __val && __val < 60)
3408 if (_M_need & _ChronoParts::_TimeOfDay)
3413 __parts |= _ChronoParts::_TimeOfDay;
3423 const _CharT* __ampms[2];
3424 __tmpunct._M_am_pm(__ampms);
3425 int __n = 0, __which = 3;
3426 while (__which != 0)
3428 auto __i = __is.peek();
3429 if (_Traits::eq_int_type(__i, _Traits::eof()))
3439 else if (__ampms[0][__n + 1] == _CharT())
3450 else if (__ampms[1][__n + 1] == _CharT())
3461 if (__which == 0 || __which == 3)
3474 __tmget.get(__is, {}, __is, __err, &__tm,
3476 if (!__is_failed(__err))
3478 __h =
hours(__tm.tm_hour);
3483 __parts |= _ChronoParts::_TimeOfDay;
3488 if (__mod || __num) [[unlikely]]
3495 auto __val = __read_unsigned(2);
3496 if (__val == -1 || __val > 23) [[unlikely]]
3498 if (_M_need & _ChronoParts::_TimeOfDay)
3502 if (!__read_chr(
':')) [[unlikely]]
3506 __val = __read_unsigned(2);
3507 if (__val == -1 || __val > 60) [[unlikely]]
3509 if (_M_need & _ChronoParts::_TimeOfDay)
3517 __parts |= _ChronoParts::_TimeOfDay;
3520 else if (!__read_chr(
':')) [[unlikely]]
3526 if (__mod ==
'E') [[unlikely]]
3528 else if (__mod ==
'O')
3531 __tmget.get(__is, {}, __is, __err, &__tm,
3533 if (!__is_failed(__err))
3536 else if constexpr (ratio_equal_v<
typename _Duration::period,
3539 auto __val = __read_unsigned(__num ? __num : 2);
3540 if (0 <= __val && __val <= 59) [[likely]]
3544 if (_M_need & _ChronoParts::_TimeOfDay)
3551 basic_stringstream<_CharT> __buf;
3552 auto __digit = _S_try_read_digit(__is, __err);
3555 __buf.put(_CharT(
'0') + __digit);
3556 __digit = _S_try_read_digit(__is, __err);
3558 __buf.put(_CharT(
'0') + __digit);
3561 auto __i = __is.peek();
3562 if (_Traits::eq_int_type(__i, _Traits::eof()))
3566 auto& __np = use_facet<numpunct<_CharT>>(__loc);
3567 auto __dp = __np.decimal_point();
3568 _CharT __c = _Traits::to_char_type(__i);
3574 = hh_mm_ss<_Duration>::fractional_width;
3577 __digit = _S_try_read_digit(__is, __err);
3579 __buf.put(_CharT(
'0') + __digit);
3587 if (!__is_failed(__err))
3589 auto& __ng = use_facet<num_get<_CharT>>(__loc);
3592 __ng.get(__buf, {}, __buf, __err2, __val);
3593 if (__is_failed(__err2)) [[unlikely]]
3597 duration<long double> __fs(__val);
3598 __s = duration_cast<_Duration>(__fs);
3602 __parts |= _ChronoParts::_TimeOfDay;
3607 if (__mod ==
'E') [[unlikely]]
3609 else if (__mod ==
'O')
3614 __tmget.get(__is, {}, __is, __err, &__tm,
3616 if (!__is_failed(__err))
3617 __wday = weekday(__tm.tm_wday);
3624 const int __lo = __c ==
'u' ? 1 : 0;
3625 const int __hi = __lo + 6;
3626 auto __val = __read_unsigned(__num ? __num : 1);
3627 if (__lo <= __val && __val <= __hi)
3628 __wday = weekday(__val);
3631 __wday = __bad_wday;
3635 __parts |= _ChronoParts::_Weekday;
3641 if (__mod ==
'E') [[unlikely]]
3643 else if (__mod ==
'O')
3645 if (__c ==
'V') [[unlikely]]
3655 const int __lo = __c ==
'V' ? 1 : 0;
3656 const int __hi = 53;
3657 auto __val = __read_unsigned(__num ? __num : 2);
3658 if (__lo <= __val && __val <= __hi)
3663 __sunday_wk = __val;
3669 __monday_wk = __val;
3674 __iso_wk = __sunday_wk = __monday_wk = -1;
3680 if (__mod ==
'O' || __num) [[unlikely]]
3685 __tmget.get(__is, {}, __is, __err, &__tm,
3686 __fmt - 2 - (__mod ==
'E'), __fmt);
3687 if (!__is_failed(__err))
3689 __y = year(__tm.tm_year + 1900);
3690 __m = month(__tm.tm_mon + 1);
3691 __d = day(__tm.tm_mday);
3694 __parts |= _ChronoParts::_Date;
3698 if (__mod ==
'O' || __num) [[unlikely]]
3703 __tmget.get(__is, {}, __is, __err, &__tm,
3704 __fmt - 2 - (__mod ==
'E'), __fmt);
3705 if (!__is_failed(__err))
3707 __h =
hours(__tm.tm_hour);
3709 __s = duration_cast<_Duration>(
seconds(__tm.tm_sec));
3712 __parts |= _ChronoParts::_TimeOfDay;
3716 if (__mod) [[unlikely]]
3719 __tmget.get(__is, {}, __is, __err, &__tm,
3721 if (!__is_failed(__err))
3723 int __cent = __tm.tm_year < 2000 ? 1900 : 2000;
3724 __yy = year(__tm.tm_year - __cent);
3725 if (__century == -1)
3731 auto __val = __read_unsigned(__num ? __num : 2);
3732 if (__val >= 0 && __val <= 99)
3735 if (__century == -1)
3736 __century = __val < 69 ? 2000 : 1900;
3739 __y = __yy = __iso_yy = __iso_y = __bad_y;
3741 __parts |= _ChronoParts::_Year;
3745 if (__mod ==
'O') [[unlikely]]
3747 else if (__mod ==
'E')
3750 __tmget.get(__is, {}, __is, __err, &__tm,
3752 if (!__is_failed(__err))
3753 __y = year(__tm.tm_year);
3757 auto __val = __read_unsigned(__num ? __num : 4);
3758 if (!__is_failed(__err))
3761 __parts |= _ChronoParts::_Year;
3765 if (__num) [[unlikely]]
3772 auto __i = __is.peek();
3773 if (_Traits::eq_int_type(__i, _Traits::eof()))
3778 _CharT __ic = _Traits::to_char_type(__i);
3779 const bool __neg = __ic == _CharT(
'-');
3780 if (__ic == _CharT(
'-') || __ic == _CharT(
'+'))
3787 __hh = __read_unsigned(2);
3792 __hh = 10 * _S_try_read_digit(__is, __err);
3793 __hh += _S_try_read_digit(__is, __err);
3796 if (__is_failed(__err))
3800 if (_Traits::eq_int_type(__i, _Traits::eof()))
3803 __tz_offset =
minutes(__hh * (__neg ? -60 : 60));
3806 __ic = _Traits::to_char_type(__i);
3808 bool __read_mm =
false;
3811 if (__ic == _GLIBCXX_WIDEN(
":")[0])
3818 else if (_CharT(
'0') <= __ic && __ic <= _CharT(
'9'))
3824 int_least32_t __mm = 0;
3827 __mm = 10 * _S_try_read_digit(__is, __err);
3828 __mm += _S_try_read_digit(__is, __err);
3831 if (!__is_failed(__err))
3833 auto __z = __hh * 60 + __mm;
3834 __tz_offset =
minutes(__neg ? -__z : __z);
3840 if (__mod || __num) [[unlikely]]
3844 basic_string_view<_CharT> __x = _GLIBCXX_WIDEN(
"_/-+");
3848 auto __i = __is.peek();
3849 if (!_Traits::eq_int_type(__i, _Traits::eof()))
3851 _CharT __a = _Traits::to_char_type(__i);
3853 || __x.find(__a) != __x.npos)
3855 __tz_abbr.push_back(__a);
3864 if (__tz_abbr.empty())
3870 if (__mod || __num) [[unlikely]]
3874 _CharT __i = __is.peek();
3875 if (_Traits::eq_int_type(__i, _Traits::eof()))
3877 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
3885 if (__mod || __num) [[unlikely]]
3889 _CharT __i = __is.peek();
3890 if (_Traits::eq_int_type(__i, _Traits::eof()))
3892 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
3898 if (__mod || __num) [[unlikely]]
3906 if (__mod || __num) [[unlikely]]
3915 if (_CharT(
'1') <= __c && __c <= _CharT(
'9'))
3917 if (!__mod) [[likely]]
3920 auto __end = __fmt + _Traits::length(__fmt);
3922 = __format::__parse_integer(__fmt - 1, __end);
3923 if (__ptr) [[likely]]
3934 if (__is_failed(__err)) [[unlikely]]
3944 if (__yy != __bad_y && __y == __bad_y)
3945 __y =
years(__century) + __yy;
3946 if (__iso_yy != __bad_y && __iso_y == __bad_y)
3947 __iso_y =
years(__century) + __iso_yy;
3950 bool __can_use_doy =
false;
3951 bool __can_use_iso_wk =
false;
3952 bool __can_use_sun_wk =
false;
3953 bool __can_use_mon_wk =
false;
3956 if (__y != __bad_y && __dayofyear >= 0)
3958 __can_use_doy =
true;
3959 __parts |= _ChronoParts::_Date;
3961 else if (__y != __bad_y && __wday != __bad_wday && __sunday_wk >= 0)
3963 __can_use_sun_wk =
true;
3964 __parts |= _ChronoParts::_Date;
3966 else if (__y != __bad_y && __wday != __bad_wday && __monday_wk >= 0)
3968 __can_use_mon_wk =
true;
3969 __parts |= _ChronoParts::_Date;
3971 else if (__iso_y != __bad_y && __wday != __bad_wday && __iso_wk > 0)
3974 __can_use_iso_wk =
true;
3975 __parts |= _ChronoParts::_Date;
3978 if (__is_failed(__err)) [[unlikely]]
3980 else if (__is_flag) [[unlikely]]
3982 else if ((_M_need & __parts) == _M_need) [[likely]]
4004 const bool __need_wday = _M_need & _ChronoParts::_Weekday;
4008 const bool __need_time = _M_need & _ChronoParts::_TimeOfDay;
4010 if (__need_wday && __wday != __bad_wday)
4012 else if (_M_need & _ChronoParts::_Date)
4016 const bool __need_ymd = !__need_wday && !__need_time;
4018 if ((_M_need & _ChronoParts::_Year && __y == __bad_y)
4019 || (_M_need & _ChronoParts::_Month && __m == __bad_mon)
4020 || (_M_need & _ChronoParts::_Day && __d == __bad_day))
4027 if ((0 < __dayofyear && __dayofyear <= 365)
4028 || (__dayofyear == 366 && __y.is_leap()))
4031 _M_sys_days = sys_days(__y/January/1)
4032 +
days(__dayofyear - 1);
4034 _M_ymd = year_month_day(_M_sys_days);
4039 else if (__can_use_iso_wk)
4047 const sys_days __jan4(__iso_y/January/4);
4048 weekday __wd1(__jan4 -
days(3));
4049 if (__wd1 != Thursday)
4050 if (__wd1 != Wednesday || !__iso_y.is_leap())
4054 if (!__is_failed(__err)) [[likely]]
4057 sys_days __w(Thursday[1]/January/__iso_y);
4059 __w -= Thursday - Monday;
4061 __w += __wday - Monday;
4065 _M_ymd = year_month_day(_M_sys_days);
4068 else if (__can_use_sun_wk)
4071 sys_days __wk1(__y/January/Sunday[1]);
4072 _M_sys_days = __wk1 +
weeks(__sunday_wk - 1)
4073 +
days(__wday.c_encoding());
4074 _M_ymd = year_month_day(_M_sys_days);
4075 if (_M_ymd.year() != __y) [[unlikely]]
4078 else if (__can_use_mon_wk)
4081 sys_days __wk1(__y/January/Monday[1]);
4082 _M_sys_days = __wk1 +
weeks(__monday_wk - 1)
4083 +
days(__wday.c_encoding() - 1);
4084 _M_ymd = year_month_day(_M_sys_days);
4085 if (_M_ymd.year() != __y) [[unlikely]]
4097 if (_M_need & _ChronoParts::_Year)
4099 if (!__y.ok()) [[unlikely]]
4102 else if (__y == __bad_y)
4105 if (_M_need & _ChronoParts::_Month)
4107 if (!__m.ok()) [[unlikely]]
4110 else if (__m == __bad_mon)
4113 if (_M_need & _ChronoParts::_Day)
4115 if (__d < day(1) || __d > (__y/__m/last).day())
4118 else if (__d == __bad_day)
4121 if (year_month_day __ymd(__y, __m, __d); __ymd.ok())
4124 if (__need_wday || __need_time)
4125 _M_sys_days = sys_days(_M_ymd);
4132 _M_wd = weekday(_M_sys_days);
4138 if (__h == __bad_h && __h12 != __bad_h)
4142 else if (__ampm == 2)
4143 __h = __h12 ==
hours(12) ? __h12 : __h12 +
hours(12);
4148 auto __t = _M_time.zero();
4157 if (__min != __bad_min)
4163 if (__s != __bad_sec)
4175 if (!__is_failed(__err)) [[likely]]
4177 if (__offset && __tz_offset != __bad_min)
4178 *__offset = __tz_offset;
4179 if (__abbrev && !__tz_abbr.empty())
4187 __is.setstate(__err);
4191#undef _GLIBCXX_WIDEN
4196_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
duration< int64_t, ratio< 86400 > > days
days
duration< int64_t, ratio< 31556952 > > years
years
duration< int64_t, ratio< 3600 > > hours
hours
constexpr enable_if_t< numeric_limits< _Rep >::is_signed, duration< _Rep, _Period > > abs(duration< _Rep, _Period > __d)
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 std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
ISO C++ entities toplevel namespace is std.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
bool isspace(_CharT __c, const locale &__loc)
Convenience interface to ctype.is(ctype_base::space, __c).
_CharT toupper(_CharT __c, const locale &__loc)
Convenience interface to ctype.toupper(__c).
bool isalnum(_CharT __c, const locale &__loc)
Convenience interface to ctype.is(ctype_base::alnum, __c).
ios_base & dec(ios_base &__base)
Calls base.setf(ios_base::dec, ios_base::basefield).
ios_base & skipws(ios_base &__base)
Calls base.setf(ios_base::skipws).
constexpr bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
basic_istream< _CharT, _Traits > & ws(basic_istream< _CharT, _Traits > &__is)
Quick and easy way to eat whitespace.
ISO C++ 2011 namespace for date and time utilities.
_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.