30#ifndef _GLIBCXX_CHRONO_IO_H
31#define _GLIBCXX_CHRONO_IO_H 1
34#pragma GCC system_header
37#if __cplusplus >= 202002L
47namespace std _GLIBCXX_VISIBILITY(default)
49_GLIBCXX_BEGIN_NAMESPACE_VERSION
59#define _GLIBCXX_WIDEN_(C, S) ::std::__format::_Widen<C>(S, L##S)
60#define _GLIBCXX_WIDEN(S) _GLIBCXX_WIDEN_(_CharT, S)
62 template<
typename _Period,
typename _CharT>
64 __units_suffix()
noexcept
69#define _GLIBCXX_UNITS_SUFFIX(period, suffix) \
70 if constexpr (is_same_v<_Period, period>) \
71 return _GLIBCXX_WIDEN(suffix); \
74 _GLIBCXX_UNITS_SUFFIX(atto,
"as")
75 _GLIBCXX_UNITS_SUFFIX(femto,
"fs")
76 _GLIBCXX_UNITS_SUFFIX(pico,
"ps")
77 _GLIBCXX_UNITS_SUFFIX(nano,
"ns")
78 _GLIBCXX_UNITS_SUFFIX(milli,
"ms")
79#if _GLIBCXX_USE_ALT_MICROSECONDS_SUFFIX
82 _GLIBCXX_UNITS_SUFFIX(micro,
"\u00b5s")
84 _GLIBCXX_UNITS_SUFFIX(micro,
"us")
86 _GLIBCXX_UNITS_SUFFIX(centi,
"cs")
87 _GLIBCXX_UNITS_SUFFIX(deci,
"ds")
89 _GLIBCXX_UNITS_SUFFIX(deca,
"das")
90 _GLIBCXX_UNITS_SUFFIX(hecto,
"hs")
91 _GLIBCXX_UNITS_SUFFIX(kilo,
"ks")
92 _GLIBCXX_UNITS_SUFFIX(mega,
"Ms")
93 _GLIBCXX_UNITS_SUFFIX(giga,
"Gs")
94 _GLIBCXX_UNITS_SUFFIX(tera,
"Ts")
95 _GLIBCXX_UNITS_SUFFIX(tera,
"Ts")
96 _GLIBCXX_UNITS_SUFFIX(peta,
"Ps")
97 _GLIBCXX_UNITS_SUFFIX(exa,
"Es")
101#undef _GLIBCXX_UNITS_SUFFIX
105 template<
typename _Period,
typename _CharT,
typename _Out>
107 __fmt_units_suffix(_Out __out)
noexcept
109 if (
auto __s = __detail::__units_suffix<_Period, _CharT>(); __s.size())
110 return __format::__write(
std::move(__out), __s);
111 else if constexpr (_Period::den == 1)
112 return std::format_to(
std::move(__out), _GLIBCXX_WIDEN(
"[{}]s"),
113 (uintmax_t)_Period::num);
115 return std::format_to(
std::move(__out), _GLIBCXX_WIDEN(
"[{}/{}]s"),
116 (uintmax_t)_Period::num,
117 (uintmax_t)_Period::den);
126 template<
typename _CharT,
typename _Traits,
127 typename _Rep,
typename _Period>
133 using period =
typename _Period::type;
141 __detail::__fmt_units_suffix<period, _CharT>(_Out(__s));
151 template<
typename _Duration>
152 struct __local_time_fmt
154 local_time<_Duration> _M_time;
155 const string* _M_abbrev;
161 template<
typename _Duration>
162 using __local_time_fmt_for
163 = __local_time_fmt<common_type_t<_Duration, seconds>>;
176 template<
typename _Duration>
177 inline __detail::__local_time_fmt<_Duration>
179 const string* __abbrev =
nullptr,
180 const seconds* __offset_sec =
nullptr)
181 {
return {__time, __abbrev, __offset_sec}; }
189 [[noreturn,__gnu__::__always_inline__]]
191 __not_valid_for_duration()
192 { __throw_format_error(
"format error: chrono-format-spec not valid for "
193 "chrono::duration"); }
195 [[noreturn,__gnu__::__always_inline__]]
197 __invalid_chrono_spec()
198 { __throw_format_error(
"format error: chrono-format-spec not valid for "
204 enum class _ChronoParts :
unsigned short {
205 _None = 0, _TotalSeconds = 1u, _Subseconds = 1u << 2,
208 _EpochUnits = 1u << 3, _UnitSuffix = 1u << 4,
209 _EpochSeconds = _EpochUnits | _TotalSeconds,
212 _LocalDays = 1u << 5,
213 _LocalSeconds = _LocalDays | _TotalSeconds,
215 _Year = 1u << 6, _Month = 1u << 7, _Day = 1u << 8,
216 _Weekday = 1u << 9, _WeekdayIndex = 1u << 10, _DayOfYear = 1u << 11,
217 _IndexedWeekday = _Weekday | _WeekdayIndex,
218 _YearMonthDay = _Year | _Month | _Day,
219 _Date = _LocalDays | _YearMonthDay | _IndexedWeekday | _DayOfYear,
221 _HoursMinutesSeconds = 1u << 12,
222 _TimeOfDay = _HoursMinutesSeconds | _Subseconds,
223 _Time = _TimeOfDay | _TotalSeconds,
224 _EpochTime = _Time | _EpochUnits | _UnitSuffix,
225 _DateTime = _Date | _Time,
227 _ZoneAbbrev = 1u << 13, _ZoneOffset = 1u << 14,
228 _TimeZone = _ZoneAbbrev | _ZoneOffset,
229 _ZonedDateTime = _DateTime | _TimeZone,
232 [[__gnu__::__always_inline__]]
233 constexpr _ChronoParts
234 operator&(_ChronoParts __x, _ChronoParts __y)
noexcept
235 {
return static_cast<_ChronoParts
>((unsigned)__x & (unsigned)__y); }
237 [[__gnu__::__always_inline__]]
238 constexpr _ChronoParts&
239 operator&=(_ChronoParts& __x, _ChronoParts __y)
noexcept
240 {
return __x = __x & __y; }
242 [[__gnu__::__always_inline__]]
243 constexpr _ChronoParts
244 operator|(_ChronoParts __x, _ChronoParts __y)
noexcept
245 {
return static_cast<_ChronoParts
>((
unsigned short)__x | (
unsigned short)__y); }
247 [[__gnu__::__always_inline__]]
248 constexpr _ChronoParts&
249 operator|=(_ChronoParts& __x, _ChronoParts __y)
noexcept
250 {
return __x = __x | __y; }
253 [[__gnu__::__always_inline__]]
254 constexpr _ChronoParts
255 operator-(_ChronoParts __x, _ChronoParts __y)
noexcept
256 {
return static_cast<_ChronoParts
>((
unsigned short)__x & ~(
unsigned short)__y); }
259 [[__gnu__::__always_inline__]]
260 constexpr _ChronoParts&
261 operator-=(_ChronoParts& __x, _ChronoParts __y)
noexcept
262 {
return __x = __x - __y; }
264 [[__gnu__::__always_inline__]]
266 operator==(_ChronoParts __x,
decltype(
nullptr)) noexcept
267 {
return (
unsigned short)__x == 0; }
269 template<
typename _CharT>
270 struct _ChronoSpec : _Spec<_CharT>
281 unsigned _M_locale_specific : 1;
284 unsigned _M_needs_ok_check : 1;
286 unsigned _M_floating_point_rep : 1;
288 unsigned _M_custom_rep : 1;
289 unsigned _M_unused : 4;
292 _ChronoParts _M_needed;
293 basic_string_view<_CharT> _M_chrono_specs;
295 [[__gnu__::__always_inline__]]
297 _M_needs(_ChronoParts __parts)
const
298 {
return (_M_needed & __parts) != 0; }
301 template<
typename _CharT>
302 struct _ChronoFormats
304 using _String_view = basic_string_view<_CharT>;
309 {
return _GLIBCXX_WIDEN(
"%F %T %Z"); }
314 {
return _S_ftz().substr(0, 5); }
319 {
return _S_ftz().substr(0, 2); }
324 {
return _S_ftz().substr(3, 2); }
329 {
return _GLIBCXX_WIDEN(
"%Y/%b/%d"); }
334 {
return _S_ymd().substr(0, 5); }
339 {
return _S_ymd().substr(3); }
344 {
return _S_ymd().substr(0, 2); }
349 {
return _S_ymd().substr(3, 2); }
354 {
return _S_ymd().substr(6, 2); }
360 {
return _String_view(_GLIBCXX_WIDEN(
"%Y/%b/%a[%\0]"), 12); }
365 {
return _S_ymwi().substr(3); }
370 {
return _S_ymwi().substr(6); }
375 {
return _S_ymwi().substr(6, 2); }
380 {
return _GLIBCXX_WIDEN(
"%Y/%b/%a[last]"); }
385 {
return _S_ymwl().substr(3); }
390 {
return _S_ymwl().substr(6); }
395 {
return _GLIBCXX_WIDEN(
"%Y/%b/last"); }
400 {
return _S_yml().substr(3); }
403 template<
typename _CharT>
406 static constexpr unsigned _S_max_prec = 18;
407 using _Attoseconds = chrono::duration<__UINT_LEAST64_TYPE__, atto>;
410 = basic_format_context<_Sink_iter<_CharT>, _CharT>;
411 using _FormatArgs = basic_format_args<_FormatContext>;
412 static inline auto _S_args = std::make_format_args<_FormatContext>();
414 _ChronoData() =
default;
415 _ChronoData(_ChronoData&&) =
delete;
418 chrono::seconds _M_eseconds;
421 _Attoseconds _M_subseconds;
425 _FormatArgs _M_ereps = _S_args;
426 basic_string_view<_CharT> _M_unit_suffix;
429 chrono::local_seconds _M_lseconds;
430 chrono::local_days _M_ldays;
432 chrono::year _M_year;
433 chrono::month _M_month;
435 chrono::weekday _M_weekday;
436 unsigned char _M_weekday_index;
437 chrono::days _M_day_of_year;
440 chrono::hours _M_hours;
441 chrono::minutes _M_minutes;
442 chrono::seconds _M_seconds;
444 chrono::seconds _M_zone_offset;
445 basic_string_view<_CharT> _M_zone_abbrev;
446 const char* _M_zone_cstr =
"";
448 template<
typename _YearMonth>
449 [[__gnu__::__always_inline__]]
451 _M_fill_year_month(
const _YearMonth& __ym, _ChronoParts __parts)
453 _M_year = __ym.year();
454 __parts -= _ChronoParts::_Year;
455 _M_month = __ym.month();
456 __parts -= _ChronoParts::_Month;
460 [[__gnu__::__always_inline__]]
462 _M_fill_day(chrono::day __d, _ChronoParts __parts)
465 __parts -= _ChronoParts::_Day;
466 _M_weekday_index = ((unsigned)__d + 6u) / 7u;
467 __parts -= _ChronoParts::_WeekdayIndex;
471 [[__gnu__::__always_inline__]]
473 _M_fill_weekday(chrono::weekday_indexed __wi, _ChronoParts __parts)
475 _M_weekday = __wi.weekday();
476 __parts -= _ChronoParts::_Weekday;
477 _M_weekday_index = __wi.index();
478 __parts -= _ChronoParts::_WeekdayIndex;
483 [[__gnu__::__always_inline__]]
485 _M_fill_aux(chrono::local_days __ld, _ChronoParts __parts)
487 using namespace chrono;
488 if ((__parts & _ChronoParts::_Weekday) != 0)
489 _M_weekday = weekday(__ld);
490 __parts -= _ChronoParts::_Weekday;
491 if ((__parts & _ChronoParts::_DayOfYear) != 0)
494 _M_day_of_year = __ld - local_days(_M_year/January/0);
495 __parts -= _ChronoParts::_DayOfYear;
500 [[__gnu__::__always_inline__]]
502 _M_fill_ldays(chrono::local_days __ld, _ChronoParts __parts)
505 __parts -= _ChronoParts::_LocalDays;
506 return _M_fill_aux(__ld, __parts);
510 _M_fill_time(chrono::seconds __d)
512 chrono::hh_mm_ss<chrono::seconds> __hms(__d);
513 _M_hours = __hms.hours();
514 _M_minutes = __hms.minutes();
515 _M_seconds = __hms.seconds();
519 _M_fill_date_time(chrono::local_seconds __ls, _ChronoParts __parts)
521 _M_ldays = chrono::floor<chrono::days>(__ls);
522 __parts -= _ChronoParts::_LocalDays;
523 if ((__parts & _ChronoParts::_HoursMinutesSeconds) != 0)
524 _M_fill_time(_M_lseconds - _M_ldays);
526 if ((__parts & _ChronoParts::_Date) != 0)
528 const chrono::year_month_day __ymd(_M_ldays);
529 _M_fill_year_month(__ymd, __parts);
530 _M_fill_day(__ymd.day(), __parts);
531 _M_fill_aux(_M_ldays, __parts);
536 _M_fill_zone(
const char* __abbrev,
const wchar_t* __wabbrev)
538 if constexpr (is_same_v<_CharT, char>)
539 _M_zone_abbrev = __abbrev;
541 _M_zone_abbrev = __wabbrev;
542 _M_zone_cstr = __abbrev;
545 [[__gnu__::__always_inline__]]
548 { _M_fill_zone(
"UTC", L
"UTC"); }
552 template<
typename _CharT>
553 struct __formatter_chrono
555 using __string_view = basic_string_view<_CharT>;
556 using __string = basic_string<_CharT>;
558 __formatter_chrono() =
default;
561 __formatter_chrono(_ChronoSpec<_CharT> __spec) noexcept
565 constexpr typename basic_format_parse_context<_CharT>::iterator
566 _M_parse(basic_format_parse_context<_CharT>& __pc, _ChronoParts __parts,
567 const _ChronoSpec<_CharT>& __def)
569 auto __first = __pc.
begin();
570 auto __last = __pc.end();
572 _ChronoSpec<_CharT> __spec = __def;
574 auto __finalize = [
this, &__spec, &__def] {
575 using enum _ChronoParts;
576 _ChronoParts __checked
577 = __spec._M_debug ? _YearMonthDay|_IndexedWeekday
581 __spec._M_needs_ok_check
582 = __spec._M_needs(__def._M_needed & __checked);
586 auto __finished = [&] {
587 if (__first == __last || *__first ==
'}')
598 __first = __spec._M_parse_fill_and_align(__first, __last);
602 __first = __spec._M_parse_width(__first, __last, __pc);
608 if ((__parts & _ChronoParts::_EpochUnits) == 0
609 || !__spec._M_floating_point_rep)
610 __throw_format_error(
"format error: invalid precision for duration");
613 __first = _Spec<_CharT>()._M_parse_precision(__first, __last, __pc);
615 __spec._M_prec_kind = _WP_value;
620 __spec._M_localized =
false;
621 __first = __spec._M_parse_locale(__first, __last);
628 __string_view __str(__first, __last - __first);
629 auto __end = __str.find(
'}');
630 if (__end != __str.npos)
632 __str.remove_suffix(__str.length() - __end);
633 __last = __first + __end;
635 if (__str.find(
'{') != __str.npos)
636 __throw_format_error(
"chrono format error: '{' in chrono-specs");
642 __spec._M_debug =
false;
643 __spec._M_locale_specific =
false;
644 __spec._M_needed = _ChronoParts::_None;
645 __spec._M_chrono_specs = __string_view();
647 const auto __chrono_specs = __first++;
648 if (*__chrono_specs !=
'%')
649 __throw_format_error(
"chrono format error: no '%' at start of "
654 while (__first != __last)
656 enum _Mods { _Mod_none, _Mod_E, _Mod_O, _Mod_E_O };
657 _Mods __allowed_mods = _Mod_none;
659 _ChronoParts __needed = _ChronoParts::_None;
660 bool __locale_specific =
false;
662 _CharT __c = *__first++;
665 using enum _ChronoParts;
669 __locale_specific =
true;
675 __locale_specific =
true;
678 __needed = _Date|_HoursMinutesSeconds;
679 __allowed_mods = _Mod_E;
680 __locale_specific =
true;
684 __allowed_mods = _Mod_E;
689 __allowed_mods = _Mod_O;
693 __needed = _YearMonthDay;
698 __needed = _LocalDays|_Year|_DayOfYear|_Weekday;
702 __needed = _HoursMinutesSeconds;
703 __allowed_mods = _Mod_O;
706 __needed = __parts & _DayOfYear;
709 if (__needed == _None)
710 __needed = _HoursMinutesSeconds;
714 __allowed_mods = _Mod_O;
717 __needed = _HoursMinutesSeconds;
718 __allowed_mods = _Mod_O;
722 __locale_specific =
true;
725 __needed = _HoursMinutesSeconds;
728 __needed = _TimeOfDay;
731 __needed = _UnitSuffix;
734 __needed = _EpochUnits;
737 __needed = _TimeOfDay;
738 __allowed_mods = _Mod_O;
743 __allowed_mods = _Mod_O;
747 __needed = _DayOfYear|_Weekday;
748 __allowed_mods = _Mod_O;
752 __locale_specific =
true;
753 __allowed_mods = _Mod_E;
756 __needed = _HoursMinutesSeconds;
757 __locale_specific =
true;
758 __allowed_mods = _Mod_E;
762 __allowed_mods = _Mod_E_O;
766 __allowed_mods = _Mod_E;
769 __needed = _ZoneOffset;
770 __allowed_mods = _Mod_E_O;
773 __needed = _ZoneAbbrev;
781 if (__mod) [[unlikely]]
783 __allowed_mods = _Mod_none;
789 __throw_format_error(
"chrono format error: invalid specifier "
793 if ((__mod ==
'E' && !(__allowed_mods & _Mod_E))
794 || (__mod ==
'O' && !(__allowed_mods & _Mod_O)))
795 __throw_format_error(
"chrono format error: invalid modifier "
797 if (__mod && __c !=
'z')
798 __locale_specific =
true;
802 if (__locale_specific)
803 __needed -= _ChronoParts::_Subseconds;
805 if ((__parts & __needed) != __needed)
806 __throw_format_error(
"chrono format error: format argument does "
807 "not contain the information required by the "
809 __spec._M_needed |= __needed;
810 __spec._M_locale_specific |= __locale_specific;
813 size_t __pos = __string_view(__first, __last - __first).find(
'%');
818 if (__pos == __string_view::npos)
824 __first += __pos + 1;
829 if (__conv || __mod != _CharT())
830 __throw_format_error(
"chrono format error: unescaped '%' in "
833 __spec._M_chrono_specs
834 = __string_view(__chrono_specs, __first - __chrono_specs);
841 template<
typename _FormatContext>
842 typename _FormatContext::iterator
843 _M_format(
const _ChronoData<_CharT>& __t, _FormatContext& __fc)
const
845#if defined _GLIBCXX_USE_NL_LANGINFO_L && __CHAR_BIT__ == 8
849 if constexpr (is_same_v<_CharT, char>)
850 if constexpr (__unicode::__literal_encoding_is_utf8())
851 if (_M_spec._M_localized && _M_spec._M_locale_specific)
853 extern locale __with_encoding_conversion(
const locale&);
857 locale __loc = __fc.locale();
858 if (__loc != locale::classic())
859 __fc._M_loc = __with_encoding_conversion(__loc);
863 const size_t __padwidth = _M_spec._M_get_width(__fc);
865 return _M_format_to(__t, __fc.out(), __fc);
867 using _Out =
typename _FormatContext::iterator;
868 _Padding_sink<_Out, _CharT> __sink(__fc.out(), __padwidth);
869 _M_format_to(__t, __sink.out(), __fc);
870 return __sink._M_finish(_M_spec._M_align, _M_spec._M_fill);
873 _ChronoSpec<_CharT> _M_spec;
876 static constexpr const _CharT* _S_chars
877 = _GLIBCXX_WIDEN(
"0123456789.Lf:/ +-{}");
878 static constexpr _CharT _S_dot = _S_chars[10];
879 static constexpr _CharT _S_colon = _S_chars[13];
880 static constexpr _CharT _S_slash = _S_chars[14];
881 static constexpr _CharT _S_space = _S_chars[15];
882 static constexpr const _CharT* _S_fp_fmt = _S_chars + 11;
883 static constexpr const _CharT* _S_plus_minus = _S_chars + 16;
884 static constexpr const _CharT* _S_minus_empty_spec = _S_chars + 17;
885 static constexpr const _CharT* _S_empty_spec = _S_chars + 18;
887 [[__gnu__::__always_inline__]]
888 static _Runtime_format_string<_CharT>
890 {
return _Runtime_format_string<_CharT>(_S_empty_spec); }
892 static constexpr const _CharT* _S_weekdays[]
894 _GLIBCXX_WIDEN(
"Sunday"),
895 _GLIBCXX_WIDEN(
"Monday"),
896 _GLIBCXX_WIDEN(
"Tuesday"),
897 _GLIBCXX_WIDEN(
"Wednesday"),
898 _GLIBCXX_WIDEN(
"Thursday"),
899 _GLIBCXX_WIDEN(
"Friday"),
900 _GLIBCXX_WIDEN(
"Saturday"),
903 static constexpr const _CharT* _S_months[]
905 _GLIBCXX_WIDEN(
"January"),
906 _GLIBCXX_WIDEN(
"February"),
907 _GLIBCXX_WIDEN(
"March"),
908 _GLIBCXX_WIDEN(
"April"),
909 _GLIBCXX_WIDEN(
"May"),
910 _GLIBCXX_WIDEN(
"June"),
911 _GLIBCXX_WIDEN(
"July"),
912 _GLIBCXX_WIDEN(
"August"),
913 _GLIBCXX_WIDEN(
"September"),
914 _GLIBCXX_WIDEN(
"October"),
915 _GLIBCXX_WIDEN(
"November"),
916 _GLIBCXX_WIDEN(
"December"),
920 template<
typename _OutIter>
922 _M_write(_OutIter __out,
const locale& __loc, __string_view __s)
const
924#if defined _GLIBCXX_USE_NL_LANGINFO_L && __CHAR_BIT__ == 8
929 if constexpr (is_same_v<_CharT, char>)
930 if constexpr (__unicode::__literal_encoding_is_utf8())
931 if (_M_spec._M_localized && _M_spec._M_locale_specific
932 && __loc != locale::classic())
935 __locale_encoding_to_utf8(
const locale&, string_view,
void*);
937 __s = __locale_encoding_to_utf8(__loc, __s, &__buf);
940 return __format::__write(
std::move(__out), __s);
943 [[__gnu__::__always_inline__]]
945 _S_localized_spec(_CharT __conv, _CharT __mod)
969 template<
typename _Iter>
971 _M_locale_fmt(_Iter __out,
const locale& __loc,
const struct tm& __tm,
972 char __fmt,
char __mod)
const
974 basic_ostringstream<_CharT> __os;
976 const auto& __tp = use_facet<time_put<_CharT>>(__loc);
977 __tp.put(__os, __os, _S_space, &__tm, __fmt, __mod);
979 __out = _M_write(
std::move(__out), __loc, __os.view());
984 _M_check_ok(
const _ChronoData<_CharT>& __t, _CharT& __conv)
const
986 if (!_M_spec._M_debug)
992 if (!__t._M_weekday.ok()) [[unlikely]]
993 __throw_format_error(
"format error: invalid weekday");
998 if (!__t._M_month.ok()) [[unlikely]]
999 __throw_format_error(
"format error: invalid month");
1004 return __string_view();
1011 if (__t._M_weekday_index < 1 || __t._M_weekday_index > 5) [[unlikely]]
1012 return _GLIBCXX_WIDEN(
"index");
1016 if (!__t._M_weekday.ok()) [[unlikely]]
1019 return _GLIBCXX_WIDEN(
"weekday");
1025 if (!__t._M_month.ok()) [[unlikely]]
1028 return _GLIBCXX_WIDEN(
"month");
1033 if (!__t._M_day.ok()) [[unlikely]]
1034 return _GLIBCXX_WIDEN(
"day");
1037 if (!(__t._M_year/__t._M_month/__t._M_day).ok()) [[unlikely]]
1038 return _GLIBCXX_WIDEN(
"date");
1041 if (!__t._M_year.ok()) [[unlikely]]
1042 return _GLIBCXX_WIDEN(
"year");
1047 return __string_view();
1050 template<
typename _OutIter,
typename _FormatContext>
1052 _M_format_to(
const _ChronoData<_CharT>& __t, _OutIter __out,
1053 _FormatContext& __fc)
const
1055 auto __first = _M_spec._M_chrono_specs.begin();
1056 const auto __last = _M_spec._M_chrono_specs.end();
1058 auto __print_sign = [__is_neg = __t._M_is_neg, &__out] ()
mutable {
1061 *__out++ = _S_plus_minus[1];
1068 bool __use_locale_fmt =
false;
1069 if (_M_spec._M_localized && _M_spec._M_locale_specific)
1070 if (__fc.locale() != locale::classic())
1072 __use_locale_fmt =
true;
1074 __tm.tm_year = (int)__t._M_year - 1900;
1075 __tm.tm_yday = __t._M_day_of_year.count();
1076 __tm.tm_mon = (unsigned)__t._M_month - 1;
1077 __tm.tm_mday = (unsigned)__t._M_day;
1078 __tm.tm_wday = __t._M_weekday.c_encoding();
1079 __tm.tm_hour = __t._M_hours.count();
1080 __tm.tm_min = __t._M_minutes.count();
1081 __tm.tm_sec = __t._M_seconds.count();
1089#ifdef _GLIBCXX_USE_STRUCT_TM_TM_ZONE
1092 if (__t._M_zone_cstr)
1093 __tm.tm_zone =
const_cast<char*
>(__t._M_zone_cstr);
1098 constexpr const _CharT* __literals = _GLIBCXX_WIDEN(
"\n\t%");
1105 _CharT __c = *__first++;
1106 __string_view __invalid;
1107 if (_M_spec._M_needs_ok_check)
1108 __invalid = _M_check_ok(__t, __c);
1110 if (__invalid.empty() &&__use_locale_fmt
1111 && _S_localized_spec(__c, __mod)) [[unlikely]]
1112 __out = _M_locale_fmt(
std::move(__out), __fc.locale(),
1118 __out = _M_wi(__t._M_weekday_index,
std::move(__out));
1122 __out = _M_a_A(__t._M_weekday,
std::move(__out), __c ==
'A');
1127 __out = _M_b_B(__t._M_month,
std::move(__out), __c ==
'B');
1135 __out = _M_C_y_Y(__t._M_year,
std::move(__out), __c);
1139 __out = _M_d_e(__t._M_day,
std::move(__out), __c);
1151 __out = _M_g_G_V(__t,
std::move(__out), __c);
1155 __out = _M_H_I(__t._M_hours, __print_sign(), __c);
1158 __out = _M_j(__t, __print_sign());
1161 __out = _M_m(__t._M_month,
std::move(__out));
1164 __out = _M_M(__t._M_minutes, __print_sign());
1167 __out = _M_p(__t._M_hours,
std::move(__out));
1170 __out = _M_q(__t._M_unit_suffix,
std::move(__out));
1173 __out = _M_Q(__t, __print_sign(), __fc);
1176 __out = _M_r(__t, __print_sign());
1180 __out = _M_R_X(__t, __print_sign(), __c !=
'R');
1183 __out = _M_T(__t, __print_sign(), __fc);
1186 __out = _M_S(__t, __print_sign(), __fc, __mod !=
'O');
1190 __out = _M_u_w(__t._M_weekday,
std::move(__out), __c);
1194 __out = _M_U_W(__t,
std::move(__out), __c);
1197 __out = _M_z(__t._M_zone_offset,
std::move(__out), (
bool)__mod);
1200 __out = _M_Z(__t._M_zone_abbrev,
std::move(__out));
1203 *__out++ = __literals[0];
1206 *__out++ = __literals[1];
1209 *__out++ = __literals[2];
1220 if (!__invalid.empty())
1222 constexpr __string_view __pref = _GLIBCXX_WIDEN(
" is not a valid ");
1223 __out = __format::__write(
std::move(__out), __pref);
1224 __out = __format::__write(
std::move(__out), __invalid);
1229 __string_view __str(__first, __last - __first);
1230 size_t __pos = __str.find(
'%');
1235 if (__pos == __str.npos)
1239 __str.remove_suffix(__str.length() - __pos);
1240 __first += __pos + 1;
1242 __out = __format::__write(
std::move(__out), __str);
1245 while (__first != __last);
1249 template<
typename _OutIter>
1251 _M_wi(
unsigned __wi, _OutIter __out)
const
1255 __out = __format::__write(
std::move(__out), _S_str_d1(__buf, __wi));
1259 template<
typename _OutIter>
1261 _M_a_A(chrono::weekday __wd, _OutIter __out,
bool __full)
const
1265 __string_view __str = _S_weekdays[__wd.c_encoding()];
1267 __str = __str.substr(0, 3);
1268 return __format::__write(
std::move(__out), __str);
1271 template<
typename _OutIter>
1273 _M_b_B(chrono::month __m, _OutIter __out,
bool __full)
const
1277 __string_view __str = _S_months[(unsigned)__m - 1];
1279 __str = __str.substr(0, 3);
1280 return __format::__write(
std::move(__out), __str);
1283 template<
typename _OutIter>
1285 _M_c(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1290 __out = _M_a_A(__t._M_weekday,
std::move(__out),
false);
1292 __out = _M_b_B(__t._M_month,
std::move(++__out),
false);
1294 __out = _M_d_e(__t._M_day,
std::move(++__out),
'e');
1296 __out = _M_R_X(__t,
std::move(++__out),
true);
1298 return _M_C_y_Y(__t._M_year,
std::move(++__out),
'Y');
1301 template<
typename _OutIter>
1303 _M_C_y_Y(chrono::year __y, _OutIter __out, _CharT __conv)
const
1313 int __yi = (int)__y;
1314 const bool __is_neg = __yi < 0;
1315 __yi = __builtin_abs(__yi);
1316 int __ci = __yi / 100;
1318 if (__conv ==
'C' && __is_neg && (__ci * 100) != __yi) [[unlikely]]
1321 if (__conv !=
'y' && __ci >= 100) [[unlikely]]
1323 using _FmtStr = _Runtime_format_string<_CharT>;
1324 __string_view __fs = _S_minus_empty_spec + !__is_neg;
1325 __out = std::format_to(
std::move(__out), _FmtStr(__fs),
1326 __conv ==
'C' ? __ci : __yi);
1331 __buf[0] = _S_plus_minus[1];
1332 __string_view __sv(__buf + 3, __buf + 3);
1335 _S_fill_two_digits(__buf + 1, __ci);
1336 __sv = __string_view(__buf + !__is_neg, __buf + 3);
1340 _S_fill_two_digits(__buf + 3, __yi % 100);
1341 __sv = __string_view(__sv.data(), __buf + 5);
1343 __out = __format::__write(
std::move(__out), __sv);
1348 template<
typename _OutIter>
1350 _M_D_x(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1356 auto __di = (unsigned)__t._M_day;
1357 auto __mi = (unsigned)__t._M_month;
1358 auto __yi = __builtin_abs((
int)__t._M_year) % 100;
1360 if (__mi >= 100 || __di >= 100) [[unlikely]]
1362 using _FmtStr = _Runtime_format_string<_CharT>;
1363 __string_view __fs = _GLIBCXX_WIDEN(
"{:02d}/{:02d}/{:02d}");
1364 __out = std::format_to(
std::move(__out), _FmtStr(__fs),
1370 __buf[2] = _S_slash;
1371 __buf[5] = _S_slash;
1372 __string_view __sv(__buf, __buf + 8);
1374 _S_fill_two_digits(__buf, __mi);
1375 _S_fill_two_digits(__buf + 3, __di);
1376 _S_fill_two_digits(__buf + 6, __yi);
1377 __out = __format::__write(
std::move(__out), __sv);
1382 template<
typename _OutIter>
1384 _M_d_e(chrono::day __d, _OutIter __out, _CharT __conv)
const
1391 unsigned __i = (unsigned)__d;
1394 auto __sv = _S_str_d2(__buf, __i);
1395 if (__conv == _CharT(
'e') && __i < 10)
1398 __buf[0] = _S_space;
1402 __out = __format::__write(
std::move(__out), __sv);
1406 template<
typename _OutIter>
1408 _M_F(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1410 auto __di = (unsigned)__t._M_day;
1411 auto __mi = (unsigned)__t._M_month;
1412 auto __yi = (int)__t._M_year;
1413 const bool __is_neg = __yi < 0;
1414 __yi = __builtin_abs(__yi);
1416 if (__yi >= 10000 || __mi >= 100 || __di >= 100) [[unlikely]]
1418 using _FmtStr = _Runtime_format_string<_CharT>;
1420 = _GLIBCXX_WIDEN(
"-{:04d}-{:02d}-{:02d}") + !__is_neg;
1421 __out = std::format_to(
std::move(__out), _FmtStr(__fs),
1427 __buf[0] = _S_plus_minus[1];
1428 __buf[5] = _S_plus_minus[1];
1429 __buf[8] = _S_plus_minus[1];
1430 __string_view __sv(__buf + !__is_neg, __buf + 11);
1432 _S_fill_two_digits(__buf + 1, __yi / 100);
1433 _S_fill_two_digits(__buf + 3, __yi % 100);
1434 _S_fill_two_digits(__buf + 6, __mi);
1435 _S_fill_two_digits(__buf + 9, __di);
1436 __out = __format::__write(
std::move(__out), __sv);
1442 template<
typename _OutIter>
1444 _M_g_G_V(
const _ChronoData<_CharT>& __t, _OutIter __out,
1445 _CharT __conv)
const
1456 using namespace chrono;
1458 const days __offset = (__t._M_weekday - Monday) -
days(3);
1460 const local_days __ild = __t._M_ldays - __offset;
1462 days __idoy = __t._M_day_of_year - __offset;
1466 if (__idoy <=
days(0))
1467 __iyear = __t._M_year -
years(1);
1468 else if (__idoy <=
days(365))
1469 __iyear = __t._M_year;
1470 else if (__idoy ==
days(366) && __t._M_year.is_leap())
1471 __iyear = __t._M_year;
1472 else if (__idoy <=
days(730))
1473 __iyear = __t._M_year +
years(1);
1475 __iyear = year_month_day(__ild).year();
1478 return _M_C_y_Y(__iyear,
std::move(__out),
"yY"[__conv ==
'G']);
1480 if (__iyear != __t._M_year)
1481 __idoy = __ild - local_days(__iyear/January/0);
1483 const auto __wi = chrono::floor<weeks>(__idoy -
days(1)).count() + 1;
1484 return __format::__write(
std::move(__out), _S_two_digits(__wi));
1487 template<
typename _OutIter>
1489 _M_H_I(chrono::hours __h, _OutIter __out, _CharT __conv)
const
1496 int __i = __h.count();
1498 if (__conv == _CharT(
'I'))
1504 else if (__i >= 100) [[unlikely]]
1505 return std::format_to(
std::move(__out), _S_empty_fs(), __i);
1507 return __format::__write(
std::move(__out), _S_two_digits(__i));
1510 template<
typename _OutIter>
1512 _M_j(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1514 if (!_M_spec._M_needs(_ChronoParts::_DayOfYear))
1517 auto __d = chrono::floor<chrono::days>(__t._M_hours).count();
1518 return std::format_to(
std::move(__out), _S_empty_fs(), __d);
1521 auto __d = __t._M_day_of_year.count();
1522 if (__d >= 1000) [[unlikely]]
1523 return std::format_to(
std::move(__out), _S_empty_fs(), __d);
1526 return __format::__write(
std::move(__out), _S_str_d3(__buf, __d));
1529 template<
typename _OutIter>
1531 _M_m(chrono::month __m, _OutIter __out)
const
1535 auto __i = (unsigned)__m;
1536 if (__i == 0 && _M_spec._M_debug) [[unlikely]]
1538 return __format::__write(
std::move(__out), _S_digit(0));
1541 return __format::__write(
std::move(__out), _S_str_d2(__buf, __i));
1544 template<
typename _OutIter>
1546 _M_M(chrono::minutes __m, _OutIter __out)
const
1551 auto __i = __m.count();
1552 return __format::__write(
std::move(__out), _S_two_digits(__i));
1555 template<
typename _OutIter>
1557 _M_p(chrono::hours __h, _OutIter __out)
const
1562 _S_fill_ampm(__buf, __h);
1563 return __format::__write(
std::move(__out), __string_view(__buf, 2));
1566 template<
typename _OutIter>
1568 _M_q(__string_view __us, _OutIter __out)
const
1571 return __format::__write(
std::move(__out), __us);
1574 template<
typename _OutIter,
typename _FormatContext>
1576 _M_Q(
const _ChronoData<_CharT>& __t, _OutIter __out,
1577 _FormatContext&)
const
1580 return std::vformat_to(
std::move(__out), _S_empty_spec, __t._M_ereps);
1583 template<
typename _OutIter>
1585 _M_r(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1588 auto __hi = __t._M_hours.count() % 12;
1593 __buf[2] = _S_colon;
1594 __buf[5] = _S_colon;
1595 __buf[8] = _S_space;
1596 _S_fill_two_digits(__buf, __hi);
1597 _S_fill_two_digits(__buf + 3, __t._M_minutes.count());
1598 _S_fill_two_digits(__buf + 6, __t._M_seconds.count());
1599 _S_fill_ampm(__buf + 9, __t._M_hours);
1601 return __format::__write(
std::move(__out), __string_view(__buf, 11));
1604 template<
typename _OutIter>
1606 _M_R_X(
const _ChronoData<_CharT>& __t, _OutIter __out,
1613 auto __hi = __t._M_hours.count();
1616 __buf[2] = _S_colon;
1617 __buf[5] = _S_colon;
1618 __string_view __sv(__buf, 8);
1620 if (__hi >= 100) [[unlikely]]
1622 __out = std::format_to(
std::move(__out), _S_empty_fs(), __hi);
1623 __sv.remove_prefix(2);
1626 _S_fill_two_digits(__buf, __hi);
1628 _S_fill_two_digits(__buf + 3, __t._M_minutes.count());
1630 _S_fill_two_digits(__buf + 6, __t._M_seconds.count());
1632 __sv.remove_suffix(3);
1634 return __format::__write(
std::move(__out), __sv);
1637 template<
typename _OutIter,
typename _FormatContext>
1639 _M_S(
const _ChronoData<_CharT>& __t, _OutIter __out,
1640 _FormatContext& __ctx,
bool __subs =
true)
const
1644 auto __s = __t._M_seconds;
1646 __out = __format::__write(
std::move(__out),
1647 _S_two_digits(__s.count()));
1649 __out = _M_subsecs(__t,
std::move(__out), __ctx);
1653 template<
typename _OutIter,
typename _FormatContext>
1655 _M_subsecs(
const _ChronoData<_CharT>& __t, _OutIter __out,
1656 _FormatContext& __ctx)
const
1658 unsigned __prec = _M_spec._M_prec_kind != _WP_none
1659 ? _M_spec._M_get_precision(__ctx)
1664 _CharT __dot = _S_dot;
1665 if (_M_spec._M_localized) [[unlikely]]
1667 auto __loc = __ctx.locale();
1668 const auto& __np = use_facet<numpunct<_CharT>>(__loc);
1669 __dot = __np.decimal_point();
1674 if (_M_spec._M_floating_point_rep)
1676 _Str_sink<_CharT> __sink;
1677 if (_M_spec._M_localized && _M_spec._M_custom_rep) [[unlikely]]
1678 std::vformat_to(__sink.out(), __ctx.locale(),
1679 _GLIBCXX_WIDEN(
"{1:0.{2}Lf}"), __t._M_ereps);
1681 std::vformat_to(__sink.out(),
1682 _GLIBCXX_WIDEN(
"{1:0.{2}f}"), __t._M_ereps);
1684 auto __sv = __sink.view();
1686 __sv.remove_prefix(2);
1687 return __format::__write(
std::move(__out), __sv);
1690 constexpr unsigned __max_prec = _ChronoData<_CharT>::_S_max_prec;
1691 constexpr typename _ChronoData<_CharT>::_Attoseconds::rep __pow10t[]
1695 10'000u, 100'000u, 1000'000u,
1696 10'000'000u, 100'000'000u, 1000'000'000u,
1697 10'000'000'000u, 100'000'000'000u, 1000'000'000'000u,
1698 10'000'000'000'000u, 100'000'000'000'000u, 1000'000'000'000'000u,
1699 10'000'000'000'000'000u, 100'000'000'000'000'000u, 1000'000'000'000'000'000u,
1702 auto __subs = __t._M_subseconds.count();
1703 if (__prec < __max_prec)
1704 __subs /= __pow10t[__max_prec - __prec];
1705 else if (__prec > __max_prec)
1706 __prec = __max_prec;
1708 using _FmtStr = _Runtime_format_string<_CharT>;
1709 return std::format_to(__out, _FmtStr(_GLIBCXX_WIDEN(
"{0:0{1}}")),
1715 template<
typename _OutIter,
typename _FormatContext>
1717 _M_T(
const _ChronoData<_CharT>& __t, _OutIter __out,
1718 _FormatContext& __ctx)
const
1721 __out = _M_R_X(__t,
std::move(__out),
true);
1722 return _M_subsecs(__t,
std::move(__out), __ctx);
1725 template<
typename _OutIter>
1727 _M_u_w(chrono::weekday __wd, _OutIter __out, _CharT __conv)
const
1733 unsigned __wdi = __conv ==
'u' ? __wd.iso_encoding()
1734 : __wd.c_encoding();
1736 return __format::__write(
std::move(__out), _S_str_d1(__buf, __wdi));
1739 template<
typename _OutIter>
1741 _M_U_W(
const _ChronoData<_CharT>& __t, _OutIter __out,
1742 _CharT __conv)
const
1749 using namespace chrono;
1750 const weekday __weekstart = __conv ==
'U' ? Sunday : Monday;
1751 const days __offset = __t._M_weekday - __weekstart;
1752 auto __weeks = chrono::floor<weeks>(__t._M_day_of_year - __offset -
days(1));
1753 return __format::__write(
std::move(__out), _S_two_digits(__weeks.count() + 1));
1756 template<
typename _OutIter>
1758 _M_z(chrono::seconds __ts, _OutIter __out,
bool __mod =
false)
const
1762 __string_view __zero
1763 = __mod ? _GLIBCXX_WIDEN(
"+00:00") : _GLIBCXX_WIDEN(
"+0000");
1764 return __format::__write(
std::move(__out), __zero);
1767 chrono::hh_mm_ss<chrono::seconds> __hms(__ts);
1768 unsigned __mo = 3 + __mod;
1771 __buf[0] = _S_plus_minus[__hms.is_negative()];
1772 __buf[3] = _S_colon;
1773 _S_fill_two_digits(__buf + 1, __hms.hours().count());
1774 _S_fill_two_digits(__buf + __mo, __hms.minutes().count());
1776 __string_view __sv(__buf, __mo + 2);
1777 return __format::__write(
std::move(__out), __sv);
1780 template<
typename _OutIter>
1782 _M_Z(__string_view __abbrev, _OutIter __out)
const
1783 {
return __format::__write(
std::move(__out), __abbrev); }
1788 static basic_string_view<_CharT>
1789 _S_digit(
int __n)
noexcept
1792 return { _GLIBCXX_WIDEN(
"0123456789999999") + (__n & 0xf), 1 };
1796 static basic_string_view<_CharT>
1797 _S_two_digits(
int __n)
noexcept
1800 _GLIBCXX_WIDEN(
"0001020304050607080910111213141516171819"
1801 "2021222324252627282930313233343536373839"
1802 "4041424344454647484950515253545556575859"
1803 "6061626364656667686970717273747576777879"
1804 "8081828384858687888990919293949596979899"
1805 "9999999999999999999999999999999999999999"
1806 "9999999999999999") + 2 * (__n & 0x7f),
1812 [[__gnu__::__always_inline__]]
1814 _S_fill_two_digits(_CharT* __buf,
unsigned __n)
1816 auto __sv = _S_two_digits(__n);
1822 [[__gnu__::__always_inline__]]
1824 _S_fill_ampm(_CharT* __buf, chrono::hours __h)
1826 auto __hi = __h.count();
1827 if (__hi >= 24) [[unlikely]]
1830 constexpr const _CharT* __apm = _GLIBCXX_WIDEN(
"APM");
1831 __buf[0] = __apm[__hi >= 12];
1832 __buf[1] = __apm[2];
1837 [[__gnu__::__always_inline__]]
1838 static basic_string_view<_CharT>
1839 _S_str_d1(span<_CharT, 3> __buf,
unsigned __n)
1841 if (__n < 10) [[likely]]
1842 return _S_digit(__n);
1843 return _S_str_d2(__buf, __n);
1848 [[__gnu__::__always_inline__]]
1849 static basic_string_view<_CharT>
1850 _S_str_d2(span<_CharT, 3> __buf,
unsigned __n)
1852 if (__n < 100) [[likely]]
1853 return _S_two_digits(__n);
1854 return _S_str_d3(__buf, __n);
1859 [[__gnu__::__always_inline__]]
1860 static basic_string_view<_CharT>
1861 _S_str_d3(span<_CharT, 3> __buf,
unsigned __n)
1863 _S_fill_two_digits(__buf.data(), __n / 10);
1864 __buf[2] = _S_chars[__n % 10];
1865 return __string_view(__buf.data(), 3);
1869 template<
typename _CharT>
1870 struct __formatter_duration :
private __formatter_chrono<_CharT>
1872 template<
typename _Rep,
typename _Period>
1873 constexpr static auto
1874 _S_subseconds(
const chrono::duration<_Rep, _Period>& __d)
1876 if constexpr (chrono::treat_as_floating_point_v<_Rep>)
1877 return chrono::duration<_Rep>(__d);
1878 else if constexpr (_Period::den == 1)
1879 return chrono::seconds(0);
1882 using _Attoseconds = _ChronoData<_CharT>::_Attoseconds;
1883 using _CRep = common_type_t<_Rep, typename _Attoseconds::rep>;
1884 chrono::duration<_CRep, _Period> subs(__d.count());
1885 return chrono::duration_cast<_Attoseconds>(subs);
1890 template<
typename _Duration>
1893 _S_spec_for(_ChronoParts __parts)
1895 using _Rep =
typename _Duration::rep;
1896 using enum _ChronoParts;
1898 _ChronoSpec<_CharT> __res{};
1899 __res._M_floating_point_rep = chrono::treat_as_floating_point_v<_Rep>;
1900 __res._M_custom_rep = !is_arithmetic_v<_Rep>;
1901 __res._M_prec = chrono::hh_mm_ss<_Duration>::fractional_width;
1902 if ((__parts & _TimeOfDay) != 0)
1903 __res._M_localized = __res._M_prec > 0 || __res._M_floating_point_rep;
1905 if ((__parts & _TimeOfDay) != 0)
1906 __res._M_needed |= _TimeOfDay;
1907 if ((__parts & _Date) != 0)
1908 __res._M_needed |= _YearMonthDay;
1909 if ((__parts & _ZoneAbbrev) != 0)
1910 __res._M_needed |= _ZoneAbbrev;
1914 case _ZonedDateTime:
1915 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ftz();
1918 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ft();
1921 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_f();
1924 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_t();
1929 __builtin_unreachable();
1934 template<
typename _Duration>
1939 using enum _ChronoParts;
1941 constexpr bool __stream_insertable =
1942 requires (basic_ostream<_CharT>& __os, chrono::sys_time<_Duration> __t)
1944 if constexpr (!__stream_insertable)
1945 return _S_spec_for<_Duration>(_None);
1946 else if constexpr (is_convertible_v<_Duration, chrono::days>)
1947 return _S_spec_for<_Duration>(_Date);
1949 return _S_spec_for<_Duration>(_DateTime);
1952 using __formatter_chrono<_CharT>::__formatter_chrono;
1953 using __formatter_chrono<_CharT>::_M_spec;
1955 template<
typename _Duration>
1956 constexpr typename basic_format_parse_context<_CharT>::iterator
1957 _M_parse(basic_format_parse_context<_CharT>& __pc, _ChronoParts __parts,
1958 const _ChronoSpec<_CharT>& __def)
1960 using _Rep =
typename _Duration::rep;
1961 using enum _ChronoParts;
1964 = __formatter_chrono<_CharT>::_M_parse(__pc, __parts, __def);
1967 _M_spec._M_needs_ok_check =
false;
1972 if constexpr (!is_floating_point_v<_Rep>)
1973 if constexpr (chrono::treat_as_floating_point_v<_Rep>)
1974 if (_M_spec._M_needs(_Subseconds|_EpochUnits)
1975 || _M_spec._M_prec_kind != _WP_none
1976 || _M_spec._M_prec_value > 0)
1978 constexpr const _CharT* __fs = _GLIBCXX_WIDEN(
"#02.5Lf");
1979 basic_format_parse_context<_CharT> __npc(__fs);
1980 formatter<_Rep, _CharT> __fmtter;
1981 __fmtter.parse(__npc);
1987 template<
typename _FormatContext>
1989 _M_locale(_FormatContext& __fc)
const
1991 if (!_M_spec._M_localized)
1994 return __fc.locale();
1998 template<
typename _Rep,
typename _Period,
typename _FormatContext>
1999 typename _FormatContext::iterator
2000 _M_format_to_ostream(
const chrono::duration<_Rep, _Period>& __d,
2002 _FormatContext& __fc)
const
2004 basic_ostringstream<_CharT> __os;
2005 __os.imbue(this->_M_locale(__fc));
2007 if (__is_neg) [[unlikely]]
2008 __os << this->_S_plus_minus[1];
2012 return __format::__write_padded_as_spec(__str, __str.size(),
2016 template<
typename _Rep1,
typename _Period1,
2017 typename _Rep2,
typename _Period2,
2018 typename _FormatContext>
2019 typename _FormatContext::iterator
2020 _M_format_units(_ChronoData<_CharT>& __cd,
2021 const chrono::duration<_Rep1, _Period1>& __ed,
2022 const chrono::duration<_Rep2, _Period2>& __ss,
2023 _FormatContext& __fc)
const
2025 __format::_Str_sink<_CharT> __suffix_store;
2026 constexpr auto _S_unit_suffix
2027 = chrono::__detail::__units_suffix<_Period1, _CharT>();
2028 if constexpr (!_S_unit_suffix.empty())
2029 __cd._M_unit_suffix = _S_unit_suffix;
2030 else if (_M_spec._M_needs(_ChronoParts::_UnitSuffix))
2033 __fmt_units_suffix<_Period1, _CharT>(__suffix_store.out());
2034 __cd._M_unit_suffix = __suffix_store.view();
2037 const auto __prec = _M_spec._M_prec_kind != _WP_none
2038 ? _M_spec._M_get_precision(__fc)
2041 using _ErasedContext =
typename _ChronoData<_CharT>::_FormatContext;
2044 auto __ereps = +__ed.count();
2045 if (!_M_spec._M_needs(_ChronoParts::_Subseconds))
2049 = std::make_format_args<_ErasedContext>(__ereps, __ssreps, __prec);
2050 __cd._M_ereps = __args_store;
2051 return this->_M_format(__cd, __fc);
2054 using _Attoseconds = _ChronoData<_CharT>::_Attoseconds;
2055 auto __nss = _S_subseconds(__ss);
2056 __cd._M_subseconds = chrono::duration_cast<_Attoseconds>(__nss);
2058 auto __ssreps = __nss.count();
2060 = std::make_format_args<_ErasedContext>(__ereps, __ssreps, __prec);
2061 __cd._M_ereps = __args_store;
2063 return this->_M_format(__cd, __fc);
2067 template<
typename _Rep1,
typename _Period1,
typename _FormatContext>
2068 typename _FormatContext::iterator
2069 _M_format_time_point(_ChronoData<_CharT>& __cd,
2070 const chrono::duration<_Rep1, _Period1>& __ed,
2071 _FormatContext& __fc)
const
2073 auto __parts = _M_spec._M_needed - _ChronoParts::_TotalSeconds;
2074 if ((__parts & _ChronoParts::_DateTime) != 0)
2075 __cd._M_fill_date_time(__cd._M_lseconds, __parts);
2076 return _M_format_units(__cd, __ed, __ed - __cd._M_eseconds, __fc);
2080#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2081 template<
typename _CharT>
2082 struct __formatter_chrono_info
2084 constexpr typename basic_format_parse_context<_CharT>::iterator
2085 parse(basic_format_parse_context<_CharT>& __pc)
2086 {
return _M_f._M_parse(__pc, _ChronoParts(), {}); }
2088 template<
typename _Info,
typename _Out>
2089 typename basic_format_context<_Out, _CharT>::iterator
2090 format(
const _Info& __i,
2091 basic_format_context<_Out, _CharT>& __fc)
const
2095 if (!_M_f._M_spec._M_chrono_specs.empty()) [[unlikely]]
2096 return _M_f._M_format(_ChronoData<_CharT>{}, __fc);
2098 const size_t __padwidth = _M_f._M_spec._M_get_width(__fc);
2099 if (__padwidth == 0)
2100 return _M_format_to(__fc.out(), __i);
2102 _Padding_sink<_Out, _CharT> __sink(__fc.out(), __padwidth);
2103 _M_format_to(__sink.out(), __i);
2104 return __sink._M_finish(_M_f._M_spec._M_align, _M_f._M_spec._M_fill);
2108 template<
typename _Out>
2110 _M_format_to(_Out __out,
const chrono::sys_info& __si)
const
2112 using _FmtStr = _Runtime_format_string<_CharT>;
2116 constexpr auto* __fs
2117 = _GLIBCXX_WIDEN(
"[{0:%F %T},{1:%F %T},{2:%T},{3:%Q%q},{0:%Z}]");
2118 const chrono::local_seconds __lb(__si.begin.time_since_epoch());
2119 return std::format_to(
std::move(__out), _FmtStr(__fs),
2120 chrono::local_time_format(__lb, &__si.abbrev),
2121 __si.end, __si.offset, __si.save);
2124 template<
typename _Out>
2126 _M_format_to(_Out __out,
const chrono::local_info& __li)
const
2128 *__out = _Separators<_CharT>::_S_squares()[0];
2130 if (__li.result == chrono::local_info::unique)
2131 __out = _M_format_to(
std::move(__out), __li.first);
2134 basic_string_view<_CharT> __sv;
2135 if (__li.result == chrono::local_info::nonexistent)
2136 __sv =_GLIBCXX_WIDEN(
"nonexistent");
2138 __sv = _GLIBCXX_WIDEN(
"ambiguous");
2139 __out = __format::__write(
std::move(__out), __sv);
2141 __sv = _GLIBCXX_WIDEN(
" local time between ");
2142 __out = __format::__write(
std::move(__out), __sv);
2143 __out = _M_format_to(
std::move(__out), __li.first);
2145 __sv = _GLIBCXX_WIDEN(
" and ");
2146 __out = __format::__write(
std::move(__out), __sv);
2147 __out = _M_format_to(
std::move(__out), __li.second);
2149 *__out = _Separators<_CharT>::_S_squares()[1];
2154 __formatter_chrono<_CharT> _M_f;
2161 template<
typename _Rep,
typename _Period,
typename _CharT>
2162 requires __format::__formattable_impl<_Rep, _CharT>
2163 struct formatter<
chrono::duration<_Rep, _Period>, _CharT>
2165 constexpr typename basic_format_parse_context<_CharT>::iterator
2166 parse(basic_format_parse_context<_CharT>& __pc)
2168 using enum __format::_ChronoParts;
2169 return _M_f.template _M_parse<_Duration>(__pc, _EpochTime, __defSpec);
2172 template<
typename _Out>
2173 typename basic_format_context<_Out, _CharT>::iterator
2174 format(
const chrono::duration<_Rep, _Period>& __d,
2175 basic_format_context<_Out, _CharT>& __fc)
const
2177 if constexpr (numeric_limits<_Rep>::is_signed)
2178 if (__d < __d.zero()) [[unlikely]]
2180 if constexpr (is_integral_v<_Rep>)
2184 using _URep = make_unsigned_t<_Rep>;
2185 auto __ucnt = -
static_cast<_URep
>(__d.count());
2186 auto __ud = chrono::duration<_URep, _Period>(__ucnt);
2187 return _M_format(__ud,
true, __fc);
2190 return _M_format(-__d,
true, __fc);
2192 return _M_format(__d,
false, __fc);
2196 using _Duration = chrono::duration<_Rep, _Period>;
2198 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2200 using enum __format::_ChronoParts;
2201 auto __res = __format::__formatter_duration<_CharT>::
2202 template _S_spec_for<_Duration>(_None);
2203 __res._M_localized = !is_integral_v<_Rep>;
2205 if constexpr (is_integral_v<_Rep>)
2207 __res._M_needed = _EpochUnits|_UnitSuffix;
2208 __res._M_chrono_specs = _GLIBCXX_WIDEN(
"%Q%q");
2213 template<
typename _Rep2,
typename _Out>
2214 typename basic_format_context<_Out, _CharT>::iterator
2215 _M_format(
const chrono::duration<_Rep2, _Period>& __d,
2217 basic_format_context<_Out, _CharT>& __fc)
const
2219 using namespace chrono;
2220 using enum __format::_ChronoParts;
2221 if constexpr (!is_integral_v<_Rep>)
2222 if (_M_f._M_spec._M_chrono_specs.empty())
2223 return _M_f._M_format_to_ostream(__d, __is_neg, __fc);
2225 __format::_ChronoData<_CharT> __cd;
2226 __cd._M_is_neg = __is_neg;
2227 auto __ts = chrono::floor<chrono::seconds>(__d);
2228 __cd._M_eseconds = __ts;
2229 if (_M_f._M_spec._M_needs(_HoursMinutesSeconds))
2230 __cd._M_fill_time(__ts);
2231 return _M_f._M_format_units(__cd, __d, __d - __ts, __fc);
2234 __format::__formatter_duration<_CharT> _M_f{__defSpec};
2237 template<__format::__
char _CharT>
2238 struct formatter<
chrono::day, _CharT>
2240 constexpr typename basic_format_parse_context<_CharT>::iterator
2241 parse(basic_format_parse_context<_CharT>& __pc)
2243 using enum __format::_ChronoParts;
2244 return _M_f._M_parse(__pc, _Day|_WeekdayIndex, __defSpec);
2247 template<
typename _Out>
2248 typename basic_format_context<_Out, _CharT>::iterator
2249 format(
const chrono::day& __t,
2250 basic_format_context<_Out, _CharT>& __fc)
const
2252 __format::_ChronoData<_CharT> __cd{};
2253 __cd._M_fill_day(__t, __defSpec._M_needed);
2254 return _M_f._M_format(__cd, __fc);
2258 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2260 using __format::_ChronoFormats;
2261 using enum __format::_ChronoParts;
2263 __format::_ChronoSpec<_CharT> __res{};
2264 __res._M_debug =
true;
2265 __res._M_needed = _Day;
2266 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_d();
2270 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2273 template<__format::__
char _CharT>
2274 struct formatter<
chrono::month, _CharT>
2276 constexpr typename basic_format_parse_context<_CharT>::iterator
2277 parse(basic_format_parse_context<_CharT>& __pc)
2279 using enum __format::_ChronoParts;
2280 return _M_f._M_parse(__pc, _Month, __defSpec);
2283 template<
typename _Out>
2284 typename basic_format_context<_Out, _CharT>::iterator
2285 format(
const chrono::month& __t,
2286 basic_format_context<_Out, _CharT>& __fc)
const
2288 __format::_ChronoData<_CharT> __cd{};
2289 __cd._M_month = __t;
2290 return _M_f._M_format(__cd, __fc);
2294 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2296 using __format::_ChronoFormats;
2297 using enum __format::_ChronoParts;
2299 __format::_ChronoSpec<_CharT> __res{};
2300 __res._M_debug =
true;
2301 __res._M_localized =
true;
2302 __res._M_locale_specific =
true;
2303 __res._M_needed = _Month;
2304 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_m();
2308 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2311 template<__format::__
char _CharT>
2312 struct formatter<
chrono::year, _CharT>
2314 constexpr typename basic_format_parse_context<_CharT>::iterator
2315 parse(basic_format_parse_context<_CharT>& __pc)
2317 using enum __format::_ChronoParts;
2318 return _M_f._M_parse(__pc, _Year, __defSpec);
2321 template<
typename _Out>
2322 typename basic_format_context<_Out, _CharT>::iterator
2323 format(
const chrono::year& __t,
2324 basic_format_context<_Out, _CharT>& __fc)
const
2326 __format::_ChronoData<_CharT> __cd{};
2328 return _M_f._M_format(__cd, __fc);
2332 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2334 using __format::_ChronoFormats;
2335 using enum __format::_ChronoParts;
2337 __format::_ChronoSpec<_CharT> __res{};
2338 __res._M_debug =
true;
2339 __res._M_needed = _Year;
2340 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_y();
2344 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2347 template<__format::__
char _CharT>
2348 struct formatter<
chrono::weekday, _CharT>
2350 constexpr typename basic_format_parse_context<_CharT>::iterator
2351 parse(basic_format_parse_context<_CharT>& __pc)
2353 using enum __format::_ChronoParts;
2354 return _M_f._M_parse(__pc, _Weekday, __defSpec);
2357 template<
typename _Out>
2358 typename basic_format_context<_Out, _CharT>::iterator
2359 format(
const chrono::weekday& __t,
2360 basic_format_context<_Out, _CharT>& __fc)
const
2362 __format::_ChronoData<_CharT> __cd{};
2363 __cd._M_weekday = __t;
2364 return _M_f._M_format(__cd, __fc);
2368 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2370 using __format::_ChronoFormats;
2371 using enum __format::_ChronoParts;
2373 __format::_ChronoSpec<_CharT> __res{};
2374 __res._M_debug =
true;
2375 __res._M_localized =
true;
2376 __res._M_locale_specific =
true;
2377 __res._M_needed = _Weekday;
2378 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_w();
2382 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2385 template<__format::__
char _CharT>
2386 struct formatter<
chrono::weekday_indexed, _CharT>
2388 constexpr typename basic_format_parse_context<_CharT>::iterator
2389 parse(basic_format_parse_context<_CharT>& __pc)
2391 using enum __format::_ChronoParts;
2392 return _M_f._M_parse(__pc, _IndexedWeekday, __defSpec);
2395 template<
typename _Out>
2396 typename basic_format_context<_Out, _CharT>::iterator
2397 format(
const chrono::weekday_indexed& __t,
2398 basic_format_context<_Out, _CharT>& __fc)
const
2400 __format::_ChronoData<_CharT> __cd{};
2401 __cd._M_fill_weekday(__t, __defSpec._M_needed);
2402 return _M_f._M_format(__cd, __fc);
2406 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2408 using __format::_ChronoFormats;
2409 using enum __format::_ChronoParts;
2411 __format::_ChronoSpec<_CharT> __res{};
2412 __res._M_debug =
true;
2413 __res._M_localized =
true;
2414 __res._M_locale_specific =
true;
2415 __res._M_needed = _IndexedWeekday;
2416 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_wi();
2420 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2423 template<__format::__
char _CharT>
2424 struct formatter<
chrono::weekday_last, _CharT>
2426 constexpr typename basic_format_parse_context<_CharT>::iterator
2427 parse(basic_format_parse_context<_CharT>& __pc)
2429 using enum __format::_ChronoParts;
2430 return _M_f._M_parse(__pc, _Weekday, __defSpec);
2433 template<
typename _Out>
2434 typename basic_format_context<_Out, _CharT>::iterator
2435 format(
const chrono::weekday_last& __t,
2436 basic_format_context<_Out, _CharT>& __fc)
const
2438 __format::_ChronoData<_CharT> __cd{};
2439 __cd._M_weekday = __t.weekday();
2440 return _M_f._M_format(__cd, __fc);
2444 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2446 using __format::_ChronoFormats;
2447 using enum __format::_ChronoParts;
2449 __format::_ChronoSpec<_CharT> __res{};
2450 __res._M_debug =
true;
2451 __res._M_localized =
true;
2452 __res._M_locale_specific =
true;
2453 __res._M_needed = _Weekday;
2454 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_wl();
2458 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2461 template<__format::__
char _CharT>
2462 struct formatter<
chrono::month_day, _CharT>
2464 constexpr typename basic_format_parse_context<_CharT>::iterator
2465 parse(basic_format_parse_context<_CharT>& __pc)
2467 using enum __format::_ChronoParts;
2468 return _M_f._M_parse(__pc, _Month|_Day|_WeekdayIndex, __defSpec);
2471 template<
typename _Out>
2472 typename basic_format_context<_Out, _CharT>::iterator
2473 format(
const chrono::month_day& __t,
2474 basic_format_context<_Out, _CharT>& __fc)
const
2476 __format::_ChronoData<_CharT> __cd{};
2477 __cd._M_month = __t.month();
2478 __cd._M_fill_day(__t.day(), __defSpec._M_needed);
2479 return _M_f._M_format(__cd, __fc);
2483 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2485 using __format::_ChronoFormats;
2486 using enum __format::_ChronoParts;
2488 __format::_ChronoSpec<_CharT> __res{};
2489 __res._M_debug =
true;
2490 __res._M_localized =
true;
2491 __res._M_locale_specific =
true;
2492 __res._M_needed = _Month|_Day;
2493 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_md();
2497 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2500 template<__format::__
char _CharT>
2501 struct formatter<
chrono::month_day_last, _CharT>
2503 constexpr typename basic_format_parse_context<_CharT>::iterator
2504 parse(basic_format_parse_context<_CharT>& __pc)
2506 using enum __format::_ChronoParts;
2507 return _M_f._M_parse(__pc, _Month, __defSpec);
2510 template<
typename _Out>
2511 typename basic_format_context<_Out, _CharT>::iterator
2512 format(
const chrono::month_day_last& __t,
2513 basic_format_context<_Out, _CharT>& __fc)
const
2515 __format::_ChronoData<_CharT> __cd{};
2516 __cd._M_month = __t.month();
2517 return _M_f._M_format(__cd, __fc);
2521 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2523 using __format::_ChronoFormats;
2524 using enum __format::_ChronoParts;
2526 __format::_ChronoSpec<_CharT> __res{};
2527 __res._M_debug =
true;
2528 __res._M_localized =
true;
2529 __res._M_locale_specific =
true;
2530 __res._M_needed = _Month;
2531 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ml();
2535 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2538 template<__format::__
char _CharT>
2539 struct formatter<
chrono::month_weekday, _CharT>
2541 constexpr typename basic_format_parse_context<_CharT>::iterator
2542 parse(basic_format_parse_context<_CharT>& __pc)
2544 using enum __format::_ChronoParts;
2545 return _M_f._M_parse(__pc, _Month|_IndexedWeekday, __defSpec);
2548 template<
typename _Out>
2549 typename basic_format_context<_Out, _CharT>::iterator
2550 format(
const chrono::month_weekday& __t,
2551 basic_format_context<_Out, _CharT>& __fc)
const
2553 __format::_ChronoData<_CharT> __cd{};
2554 __cd._M_month = __t.month();
2555 __cd._M_fill_weekday(__t.weekday_indexed(), __defSpec._M_needed);
2556 return _M_f._M_format(__cd, __fc);
2560 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2562 using __format::_ChronoFormats;
2563 using enum __format::_ChronoParts;
2565 __format::_ChronoSpec<_CharT> __res{};
2566 __res._M_debug =
true;
2567 __res._M_localized =
true;
2568 __res._M_locale_specific =
true;
2569 __res._M_needed = _Month|_IndexedWeekday;
2570 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_mwi();
2574 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2577 template<__format::__
char _CharT>
2578 struct formatter<
chrono::month_weekday_last, _CharT>
2580 constexpr typename basic_format_parse_context<_CharT>::iterator
2581 parse(basic_format_parse_context<_CharT>& __pc)
2583 using enum __format::_ChronoParts;
2584 return _M_f._M_parse(__pc, _Month|_Weekday, __defSpec);
2587 template<
typename _Out>
2588 typename basic_format_context<_Out, _CharT>::iterator
2589 format(
const chrono::month_weekday_last& __t,
2590 basic_format_context<_Out, _CharT>& __fc)
const
2592 __format::_ChronoData<_CharT> __cd{};
2593 __cd._M_month = __t.month();
2594 __cd._M_weekday = __t.weekday_last().weekday();
2595 return _M_f._M_format(__cd, __fc);
2599 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2601 using __format::_ChronoFormats;
2602 using enum __format::_ChronoParts;
2604 __format::_ChronoSpec<_CharT> __res{};
2605 __res._M_debug =
true;
2606 __res._M_localized =
true;
2607 __res._M_locale_specific =
true;
2608 __res._M_needed = _Month|_Weekday;
2609 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_mwl();
2613 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2616 template<__format::__
char _CharT>
2617 struct formatter<
chrono::year_month, _CharT>
2619 constexpr typename basic_format_parse_context<_CharT>::iterator
2620 parse(basic_format_parse_context<_CharT>& __pc)
2622 using enum __format::_ChronoParts;
2623 return _M_f._M_parse(__pc, _Year|_Month, __defSpec);
2626 template<
typename _Out>
2627 typename basic_format_context<_Out, _CharT>::iterator
2628 format(
const chrono::year_month& __t,
2629 basic_format_context<_Out, _CharT>& __fc)
const
2631 __format::_ChronoData<_CharT> __cd{};
2632 __cd._M_fill_year_month(__t, __defSpec._M_needed);
2633 return _M_f._M_format(__cd, __fc);
2637 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2639 using __format::_ChronoFormats;
2640 using enum __format::_ChronoParts;
2642 __format::_ChronoSpec<_CharT> __res{};
2643 __res._M_debug =
true;
2644 __res._M_localized =
true;
2645 __res._M_locale_specific =
true;
2646 __res._M_needed = _Year|_Month;
2647 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ym();
2651 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2654 template<__format::__
char _CharT>
2655 struct formatter<
chrono::year_month_day, _CharT>
2657 constexpr typename basic_format_parse_context<_CharT>::iterator
2658 parse(basic_format_parse_context<_CharT>& __pc)
2660 using enum __format::_ChronoParts;
2661 return _M_f._M_parse(__pc, _Date, __defSpec);
2664 template<
typename _Out>
2665 typename basic_format_context<_Out, _CharT>::iterator
2666 format(
const chrono::year_month_day& __t,
2667 basic_format_context<_Out, _CharT>& __fc)
const
2669 __format::_ChronoData<_CharT> __cd{};
2670 auto __parts = _M_f._M_spec._M_needed;
2671 __parts = __cd._M_fill_year_month(__t, __parts);
2672 __parts = __cd._M_fill_day(__t.day(), __parts);
2674 return _M_f._M_format(__cd, __fc);
2676 __cd._M_fill_ldays(chrono::local_days(__t), __parts);
2677 return _M_f._M_format(__cd, __fc);
2681 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2683 using __format::_ChronoFormats;
2684 using enum __format::_ChronoParts;
2686 __format::_ChronoSpec<_CharT> __res{};
2687 __res._M_debug =
true;
2688 __res._M_needed = _YearMonthDay;
2689 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_f();
2693 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2696 template<__format::__
char _CharT>
2697 struct formatter<
chrono::year_month_day_last, _CharT>
2699 constexpr typename basic_format_parse_context<_CharT>::iterator
2700 parse(basic_format_parse_context<_CharT>& __pc)
2702 using enum __format::_ChronoParts;
2703 return _M_f._M_parse(__pc, _Date, __defSpec);
2706 template<
typename _Out>
2707 typename basic_format_context<_Out, _CharT>::iterator
2708 format(
const chrono::year_month_day_last& __t,
2709 basic_format_context<_Out, _CharT>& __fc)
const
2711 using enum __format::_ChronoParts;
2713 __format::_ChronoData<_CharT> __cd{};
2714 auto __parts = _M_f._M_spec._M_needed;
2715 __parts = __cd._M_fill_year_month(__t, __parts);
2716 if (_M_f._M_spec._M_needs(_Day|_WeekdayIndex))
2717 __parts = __cd._M_fill_day(__t.day(), __parts);
2719 return _M_f._M_format(__cd, __fc);
2721 __cd._M_fill_ldays(chrono::local_days(__t), __parts);
2722 return _M_f._M_format(__cd, __fc);
2726 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2728 using __format::_ChronoFormats;
2729 using enum __format::_ChronoParts;
2731 __format::_ChronoSpec<_CharT> __res{};
2732 __res._M_debug =
true;
2733 __res._M_localized =
true;
2734 __res._M_locale_specific =
true;
2735 __res._M_needed = _Year|_Month;
2736 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_yml();
2740 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2743 template<__format::__
char _CharT>
2744 struct formatter<
chrono::year_month_weekday, _CharT>
2746 constexpr typename basic_format_parse_context<_CharT>::iterator
2747 parse(basic_format_parse_context<_CharT>& __pc)
2749 using enum __format::_ChronoParts;
2750 return _M_f._M_parse(__pc, _Date, __defSpec);
2753 template<
typename _Out>
2754 typename basic_format_context<_Out, _CharT>::iterator
2755 format(
const chrono::year_month_weekday& __t,
2756 basic_format_context<_Out, _CharT>& __fc)
const
2758 __format::_ChronoData<_CharT> __cd{};
2759 auto __parts = _M_f._M_spec._M_needed;
2760 __parts = __cd._M_fill_year_month(__t, __parts);
2761 __parts = __cd._M_fill_weekday(__t.weekday_indexed(), __parts);
2762 if (__t.index() == 0) [[unlikely]]
2765 __parts -= __format::_ChronoParts::_Day;
2767 return _M_f._M_format(__cd, __fc);
2769 chrono::local_days __ld(__t);
2770 __parts = __cd._M_fill_ldays(__ld, __parts);
2772 return _M_f._M_format(__cd, __fc);
2774 auto __dom = __ld - chrono::local_days(__t.year()/__t.month()/0);
2776 __cd._M_day = chrono::day(__dom.count());
2777 return _M_f._M_format(__cd, __fc);
2781 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2783 using __format::_ChronoFormats;
2784 using enum __format::_ChronoParts;
2786 __format::_ChronoSpec<_CharT> __res{};
2787 __res._M_debug =
true;
2788 __res._M_localized =
true;
2789 __res._M_locale_specific =
true;
2790 __res._M_needed = _Year|_Month|_IndexedWeekday;
2791 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ymwi();
2795 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2798 template<__format::__
char _CharT>
2799 struct formatter<
chrono::year_month_weekday_last, _CharT>
2801 constexpr typename basic_format_parse_context<_CharT>::iterator
2802 parse(basic_format_parse_context<_CharT>& __pc)
2804 using enum __format::_ChronoParts;
2805 return _M_f._M_parse(__pc, _Date, __defSpec);
2808 template<
typename _Out>
2809 typename basic_format_context<_Out, _CharT>::iterator
2810 format(
const chrono::year_month_weekday_last& __t,
2811 basic_format_context<_Out, _CharT>& __fc)
const
2813 __format::_ChronoData<_CharT> __cd{};
2814 auto __parts = _M_f._M_spec._M_needed;
2815 __parts = __cd._M_fill_year_month(__t, __parts);
2816 __cd._M_weekday = __t.weekday_last().weekday();
2817 __parts -= __format::_ChronoParts::_Weekday;
2819 return _M_f._M_format(__cd, __fc);
2821 chrono::local_days __ld(__t);
2822 __parts = __cd._M_fill_ldays(__ld, __parts);
2824 return _M_f._M_format(__cd, __fc);
2826 auto __dom = __ld - chrono::local_days(__t.year()/__t.month()/0);
2827 __cd._M_fill_day(chrono::day(__dom.count()), __parts);
2828 return _M_f._M_format(__cd, __fc);
2832 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2834 using __format::_ChronoFormats;
2835 using enum __format::_ChronoParts;
2837 __format::_ChronoSpec<_CharT> __res{};
2838 __res._M_debug =
true;
2839 __res._M_localized =
true;
2840 __res._M_locale_specific =
true;
2841 __res._M_needed = _Year|_Month|_Weekday;
2842 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ymwl();
2846 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2849 template<
typename _Rep,
typename _Period, __format::__
char _CharT>
2850 struct formatter<
chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>, _CharT>
2852 constexpr typename basic_format_parse_context<_CharT>::iterator
2853 parse(basic_format_parse_context<_CharT>& __pc)
2855 using enum __format::_ChronoParts;
2856 return _M_f.template _M_parse<_Precision>(__pc, _Time, __defSpec);
2859 template<
typename _Out>
2860 typename basic_format_context<_Out, _CharT>::iterator
2861 format(
const chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>& __t,
2862 basic_format_context<_Out, _CharT>& __fc)
const
2864 using enum __format::_ChronoParts;
2866 __format::_ChronoData<_CharT> __cd;
2867 __cd._M_is_neg = __t.is_negative();
2868 __cd._M_hours = __t.hours();
2869 __cd._M_minutes = __t.minutes();
2870 __cd._M_seconds = __t.seconds();
2875 if (_M_f._M_spec._M_needs(_EpochUnits))
2876 __d = __t.to_duration();
2877 if (_M_f._M_spec._M_needs(_TotalSeconds))
2879 = __cd._M_hours + __cd._M_minutes + __cd._M_seconds;
2880 return _M_f._M_format_units(__cd, __d, __t.subseconds(), __fc);
2885 =
typename chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>::precision;
2886 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
2887 __format::__formatter_duration<_CharT>::
2888 template _S_spec_for<_Precision>(__format::_ChronoParts::_Time);
2890 __format::__formatter_duration<_CharT> _M_f{__defSpec};
2893#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2894 template<__format::__
char _CharT>
2895 struct formatter<
chrono::sys_info, _CharT>
2897 constexpr typename basic_format_parse_context<_CharT>::iterator
2898 parse(basic_format_parse_context<_CharT>& __pc)
2899 {
return _M_f.parse(__pc); }
2901 template<
typename _Out>
2902 typename basic_format_context<_Out, _CharT>::iterator
2903 format(
const chrono::sys_info& __i,
2904 basic_format_context<_Out, _CharT>& __fc)
const
2905 {
return _M_f.format(__i, __fc); }
2908 __format::__formatter_chrono_info<_CharT> _M_f;
2911 template<__format::__
char _CharT>
2912 struct formatter<
chrono::local_info, _CharT>
2914 constexpr typename basic_format_parse_context<_CharT>::iterator
2915 parse(basic_format_parse_context<_CharT>& __pc)
2916 {
return _M_f.parse(__pc); }
2918 template<
typename _Out>
2919 typename basic_format_context<_Out, _CharT>::iterator
2920 format(
const chrono::local_info& __i,
2921 basic_format_context<_Out, _CharT>& __fc)
const
2922 {
return _M_f.format(__i, __fc); }
2925 __format::__formatter_chrono_info<_CharT> _M_f;
2929 template<
typename _Duration, __format::__
char _CharT>
2930 struct formatter<
chrono::sys_time<_Duration>, _CharT>
2932 constexpr typename basic_format_parse_context<_CharT>::iterator
2933 parse(basic_format_parse_context<_CharT>& __pc)
2935 using enum __format::_ChronoParts;
2937 = _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
2938 if constexpr (__defSpec._M_chrono_specs.empty())
2939 if (_M_f._M_spec._M_chrono_specs.empty())
2940 __format::__invalid_chrono_spec();
2944 template<
typename _Out>
2945 typename basic_format_context<_Out, _CharT>::iterator
2946 format(
const chrono::sys_time<_Duration>& __t,
2947 basic_format_context<_Out, _CharT>& __fc)
const
2949 __format::_ChronoData<_CharT> __cd{};
2950 __cd._M_fill_utc_zone();
2952 _Duration __ed = __t.time_since_epoch();
2953 __cd._M_eseconds = chrono::floor<chrono::seconds>(__ed);
2954 __cd._M_lseconds = chrono::local_seconds(__cd._M_eseconds);
2955 return _M_f._M_format_time_point(__cd, __ed, __fc);
2959 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
2960 __format::__formatter_duration<_CharT>::template _S_spec_for_tp<_Duration>();
2962 __format::__formatter_duration<_CharT> _M_f{__defSpec};
2965 template<
typename _Duration, __format::__
char _CharT>
2966 struct formatter<
chrono::utc_time<_Duration>, _CharT>
2968 constexpr typename basic_format_parse_context<_CharT>::iterator
2969 parse(basic_format_parse_context<_CharT>& __pc)
2971 using enum __format::_ChronoParts;
2972 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
2975 template<
typename _Out>
2976 typename basic_format_context<_Out, _CharT>::iterator
2977 format(
const chrono::utc_time<_Duration>& __t,
2978 basic_format_context<_Out, _CharT>& __fc)
const
2980 using __format::_ChronoParts;
2981 using namespace chrono;
2982 __format::_ChronoData<_CharT> __cd{};
2983 __cd._M_fill_utc_zone();
2985 _Duration __ed = __t.time_since_epoch();
2986 __cd._M_eseconds = chrono::floor<seconds>(__ed);
2990 const auto __li = chrono::get_leap_second_info(__t);
2991 __cd._M_lseconds = local_seconds(__cd._M_eseconds - __li.elapsed);
2992 auto __parts = _M_f._M_spec._M_needed - _ChronoParts::_TotalSeconds;
2993 if ((__parts & _ChronoParts::_DateTime) != 0)
2995 __cd._M_fill_date_time(__cd._M_lseconds, __parts);
2996 __cd._M_seconds +=
seconds(__li.is_leap_second);
2998 return _M_f._M_format_units(__cd, __ed, __ed - __cd._M_eseconds, __fc);
3002 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3003 __format::__formatter_duration<_CharT>::
3004 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3006 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3009 template<
typename _Duration, __format::__
char _CharT>
3010 struct formatter<
chrono::tai_time<_Duration>, _CharT>
3012 constexpr typename basic_format_parse_context<_CharT>::iterator
3013 parse(basic_format_parse_context<_CharT>& __pc)
3015 using enum __format::_ChronoParts;
3016 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3019 template<
typename _Out>
3020 typename basic_format_context<_Out, _CharT>::iterator
3021 format(
const chrono::tai_time<_Duration>& __t,
3022 basic_format_context<_Out, _CharT>& __fc)
const
3024 using namespace chrono;
3025 __format::_ChronoData<_CharT> __cd{};
3026 __cd._M_fill_zone(
"TAI", L
"TAI");
3028 _Duration __ed = __t.time_since_epoch();
3029 __cd._M_eseconds = chrono::floor<seconds>(__ed);
3031 constexpr chrono::days __tai_offset = chrono::days(4383);
3032 __cd._M_lseconds = local_seconds(__cd._M_eseconds - __tai_offset);
3033 return _M_f._M_format_time_point(__cd, __ed, __fc);
3037 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3038 __format::__formatter_duration<_CharT>::
3039 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3041 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3044 template<
typename _Duration, __format::__
char _CharT>
3045 struct formatter<
chrono::gps_time<_Duration>, _CharT>
3047 constexpr typename basic_format_parse_context<_CharT>::iterator
3048 parse(basic_format_parse_context<_CharT>& __pc)
3050 using enum __format::_ChronoParts;
3051 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3054 template<
typename _Out>
3055 typename basic_format_context<_Out, _CharT>::iterator
3056 format(
const chrono::gps_time<_Duration>& __t,
3057 basic_format_context<_Out, _CharT>& __fc)
const
3059 using namespace chrono;
3060 __format::_ChronoData<_CharT> __cd{};
3061 __cd._M_fill_zone(
"GPS", L
"GPS");
3063 _Duration __ed = __t.time_since_epoch();
3064 __cd._M_eseconds = chrono::floor<seconds>(__ed);
3066 constexpr chrono::days __gps_offset = chrono::days(3657);
3067 __cd._M_lseconds = local_seconds(__cd._M_eseconds + __gps_offset);
3068 return _M_f._M_format_time_point(__cd, __ed, __fc);
3072 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3073 __format::__formatter_duration<_CharT>::
3074 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3076 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3079 template<
typename _Duration, __format::__
char _CharT>
3080 struct formatter<
chrono::file_time<_Duration>, _CharT>
3082 constexpr typename basic_format_parse_context<_CharT>::iterator
3083 parse(basic_format_parse_context<_CharT>& __pc)
3085 using enum __format::_ChronoParts;
3086 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3089 template<
typename _Out>
3090 typename basic_format_context<_Out, _CharT>::iterator
3091 format(
const chrono::file_time<_Duration>& __t,
3092 basic_format_context<_Out, _CharT>& __fc)
const
3094 using namespace chrono;
3095 __format::_ChronoData<_CharT> __cd{};
3096 __cd._M_fill_utc_zone();
3098 _Duration __ed = __t.time_since_epoch();
3099 __cd._M_eseconds = chrono::floor<seconds>(__ed);
3100 auto __st = chrono::clock_cast<system_clock>(__t);
3102 = local_seconds(chrono::floor<seconds>(__st.time_since_epoch()));
3103 return _M_f._M_format_time_point(__cd, __ed, __fc);
3107 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3108 __format::__formatter_duration<_CharT>::
3109 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3111 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3114 template<
typename _Duration, __format::__
char _CharT>
3115 struct formatter<
chrono::local_time<_Duration>, _CharT>
3117 constexpr typename basic_format_parse_context<_CharT>::iterator
3118 parse(basic_format_parse_context<_CharT>& __pc)
3120 using enum __format::_ChronoParts;
3122 = _M_f.template _M_parse<_Duration>(__pc, _DateTime, __defSpec);
3123 if constexpr (__defSpec._M_chrono_specs.empty())
3124 if (_M_f._M_spec._M_chrono_specs.empty())
3125 __format::__invalid_chrono_spec();
3129 template<
typename _Out>
3130 typename basic_format_context<_Out, _CharT>::iterator
3131 format(
const chrono::local_time<_Duration>& __lt,
3132 basic_format_context<_Out, _CharT>& __fc)
const
3134 __format::_ChronoData<_CharT> __cd{};
3135 _Duration __ed = __lt.time_since_epoch();
3136 __cd._M_lseconds = chrono::floor<chrono::seconds>(__lt);
3137 __cd._M_eseconds = __cd._M_lseconds.time_since_epoch();
3138 return _M_f._M_format_time_point(__cd, __ed, __fc);
3142 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3143 __format::__formatter_duration<_CharT>::template _S_spec_for_tp<_Duration>();
3145 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3148 template<
typename _Duration, __format::__
char _CharT>
3149 struct formatter<
chrono::__detail::__local_time_fmt<_Duration>, _CharT>
3151 constexpr typename basic_format_parse_context<_CharT>::iterator
3152 parse(basic_format_parse_context<_CharT>& __pc)
3154 using enum __format::_ChronoParts;
3155 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3158 template<
typename _Out>
3159 typename basic_format_context<_Out, _CharT>::iterator
3160 format(
const chrono::__detail::__local_time_fmt<_Duration>& __zt,
3161 basic_format_context<_Out, _CharT>& __fc)
const
3163 using enum __format::_ChronoParts;
3164 __format::_ChronoData<_CharT> __cd{};
3166 if (_M_f._M_spec._M_needs(_ZoneOffset))
3168 if (!__zt._M_offset_sec)
3169 std::__throw_format_error(
"format error: no timezone available for %z");
3170 __cd._M_zone_offset = *__zt._M_offset_sec;
3173 basic_string<_CharT> __zone_store;
3174 if (_M_f._M_spec._M_needs(_ZoneAbbrev))
3176 if (!__zt._M_abbrev)
3177 std::__throw_format_error(
"format error: no timezone available for %Z");
3179 __cd._M_zone_cstr = __zt._M_abbrev->data();
3180 if constexpr (is_same_v<_CharT, char>)
3181 __cd._M_zone_abbrev = *__zt._M_abbrev;
3185 __zone_store.resize(__zt._M_abbrev->size());
3186 auto& __ct = use_facet<ctype<_CharT>>(_M_f._M_locale(__fc));
3187 __ct.widen(__zt._M_abbrev->data(),
3188 __zt._M_abbrev->data() + __zt._M_abbrev->size(),
3189 __zone_store.data());
3190 __cd._M_zone_abbrev = __zone_store;
3194 _Duration __ed = __zt._M_time.time_since_epoch();
3195 __cd._M_lseconds = chrono::floor<chrono::seconds>(__zt._M_time);
3196 __cd._M_eseconds = __cd._M_lseconds.time_since_epoch();
3197 return _M_f._M_format_time_point(__cd, __ed, __fc);
3201 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3202 __format::__formatter_duration<_CharT>::
3203 template _S_spec_for<_Duration>(__format::_ChronoParts::_ZonedDateTime);
3205 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3208#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
3209 template<
typename _Duration,
typename _TimeZonePtr, __format::__
char _CharT>
3210 struct formatter<
chrono::zoned_time<_Duration, _TimeZonePtr>, _CharT>
3211 : formatter<chrono::__detail::__local_time_fmt_for<_Duration>, _CharT>
3213 template<
typename _Out>
3214 typename basic_format_context<_Out, _CharT>::iterator
3215 format(
const chrono::zoned_time<_Duration, _TimeZonePtr>& __tp,
3216 basic_format_context<_Out, _CharT>& __fc)
const
3218 using _Ltf = chrono::__detail::__local_time_fmt_for<_Duration>;
3219 using _Base = formatter<_Ltf, _CharT>;
3220 const chrono::sys_info __info = __tp.get_info();
3221 const auto __lf = chrono::local_time_format(__tp.get_local_time(),
3224 return _Base::format(__lf, __fc);
3237 template<
typename _Duration = seconds>
3240 static_assert(is_same_v<common_type_t<_Duration, seconds>, _Duration>);
3243 _Parser(__format::_ChronoParts __need) : _M_need(__need) { }
3245 _Parser(_Parser&&) =
delete;
3246 void operator=(_Parser&&) =
delete;
3248 _Duration _M_time{};
3249 sys_days _M_sys_days{};
3250 year_month_day _M_ymd{};
3252 __format::_ChronoParts _M_need;
3253 unsigned _M_is_leap_second : 1 {};
3254 unsigned _M_reserved : 15 {};
3256 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3257 basic_istream<_CharT, _Traits>&
3258 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3259 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3260 minutes* __offset =
nullptr);
3265 template<
typename _CharT,
typename _Traits>
3266 static int_least32_t
3267 _S_read_unsigned(basic_istream<_CharT, _Traits>& __is,
3268 ios_base::iostate& __err,
int __n)
3270 int_least32_t __val = _S_try_read_digit(__is, __err);
3271 if (__val == -1) [[unlikely]]
3272 __err |= ios_base::failbit;
3277 for (
int __i = 1; __i < __n1; ++__i)
3278 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
3284 while (__n1++ < __n) [[unlikely]]
3285 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
3287 if (__builtin_mul_overflow(__val, 10, &__val)
3288 || __builtin_add_overflow(__val, __dig, &__val))
3290 __err |= ios_base::failbit;
3300 template<
typename _CharT,
typename _Traits>
3301 static int_least32_t
3302 _S_read_signed(basic_istream<_CharT, _Traits>& __is,
3303 ios_base::iostate& __err,
int __n)
3305 auto __sign = __is.peek();
3306 if (__sign ==
'-' || __sign ==
'+')
3308 int_least32_t __val = _S_read_unsigned(__is, __err, __n);
3309 if (__err & ios_base::failbit)
3311 if (__sign ==
'-') [[unlikely]]
3319 template<
typename _CharT,
typename _Traits>
3320 static int_least32_t
3321 _S_try_read_digit(basic_istream<_CharT, _Traits>& __is,
3322 ios_base::iostate& __err)
3324 int_least32_t __val = -1;
3325 auto __i = __is.peek();
3326 if (!_Traits::eq_int_type(__i, _Traits::eof())) [[likely]]
3328 _CharT __c = _Traits::to_char_type(__i);
3329 if (_CharT(
'0') <= __c && __c <= _CharT(
'9')) [[likely]]
3332 __val = __c - _CharT(
'0');
3336 __err |= ios_base::eofbit;
3342 template<
typename _CharT,
typename _Traits>
3344 _S_read_chr(basic_istream<_CharT, _Traits>& __is,
3345 ios_base::iostate& __err, _CharT __c)
3347 auto __i = __is.peek();
3348 if (_Traits::eq_int_type(__i, _Traits::eof()))
3349 __err |= ios_base::eofbit;
3350 else if (_Traits::to_char_type(__i) == __c) [[likely]]
3355 __err |= ios_base::failbit;
3360 template<
typename _Duration>
3361 using _Parser_t = _Parser<common_type_t<_Duration, seconds>>;
3363 template<
typename _Duration>
3367 if constexpr (_Duration::period::den == 1)
3369 switch (_Duration::period::num)
3371 case minutes::period::num:
3372 case hours::period::num:
3373 case days::period::num:
3374 case weeks::period::num:
3375 case years::period::num:
3392 template<
typename _ToDur,
typename _Tp>
3394 __round(
const _Tp& __t)
3396 if constexpr (__is_duration_v<_Tp>)
3398 if constexpr (treat_as_floating_point_v<typename _Tp::rep>)
3400 else if constexpr (__detail::__use_floor<_ToDur>())
3407 static_assert(__is_time_point_v<_Tp>);
3408 using _Tpt = time_point<typename _Tp::clock, _ToDur>;
3409 return _Tpt(__detail::__round<_ToDur>(__t.time_since_epoch()));
3416 template<
typename _CharT,
typename _Traits,
typename _Rep,
typename _Period,
3417 typename _Alloc = allocator<_CharT>>
3418 inline basic_istream<_CharT, _Traits>&
3419 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3421 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3424 auto __need = __format::_ChronoParts::_TimeOfDay;
3425 __detail::_Parser_t<duration<_Rep, _Period>> __p(__need);
3426 if (__p(__is, __fmt, __abbrev, __offset))
3427 __d = __detail::__round<duration<_Rep, _Period>>(__p._M_time);
3431 template<
typename _CharT,
typename _Traits>
3432 inline basic_ostream<_CharT, _Traits>&
3433 operator<<(basic_ostream<_CharT, _Traits>& __os,
const day& __d)
3435 using _Ctx = __format::__format_context<_CharT>;
3436 using _Str = basic_string_view<_CharT>;
3437 _Str __s = _GLIBCXX_WIDEN(
"{:02d} is not a valid day");
3439 __s = __s.substr(0, 6);
3440 auto __u = (unsigned)__d;
3441 __os << std::vformat(__s, make_format_args<_Ctx>(__u));
3445 template<
typename _CharT,
typename _Traits,
3446 typename _Alloc = allocator<_CharT>>
3447 inline basic_istream<_CharT, _Traits>&
3448 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3450 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3453 __detail::_Parser<> __p(__format::_ChronoParts::_Day);
3454 if (__p(__is, __fmt, __abbrev, __offset))
3455 __d = __p._M_ymd.day();
3459 template<
typename _CharT,
typename _Traits>
3460 inline basic_ostream<_CharT, _Traits>&
3461 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month& __m)
3463 using _Ctx = __format::__format_context<_CharT>;
3464 using _Str = basic_string_view<_CharT>;
3465 _Str __s = _GLIBCXX_WIDEN(
"{:L%b}{} is not a valid month");
3467 __os << std::vformat(__os.getloc(), __s.substr(0, 6),
3468 make_format_args<_Ctx>(__m));
3471 auto __u = (unsigned)__m;
3472 __os << std::vformat(__s.substr(6), make_format_args<_Ctx>(__u));
3477 template<
typename _CharT,
typename _Traits,
3478 typename _Alloc = allocator<_CharT>>
3479 inline basic_istream<_CharT, _Traits>&
3480 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3482 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3485 __detail::_Parser<> __p(__format::_ChronoParts::_Month);
3486 if (__p(__is, __fmt, __abbrev, __offset))
3487 __m = __p._M_ymd.month();
3491 template<
typename _CharT,
typename _Traits>
3492 inline basic_ostream<_CharT, _Traits>&
3493 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year& __y)
3495 using _Ctx = __format::__format_context<_CharT>;
3496 using _Str = basic_string_view<_CharT>;
3497 _Str __s = _GLIBCXX_WIDEN(
"-{:04d} is not a valid year");
3499 __s = __s.substr(0, 7);
3501 if (__i >= 0) [[likely]]
3502 __s.remove_prefix(1);
3505 __os << std::vformat(__s, make_format_args<_Ctx>(__i));
3509 template<
typename _CharT,
typename _Traits,
3510 typename _Alloc = allocator<_CharT>>
3511 inline basic_istream<_CharT, _Traits>&
3512 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3514 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3517 __detail::_Parser<> __p(__format::_ChronoParts::_Year);
3518 if (__p(__is, __fmt, __abbrev, __offset))
3519 __y = __p._M_ymd.year();
3523 template<
typename _CharT,
typename _Traits>
3524 inline basic_ostream<_CharT, _Traits>&
3525 operator<<(basic_ostream<_CharT, _Traits>& __os,
const weekday& __wd)
3527 using _Ctx = __format::__format_context<_CharT>;
3528 using _Str = basic_string_view<_CharT>;
3529 _Str __s = _GLIBCXX_WIDEN(
"{:L%a}{} is not a valid weekday");
3531 __os << std::vformat(__os.getloc(), __s.substr(0, 6),
3532 make_format_args<_Ctx>(__wd));
3535 auto __c = __wd.c_encoding();
3536 __os << std::vformat(__s.substr(6), make_format_args<_Ctx>(__c));
3541 template<
typename _CharT,
typename _Traits,
3542 typename _Alloc = allocator<_CharT>>
3543 inline basic_istream<_CharT, _Traits>&
3544 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3546 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3549 __detail::_Parser<> __p(__format::_ChronoParts::_Weekday);
3550 if (__p(__is, __fmt, __abbrev, __offset))
3555 template<
typename _CharT,
typename _Traits>
3556 inline basic_ostream<_CharT, _Traits>&
3557 operator<<(basic_ostream<_CharT, _Traits>& __os,
3558 const weekday_indexed& __wdi)
3563 basic_stringstream<_CharT> __os2;
3564 __os2.imbue(__os.getloc());
3565 __os2 << __wdi.weekday();
3566 const auto __i = __wdi.index();
3567 basic_string_view<_CharT> __s
3568 = _GLIBCXX_WIDEN(
"[ is not a valid index]");
3570 __os2 << std::format(_GLIBCXX_WIDEN(
"{}"), __i);
3571 if (__i >= 1 && __i <= 5)
3572 __os2 << __s.back();
3574 __os2 << __s.substr(1);
3575 __os << __os2.view();
3579 template<
typename _CharT,
typename _Traits>
3580 inline basic_ostream<_CharT, _Traits>&
3581 operator<<(basic_ostream<_CharT, _Traits>& __os,
3582 const weekday_last& __wdl)
3585 basic_stringstream<_CharT> __os2;
3586 __os2.imbue(__os.getloc());
3587 __os2 << __wdl.weekday() << _GLIBCXX_WIDEN(
"[last]");
3588 __os << __os2.view();
3592 template<
typename _CharT,
typename _Traits>
3593 inline basic_ostream<_CharT, _Traits>&
3594 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month_day& __md)
3597 basic_stringstream<_CharT> __os2;
3598 __os2.imbue(__os.getloc());
3599 __os2 << __md.month();
3600 if constexpr (is_same_v<_CharT, char>)
3604 __os2 << __md.day();
3605 __os << __os2.view();
3609 template<
typename _CharT,
typename _Traits,
3610 typename _Alloc = allocator<_CharT>>
3611 inline basic_istream<_CharT, _Traits>&
3612 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3614 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3617 using __format::_ChronoParts;
3618 auto __need = _ChronoParts::_Month | _ChronoParts::_Day;
3619 __detail::_Parser<> __p(__need);
3620 if (__p(__is, __fmt, __abbrev, __offset))
3621 __md = month_day(__p._M_ymd.month(), __p._M_ymd.day());
3625 template<
typename _CharT,
typename _Traits>
3626 inline basic_ostream<_CharT, _Traits>&
3627 operator<<(basic_ostream<_CharT, _Traits>& __os,
3628 const month_day_last& __mdl)
3631 basic_stringstream<_CharT> __os2;
3632 __os2.imbue(__os.getloc());
3633 __os2 << __mdl.month() << _GLIBCXX_WIDEN(
"/last");
3634 __os << __os2.view();
3638 template<
typename _CharT,
typename _Traits>
3639 inline basic_ostream<_CharT, _Traits>&
3640 operator<<(basic_ostream<_CharT, _Traits>& __os,
3641 const month_weekday& __mwd)
3644 basic_stringstream<_CharT> __os2;
3645 __os2.imbue(__os.getloc());
3646 __os2 << __mwd.month();
3647 if constexpr (is_same_v<_CharT, char>)
3651 __os2 << __mwd.weekday_indexed();
3652 __os << __os2.view();
3656 template<
typename _CharT,
typename _Traits>
3657 inline basic_ostream<_CharT, _Traits>&
3658 operator<<(basic_ostream<_CharT, _Traits>& __os,
3659 const month_weekday_last& __mwdl)
3662 basic_stringstream<_CharT> __os2;
3663 __os2.imbue(__os.getloc());
3664 __os2 << __mwdl.month();
3665 if constexpr (is_same_v<_CharT, char>)
3669 __os2 << __mwdl.weekday_last();
3670 __os << __os2.view();
3674 template<
typename _CharT,
typename _Traits>
3675 inline basic_ostream<_CharT, _Traits>&
3676 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year_month& __ym)
3679 basic_stringstream<_CharT> __os2;
3680 __os2.imbue(__os.getloc());
3681 __os2 << __ym.year();
3682 if constexpr (is_same_v<_CharT, char>)
3686 __os2 << __ym.month();
3687 __os << __os2.view();
3691 template<
typename _CharT,
typename _Traits,
3692 typename _Alloc = allocator<_CharT>>
3693 inline basic_istream<_CharT, _Traits>&
3694 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3696 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3699 using __format::_ChronoParts;
3700 auto __need = _ChronoParts::_Year | _ChronoParts::_Month;
3701 __detail::_Parser<> __p(__need);
3702 if (__p(__is, __fmt, __abbrev, __offset))
3703 __ym = year_month(__p._M_ymd.year(), __p._M_ymd.month());
3707 template<
typename _CharT,
typename _Traits>
3708 inline basic_ostream<_CharT, _Traits>&
3709 operator<<(basic_ostream<_CharT, _Traits>& __os,
3710 const year_month_day& __ymd)
3712 using _Ctx = __format::__format_context<_CharT>;
3713 using _Str = basic_string_view<_CharT>;
3714 _Str __s = _GLIBCXX_WIDEN(
"{:%F} is not a valid date");
3715 __os << std::vformat(__ymd.ok() ? __s.substr(0, 5) : __s,
3716 make_format_args<_Ctx>(__ymd));
3720 template<
typename _CharT,
typename _Traits,
3721 typename _Alloc = allocator<_CharT>>
3722 inline basic_istream<_CharT, _Traits>&
3724 year_month_day& __ymd,
3728 using __format::_ChronoParts;
3729 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3730 | _ChronoParts::_Day;
3731 __detail::_Parser<> __p(__need);
3732 if (__p(__is, __fmt, __abbrev, __offset))
3737 template<
typename _CharT,
typename _Traits>
3740 const year_month_day_last& __ymdl)
3745 __os2 << __ymdl.year();
3746 if constexpr (is_same_v<_CharT, char>)
3750 __os2 << __ymdl.month_day_last();
3751 __os << __os2.view();
3755 template<
typename _CharT,
typename _Traits>
3756 inline basic_ostream<_CharT, _Traits>&
3757 operator<<(basic_ostream<_CharT, _Traits>& __os,
3758 const year_month_weekday& __ymwd)
3762 basic_stringstream<_CharT> __os2;
3763 __os2.
imbue(__os.getloc());
3765 if constexpr (is_same_v<_CharT, char>)
3769 __os2 << __ymwd.year() << __slash << __ymwd.month() << __slash
3770 << __ymwd.weekday_indexed();
3771 __os << __os2.view();
3775 template<
typename _CharT,
typename _Traits>
3776 inline basic_ostream<_CharT, _Traits>&
3777 operator<<(basic_ostream<_CharT, _Traits>& __os,
3778 const year_month_weekday_last& __ymwdl)
3782 basic_stringstream<_CharT> __os2;
3783 __os2.imbue(__os.getloc());
3785 if constexpr (is_same_v<_CharT, char>)
3789 __os2 << __ymwdl.year() << __slash << __ymwdl.month() << __slash
3790 << __ymwdl.weekday_last();
3791 __os << __os2.view();
3795 template<
typename _CharT,
typename _Traits,
typename _Duration>
3796 inline basic_ostream<_CharT, _Traits>&
3797 operator<<(basic_ostream<_CharT, _Traits>& __os,
3800 return __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%T}"), __hms);
3803#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
3805 template<
typename _CharT,
typename _Traits>
3806 basic_ostream<_CharT, _Traits>&
3807 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_info& __i)
3809 return __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{}"), __i);
3813 template<
typename _CharT,
typename _Traits>
3814 basic_ostream<_CharT, _Traits>&
3815 operator<<(basic_ostream<_CharT, _Traits>& __os,
const local_info& __li)
3817 __os << __format::_Separators<_CharT>::_S_squares()[0];
3818 if (__li.result == local_info::unique)
3822 if (__li.result == local_info::nonexistent)
3823 __os << _GLIBCXX_WIDEN(
"nonexistent");
3825 __os << _GLIBCXX_WIDEN(
"ambiguous");
3826 __os << _GLIBCXX_WIDEN(
" local time between ") << __li.first;
3827 __os << _GLIBCXX_WIDEN(
" and ") << __li.second;
3829 __os << __format::_Separators<_CharT>::_S_squares()[1];
3833 template<
typename _CharT,
typename _Traits,
typename _Duration,
3834 typename _TimeZonePtr>
3835 inline basic_ostream<_CharT, _Traits>&
3836 operator<<(basic_ostream<_CharT, _Traits>& __os,
3837 const zoned_time<_Duration, _TimeZonePtr>& __t)
3839 __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T %Z}"), __t);
3844 template<
typename _CharT,
typename _Traits,
typename _Duration>
3845 requires (!treat_as_floating_point_v<typename _Duration::rep>)
3846 && ratio_less_v<typename _Duration::period, days::period>
3847 inline basic_ostream<_CharT, _Traits>&
3848 operator<<(basic_ostream<_CharT, _Traits>& __os,
3849 const sys_time<_Duration>& __tp)
3851 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __tp);
3855 template<
typename _CharT,
typename _Traits>
3856 inline basic_ostream<_CharT, _Traits>&
3857 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_days& __dp)
3859 __os << year_month_day{__dp};
3863 template<
typename _CharT,
typename _Traits,
typename _Duration,
3864 typename _Alloc = allocator<_CharT>>
3865 basic_istream<_CharT, _Traits>&
3866 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3867 sys_time<_Duration>& __tp,
3868 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3874 using __format::_ChronoParts;
3875 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3876 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
3877 __detail::_Parser_t<_Duration> __p(__need);
3878 if (__p(__is, __fmt, __abbrev, __offset))
3880 if (__p._M_is_leap_second)
3884 auto __st = __p._M_sys_days + __p._M_time - *__offset;
3885 __tp = __detail::__round<_Duration>(__st);
3891 template<
typename _CharT,
typename _Traits,
typename _Duration>
3892 inline basic_ostream<_CharT, _Traits>&
3893 operator<<(basic_ostream<_CharT, _Traits>& __os,
3894 const utc_time<_Duration>& __t)
3896 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
3900 template<
typename _CharT,
typename _Traits,
typename _Duration,
3901 typename _Alloc = allocator<_CharT>>
3902 inline basic_istream<_CharT, _Traits>&
3903 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3904 utc_time<_Duration>& __tp,
3905 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3911 using __format::_ChronoParts;
3912 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3913 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
3914 __detail::_Parser_t<_Duration> __p(__need);
3915 if (__p(__is, __fmt, __abbrev, __offset))
3919 auto __ut = utc_clock::from_sys(__p._M_sys_days) + __p._M_time
3921 __tp = __detail::__round<_Duration>(__ut);
3926 template<
typename _CharT,
typename _Traits,
typename _Duration>
3927 inline basic_ostream<_CharT, _Traits>&
3928 operator<<(basic_ostream<_CharT, _Traits>& __os,
3929 const tai_time<_Duration>& __t)
3931 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
3935 template<
typename _CharT,
typename _Traits,
typename _Duration,
3936 typename _Alloc = allocator<_CharT>>
3937 inline basic_istream<_CharT, _Traits>&
3938 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3939 tai_time<_Duration>& __tp,
3940 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3946 using __format::_ChronoParts;
3947 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3948 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
3949 __detail::_Parser_t<_Duration> __p(__need);
3950 if (__p(__is, __fmt, __abbrev, __offset))
3952 if (__p._M_is_leap_second)
3956 constexpr sys_days __epoch(-
days(4383));
3957 auto __d = __p._M_sys_days - __epoch + __p._M_time - *__offset;
3958 tai_time<common_type_t<_Duration, seconds>> __tt(__d);
3959 __tp = __detail::__round<_Duration>(__tt);
3965 template<
typename _CharT,
typename _Traits,
typename _Duration>
3966 inline basic_ostream<_CharT, _Traits>&
3967 operator<<(basic_ostream<_CharT, _Traits>& __os,
3968 const gps_time<_Duration>& __t)
3970 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
3974 template<
typename _CharT,
typename _Traits,
typename _Duration,
3975 typename _Alloc = allocator<_CharT>>
3976 inline basic_istream<_CharT, _Traits>&
3977 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3978 gps_time<_Duration>& __tp,
3979 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3985 using __format::_ChronoParts;
3986 auto __need = _ChronoParts::_YearMonthDay | _ChronoParts::_TimeOfDay;
3987 __detail::_Parser_t<_Duration> __p(__need);
3988 if (__p(__is, __fmt, __abbrev, __offset))
3990 if (__p._M_is_leap_second)
3994 constexpr sys_days __epoch(
days(3657));
3995 auto __d = __p._M_sys_days - __epoch + __p._M_time - *__offset;
3996 gps_time<common_type_t<_Duration, seconds>> __gt(__d);
3997 __tp = __detail::__round<_Duration>(__gt);
4003 template<
typename _CharT,
typename _Traits,
typename _Duration>
4004 inline basic_ostream<_CharT, _Traits>&
4005 operator<<(basic_ostream<_CharT, _Traits>& __os,
4006 const file_time<_Duration>& __t)
4008 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
4012 template<
typename _CharT,
typename _Traits,
typename _Duration,
4013 typename _Alloc = allocator<_CharT>>
4014 inline basic_istream<_CharT, _Traits>&
4015 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4016 file_time<_Duration>& __tp,
4017 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4020 sys_time<_Duration> __st;
4021 if (chrono::from_stream(__is, __fmt, __st, __abbrev, __offset))
4022 __tp = __detail::__round<_Duration>(file_clock::from_sys(__st));
4026 template<
typename _CharT,
typename _Traits,
typename _Duration>
4027 inline basic_ostream<_CharT, _Traits>&
4028 operator<<(basic_ostream<_CharT, _Traits>& __os,
4029 const local_time<_Duration>& __lt)
4032 requires requires(
const sys_time<_Duration>& __st) { __os << __st; }
4034 __os << sys_time<_Duration>{__lt.time_since_epoch()};
4038 template<
typename _CharT,
typename _Traits,
typename _Duration,
4039 typename _Alloc = allocator<_CharT>>
4040 basic_istream<_CharT, _Traits>&
4041 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4042 local_time<_Duration>& __tp,
4043 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4046 using __format::_ChronoParts;
4047 auto __need = _ChronoParts::_YearMonthDay | _ChronoParts::_TimeOfDay;
4048 __detail::_Parser_t<_Duration> __p(__need);
4049 if (__p(__is, __fmt, __abbrev, __offset))
4051 days __d = __p._M_sys_days.time_since_epoch();
4052 auto __t = local_days(__d) + __p._M_time;
4053 __tp = __detail::__round<_Duration>(__t);
4064 void from_stream() =
delete;
4066 template<
typename _Parsable,
typename _CharT,
4067 typename _Traits = std::char_traits<_CharT>,
4068 typename... _OptArgs>
4069 concept __parsable =
requires (basic_istream<_CharT, _Traits>& __is,
4070 const _CharT* __fmt, _Parsable& __tp,
4071 _OptArgs*... __args)
4072 { from_stream(__is, __fmt, __tp, __args...); };
4074 template<
typename _Parsable,
typename _CharT,
4075 typename _Traits = char_traits<_CharT>,
4076 typename _Alloc = allocator<_CharT>>
4080 using __string_type = basic_string<_CharT, _Traits, _Alloc>;
4083 _Parse(
const _CharT* __fmt, _Parsable& __tp,
4084 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4087 _M_abbrev(__abbrev), _M_offset(__offset)
4090 _Parse(_Parse&&) =
delete;
4091 _Parse& operator=(_Parse&&) =
delete;
4094 using __stream_type = basic_istream<_CharT, _Traits>;
4096 const _CharT*
const _M_fmt;
4097 _Parsable*
const _M_tp;
4098 __string_type*
const _M_abbrev;
4101 friend __stream_type&
4102 operator>>(__stream_type& __is, _Parse&& __p)
4105 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev,
4107 else if (__p._M_abbrev)
4108 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev);
4110 from_stream(__is, __p._M_fmt, *__p._M_tp);
4114 friend void operator>>(__stream_type&, _Parse&) =
delete;
4115 friend void operator>>(__stream_type&,
const _Parse&) =
delete;
4119 template<
typename _CharT, __detail::__parsable<_CharT> _Parsable>
4120 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4122 parse(
const _CharT* __fmt, _Parsable& __tp)
4123 {
return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp); }
4125 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4126 __detail::__parsable<_CharT, _Traits> _Parsable>
4129 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp)
4131 return __detail::_Parse<_Parsable, _CharT, _Traits>(__fmt.c_str(), __tp);
4134 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4135 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4136 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
4137 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4139 parse(
const _CharT* __fmt, _Parsable& __tp,
4140 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
4143 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
4147 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4148 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4149 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
4152 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
4153 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
4156 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
4160 template<
typename _CharT,
typename _Traits =
char_traits<_CharT>,
4161 typename _StrT = basic_
string<_CharT, _Traits>,
4162 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4163 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4165 parse(
const _CharT* __fmt, _Parsable& __tp,
minutes& __offset)
4167 return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp,
nullptr,
4171 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4172 typename _StrT = basic_string<_CharT, _Traits>,
4173 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4176 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
4179 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
4184 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4185 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4186 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4187 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4189 parse(
const _CharT* __fmt, _Parsable& __tp,
4190 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
4193 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
4198 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4199 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4200 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4203 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
4204 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
4207 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
4213 template<
typename _Duration>
4214 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4215 basic_istream<_CharT, _Traits>&
4216 __detail::_Parser<_Duration>::
4217 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4218 basic_string<_CharT, _Traits, _Alloc>* __abbrev,
4221 using sentry =
typename basic_istream<_CharT, _Traits>::sentry;
4223 if (sentry __cerb(__is,
true); __cerb)
4225 locale __loc = __is.getloc();
4230 struct _Stream_state
4233 _Stream_state(basic_istream<_CharT, _Traits>& __i)
4235 _M_flags(__i.flags(ios_base::
skipws | ios_base::
dec)),
4241 _M_is.flags(_M_flags);
4245 _Stream_state(_Stream_state&&) =
delete;
4247 basic_istream<_CharT, _Traits>& _M_is;
4248 ios_base::fmtflags _M_flags;
4258 auto __read_unsigned = [&] (
int __n) {
4259 return _S_read_unsigned(__is, __err, __n);
4264 auto __read_signed = [&] (
int __n) {
4265 return _S_read_signed(__is, __err, __n);
4269 auto __read_chr = [&__is, &__err] (_CharT __c) {
4270 return _S_read_chr(__is, __err, __c);
4273 using __format::_ChronoParts;
4274 _ChronoParts __parts{};
4276 const year __bad_y = --year::min();
4277 const month __bad_mon(255);
4278 const day __bad_day(255);
4279 const weekday __bad_wday(255);
4280 const hours __bad_h(-1);
4281 const minutes __bad_min(-9999);
4284 year __y = __bad_y, __yy = __bad_y;
4285 year __iso_y = __bad_y, __iso_yy = __bad_y;
4286 month __m = __bad_mon;
4287 day __d = __bad_day;
4288 weekday __wday = __bad_wday;
4289 hours __h = __bad_h, __h12 = __bad_h;
4291 _Duration __s = __bad_sec;
4293 int __iso_wk = -1, __sunday_wk = -1, __monday_wk = -1;
4295 int __dayofyear = -1;
4297 minutes __tz_offset = __bad_min;
4298 basic_string<_CharT, _Traits> __tz_abbr;
4300 if ((_M_need & _ChronoParts::_TimeOfDay) != 0
4301 && (_M_need & _ChronoParts::_Year) != 0)
4307 __parts = _ChronoParts::_TimeOfDay;
4314 bool __is_flag =
false;
4316 constexpr bool __is_floating
4317 = treat_as_floating_point_v<typename _Duration::rep>;
4336 _CharT __c = *__fmt++;
4343 else if (!__read_chr(__c)) [[unlikely]]
4354 if (__mod || __num) [[unlikely]]
4359 __tmget.get(__is, {}, __is, __err, &__tm,
4361 if (!__is_failed(__err))
4362 __wday = weekday(__tm.tm_wday);
4364 __parts |= _ChronoParts::_Weekday;
4370 if (__mod || __num) [[unlikely]]
4378 __tmget.get(__is, {}, __is, __err, &__tm,
4380 if (!__is_failed(__err))
4381 __m = month(__tm.tm_mon + 1);
4383 __parts |= _ChronoParts::_Month;
4387 if (__mod ==
'O' || __num) [[unlikely]]
4392 __tmget.get(__is, {}, __is, __err, &__tm,
4393 __fmt - 2 - (__mod ==
'E'), __fmt);
4394 if (!__is_failed(__err))
4396 __y = year(__tm.tm_year + 1900);
4397 __m = month(__tm.tm_mon + 1);
4398 __d = day(__tm.tm_mday);
4399 __h =
hours(__tm.tm_hour);
4404 __parts |= _ChronoParts::_DateTime;
4408 if (!__mod) [[likely]]
4410 auto __v = __read_signed(__num ? __num : 2);
4411 if (!__is_failed(__err))
4413 int __cmin = (int)year::min() / 100;
4414 int __cmax = (int)year::max() / 100;
4415 if (__cmin <= __v && __v <= __cmax)
4416 __century = __v * 100;
4421 else if (__mod ==
'E')
4424 __tmget.get(__is, {}, __is, __err, &__tm,
4426 if (!__is_failed(__err))
4427 __century = __tm.tm_year;
4436 if (!__mod) [[likely]]
4438 auto __v = __read_unsigned(__num ? __num : 2);
4439 if (!__is_failed(__err))
4442 else if (__mod ==
'O')
4445 __tmget.get(__is, {}, __is, __err, &__tm,
4447 if (!__is_failed(__err))
4448 __d = day(__tm.tm_mday);
4452 __parts |= _ChronoParts::_Day;
4456 if (__mod || __num) [[unlikely]]
4460 auto __month = __read_unsigned(2);
4462 auto __day = __read_unsigned(2);
4464 auto __year = __read_unsigned(2);
4465 if (__is_failed(__err))
4467 __y = year(__year + 1900 + 100 *
int(__year < 69));
4468 __m = month(__month);
4470 if (!year_month_day(__y, __m, __d).ok())
4472 __y = __yy = __iso_y = __iso_yy = __bad_y;
4478 __parts |= _ChronoParts::_Date;
4482 if (__mod) [[unlikely]]
4486 auto __year = __read_signed(__num ? __num : 4);
4488 auto __month = __read_unsigned(2);
4490 auto __day = __read_unsigned(2);
4491 if (__is_failed(__err))
4494 __m = month(__month);
4496 if (!year_month_day(__y, __m, __d).ok())
4498 __y = __yy = __iso_y = __iso_yy = __bad_y;
4504 __parts |= _ChronoParts::_Date;
4508 if (__mod) [[unlikely]]
4512 auto __val = __read_unsigned(__num ? __num : 2);
4513 if (__val >= 0 && __val <= 99)
4515 __iso_yy = year(__val);
4516 if (__century == -1)
4520 __iso_yy = __iso_y = __y = __yy = __bad_y;
4522 __parts |= _ChronoParts::_Year;
4526 if (__mod) [[unlikely]]
4529 __iso_y = year(__read_unsigned(__num ? __num : 4));
4530 __parts |= _ChronoParts::_Year;
4535 if (__mod ==
'E') [[unlikely]]
4537 else if (__mod ==
'O')
4542 __tmget.get(__is, {}, __is, __err, &__tm,
4544 if (!__is_failed(__err))
4548 __h12 =
hours(__tm.tm_hour);
4552 __h =
hours(__tm.tm_hour);
4561 auto __val = __read_unsigned(__num ? __num : 2);
4562 if (__c ==
'I' && __val >= 1 && __val <= 12)
4564 __h12 =
hours(__val);
4567 else if (__c ==
'H' && __val >= 0 && __val <= 23)
4574 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4579 __parts |= _ChronoParts::_TimeOfDay;
4583 if (__mod) [[unlikely]]
4585 else if (_M_need == _ChronoParts::_TimeOfDay)
4587 auto __val = __read_signed(__num ? __num : 3);
4588 if (!__is_failed(__err))
4591 __parts |= _ChronoParts::_TimeOfDay;
4596 __dayofyear = __read_unsigned(__num ? __num : 3);
4603 if (__mod ==
'E') [[unlikely]]
4605 else if (__mod ==
'O')
4608 __tmget.get(__is, {}, __is, __err, &__tm,
4610 if (!__is_failed(__err))
4611 __m = month(__tm.tm_mon + 1);
4615 auto __val = __read_unsigned(__num ? __num : 2);
4616 if (__val >= 1 && __val <= 12)
4621 __parts |= _ChronoParts::_Month;
4625 if (__mod ==
'E') [[unlikely]]
4627 else if (__mod ==
'O')
4630 __tmget.get(__is, {}, __is, __err, &__tm,
4632 if (!__is_failed(__err))
4637 auto __val = __read_unsigned(__num ? __num : 2);
4638 if (0 <= __val && __val < 60)
4642 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4647 __parts |= _ChronoParts::_TimeOfDay;
4657 const _CharT* __ampms[2];
4658 __tmpunct._M_am_pm(__ampms);
4659 int __n = 0, __which = 3;
4660 while (__which != 0)
4662 auto __i = __is.peek();
4663 if (_Traits::eq_int_type(__i, _Traits::eof()))
4673 else if (__ampms[0][__n + 1] == _CharT())
4684 else if (__ampms[1][__n + 1] == _CharT())
4695 if (__which == 0 || __which == 3)
4708 __tmget.get(__is, {}, __is, __err, &__tm,
4710 if (!__is_failed(__err))
4712 __h =
hours(__tm.tm_hour);
4717 __parts |= _ChronoParts::_TimeOfDay;
4722 if (__mod || __num) [[unlikely]]
4729 auto __val = __read_unsigned(2);
4730 if (__val == -1 || __val > 23) [[unlikely]]
4732 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4736 if (!__read_chr(
':')) [[unlikely]]
4740 __val = __read_unsigned(2);
4741 if (__val == -1 || __val > 60) [[unlikely]]
4743 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4751 __parts |= _ChronoParts::_TimeOfDay;
4754 else if (!__read_chr(
':')) [[unlikely]]
4760 if (__mod ==
'E') [[unlikely]]
4762 else if (__mod ==
'O')
4765 __tmget.get(__is, {}, __is, __err, &__tm,
4767 if (!__is_failed(__err))
4770 else if constexpr (_Duration::period::den == 1
4773 auto __val = __read_unsigned(__num ? __num : 2);
4774 if (0 <= __val && __val <= 59) [[likely]]
4778 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4785 basic_stringstream<_CharT> __buf;
4786 auto __digit = _S_try_read_digit(__is, __err);
4789 __buf.put(_CharT(
'0') + __digit);
4790 __digit = _S_try_read_digit(__is, __err);
4792 __buf.put(_CharT(
'0') + __digit);
4795 auto __i = __is.peek();
4796 if (_Traits::eq_int_type(__i, _Traits::eof()))
4804 __dp = __np.decimal_point();
4806 _CharT __c = _Traits::to_char_type(__i);
4812 = hh_mm_ss<_Duration>::fractional_width;
4815 __digit = _S_try_read_digit(__is, __err);
4817 __buf.put(_CharT(
'0') + __digit);
4825 if (!__is_failed(__err)) [[likely]]
4827 long double __val{};
4828#if __cpp_lib_to_chars
4830 auto __first = __str.data();
4831 auto __last = __first + __str.size();
4835 if ((
bool)ec || ptr != __last) [[unlikely]]
4843 if constexpr (__is_floating)
4850 __parts |= _ChronoParts::_TimeOfDay;
4855 if (__mod ==
'E') [[unlikely]]
4857 else if (__mod ==
'O')
4862 __tmget.get(__is, {}, __is, __err, &__tm,
4864 if (!__is_failed(__err))
4865 __wday = weekday(__tm.tm_wday);
4872 const int __lo = __c ==
'u' ? 1 : 0;
4873 const int __hi = __lo + 6;
4874 auto __val = __read_unsigned(__num ? __num : 1);
4875 if (__lo <= __val && __val <= __hi)
4876 __wday = weekday(__val);
4879 __wday = __bad_wday;
4883 __parts |= _ChronoParts::_Weekday;
4889 if (__mod ==
'E') [[unlikely]]
4891 else if (__mod ==
'O')
4893 if (__c ==
'V') [[unlikely]]
4903 const int __lo = __c ==
'V' ? 1 : 0;
4904 const int __hi = 53;
4905 auto __val = __read_unsigned(__num ? __num : 2);
4906 if (__lo <= __val && __val <= __hi)
4911 __sunday_wk = __val;
4917 __monday_wk = __val;
4922 __iso_wk = __sunday_wk = __monday_wk = -1;
4928 if (__mod ==
'O' || __num) [[unlikely]]
4933 __tmget.get(__is, {}, __is, __err, &__tm,
4934 __fmt - 2 - (__mod ==
'E'), __fmt);
4935 if (!__is_failed(__err))
4937 __y = year(__tm.tm_year + 1900);
4938 __m = month(__tm.tm_mon + 1);
4939 __d = day(__tm.tm_mday);
4942 __parts |= _ChronoParts::_Date;
4946 if (__mod ==
'O' || __num) [[unlikely]]
4951 __tmget.get(__is, {}, __is, __err, &__tm,
4952 __fmt - 2 - (__mod ==
'E'), __fmt);
4953 if (!__is_failed(__err))
4955 __h =
hours(__tm.tm_hour);
4960 __parts |= _ChronoParts::_TimeOfDay;
4964 if (__mod) [[unlikely]]
4967 __tmget.get(__is, {}, __is, __err, &__tm,
4969 if (!__is_failed(__err))
4971 int __cent = __tm.tm_year < 2000 ? 1900 : 2000;
4972 __yy = year(__tm.tm_year - __cent);
4973 if (__century == -1)
4979 auto __val = __read_unsigned(__num ? __num : 2);
4980 if (__val >= 0 && __val <= 99)
4983 if (__century == -1)
4984 __century = __val < 69 ? 2000 : 1900;
4987 __y = __yy = __iso_yy = __iso_y = __bad_y;
4989 __parts |= _ChronoParts::_Year;
4993 if (__mod ==
'O') [[unlikely]]
4995 else if (__mod ==
'E')
4998 __tmget.get(__is, {}, __is, __err, &__tm,
5000 if (!__is_failed(__err))
5001 __y = year(__tm.tm_year);
5005 auto __val = __read_unsigned(__num ? __num : 4);
5006 if (!__is_failed(__err))
5009 __parts |= _ChronoParts::_Year;
5013 if (__num) [[unlikely]]
5020 auto __i = __is.peek();
5021 if (_Traits::eq_int_type(__i, _Traits::eof()))
5026 _CharT __ic = _Traits::to_char_type(__i);
5027 const bool __neg = __ic == _CharT(
'-');
5028 if (__ic == _CharT(
'-') || __ic == _CharT(
'+'))
5035 __hh = __read_unsigned(2);
5040 __hh = 10 * _S_try_read_digit(__is, __err);
5041 __hh += _S_try_read_digit(__is, __err);
5044 if (__is_failed(__err))
5048 if (_Traits::eq_int_type(__i, _Traits::eof()))
5051 __tz_offset =
minutes(__hh * (__neg ? -60 : 60));
5054 __ic = _Traits::to_char_type(__i);
5056 bool __read_mm =
false;
5059 if (__ic == _GLIBCXX_WIDEN(
":")[0])
5066 else if (_CharT(
'0') <= __ic && __ic <= _CharT(
'9'))
5072 int_least32_t __mm = 0;
5075 __mm = 10 * _S_try_read_digit(__is, __err);
5076 __mm += _S_try_read_digit(__is, __err);
5079 if (!__is_failed(__err))
5081 auto __z = __hh * 60 + __mm;
5082 __tz_offset =
minutes(__neg ? -__z : __z);
5088 if (__mod || __num) [[unlikely]]
5092 basic_string_view<_CharT> __x = _GLIBCXX_WIDEN(
"_/-+");
5096 auto __i = __is.peek();
5097 if (!_Traits::eq_int_type(__i, _Traits::eof()))
5099 _CharT __a = _Traits::to_char_type(__i);
5101 || __x.find(__a) != __x.npos)
5103 __tz_abbr.push_back(__a);
5112 if (__tz_abbr.empty())
5118 if (__mod || __num) [[unlikely]]
5122 _CharT __i = __is.peek();
5123 if (_Traits::eq_int_type(__i, _Traits::eof()))
5125 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
5133 if (__mod || __num) [[unlikely]]
5137 _CharT __i = __is.peek();
5138 if (_Traits::eq_int_type(__i, _Traits::eof()))
5140 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
5146 if (__mod || __num) [[unlikely]]
5154 if (__mod || __num) [[unlikely]]
5163 if (_CharT(
'1') <= __c && __c <= _CharT(
'9'))
5165 if (!__mod) [[likely]]
5168 auto __end = __fmt + _Traits::length(__fmt);
5170 = __format::__parse_integer(__fmt - 1, __end);
5171 if (__ptr) [[likely]]
5182 if (__is_failed(__err)) [[unlikely]]
5192 if (__yy != __bad_y && __y == __bad_y)
5193 __y =
years(__century) + __yy;
5194 if (__iso_yy != __bad_y && __iso_y == __bad_y)
5195 __iso_y =
years(__century) + __iso_yy;
5198 bool __can_use_doy =
false;
5199 bool __can_use_iso_wk =
false;
5200 bool __can_use_sun_wk =
false;
5201 bool __can_use_mon_wk =
false;
5204 if (__y != __bad_y && __dayofyear >= 0)
5206 __can_use_doy =
true;
5207 __parts |= _ChronoParts::_Date;
5209 else if (__y != __bad_y && __wday != __bad_wday && __sunday_wk >= 0)
5211 __can_use_sun_wk =
true;
5212 __parts |= _ChronoParts::_Date;
5214 else if (__y != __bad_y && __wday != __bad_wday && __monday_wk >= 0)
5216 __can_use_mon_wk =
true;
5217 __parts |= _ChronoParts::_Date;
5219 else if (__iso_y != __bad_y && __wday != __bad_wday && __iso_wk > 0)
5222 __can_use_iso_wk =
true;
5223 __parts |= _ChronoParts::_Date;
5226 if (__is_failed(__err)) [[unlikely]]
5228 else if (__is_flag) [[unlikely]]
5230 else if ((_M_need & __parts) == _M_need) [[likely]]
5252 const bool __need_wday = (_M_need & _ChronoParts::_Weekday) != 0;
5256 const bool __need_time = (_M_need & _ChronoParts::_TimeOfDay) != 0;
5258 if (__need_wday && __wday != __bad_wday)
5260 else if ((_M_need & _ChronoParts::_Date) != 0)
5264 const bool __need_ymd = !__need_wday && !__need_time;
5266 if (((_M_need & _ChronoParts::_Year) != 0 && __y == __bad_y)
5267 || ((_M_need & _ChronoParts::_Month) != 0 && __m == __bad_mon)
5268 || ((_M_need & _ChronoParts::_Day) != 0 && __d == __bad_day))
5275 if ((0 < __dayofyear && __dayofyear <= 365)
5276 || (__dayofyear == 366 && __y.is_leap()))
5279 _M_sys_days = sys_days(__y/January/1)
5280 +
days(__dayofyear - 1);
5282 _M_ymd = year_month_day(_M_sys_days);
5287 else if (__can_use_iso_wk)
5295 const sys_days __jan4(__iso_y/January/4);
5296 weekday __wd1(__jan4 -
days(3));
5297 if (__wd1 != Thursday)
5298 if (__wd1 != Wednesday || !__iso_y.is_leap())
5302 if (!__is_failed(__err)) [[likely]]
5305 sys_days __w(Thursday[1]/January/__iso_y);
5307 __w -= Thursday - Monday;
5309 __w += __wday - Monday;
5313 _M_ymd = year_month_day(_M_sys_days);
5316 else if (__can_use_sun_wk)
5319 sys_days __wk1(__y/January/Sunday[1]);
5320 _M_sys_days = __wk1 +
weeks(__sunday_wk - 1)
5321 +
days(__wday.c_encoding());
5322 _M_ymd = year_month_day(_M_sys_days);
5323 if (_M_ymd.year() != __y) [[unlikely]]
5326 else if (__can_use_mon_wk)
5329 sys_days __wk1(__y/January/Monday[1]);
5330 _M_sys_days = __wk1 +
weeks(__monday_wk - 1)
5331 +
days(__wday.c_encoding() - 1);
5332 _M_ymd = year_month_day(_M_sys_days);
5333 if (_M_ymd.year() != __y) [[unlikely]]
5345 if ((_M_need & _ChronoParts::_Year) != 0)
5347 if (!__y.ok()) [[unlikely]]
5350 else if (__y == __bad_y)
5353 if ((_M_need & _ChronoParts::_Month) != 0)
5355 if (!__m.ok()) [[unlikely]]
5358 else if (__m == __bad_mon)
5361 if ((_M_need & _ChronoParts::_Day) != 0)
5363 if (__d < day(1) || __d > (__y/__m/last).day())
5366 else if (__d == __bad_day)
5369 if (year_month_day __ymd(__y, __m, __d); __ymd.ok())
5372 if (__need_wday || __need_time)
5373 _M_sys_days = sys_days(_M_ymd);
5380 _M_wd = weekday(_M_sys_days);
5386 if (__h == __bad_h && __h12 != __bad_h)
5390 else if (__ampm == 2)
5391 __h = __h12 ==
hours(12) ? __h12 : __h12 +
hours(12);
5396 auto __t = _M_time.zero();
5405 if (__min != __bad_min)
5411 if (__s != __bad_sec)
5415 _M_is_leap_second = __s >=
seconds(60);
5424 if (!__is_failed(__err)) [[likely]]
5426 if (__offset && __tz_offset != __bad_min)
5427 *__offset = __tz_offset;
5428 if (__abbrev && !__tz_abbr.empty())
5436 __is.setstate(__err);
5440#undef _GLIBCXX_WIDEN
5445_GLIBCXX_END_NAMESPACE_VERSION
__detail::__local_time_fmt< _Duration > local_time_format(local_time< _Duration > __time, const string *__abbrev=nullptr, const seconds *__offset_sec=nullptr)
duration< int64_t, ratio< 604800 > > weeks
weeks
constexpr __enable_if_is_duration< _ToDur > floor(const duration< _Rep, _Period > &__d)
constexpr enable_if_t< __and_< __is_duration< _ToDur >, __not_< treat_as_floating_point< typename _ToDur::rep > > >::value, _ToDur > round(const duration< _Rep, _Period > &__d)
duration< int64_t, ratio< 86400 > > days
days
duration< int64_t, ratio< 31556952 > > years
years
duration< int64_t, ratio< 3600 > > hours
hours
duration< int64_t, ratio< 60 > > minutes
minutes
basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const duration< _Rep, _Period > &__d)
duration< int64_t > seconds
seconds
constexpr __enable_if_is_duration< _ToDur > duration_cast(const duration< _Rep, _Period > &__d)
constexpr complex< _Tp > operator-(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x minus y.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
const _Facet & use_facet(const locale &__loc)
Return a facet.
ISO C++ entities toplevel namespace is std.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
chars_format
floating-point format for primitive numerical conversion
bool isspace(_CharT __c, const locale &__loc)
Convenience interface to ctype.is(ctype_base::space, __c).
_CharT toupper(_CharT __c, const locale &__loc)
Convenience interface to ctype.toupper(__c).
bool isalnum(_CharT __c, const locale &__loc)
Convenience interface to ctype.is(ctype_base::alnum, __c).
ios_base & dec(ios_base &__base)
Calls base.setf(ios_base::dec, ios_base::basefield).
ios_base & skipws(ios_base &__base)
Calls base.setf(ios_base::skipws).
constexpr bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
basic_istream< _CharT, _Traits > & ws(basic_istream< _CharT, _Traits > &__is)
Quick and easy way to eat whitespace.
constexpr bitset< _Nb > operator&(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
constexpr from_chars_result from_chars(const char *__first, const char *__last, _Tp &__value, int __base=10)
std::from_chars for integral types.
ISO C++ 2011 namespace for date and time utilities.
locale imbue(const locale &__loc)
Moves to a new locale.
Template class basic_istream.
Template class basic_ostream.
Controlling output for std::string.
Controlling input and output for std::string.
Provides output iterator semantics for streambufs.
Provides compile-time rational arithmetic.
A non-owning reference to a string.
Managing sequences of characters and character-like objects.
constexpr iterator begin() noexcept
chrono::duration represents a distance between two points in time
_Ios_Iostate iostate
This is a bitmask type.
streamsize precision() const
Flags access.
fmtflags flags() const
Access to format flags.
static const iostate eofbit
Indicates that an input operation reached the end of an input sequence.
static const iostate goodbit
Indicates all is well.
locale getloc() const
Locale access.
static const iostate failbit
Indicates that an input operation failed to read the expected characters, or that an output operation...
static const locale & classic()
Return reference to the C locale.