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;
482 [[__gnu__::__always_inline__]]
484 _M_fill_aux(chrono::local_days __ld, _ChronoParts __parts)
486 using namespace chrono;
487 if ((__parts & _ChronoParts::_Weekday) != 0)
488 _M_weekday = weekday(__ld);
489 __parts -= _ChronoParts::_Weekday;
490 if ((__parts & _ChronoParts::_DayOfYear) != 0)
493 _M_day_of_year = __ld - local_days(_M_year/January/0);
494 __parts -= _ChronoParts::_DayOfYear;
498 [[__gnu__::__always_inline__]]
500 _M_fill_ldays(chrono::local_days __ld, _ChronoParts __parts)
503 __parts -= _ChronoParts::_LocalDays;
504 return _M_fill_aux(__ld, __parts);
508 _M_fill_time(chrono::seconds __d)
510 chrono::hh_mm_ss<chrono::seconds> __hms(__d);
511 _M_hours = __hms.hours();
512 _M_minutes = __hms.minutes();
513 _M_seconds = __hms.seconds();
517 _M_fill_date_time(chrono::local_seconds __ls, _ChronoParts __parts)
519 _M_ldays = chrono::floor<chrono::days>(__ls);
520 __parts -= _ChronoParts::_LocalDays;
521 if ((__parts & _ChronoParts::_HoursMinutesSeconds) != 0)
522 _M_fill_time(_M_lseconds - _M_ldays);
524 if ((__parts & _ChronoParts::_Date) != 0)
526 const chrono::year_month_day __ymd(_M_ldays);
527 _M_fill_year_month(__ymd, __parts);
528 _M_fill_day(__ymd.day(), __parts);
529 _M_fill_aux(_M_ldays, __parts);
534 _M_fill_zone(
const char* __abbrev,
const wchar_t* __wabbrev)
536 if constexpr (is_same_v<_CharT, char>)
537 _M_zone_abbrev = __abbrev;
539 _M_zone_abbrev = __wabbrev;
540 _M_zone_cstr = __abbrev;
543 [[__gnu__::__always_inline__]]
546 { _M_fill_zone(
"UTC", L
"UTC"); }
550 template<
typename _CharT>
551 struct __formatter_chrono
553 using __string_view = basic_string_view<_CharT>;
554 using __string = basic_string<_CharT>;
556 __formatter_chrono() =
default;
559 __formatter_chrono(_ChronoSpec<_CharT> __spec) noexcept
563 template<
typename _ParseContext>
564 constexpr typename _ParseContext::iterator
565 _M_parse(_ParseContext& __pc, _ChronoParts __parts,
566 const _ChronoSpec<_CharT>& __def)
568 auto __first = __pc.
begin();
569 auto __last = __pc.end();
571 _ChronoSpec<_CharT> __spec = __def;
573 auto __finalize = [
this, &__spec, &__def] {
574 using enum _ChronoParts;
575 _ChronoParts __checked
576 = __spec._M_debug ? _YearMonthDay|_IndexedWeekday
580 __spec._M_needs_ok_check
581 = __spec._M_needs(__def._M_needed & __checked);
585 auto __finished = [&] {
586 if (__first == __last || *__first ==
'}')
597 __first = __spec._M_parse_fill_and_align(__first, __last);
601 __first = __spec._M_parse_width(__first, __last, __pc);
607 if ((__parts & _ChronoParts::_EpochUnits) == 0
608 || !__spec._M_floating_point_rep)
609 __throw_format_error(
"format error: invalid precision for duration");
612 __first = _Spec<_CharT>()._M_parse_precision(__first, __last, __pc);
614 __spec._M_prec_kind = _WP_value;
619 __spec._M_localized =
false;
620 __first = __spec._M_parse_locale(__first, __last);
627 __string_view __str(__first, __last - __first);
628 auto __end = __str.find(
'}');
629 if (__end != __str.npos)
631 __str.remove_suffix(__str.length() - __end);
632 __last = __first + __end;
634 if (__str.find(
'{') != __str.npos)
635 __throw_format_error(
"chrono format error: '{' in chrono-specs");
641 __spec._M_debug =
false;
642 __spec._M_locale_specific =
false;
643 __spec._M_needed = _ChronoParts::_None;
644 __spec._M_chrono_specs = __string_view();
646 const auto __chrono_specs = __first++;
647 if (*__chrono_specs !=
'%')
648 __throw_format_error(
"chrono format error: no '%' at start of "
653 while (__first != __last)
655 enum _Mods { _Mod_none, _Mod_E, _Mod_O, _Mod_E_O };
656 _Mods __allowed_mods = _Mod_none;
658 _ChronoParts __needed = _ChronoParts::_None;
659 bool __locale_specific =
false;
661 _CharT __c = *__first++;
664 using enum _ChronoParts;
668 __locale_specific =
true;
674 __locale_specific =
true;
677 __needed = _Date|_HoursMinutesSeconds;
678 __allowed_mods = _Mod_E;
679 __locale_specific =
true;
683 __allowed_mods = _Mod_E;
688 __allowed_mods = _Mod_O;
692 __needed = _YearMonthDay;
696 __needed = _LocalDays|_Weekday;
700 __needed = _HoursMinutesSeconds;
701 __allowed_mods = _Mod_O;
704 __needed = __parts & _DayOfYear;
707 if (__needed == _None)
708 __needed = _HoursMinutesSeconds;
712 __allowed_mods = _Mod_O;
715 __needed = _HoursMinutesSeconds;
716 __allowed_mods = _Mod_O;
720 __locale_specific =
true;
723 __needed = _HoursMinutesSeconds;
726 __needed = _TimeOfDay;
729 __needed = _UnitSuffix;
732 __needed = _EpochUnits;
735 __needed = _TimeOfDay;
736 __allowed_mods = _Mod_O;
741 __allowed_mods = _Mod_O;
746 __needed = _LocalDays|_Year|_DayOfYear|_Weekday;
747 __allowed_mods = _Mod_O;
751 __locale_specific =
true;
752 __allowed_mods = _Mod_E;
755 __needed = _HoursMinutesSeconds;
756 __locale_specific =
true;
757 __allowed_mods = _Mod_E;
761 __allowed_mods = _Mod_E_O;
765 __allowed_mods = _Mod_E;
768 __needed = _ZoneOffset;
769 __allowed_mods = _Mod_E_O;
772 __needed = _ZoneAbbrev;
780 if (__mod) [[unlikely]]
782 __allowed_mods = _Mod_none;
788 __throw_format_error(
"chrono format error: invalid "
789 " specifier in chrono-specs");
792 if ((__mod ==
'E' && !(__allowed_mods & _Mod_E))
793 || (__mod ==
'O' && !(__allowed_mods & _Mod_O)))
794 __throw_format_error(
"chrono format error: invalid "
795 " modifier in chrono-specs");
796 if (__mod && __c !=
'z')
797 __locale_specific =
true;
801 if (__locale_specific)
802 __needed -= _ChronoParts::_Subseconds;
804 if ((__parts & __needed) != __needed)
805 __throw_format_error(
"chrono format error: format argument "
806 "does not contain the information "
807 "required by the chrono-specs");
808 __spec._M_needed |= __needed;
809 __spec._M_locale_specific |= __locale_specific;
812 size_t __pos = __string_view(__first, __last - __first).find(
'%');
817 if (__pos == __string_view::npos)
823 __first += __pos + 1;
828 if (__conv || __mod != _CharT())
829 __throw_format_error(
"chrono format error: unescaped '%' in "
832 __spec._M_chrono_specs
833 = __string_view(__chrono_specs, __first - __chrono_specs);
840 template<
typename _FormatContext>
841 typename _FormatContext::iterator
842 _M_format(
const _ChronoData<_CharT>& __t, _FormatContext& __fc)
const
844#if defined _GLIBCXX_USE_NL_LANGINFO_L && __CHAR_BIT__ == 8
848 if constexpr (is_same_v<_CharT, char>)
849 if constexpr (__unicode::__literal_encoding_is_utf8())
850 if (_M_spec._M_localized && _M_spec._M_locale_specific)
852 extern locale __with_encoding_conversion(
const locale&);
856 locale __loc = __fc.locale();
857 if (__loc != locale::classic())
858 __fc._M_loc = __with_encoding_conversion(__loc);
862 const size_t __padwidth = _M_spec._M_get_width(__fc);
864 return _M_format_to(__t, __fc.out(), __fc);
866 using _Out =
typename _FormatContext::iterator;
867 _Padding_sink<_Out, _CharT> __sink(__fc.out(), __padwidth);
868 _M_format_to(__t, __sink.out(), __fc);
869 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);
1150 __out = _M_g_G(__t,
std::move(__out), __c ==
'G');
1154 __out = _M_H_I(__t._M_hours, __print_sign(), __c);
1157 __out = _M_j(__t, __print_sign());
1160 __out = _M_m(__t._M_month,
std::move(__out));
1163 __out = _M_M(__t._M_minutes, __print_sign());
1166 __out = _M_p(__t._M_hours,
std::move(__out));
1169 __out = _M_q(__t._M_unit_suffix,
std::move(__out));
1172 __out = _M_Q(__t, __print_sign(), __fc);
1175 __out = _M_r(__t, __print_sign());
1179 __out = _M_R_X(__t, __print_sign(), __c !=
'R');
1182 __out = _M_T(__t, __print_sign(), __fc);
1185 __out = _M_S(__t, __print_sign(), __fc, __mod !=
'O');
1189 __out = _M_u_w(__t._M_weekday,
std::move(__out), __c);
1194 __out = _M_U_V_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(
const _ChronoData<_CharT>& __t, _OutIter __out,
1449 using namespace chrono;
1450 auto __d = __t._M_ldays;
1452 __d -= (__t._M_weekday - Monday) -
days(3);
1454 year __y = year_month_day(__d).year();
1455 return _M_C_y_Y(__y,
std::move(__out),
"yY"[__full]);
1458 template<
typename _OutIter>
1460 _M_H_I(chrono::hours __h, _OutIter __out, _CharT __conv)
const
1467 int __i = __h.count();
1469 if (__conv == _CharT(
'I'))
1475 else if (__i >= 100) [[unlikely]]
1476 return std::format_to(
std::move(__out), _S_empty_fs(), __i);
1478 return __format::__write(
std::move(__out), _S_two_digits(__i));
1481 template<
typename _OutIter>
1483 _M_j(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1485 if (!_M_spec._M_needs(_ChronoParts::_DayOfYear))
1488 auto __d = chrono::floor<chrono::days>(__t._M_hours).count();
1489 return std::format_to(
std::move(__out), _S_empty_fs(), __d);
1492 auto __d = __t._M_day_of_year.count();
1493 if (__d >= 1000) [[unlikely]]
1494 return std::format_to(
std::move(__out), _S_empty_fs(), __d);
1497 return __format::__write(
std::move(__out), _S_str_d3(__buf, __d));
1500 template<
typename _OutIter>
1502 _M_m(chrono::month __m, _OutIter __out)
const
1506 auto __i = (unsigned)__m;
1507 if (__i == 0 && _M_spec._M_debug) [[unlikely]]
1509 return __format::__write(
std::move(__out), _S_digit(0));
1512 return __format::__write(
std::move(__out), _S_str_d2(__buf, __i));
1515 template<
typename _OutIter>
1517 _M_M(chrono::minutes __m, _OutIter __out)
const
1522 auto __i = __m.count();
1523 return __format::__write(
std::move(__out), _S_two_digits(__i));
1526 template<
typename _OutIter>
1528 _M_p(chrono::hours __h, _OutIter __out)
const
1533 _S_fill_ampm(__buf, __h);
1534 return __format::__write(
std::move(__out), __string_view(__buf, 2));
1537 template<
typename _OutIter>
1539 _M_q(__string_view __us, _OutIter __out)
const
1542 return __format::__write(
std::move(__out), __us);
1545 template<
typename _OutIter,
typename _FormatContext>
1547 _M_Q(
const _ChronoData<_CharT>& __t, _OutIter __out,
1548 _FormatContext&)
const
1551 return std::vformat_to(
std::move(__out), _S_empty_spec, __t._M_ereps);
1554 template<
typename _OutIter>
1556 _M_r(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1559 auto __hi = __t._M_hours.count() % 12;
1564 __buf[2] = _S_colon;
1565 __buf[5] = _S_colon;
1566 __buf[8] = _S_space;
1567 _S_fill_two_digits(__buf, __hi);
1568 _S_fill_two_digits(__buf + 3, __t._M_minutes.count());
1569 _S_fill_two_digits(__buf + 6, __t._M_seconds.count());
1570 _S_fill_ampm(__buf + 9, __t._M_hours);
1572 return __format::__write(
std::move(__out), __string_view(__buf, 11));
1575 template<
typename _OutIter>
1577 _M_R_X(
const _ChronoData<_CharT>& __t, _OutIter __out,
1584 auto __hi = __t._M_hours.count();
1587 __buf[2] = _S_colon;
1588 __buf[5] = _S_colon;
1589 __string_view __sv(__buf, 8);
1591 if (__hi >= 100) [[unlikely]]
1593 __out = std::format_to(
std::move(__out), _S_empty_fs(), __hi);
1594 __sv.remove_prefix(2);
1597 _S_fill_two_digits(__buf, __hi);
1599 _S_fill_two_digits(__buf + 3, __t._M_minutes.count());
1601 _S_fill_two_digits(__buf + 6, __t._M_seconds.count());
1603 __sv.remove_suffix(3);
1605 return __format::__write(
std::move(__out), __sv);
1608 template<
typename _OutIter,
typename _FormatContext>
1610 _M_S(
const _ChronoData<_CharT>& __t, _OutIter __out,
1611 _FormatContext& __ctx,
bool __subs =
true)
const
1615 auto __s = __t._M_seconds;
1617 __out = __format::__write(
std::move(__out),
1618 _S_two_digits(__s.count()));
1620 __out = _M_subsecs(__t,
std::move(__out), __ctx);
1624 template<
typename _OutIter,
typename _FormatContext>
1626 _M_subsecs(
const _ChronoData<_CharT>& __t, _OutIter __out,
1627 _FormatContext& __ctx)
const
1629 unsigned __prec = _M_spec._M_prec_kind != _WP_none
1630 ? _M_spec._M_get_precision(__ctx)
1635 _CharT __dot = _S_dot;
1636 if (_M_spec._M_localized) [[unlikely]]
1638 auto __loc = __ctx.locale();
1639 const auto& __np = use_facet<numpunct<_CharT>>(__loc);
1640 __dot = __np.decimal_point();
1645 if (_M_spec._M_floating_point_rep)
1647 _Str_sink<_CharT> __sink;
1648 if (_M_spec._M_localized && _M_spec._M_custom_rep) [[unlikely]]
1649 std::vformat_to(__sink.out(), __ctx.locale(),
1650 _GLIBCXX_WIDEN(
"{1:0.{2}Lf}"), __t._M_ereps);
1652 std::vformat_to(__sink.out(),
1653 _GLIBCXX_WIDEN(
"{1:0.{2}f}"), __t._M_ereps);
1655 auto __sv = __sink.view();
1657 __sv.remove_prefix(2);
1658 return __format::__write(
std::move(__out), __sv);
1661 constexpr unsigned __max_prec = _ChronoData<_CharT>::_S_max_prec;
1662 constexpr typename _ChronoData<_CharT>::_Attoseconds::rep __pow10t[]
1666 10'000u, 100'000u, 1000'000u,
1667 10'000'000u, 100'000'000u, 1000'000'000u,
1668 10'000'000'000u, 100'000'000'000u, 1000'000'000'000u,
1669 10'000'000'000'000u, 100'000'000'000'000u, 1000'000'000'000'000u,
1670 10'000'000'000'000'000u, 100'000'000'000'000'000u, 1000'000'000'000'000'000u,
1673 auto __subs = __t._M_subseconds.count();
1674 if (__prec < __max_prec)
1675 __subs /= __pow10t[__max_prec - __prec];
1676 else if (__prec > __max_prec)
1677 __prec = __max_prec;
1679 using _FmtStr = _Runtime_format_string<_CharT>;
1680 return std::format_to(__out, _FmtStr(_GLIBCXX_WIDEN(
"{0:0{1}}")),
1686 template<
typename _OutIter,
typename _FormatContext>
1688 _M_T(
const _ChronoData<_CharT>& __t, _OutIter __out,
1689 _FormatContext& __ctx)
const
1692 __out = _M_R_X(__t,
std::move(__out),
true);
1693 return _M_subsecs(__t,
std::move(__out), __ctx);
1696 template<
typename _OutIter>
1698 _M_u_w(chrono::weekday __wd, _OutIter __out, _CharT __conv)
const
1704 unsigned __wdi = __conv ==
'u' ? __wd.iso_encoding()
1705 : __wd.c_encoding();
1707 return __format::__write(
std::move(__out), _S_str_d1(__buf, __wdi));
1710 template<
typename _OutIter>
1712 _M_U_V_W(
const _ChronoData<_CharT>& __t, _OutIter __out,
1713 _CharT __conv)
const
1721 using namespace chrono;
1723 auto __d = __t._M_ldays;
1728 __d -= (__t._M_weekday - Monday) -
days(3);
1731 __first = local_days(year_month_day(__d).year()/January/1);
1735 const weekday __weekstart = __conv ==
'U' ? Sunday : Monday;
1736 __first = local_days(__t._M_year/January/__weekstart[1]);
1738 auto __weeks = chrono::floor<weeks>(__d - __first);
1739 __string_view __sv = _S_two_digits(__weeks.count() + 1);
1740 return __format::__write(
std::move(__out), __sv);
1743 template<
typename _OutIter>
1745 _M_z(chrono::seconds __ts, _OutIter __out,
bool __mod =
false)
const
1749 __string_view __zero
1750 = __mod ? _GLIBCXX_WIDEN(
"+00:00") : _GLIBCXX_WIDEN(
"+0000");
1751 return __format::__write(
std::move(__out), __zero);
1754 chrono::hh_mm_ss<chrono::seconds> __hms(__ts);
1755 unsigned __mo = 3 + __mod;
1758 __buf[0] = _S_plus_minus[__hms.is_negative()];
1759 __buf[3] = _S_colon;
1760 _S_fill_two_digits(__buf + 1, __hms.hours().count());
1761 _S_fill_two_digits(__buf + __mo, __hms.minutes().count());
1763 __string_view __sv(__buf, __mo + 2);
1764 return __format::__write(
std::move(__out), __sv);
1767 template<
typename _OutIter>
1769 _M_Z(__string_view __abbrev, _OutIter __out)
const
1770 {
return __format::__write(
std::move(__out), __abbrev); }
1775 static basic_string_view<_CharT>
1776 _S_digit(
int __n)
noexcept
1779 return { _GLIBCXX_WIDEN(
"0123456789999999") + (__n & 0xf), 1 };
1783 static basic_string_view<_CharT>
1784 _S_two_digits(
int __n)
noexcept
1787 _GLIBCXX_WIDEN(
"0001020304050607080910111213141516171819"
1788 "2021222324252627282930313233343536373839"
1789 "4041424344454647484950515253545556575859"
1790 "6061626364656667686970717273747576777879"
1791 "8081828384858687888990919293949596979899"
1792 "9999999999999999999999999999999999999999"
1793 "9999999999999999") + 2 * (__n & 0x7f),
1799 [[__gnu__::__always_inline__]]
1801 _S_fill_two_digits(_CharT* __buf,
unsigned __n)
1803 auto __sv = _S_two_digits(__n);
1809 [[__gnu__::__always_inline__]]
1811 _S_fill_ampm(_CharT* __buf, chrono::hours __h)
1813 auto __hi = __h.count();
1814 if (__hi >= 24) [[unlikely]]
1817 constexpr const _CharT* __apm = _GLIBCXX_WIDEN(
"APM");
1818 __buf[0] = __apm[__hi >= 12];
1819 __buf[1] = __apm[2];
1824 [[__gnu__::__always_inline__]]
1825 static basic_string_view<_CharT>
1826 _S_str_d1(span<_CharT, 3> __buf,
unsigned __n)
1828 if (__n < 10) [[likely]]
1829 return _S_digit(__n);
1830 return _S_str_d2(__buf, __n);
1835 [[__gnu__::__always_inline__]]
1836 static basic_string_view<_CharT>
1837 _S_str_d2(span<_CharT, 3> __buf,
unsigned __n)
1839 if (__n < 100) [[likely]]
1840 return _S_two_digits(__n);
1841 return _S_str_d3(__buf, __n);
1846 [[__gnu__::__always_inline__]]
1847 static basic_string_view<_CharT>
1848 _S_str_d3(span<_CharT, 3> __buf,
unsigned __n)
1850 _S_fill_two_digits(__buf.data(), __n / 10);
1851 __buf[2] = _S_chars[__n % 10];
1852 return __string_view(__buf.data(), 3);
1856 template<
typename _CharT>
1857 struct __formatter_duration :
private __formatter_chrono<_CharT>
1859 template<
typename _Rep,
typename _Period>
1860 constexpr static auto
1861 _S_subseconds(
const chrono::duration<_Rep, _Period>& __d)
1863 if constexpr (chrono::treat_as_floating_point_v<_Rep>)
1864 return chrono::duration<_Rep>(__d);
1865 else if constexpr (_Period::den == 1)
1866 return chrono::seconds(0);
1869 using _Attoseconds = _ChronoData<_CharT>::_Attoseconds;
1870 using _CRep = common_type_t<_Rep, typename _Attoseconds::rep>;
1871 chrono::duration<_CRep, _Period> subs(__d.count());
1872 return chrono::duration_cast<_Attoseconds>(subs);
1877 template<
typename _Duration>
1880 _S_spec_for(_ChronoParts __parts)
1882 using _Rep =
typename _Duration::rep;
1883 using enum _ChronoParts;
1885 _ChronoSpec<_CharT> __res{};
1886 __res._M_floating_point_rep = chrono::treat_as_floating_point_v<_Rep>;
1887 __res._M_custom_rep = !is_arithmetic_v<_Rep>;
1888 __res._M_prec = chrono::hh_mm_ss<_Duration>::fractional_width;
1889 if ((__parts & _TimeOfDay) != 0)
1890 __res._M_localized = __res._M_prec > 0 || __res._M_floating_point_rep;
1892 if ((__parts & _TimeOfDay) != 0)
1893 __res._M_needed |= _TimeOfDay;
1894 if ((__parts & _Date) != 0)
1895 __res._M_needed |= _YearMonthDay;
1896 if ((__parts & _ZoneAbbrev) != 0)
1897 __res._M_needed |= _ZoneAbbrev;
1901 case _ZonedDateTime:
1902 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ftz();
1905 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ft();
1908 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_f();
1911 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_t();
1916 __builtin_unreachable();
1921 using __formatter_chrono<_CharT>::__formatter_chrono;
1922 using __formatter_chrono<_CharT>::_M_spec;
1924 template<
typename _Duration,
typename _ParseContext>
1925 constexpr typename _ParseContext::iterator
1926 _M_parse(_ParseContext& __pc, _ChronoParts __parts,
1927 const _ChronoSpec<_CharT>& __def = {})
1929 using _Rep =
typename _Duration::rep;
1930 using enum _ChronoParts;
1933 = __formatter_chrono<_CharT>::_M_parse(__pc, __parts, __def);
1936 _M_spec._M_needs_ok_check =
false;
1941 if constexpr (!is_floating_point_v<_Rep>)
1942 if constexpr (chrono::treat_as_floating_point_v<_Rep>)
1943 if (_M_spec._M_needs(_Subseconds|_EpochUnits)
1944 || _M_spec._M_prec_kind != _WP_none
1945 || _M_spec._M_prec_value > 0)
1947 constexpr const _CharT* __fs = _GLIBCXX_WIDEN(
"#02.5Lf");
1948 basic_format_parse_context<_CharT> __npc(__fs);
1949 formatter<_Rep, _CharT> __fmtter;
1950 __fmtter.parse(__npc);
1956 template<
typename _FormatContext>
1958 _M_locale(_FormatContext& __fc)
const
1960 if (!_M_spec._M_localized)
1963 return __fc.locale();
1967 template<
typename _Rep,
typename _Period,
typename _FormatContext>
1968 typename _FormatContext::iterator
1969 _M_format_to_ostream(
const chrono::duration<_Rep, _Period>& __d,
1971 _FormatContext& __fc)
const
1973 basic_ostringstream<_CharT> __os;
1974 __os.imbue(this->_M_locale(__fc));
1976 if (__is_neg) [[unlikely]]
1977 __os << this->_S_plus_minus[1];
1981 return __format::__write_padded_as_spec(__str, __str.size(),
1985 template<
typename _Rep1,
typename _Period1,
1986 typename _Rep2,
typename _Period2,
1987 typename _FormatContext>
1988 typename _FormatContext::iterator
1989 _M_format_units(_ChronoData<_CharT>& __cd,
1990 const chrono::duration<_Rep1, _Period1>& __ed,
1991 const chrono::duration<_Rep2, _Period2>& __ss,
1992 _FormatContext& __fc)
const
1994 __format::_Str_sink<_CharT> __suffix_store;
1995 constexpr auto _S_unit_suffix
1996 = chrono::__detail::__units_suffix<_Period1, _CharT>();
1997 if constexpr (!_S_unit_suffix.empty())
1998 __cd._M_unit_suffix = _S_unit_suffix;
1999 else if (_M_spec._M_needs(_ChronoParts::_UnitSuffix))
2002 __fmt_units_suffix<_Period1, _CharT>(__suffix_store.out());
2003 __cd._M_unit_suffix = __suffix_store.view();
2006 const auto __prec = _M_spec._M_prec_kind != _WP_none
2007 ? _M_spec._M_get_precision(__fc)
2010 using _ErasedContext =
typename _ChronoData<_CharT>::_FormatContext;
2013 auto __ereps = +__ed.count();
2014 if (!_M_spec._M_needs(_ChronoParts::_Subseconds))
2018 = std::make_format_args<_ErasedContext>(__ereps, __ssreps, __prec);
2019 __cd._M_ereps = __args_store;
2020 return this->_M_format(__cd, __fc);
2023 using _Attoseconds = _ChronoData<_CharT>::_Attoseconds;
2024 auto __nss = _S_subseconds(__ss);
2025 __cd._M_subseconds = chrono::duration_cast<_Attoseconds>(__nss);
2027 auto __ssreps = __nss.count();
2029 = std::make_format_args<_ErasedContext>(__ereps, __ssreps, __prec);
2030 __cd._M_ereps = __args_store;
2032 return this->_M_format(__cd, __fc);
2036 template<
typename _Rep1,
typename _Period1,
typename _FormatContext>
2037 typename _FormatContext::iterator
2038 _M_format_time_point(_ChronoData<_CharT>& __cd,
2039 const chrono::duration<_Rep1, _Period1>& __ed,
2040 _FormatContext& __fc)
const
2042 auto __parts = _M_spec._M_needed - _ChronoParts::_TotalSeconds;
2043 if ((__parts & _ChronoParts::_DateTime) != 0)
2044 __cd._M_fill_date_time(__cd._M_lseconds, __parts);
2045 return _M_format_units(__cd, __ed, __ed - __cd._M_eseconds, __fc);
2049#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2050 template<
typename _CharT>
2051 struct __formatter_chrono_info
2053 constexpr typename basic_format_parse_context<_CharT>::iterator
2054 parse(basic_format_parse_context<_CharT>& __pc)
2055 {
return _M_f._M_parse(__pc, _ChronoParts(), {}); }
2057 template<
typename _Info,
typename _Out>
2058 typename basic_format_context<_Out, _CharT>::iterator
2059 format(
const _Info& __i,
2060 basic_format_context<_Out, _CharT>& __fc)
const
2064 if (!_M_f._M_spec._M_chrono_specs.empty()) [[unlikely]]
2065 return _M_f._M_format(_ChronoData<_CharT>{}, __fc);
2067 const size_t __padwidth = _M_f._M_spec._M_get_width(__fc);
2068 if (__padwidth == 0)
2069 return _M_format_to(__fc.out(), __i);
2071 _Padding_sink<_Out, _CharT> __sink(__fc.out(), __padwidth);
2072 _M_format_to(__sink.out(), __i);
2073 return __sink._M_finish(_M_f._M_spec._M_align, _M_f._M_spec._M_fill);
2077 template<
typename _Out>
2079 _M_format_to(_Out __out,
const chrono::sys_info& __si)
const
2081 using _FmtStr = _Runtime_format_string<_CharT>;
2085 constexpr auto* __fs
2086 = _GLIBCXX_WIDEN(
"[{0:%F %T},{1:%F %T},{2:%T},{3:%Q%q},{0:%Z}]");
2087 const chrono::local_seconds __lb(__si.begin.time_since_epoch());
2088 return std::format_to(
std::move(__out), _FmtStr(__fs),
2089 chrono::local_time_format(__lb, &__si.abbrev),
2090 __si.end, __si.offset, __si.save);
2093 template<
typename _Out>
2095 _M_format_to(_Out __out,
const chrono::local_info& __li)
const
2097 *__out = _Separators<_CharT>::_S_squares()[0];
2099 if (__li.result == chrono::local_info::unique)
2100 __out = _M_format_to(
std::move(__out), __li.first);
2103 basic_string_view<_CharT> __sv;
2104 if (__li.result == chrono::local_info::nonexistent)
2105 __sv =_GLIBCXX_WIDEN(
"nonexistent");
2107 __sv = _GLIBCXX_WIDEN(
"ambiguous");
2108 __out = __format::__write(
std::move(__out), __sv);
2110 __sv = _GLIBCXX_WIDEN(
" local time between ");
2111 __out = __format::__write(
std::move(__out), __sv);
2112 __out = _M_format_to(
std::move(__out), __li.first);
2114 __sv = _GLIBCXX_WIDEN(
" and ");
2115 __out = __format::__write(
std::move(__out), __sv);
2116 __out = _M_format_to(
std::move(__out), __li.second);
2118 *__out = _Separators<_CharT>::_S_squares()[1];
2123 __formatter_chrono<_CharT> _M_f;
2130 template<
typename _Rep,
typename _Period,
typename _CharT>
2131 requires __format::__formattable_impl<_Rep, _CharT>
2132 struct formatter<
chrono::duration<_Rep, _Period>, _CharT>
2134 constexpr typename basic_format_parse_context<_CharT>::iterator
2135 parse(basic_format_parse_context<_CharT>& __pc)
2137 using enum __format::_ChronoParts;
2138 return _M_f.template _M_parse<_Duration>(__pc, _EpochTime, __defSpec);
2141 template<
typename _Out>
2142 typename basic_format_context<_Out, _CharT>::iterator
2143 format(
const chrono::duration<_Rep, _Period>& __d,
2144 basic_format_context<_Out, _CharT>& __fc)
const
2146 if constexpr (numeric_limits<_Rep>::is_signed)
2147 if (__d < __d.zero()) [[unlikely]]
2149 if constexpr (is_integral_v<_Rep>)
2153 using _URep = make_unsigned_t<_Rep>;
2154 auto __ucnt = -
static_cast<_URep
>(__d.count());
2155 auto __ud = chrono::duration<_URep, _Period>(__ucnt);
2156 return _M_format(__ud,
true, __fc);
2159 return _M_format(-__d,
true, __fc);
2161 return _M_format(__d,
false, __fc);
2165 using _Duration = chrono::duration<_Rep, _Period>;
2167 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2169 using enum __format::_ChronoParts;
2170 auto __res = __format::__formatter_duration<_CharT>::
2171 template _S_spec_for<_Duration>(_None);
2172 __res._M_localized = !is_integral_v<_Rep>;
2174 if constexpr (is_integral_v<_Rep>)
2176 __res._M_needed = _EpochUnits|_UnitSuffix;
2177 __res._M_chrono_specs = _GLIBCXX_WIDEN(
"%Q%q");
2182 template<
typename _Rep2,
typename _Out>
2183 typename basic_format_context<_Out, _CharT>::iterator
2184 _M_format(
const chrono::duration<_Rep2, _Period>& __d,
2186 basic_format_context<_Out, _CharT>& __fc)
const
2188 using namespace chrono;
2189 using enum __format::_ChronoParts;
2190 if constexpr (!is_integral_v<_Rep>)
2191 if (_M_f._M_spec._M_chrono_specs.empty())
2192 return _M_f._M_format_to_ostream(__d, __is_neg, __fc);
2194 __format::_ChronoData<_CharT> __cd;
2195 __cd._M_is_neg = __is_neg;
2196 auto __ts = chrono::floor<chrono::seconds>(__d);
2197 __cd._M_eseconds = __ts;
2198 if (_M_f._M_spec._M_needs(_HoursMinutesSeconds))
2199 __cd._M_fill_time(__ts);
2200 return _M_f._M_format_units(__cd, __d, __d - __ts, __fc);
2203 __format::__formatter_duration<_CharT> _M_f{__defSpec};
2206 template<__format::__
char _CharT>
2207 struct formatter<
chrono::day, _CharT>
2209 constexpr typename basic_format_parse_context<_CharT>::iterator
2210 parse(basic_format_parse_context<_CharT>& __pc)
2212 using enum __format::_ChronoParts;
2213 return _M_f._M_parse(__pc, _Day|_WeekdayIndex, __defSpec);
2216 template<
typename _Out>
2217 typename basic_format_context<_Out, _CharT>::iterator
2218 format(
const chrono::day& __t,
2219 basic_format_context<_Out, _CharT>& __fc)
const
2221 __format::_ChronoData<_CharT> __cd{};
2222 __cd._M_fill_day(__t, __defSpec._M_needed);
2223 return _M_f._M_format(__cd, __fc);
2227 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2229 using __format::_ChronoFormats;
2230 using enum __format::_ChronoParts;
2232 __format::_ChronoSpec<_CharT> __res{};
2233 __res._M_debug =
true;
2234 __res._M_needed = _Day;
2235 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_d();
2239 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2242 template<__format::__
char _CharT>
2243 struct formatter<
chrono::month, _CharT>
2245 constexpr typename basic_format_parse_context<_CharT>::iterator
2246 parse(basic_format_parse_context<_CharT>& __pc)
2248 using enum __format::_ChronoParts;
2249 return _M_f._M_parse(__pc, _Month, __defSpec);
2252 template<
typename _Out>
2253 typename basic_format_context<_Out, _CharT>::iterator
2254 format(
const chrono::month& __t,
2255 basic_format_context<_Out, _CharT>& __fc)
const
2257 __format::_ChronoData<_CharT> __cd{};
2258 __cd._M_month = __t;
2259 return _M_f._M_format(__cd, __fc);
2263 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2265 using __format::_ChronoFormats;
2266 using enum __format::_ChronoParts;
2268 __format::_ChronoSpec<_CharT> __res{};
2269 __res._M_debug =
true;
2270 __res._M_localized =
true;
2271 __res._M_locale_specific =
true;
2272 __res._M_needed = _Month;
2273 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_m();
2277 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2280 template<__format::__
char _CharT>
2281 struct formatter<
chrono::year, _CharT>
2283 constexpr typename basic_format_parse_context<_CharT>::iterator
2284 parse(basic_format_parse_context<_CharT>& __pc)
2286 using enum __format::_ChronoParts;
2287 return _M_f._M_parse(__pc, _Year, __defSpec);
2290 template<
typename _Out>
2291 typename basic_format_context<_Out, _CharT>::iterator
2292 format(
const chrono::year& __t,
2293 basic_format_context<_Out, _CharT>& __fc)
const
2295 __format::_ChronoData<_CharT> __cd{};
2297 return _M_f._M_format(__cd, __fc);
2301 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2303 using __format::_ChronoFormats;
2304 using enum __format::_ChronoParts;
2306 __format::_ChronoSpec<_CharT> __res{};
2307 __res._M_debug =
true;
2308 __res._M_needed = _Year;
2309 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_y();
2313 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2316 template<__format::__
char _CharT>
2317 struct formatter<
chrono::weekday, _CharT>
2319 constexpr typename basic_format_parse_context<_CharT>::iterator
2320 parse(basic_format_parse_context<_CharT>& __pc)
2322 using enum __format::_ChronoParts;
2323 return _M_f._M_parse(__pc, _Weekday, __defSpec);
2326 template<
typename _Out>
2327 typename basic_format_context<_Out, _CharT>::iterator
2328 format(
const chrono::weekday& __t,
2329 basic_format_context<_Out, _CharT>& __fc)
const
2331 __format::_ChronoData<_CharT> __cd{};
2332 __cd._M_weekday = __t;
2333 return _M_f._M_format(__cd, __fc);
2337 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2339 using __format::_ChronoFormats;
2340 using enum __format::_ChronoParts;
2342 __format::_ChronoSpec<_CharT> __res{};
2343 __res._M_debug =
true;
2344 __res._M_localized =
true;
2345 __res._M_locale_specific =
true;
2346 __res._M_needed = _Weekday;
2347 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_w();
2351 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2354 template<__format::__
char _CharT>
2355 struct formatter<
chrono::weekday_indexed, _CharT>
2357 constexpr typename basic_format_parse_context<_CharT>::iterator
2358 parse(basic_format_parse_context<_CharT>& __pc)
2360 using enum __format::_ChronoParts;
2361 return _M_f._M_parse(__pc, _IndexedWeekday, __defSpec);
2364 template<
typename _Out>
2365 typename basic_format_context<_Out, _CharT>::iterator
2366 format(
const chrono::weekday_indexed& __t,
2367 basic_format_context<_Out, _CharT>& __fc)
const
2369 __format::_ChronoData<_CharT> __cd{};
2370 __cd._M_fill_weekday(__t, __defSpec._M_needed);
2371 return _M_f._M_format(__cd, __fc);
2375 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2377 using __format::_ChronoFormats;
2378 using enum __format::_ChronoParts;
2380 __format::_ChronoSpec<_CharT> __res{};
2381 __res._M_debug =
true;
2382 __res._M_localized =
true;
2383 __res._M_locale_specific =
true;
2384 __res._M_needed = _IndexedWeekday;
2385 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_wi();
2389 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2392 template<__format::__
char _CharT>
2393 struct formatter<
chrono::weekday_last, _CharT>
2395 constexpr typename basic_format_parse_context<_CharT>::iterator
2396 parse(basic_format_parse_context<_CharT>& __pc)
2398 using enum __format::_ChronoParts;
2399 return _M_f._M_parse(__pc, _Weekday, __defSpec);
2402 template<
typename _Out>
2403 typename basic_format_context<_Out, _CharT>::iterator
2404 format(
const chrono::weekday_last& __t,
2405 basic_format_context<_Out, _CharT>& __fc)
const
2407 __format::_ChronoData<_CharT> __cd{};
2408 __cd._M_weekday = __t.weekday();
2409 return _M_f._M_format(__cd, __fc);
2413 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2415 using __format::_ChronoFormats;
2416 using enum __format::_ChronoParts;
2418 __format::_ChronoSpec<_CharT> __res{};
2419 __res._M_debug =
true;
2420 __res._M_localized =
true;
2421 __res._M_locale_specific =
true;
2422 __res._M_needed = _Weekday;
2423 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_wl();
2427 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2430 template<__format::__
char _CharT>
2431 struct formatter<
chrono::month_day, _CharT>
2433 constexpr typename basic_format_parse_context<_CharT>::iterator
2434 parse(basic_format_parse_context<_CharT>& __pc)
2436 using enum __format::_ChronoParts;
2437 return _M_f._M_parse(__pc, _Month|_Day|_WeekdayIndex, __defSpec);
2440 template<
typename _Out>
2441 typename basic_format_context<_Out, _CharT>::iterator
2442 format(
const chrono::month_day& __t,
2443 basic_format_context<_Out, _CharT>& __fc)
const
2445 __format::_ChronoData<_CharT> __cd{};
2446 __cd._M_month = __t.month();
2447 __cd._M_fill_day(__t.day(), __defSpec._M_needed);
2448 return _M_f._M_format(__cd, __fc);
2452 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2454 using __format::_ChronoFormats;
2455 using enum __format::_ChronoParts;
2457 __format::_ChronoSpec<_CharT> __res{};
2458 __res._M_debug =
true;
2459 __res._M_localized =
true;
2460 __res._M_locale_specific =
true;
2461 __res._M_needed = _Month|_Day;
2462 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_md();
2466 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2469 template<__format::__
char _CharT>
2470 struct formatter<
chrono::month_day_last, _CharT>
2472 constexpr typename basic_format_parse_context<_CharT>::iterator
2473 parse(basic_format_parse_context<_CharT>& __pc)
2475 using enum __format::_ChronoParts;
2476 return _M_f._M_parse(__pc, _Month, __defSpec);
2479 template<
typename _Out>
2480 typename basic_format_context<_Out, _CharT>::iterator
2481 format(
const chrono::month_day_last& __t,
2482 basic_format_context<_Out, _CharT>& __fc)
const
2484 __format::_ChronoData<_CharT> __cd{};
2485 __cd._M_month = __t.month();
2486 return _M_f._M_format(__cd, __fc);
2490 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2492 using __format::_ChronoFormats;
2493 using enum __format::_ChronoParts;
2495 __format::_ChronoSpec<_CharT> __res{};
2496 __res._M_debug =
true;
2497 __res._M_localized =
true;
2498 __res._M_locale_specific =
true;
2499 __res._M_needed = _Month;
2500 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ml();
2504 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2507 template<__format::__
char _CharT>
2508 struct formatter<
chrono::month_weekday, _CharT>
2510 constexpr typename basic_format_parse_context<_CharT>::iterator
2511 parse(basic_format_parse_context<_CharT>& __pc)
2513 using enum __format::_ChronoParts;
2514 return _M_f._M_parse(__pc, _Month|_IndexedWeekday, __defSpec);
2517 template<
typename _Out>
2518 typename basic_format_context<_Out, _CharT>::iterator
2519 format(
const chrono::month_weekday& __t,
2520 basic_format_context<_Out, _CharT>& __fc)
const
2522 __format::_ChronoData<_CharT> __cd{};
2523 __cd._M_month = __t.month();
2524 __cd._M_fill_weekday(__t.weekday_indexed(), __defSpec._M_needed);
2525 return _M_f._M_format(__cd, __fc);
2529 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2531 using __format::_ChronoFormats;
2532 using enum __format::_ChronoParts;
2534 __format::_ChronoSpec<_CharT> __res{};
2535 __res._M_debug =
true;
2536 __res._M_localized =
true;
2537 __res._M_locale_specific =
true;
2538 __res._M_needed = _Month|_IndexedWeekday;
2539 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_mwi();
2543 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2546 template<__format::__
char _CharT>
2547 struct formatter<
chrono::month_weekday_last, _CharT>
2549 constexpr typename basic_format_parse_context<_CharT>::iterator
2550 parse(basic_format_parse_context<_CharT>& __pc)
2552 using enum __format::_ChronoParts;
2553 return _M_f._M_parse(__pc, _Month|_Weekday, __defSpec);
2556 template<
typename _Out>
2557 typename basic_format_context<_Out, _CharT>::iterator
2558 format(
const chrono::month_weekday_last& __t,
2559 basic_format_context<_Out, _CharT>& __fc)
const
2561 __format::_ChronoData<_CharT> __cd{};
2562 __cd._M_month = __t.month();
2563 __cd._M_weekday = __t.weekday_last().weekday();
2564 return _M_f._M_format(__cd, __fc);
2568 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2570 using __format::_ChronoFormats;
2571 using enum __format::_ChronoParts;
2573 __format::_ChronoSpec<_CharT> __res{};
2574 __res._M_debug =
true;
2575 __res._M_localized =
true;
2576 __res._M_locale_specific =
true;
2577 __res._M_needed = _Month|_Weekday;
2578 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_mwl();
2582 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2585 template<__format::__
char _CharT>
2586 struct formatter<
chrono::year_month, _CharT>
2588 constexpr typename basic_format_parse_context<_CharT>::iterator
2589 parse(basic_format_parse_context<_CharT>& __pc)
2591 using enum __format::_ChronoParts;
2592 return _M_f._M_parse(__pc, _Year|_Month, __defSpec);
2595 template<
typename _Out>
2596 typename basic_format_context<_Out, _CharT>::iterator
2597 format(
const chrono::year_month& __t,
2598 basic_format_context<_Out, _CharT>& __fc)
const
2600 __format::_ChronoData<_CharT> __cd{};
2601 __cd._M_fill_year_month(__t, __defSpec._M_needed);
2602 return _M_f._M_format(__cd, __fc);
2606 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2608 using __format::_ChronoFormats;
2609 using enum __format::_ChronoParts;
2611 __format::_ChronoSpec<_CharT> __res{};
2612 __res._M_debug =
true;
2613 __res._M_localized =
true;
2614 __res._M_locale_specific =
true;
2615 __res._M_needed = _Year|_Month;
2616 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ym();
2620 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2623 template<__format::__
char _CharT>
2624 struct formatter<
chrono::year_month_day, _CharT>
2626 constexpr typename basic_format_parse_context<_CharT>::iterator
2627 parse(basic_format_parse_context<_CharT>& __pc)
2629 using enum __format::_ChronoParts;
2630 return _M_f._M_parse(__pc, _Date, __defSpec);
2633 template<
typename _Out>
2634 typename basic_format_context<_Out, _CharT>::iterator
2635 format(
const chrono::year_month_day& __t,
2636 basic_format_context<_Out, _CharT>& __fc)
const
2638 __format::_ChronoData<_CharT> __cd{};
2639 auto __parts = _M_f._M_spec._M_needed;
2640 __parts = __cd._M_fill_year_month(__t, __parts);
2641 __parts = __cd._M_fill_day(__t.day(), __parts);
2643 return _M_f._M_format(__cd, __fc);
2645 chrono::local_days __ld(__t);
2646 __cd._M_fill_ldays(__ld, __parts);
2647 return _M_f._M_format(__cd, __fc);
2651 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2653 using __format::_ChronoFormats;
2654 using enum __format::_ChronoParts;
2656 __format::_ChronoSpec<_CharT> __res{};
2657 __res._M_debug =
true;
2658 __res._M_needed = _YearMonthDay;
2659 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_f();
2663 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2666 template<__format::__
char _CharT>
2667 struct formatter<
chrono::year_month_day_last, _CharT>
2669 constexpr typename basic_format_parse_context<_CharT>::iterator
2670 parse(basic_format_parse_context<_CharT>& __pc)
2672 using enum __format::_ChronoParts;
2673 return _M_f._M_parse(__pc, _Date, __defSpec);
2676 template<
typename _Out>
2677 typename basic_format_context<_Out, _CharT>::iterator
2678 format(
const chrono::year_month_day_last& __t,
2679 basic_format_context<_Out, _CharT>& __fc)
const
2681 __format::_ChronoData<_CharT> __cd{};
2682 auto __parts = _M_f._M_spec._M_needed;
2683 __parts = __cd._M_fill_year_month(__t, __parts);
2685 return _M_f._M_format(__cd, __fc);
2687 chrono::local_days __ld(__t);
2688 __parts = __cd._M_fill_ldays(__ld, __parts);
2690 return _M_f._M_format(__cd, __fc);
2692 chrono::year_month_day __ymd(__ld);
2693 __cd._M_fill_day(__ymd.day(), __parts);
2694 return _M_f._M_format(__cd, __fc);
2698 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2700 using __format::_ChronoFormats;
2701 using enum __format::_ChronoParts;
2703 __format::_ChronoSpec<_CharT> __res{};
2704 __res._M_debug =
true;
2705 __res._M_localized =
true;
2706 __res._M_locale_specific =
true;
2707 __res._M_needed = _Year|_Month;
2708 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_yml();
2712 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2715 template<__format::__
char _CharT>
2716 struct formatter<
chrono::year_month_weekday, _CharT>
2718 constexpr typename basic_format_parse_context<_CharT>::iterator
2719 parse(basic_format_parse_context<_CharT>& __pc)
2721 using enum __format::_ChronoParts;
2722 return _M_f._M_parse(__pc, _Date, __defSpec);
2725 template<
typename _Out>
2726 typename basic_format_context<_Out, _CharT>::iterator
2727 format(
const chrono::year_month_weekday& __t,
2728 basic_format_context<_Out, _CharT>& __fc)
const
2730 __format::_ChronoData<_CharT> __cd{};
2731 auto __parts = _M_f._M_spec._M_needed;
2732 __parts = __cd._M_fill_year_month(__t, __parts);
2733 __parts = __cd._M_fill_weekday(__t.weekday_indexed(), __parts);
2735 return _M_f._M_format(__cd, __fc);
2737 chrono::local_days __ld(__t);
2738 __parts = __cd._M_fill_ldays(__ld, __parts);
2740 return _M_f._M_format(__cd, __fc);
2742 chrono::year_month_day __ymd(__ld);
2744 __cd._M_day = __ymd.day();
2745 return _M_f._M_format(__cd, __fc);
2749 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2751 using __format::_ChronoFormats;
2752 using enum __format::_ChronoParts;
2754 __format::_ChronoSpec<_CharT> __res{};
2755 __res._M_debug =
true;
2756 __res._M_localized =
true;
2757 __res._M_locale_specific =
true;
2758 __res._M_needed = _Year|_Month|_IndexedWeekday;
2759 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ymwi();
2763 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2766 template<__format::__
char _CharT>
2767 struct formatter<
chrono::year_month_weekday_last, _CharT>
2769 constexpr typename basic_format_parse_context<_CharT>::iterator
2770 parse(basic_format_parse_context<_CharT>& __pc)
2772 using enum __format::_ChronoParts;
2773 return _M_f._M_parse(__pc, _Date, __defSpec);
2776 template<
typename _Out>
2777 typename basic_format_context<_Out, _CharT>::iterator
2778 format(
const chrono::year_month_weekday_last& __t,
2779 basic_format_context<_Out, _CharT>& __fc)
const
2781 __format::_ChronoData<_CharT> __cd{};
2782 auto __parts = _M_f._M_spec._M_needed;
2783 __parts = __cd._M_fill_year_month(__t, __parts);
2784 __cd._M_weekday = __t.weekday_last().weekday();
2785 __parts -= __format::_ChronoParts::_Weekday;
2787 return _M_f._M_format(__cd, __fc);
2789 chrono::local_days __ld(__t);
2790 __parts = __cd._M_fill_ldays(__ld, __parts);
2792 return _M_f._M_format(__cd, __fc);
2794 chrono::year_month_day __ymd(__ld);
2795 __cd._M_fill_day(__ymd.day(), __parts);
2796 return _M_f._M_format(__cd, __fc);
2800 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2802 using __format::_ChronoFormats;
2803 using enum __format::_ChronoParts;
2805 __format::_ChronoSpec<_CharT> __res{};
2806 __res._M_debug =
true;
2807 __res._M_localized =
true;
2808 __res._M_locale_specific =
true;
2809 __res._M_needed = _Year|_Month|_Weekday;
2810 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ymwl();
2814 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2817 template<
typename _Rep,
typename _Period, __format::__
char _CharT>
2818 struct formatter<
chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>, _CharT>
2820 constexpr typename basic_format_parse_context<_CharT>::iterator
2821 parse(basic_format_parse_context<_CharT>& __pc)
2823 using enum __format::_ChronoParts;
2824 return _M_f.template _M_parse<_Precision>(__pc, _Time, __defSpec);
2827 template<
typename _Out>
2828 typename basic_format_context<_Out, _CharT>::iterator
2829 format(
const chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>& __t,
2830 basic_format_context<_Out, _CharT>& __fc)
const
2832 using enum __format::_ChronoParts;
2834 __format::_ChronoData<_CharT> __cd;
2835 __cd._M_is_neg = __t.is_negative();
2836 __cd._M_hours = __t.hours();
2837 __cd._M_minutes = __t.minutes();
2838 __cd._M_seconds = __t.seconds();
2843 if (_M_f._M_spec._M_needs(_EpochUnits))
2844 __d = __t.to_duration();
2845 if (_M_f._M_spec._M_needs(_TotalSeconds))
2847 = __cd._M_hours + __cd._M_minutes + __cd._M_seconds;
2848 return _M_f._M_format_units(__cd, __d, __t.subseconds(), __fc);
2853 =
typename chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>::precision;
2854 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
2855 __format::__formatter_duration<_CharT>::
2856 template _S_spec_for<_Precision>(__format::_ChronoParts::_Time);
2858 __format::__formatter_duration<_CharT> _M_f{__defSpec};
2861#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2862 template<__format::__
char _CharT>
2863 struct formatter<
chrono::sys_info, _CharT>
2865 constexpr typename basic_format_parse_context<_CharT>::iterator
2866 parse(basic_format_parse_context<_CharT>& __pc)
2867 {
return _M_f.parse(__pc); }
2869 template<
typename _Out>
2870 typename basic_format_context<_Out, _CharT>::iterator
2871 format(
const chrono::sys_info& __i,
2872 basic_format_context<_Out, _CharT>& __fc)
const
2873 {
return _M_f.format(__i, __fc); }
2876 __format::__formatter_chrono_info<_CharT> _M_f;
2879 template<__format::__
char _CharT>
2880 struct formatter<
chrono::local_info, _CharT>
2882 constexpr typename basic_format_parse_context<_CharT>::iterator
2883 parse(basic_format_parse_context<_CharT>& __pc)
2884 {
return _M_f.parse(__pc); }
2886 template<
typename _Out>
2887 typename basic_format_context<_Out, _CharT>::iterator
2888 format(
const chrono::local_info& __i,
2889 basic_format_context<_Out, _CharT>& __fc)
const
2890 {
return _M_f.format(__i, __fc); }
2893 __format::__formatter_chrono_info<_CharT> _M_f;
2897 template<
typename _Duration, __format::__
char _CharT>
2898 struct formatter<
chrono::sys_time<_Duration>, _CharT>
2900 constexpr typename basic_format_parse_context<_CharT>::iterator
2901 parse(basic_format_parse_context<_CharT>& __pc)
2903 using enum __format::_ChronoParts;
2905 = _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
2906 if constexpr (!__stream_insertable)
2907 if (_M_f._M_spec._M_chrono_specs.empty())
2908 __format::__invalid_chrono_spec();
2912 template<
typename _Out>
2913 typename basic_format_context<_Out, _CharT>::iterator
2914 format(
const chrono::sys_time<_Duration>& __t,
2915 basic_format_context<_Out, _CharT>& __fc)
const
2917 __format::_ChronoData<_CharT> __cd{};
2918 __cd._M_fill_utc_zone();
2920 _Duration __ed = __t.time_since_epoch();
2921 __cd._M_eseconds = chrono::floor<chrono::seconds>(__ed);
2922 __cd._M_lseconds = chrono::local_seconds(__cd._M_eseconds);
2923 return _M_f._M_format_time_point(__cd, __ed, __fc);
2927 static constexpr bool __stream_insertable
2928 =
requires (basic_ostream<_CharT>& __os,
2929 chrono::sys_time<_Duration> __t) { __os << __t; };
2931 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2933 using enum __format::_ChronoParts;
2934 __format::_ChronoParts __needed = _DateTime;
2935 if constexpr (!__stream_insertable)
2937 else if constexpr (is_convertible_v<_Duration, chrono::days>)
2939 return __format::__formatter_duration<_CharT>::
2940 template _S_spec_for<_Duration>(__needed);
2943 __format::__formatter_duration<_CharT> _M_f{__defSpec};
2946 template<
typename _Duration, __format::__
char _CharT>
2947 struct formatter<
chrono::utc_time<_Duration>, _CharT>
2948 : __format::__formatter_chrono<_CharT>
2950 constexpr typename basic_format_parse_context<_CharT>::iterator
2951 parse(basic_format_parse_context<_CharT>& __pc)
2953 using enum __format::_ChronoParts;
2954 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
2957 template<
typename _Out>
2958 typename basic_format_context<_Out, _CharT>::iterator
2959 format(
const chrono::utc_time<_Duration>& __t,
2960 basic_format_context<_Out, _CharT>& __fc)
const
2962 using __format::_ChronoParts;
2963 using namespace chrono;
2964 __format::_ChronoData<_CharT> __cd{};
2965 __cd._M_fill_utc_zone();
2967 _Duration __ed = __t.time_since_epoch();
2968 __cd._M_eseconds = chrono::floor<seconds>(__ed);
2972 const auto __li = chrono::get_leap_second_info(__t);
2973 __cd._M_lseconds = local_seconds(__cd._M_eseconds - __li.elapsed);
2974 auto __parts = _M_f._M_spec._M_needed - _ChronoParts::_TotalSeconds;
2975 if ((__parts & _ChronoParts::_DateTime) != 0)
2977 __cd._M_fill_date_time(__cd._M_lseconds, __parts);
2978 __cd._M_seconds +=
seconds(__li.is_leap_second);
2980 return _M_f._M_format_units(__cd, __ed, __ed - __cd._M_eseconds, __fc);
2984 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
2985 __format::__formatter_duration<_CharT>::
2986 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
2988 __format::__formatter_duration<_CharT> _M_f{__defSpec};
2991 template<
typename _Duration, __format::__
char _CharT>
2992 struct formatter<
chrono::tai_time<_Duration>, _CharT>
2993 : __format::__formatter_chrono<_CharT>
2995 constexpr typename basic_format_parse_context<_CharT>::iterator
2996 parse(basic_format_parse_context<_CharT>& __pc)
2998 using enum __format::_ChronoParts;
2999 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3002 template<
typename _Out>
3003 typename basic_format_context<_Out, _CharT>::iterator
3004 format(
const chrono::tai_time<_Duration>& __t,
3005 basic_format_context<_Out, _CharT>& __fc)
const
3007 using namespace chrono;
3008 __format::_ChronoData<_CharT> __cd{};
3009 __cd._M_fill_zone(
"TAI", L
"TAI");
3011 _Duration __ed = __t.time_since_epoch();
3012 __cd._M_eseconds = chrono::floor<seconds>(__ed);
3014 constexpr chrono::days __tai_offset = chrono::days(4383);
3015 __cd._M_lseconds = local_seconds(__cd._M_eseconds - __tai_offset);
3016 return _M_f._M_format_time_point(__cd, __ed, __fc);
3020 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3021 __format::__formatter_duration<_CharT>::
3022 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3024 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3027 template<
typename _Duration, __format::__
char _CharT>
3028 struct formatter<
chrono::gps_time<_Duration>, _CharT>
3029 : __format::__formatter_chrono<_CharT>
3031 constexpr typename basic_format_parse_context<_CharT>::iterator
3032 parse(basic_format_parse_context<_CharT>& __pc)
3034 using enum __format::_ChronoParts;
3035 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3038 template<
typename _Out>
3039 typename basic_format_context<_Out, _CharT>::iterator
3040 format(
const chrono::gps_time<_Duration>& __t,
3041 basic_format_context<_Out, _CharT>& __fc)
const
3043 using namespace chrono;
3044 __format::_ChronoData<_CharT> __cd{};
3045 __cd._M_fill_zone(
"GPS", L
"GPS");
3047 _Duration __ed = __t.time_since_epoch();
3048 __cd._M_eseconds = chrono::floor<seconds>(__ed);
3050 constexpr chrono::days __gps_offset = chrono::days(3657);
3051 __cd._M_lseconds = local_seconds(__cd._M_eseconds + __gps_offset);
3052 return _M_f._M_format_time_point(__cd, __ed, __fc);
3056 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3057 __format::__formatter_duration<_CharT>::
3058 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3060 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3063 template<
typename _Duration, __format::__
char _CharT>
3064 struct formatter<
chrono::file_time<_Duration>, _CharT>
3066 constexpr typename basic_format_parse_context<_CharT>::iterator
3067 parse(basic_format_parse_context<_CharT>& __pc)
3069 using enum __format::_ChronoParts;
3070 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3073 template<
typename _Out>
3074 typename basic_format_context<_Out, _CharT>::iterator
3075 format(
const chrono::file_time<_Duration>& __t,
3076 basic_format_context<_Out, _CharT>& __fc)
const
3078 using namespace chrono;
3079 __format::_ChronoData<_CharT> __cd{};
3080 __cd._M_fill_utc_zone();
3082 _Duration __ed = __t.time_since_epoch();
3083 __cd._M_eseconds = chrono::floor<seconds>(__ed);
3084 auto __st = chrono::clock_cast<system_clock>(__t);
3086 = local_seconds(chrono::floor<seconds>(__st.time_since_epoch()));
3087 return _M_f._M_format_time_point(__cd, __ed, __fc);
3091 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3092 __format::__formatter_duration<_CharT>::
3093 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3095 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3098 template<
typename _Duration, __format::__
char _CharT>
3099 struct formatter<
chrono::local_time<_Duration>, _CharT>
3101 constexpr typename basic_format_parse_context<_CharT>::iterator
3102 parse(basic_format_parse_context<_CharT>& __pc)
3104 using enum __format::_ChronoParts;
3105 return _M_f.template _M_parse<_Duration>(__pc, _DateTime, __defSpec);
3108 template<
typename _Out>
3109 typename basic_format_context<_Out, _CharT>::iterator
3110 format(
const chrono::local_time<_Duration>& __lt,
3111 basic_format_context<_Out, _CharT>& __fc)
const
3113 __format::_ChronoData<_CharT> __cd{};
3114 _Duration __ed = __lt.time_since_epoch();
3115 __cd._M_lseconds = chrono::floor<chrono::seconds>(__lt);
3116 __cd._M_eseconds = __cd._M_lseconds.time_since_epoch();
3117 return _M_f._M_format_time_point(__cd, __ed, __fc);
3121 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
3123 using enum __format::_ChronoParts;
3124 __format::_ChronoParts __needed = _DateTime;
3125 if constexpr (is_convertible_v<_Duration, chrono::days>)
3127 return __format::__formatter_duration<_CharT>::
3128 template _S_spec_for<_Duration>(__needed);
3131 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3134 template<
typename _Duration, __format::__
char _CharT>
3135 struct formatter<
chrono::__detail::__local_time_fmt<_Duration>, _CharT>
3137 constexpr typename basic_format_parse_context<_CharT>::iterator
3138 parse(basic_format_parse_context<_CharT>& __pc)
3140 using enum __format::_ChronoParts;
3141 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3144 template<
typename _Out>
3145 typename basic_format_context<_Out, _CharT>::iterator
3146 format(
const chrono::__detail::__local_time_fmt<_Duration>& __zt,
3147 basic_format_context<_Out, _CharT>& __fc)
const
3149 using enum __format::_ChronoParts;
3150 __format::_ChronoData<_CharT> __cd{};
3152 if (_M_f._M_spec._M_needs(_ZoneOffset))
3154 if (!__zt._M_offset_sec)
3155 std::__throw_format_error(
"format error: no timezone available for %z");
3156 __cd._M_zone_offset = *__zt._M_offset_sec;
3159 basic_string<_CharT> __zone_store;
3160 if (_M_f._M_spec._M_needs(_ZoneAbbrev))
3162 if (!__zt._M_abbrev)
3163 std::__throw_format_error(
"format error: no timezone available for %Z");
3165 __cd._M_zone_cstr = __zt._M_abbrev->data();
3166 if constexpr (is_same_v<_CharT, char>)
3167 __cd._M_zone_abbrev = *__zt._M_abbrev;
3171 __zone_store.resize(__zt._M_abbrev->size());
3172 auto& __ct = use_facet<ctype<_CharT>>(_M_f._M_locale(__fc));
3173 __ct.widen(__zt._M_abbrev->data(),
3174 __zt._M_abbrev->data() + __zt._M_abbrev->size(),
3175 __zone_store.data());
3176 __cd._M_zone_abbrev = __zone_store;
3180 _Duration __ed = __zt._M_time.time_since_epoch();
3181 __cd._M_lseconds = chrono::floor<chrono::seconds>(__zt._M_time);
3182 __cd._M_eseconds = __cd._M_lseconds.time_since_epoch();
3183 return _M_f._M_format_time_point(__cd, __ed, __fc);
3187 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3188 __format::__formatter_duration<_CharT>::
3189 template _S_spec_for<_Duration>(__format::_ChronoParts::_ZonedDateTime);
3191 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3194#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
3195 template<
typename _Duration,
typename _TimeZonePtr, __format::__
char _CharT>
3196 struct formatter<
chrono::zoned_time<_Duration, _TimeZonePtr>, _CharT>
3197 : formatter<chrono::__detail::__local_time_fmt_for<_Duration>, _CharT>
3199 template<
typename _Out>
3200 typename basic_format_context<_Out, _CharT>::iterator
3201 format(
const chrono::zoned_time<_Duration, _TimeZonePtr>& __tp,
3202 basic_format_context<_Out, _CharT>& __fc)
const
3204 using _Ltf = chrono::__detail::__local_time_fmt_for<_Duration>;
3205 using _Base = formatter<_Ltf, _CharT>;
3206 const chrono::sys_info __info = __tp.get_info();
3207 const auto __lf = chrono::local_time_format(__tp.get_local_time(),
3210 return _Base::format(__lf, __fc);
3223 template<
typename _Duration = seconds>
3226 static_assert(is_same_v<common_type_t<_Duration, seconds>, _Duration>);
3229 _Parser(__format::_ChronoParts __need) : _M_need(__need) { }
3231 _Parser(_Parser&&) =
delete;
3232 void operator=(_Parser&&) =
delete;
3234 _Duration _M_time{};
3235 sys_days _M_sys_days{};
3236 year_month_day _M_ymd{};
3238 __format::_ChronoParts _M_need;
3239 unsigned _M_is_leap_second : 1 {};
3240 unsigned _M_reserved : 15 {};
3242 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3243 basic_istream<_CharT, _Traits>&
3244 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3245 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3246 minutes* __offset =
nullptr);
3251 template<
typename _CharT,
typename _Traits>
3252 static int_least32_t
3253 _S_read_unsigned(basic_istream<_CharT, _Traits>& __is,
3254 ios_base::iostate& __err,
int __n)
3256 int_least32_t __val = _S_try_read_digit(__is, __err);
3257 if (__val == -1) [[unlikely]]
3258 __err |= ios_base::failbit;
3263 for (
int __i = 1; __i < __n1; ++__i)
3264 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
3270 while (__n1++ < __n) [[unlikely]]
3271 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
3273 if (__builtin_mul_overflow(__val, 10, &__val)
3274 || __builtin_add_overflow(__val, __dig, &__val))
3276 __err |= ios_base::failbit;
3286 template<
typename _CharT,
typename _Traits>
3287 static int_least32_t
3288 _S_read_signed(basic_istream<_CharT, _Traits>& __is,
3289 ios_base::iostate& __err,
int __n)
3291 auto __sign = __is.peek();
3292 if (__sign ==
'-' || __sign ==
'+')
3294 int_least32_t __val = _S_read_unsigned(__is, __err, __n);
3295 if (__err & ios_base::failbit)
3297 if (__sign ==
'-') [[unlikely]]
3305 template<
typename _CharT,
typename _Traits>
3306 static int_least32_t
3307 _S_try_read_digit(basic_istream<_CharT, _Traits>& __is,
3308 ios_base::iostate& __err)
3310 int_least32_t __val = -1;
3311 auto __i = __is.peek();
3312 if (!_Traits::eq_int_type(__i, _Traits::eof())) [[likely]]
3314 _CharT __c = _Traits::to_char_type(__i);
3315 if (_CharT(
'0') <= __c && __c <= _CharT(
'9')) [[likely]]
3318 __val = __c - _CharT(
'0');
3322 __err |= ios_base::eofbit;
3328 template<
typename _CharT,
typename _Traits>
3330 _S_read_chr(basic_istream<_CharT, _Traits>& __is,
3331 ios_base::iostate& __err, _CharT __c)
3333 auto __i = __is.peek();
3334 if (_Traits::eq_int_type(__i, _Traits::eof()))
3335 __err |= ios_base::eofbit;
3336 else if (_Traits::to_char_type(__i) == __c) [[likely]]
3341 __err |= ios_base::failbit;
3346 template<
typename _Duration>
3347 using _Parser_t = _Parser<common_type_t<_Duration, seconds>>;
3349 template<
typename _Duration>
3353 if constexpr (_Duration::period::den == 1)
3355 switch (_Duration::period::num)
3357 case minutes::period::num:
3358 case hours::period::num:
3359 case days::period::num:
3360 case weeks::period::num:
3361 case years::period::num:
3378 template<
typename _ToDur,
typename _Tp>
3380 __round(
const _Tp& __t)
3382 if constexpr (__is_duration_v<_Tp>)
3384 if constexpr (treat_as_floating_point_v<typename _Tp::rep>)
3386 else if constexpr (__detail::__use_floor<_ToDur>())
3393 static_assert(__is_time_point_v<_Tp>);
3394 using _Tpt = time_point<typename _Tp::clock, _ToDur>;
3395 return _Tpt(__detail::__round<_ToDur>(__t.time_since_epoch()));
3402 template<
typename _CharT,
typename _Traits,
typename _Rep,
typename _Period,
3403 typename _Alloc = allocator<_CharT>>
3404 inline basic_istream<_CharT, _Traits>&
3405 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3407 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3410 auto __need = __format::_ChronoParts::_TimeOfDay;
3411 __detail::_Parser_t<duration<_Rep, _Period>> __p(__need);
3412 if (__p(__is, __fmt, __abbrev, __offset))
3413 __d = __detail::__round<duration<_Rep, _Period>>(__p._M_time);
3417 template<
typename _CharT,
typename _Traits>
3418 inline basic_ostream<_CharT, _Traits>&
3419 operator<<(basic_ostream<_CharT, _Traits>& __os,
const day& __d)
3421 using _Ctx = __format::__format_context<_CharT>;
3422 using _Str = basic_string_view<_CharT>;
3423 _Str __s = _GLIBCXX_WIDEN(
"{:02d} is not a valid day");
3425 __s = __s.substr(0, 6);
3426 auto __u = (unsigned)__d;
3427 __os << std::vformat(__s, make_format_args<_Ctx>(__u));
3431 template<
typename _CharT,
typename _Traits,
3432 typename _Alloc = allocator<_CharT>>
3433 inline basic_istream<_CharT, _Traits>&
3434 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3436 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3439 __detail::_Parser<> __p(__format::_ChronoParts::_Day);
3440 if (__p(__is, __fmt, __abbrev, __offset))
3441 __d = __p._M_ymd.day();
3445 template<
typename _CharT,
typename _Traits>
3446 inline basic_ostream<_CharT, _Traits>&
3447 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month& __m)
3449 using _Ctx = __format::__format_context<_CharT>;
3450 using _Str = basic_string_view<_CharT>;
3451 _Str __s = _GLIBCXX_WIDEN(
"{:L%b}{} is not a valid month");
3453 __os << std::vformat(__os.getloc(), __s.substr(0, 6),
3454 make_format_args<_Ctx>(__m));
3457 auto __u = (unsigned)__m;
3458 __os << std::vformat(__s.substr(6), make_format_args<_Ctx>(__u));
3463 template<
typename _CharT,
typename _Traits,
3464 typename _Alloc = allocator<_CharT>>
3465 inline basic_istream<_CharT, _Traits>&
3466 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3468 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3471 __detail::_Parser<> __p(__format::_ChronoParts::_Month);
3472 if (__p(__is, __fmt, __abbrev, __offset))
3473 __m = __p._M_ymd.month();
3477 template<
typename _CharT,
typename _Traits>
3478 inline basic_ostream<_CharT, _Traits>&
3479 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year& __y)
3481 using _Ctx = __format::__format_context<_CharT>;
3482 using _Str = basic_string_view<_CharT>;
3483 _Str __s = _GLIBCXX_WIDEN(
"-{:04d} is not a valid year");
3485 __s = __s.substr(0, 7);
3487 if (__i >= 0) [[likely]]
3488 __s.remove_prefix(1);
3491 __os << std::vformat(__s, make_format_args<_Ctx>(__i));
3495 template<
typename _CharT,
typename _Traits,
3496 typename _Alloc = allocator<_CharT>>
3497 inline basic_istream<_CharT, _Traits>&
3498 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3500 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3503 __detail::_Parser<> __p(__format::_ChronoParts::_Year);
3504 if (__p(__is, __fmt, __abbrev, __offset))
3505 __y = __p._M_ymd.year();
3509 template<
typename _CharT,
typename _Traits>
3510 inline basic_ostream<_CharT, _Traits>&
3511 operator<<(basic_ostream<_CharT, _Traits>& __os,
const weekday& __wd)
3513 using _Ctx = __format::__format_context<_CharT>;
3514 using _Str = basic_string_view<_CharT>;
3515 _Str __s = _GLIBCXX_WIDEN(
"{:L%a}{} is not a valid weekday");
3517 __os << std::vformat(__os.getloc(), __s.substr(0, 6),
3518 make_format_args<_Ctx>(__wd));
3521 auto __c = __wd.c_encoding();
3522 __os << std::vformat(__s.substr(6), make_format_args<_Ctx>(__c));
3527 template<
typename _CharT,
typename _Traits,
3528 typename _Alloc = allocator<_CharT>>
3529 inline basic_istream<_CharT, _Traits>&
3530 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3532 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3535 __detail::_Parser<> __p(__format::_ChronoParts::_Weekday);
3536 if (__p(__is, __fmt, __abbrev, __offset))
3541 template<
typename _CharT,
typename _Traits>
3542 inline basic_ostream<_CharT, _Traits>&
3543 operator<<(basic_ostream<_CharT, _Traits>& __os,
3544 const weekday_indexed& __wdi)
3549 basic_stringstream<_CharT> __os2;
3550 __os2.imbue(__os.getloc());
3551 __os2 << __wdi.weekday();
3552 const auto __i = __wdi.index();
3553 basic_string_view<_CharT> __s
3554 = _GLIBCXX_WIDEN(
"[ is not a valid index]");
3556 __os2 << std::format(_GLIBCXX_WIDEN(
"{}"), __i);
3557 if (__i >= 1 && __i <= 5)
3558 __os2 << __s.back();
3560 __os2 << __s.substr(1);
3561 __os << __os2.view();
3565 template<
typename _CharT,
typename _Traits>
3566 inline basic_ostream<_CharT, _Traits>&
3567 operator<<(basic_ostream<_CharT, _Traits>& __os,
3568 const weekday_last& __wdl)
3571 basic_stringstream<_CharT> __os2;
3572 __os2.imbue(__os.getloc());
3573 __os2 << __wdl.weekday() << _GLIBCXX_WIDEN(
"[last]");
3574 __os << __os2.view();
3578 template<
typename _CharT,
typename _Traits>
3579 inline basic_ostream<_CharT, _Traits>&
3580 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month_day& __md)
3583 basic_stringstream<_CharT> __os2;
3584 __os2.imbue(__os.getloc());
3585 __os2 << __md.month();
3586 if constexpr (is_same_v<_CharT, char>)
3590 __os2 << __md.day();
3591 __os << __os2.view();
3595 template<
typename _CharT,
typename _Traits,
3596 typename _Alloc = allocator<_CharT>>
3597 inline basic_istream<_CharT, _Traits>&
3598 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3600 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3603 using __format::_ChronoParts;
3604 auto __need = _ChronoParts::_Month | _ChronoParts::_Day;
3605 __detail::_Parser<> __p(__need);
3606 if (__p(__is, __fmt, __abbrev, __offset))
3607 __md = month_day(__p._M_ymd.month(), __p._M_ymd.day());
3611 template<
typename _CharT,
typename _Traits>
3612 inline basic_ostream<_CharT, _Traits>&
3613 operator<<(basic_ostream<_CharT, _Traits>& __os,
3614 const month_day_last& __mdl)
3617 basic_stringstream<_CharT> __os2;
3618 __os2.imbue(__os.getloc());
3619 __os2 << __mdl.month() << _GLIBCXX_WIDEN(
"/last");
3620 __os << __os2.view();
3624 template<
typename _CharT,
typename _Traits>
3625 inline basic_ostream<_CharT, _Traits>&
3626 operator<<(basic_ostream<_CharT, _Traits>& __os,
3627 const month_weekday& __mwd)
3630 basic_stringstream<_CharT> __os2;
3631 __os2.imbue(__os.getloc());
3632 __os2 << __mwd.month();
3633 if constexpr (is_same_v<_CharT, char>)
3637 __os2 << __mwd.weekday_indexed();
3638 __os << __os2.view();
3642 template<
typename _CharT,
typename _Traits>
3643 inline basic_ostream<_CharT, _Traits>&
3644 operator<<(basic_ostream<_CharT, _Traits>& __os,
3645 const month_weekday_last& __mwdl)
3648 basic_stringstream<_CharT> __os2;
3649 __os2.imbue(__os.getloc());
3650 __os2 << __mwdl.month();
3651 if constexpr (is_same_v<_CharT, char>)
3655 __os2 << __mwdl.weekday_last();
3656 __os << __os2.view();
3660 template<
typename _CharT,
typename _Traits>
3661 inline basic_ostream<_CharT, _Traits>&
3662 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year_month& __ym)
3665 basic_stringstream<_CharT> __os2;
3666 __os2.imbue(__os.getloc());
3667 __os2 << __ym.year();
3668 if constexpr (is_same_v<_CharT, char>)
3672 __os2 << __ym.month();
3673 __os << __os2.view();
3677 template<
typename _CharT,
typename _Traits,
3678 typename _Alloc = allocator<_CharT>>
3679 inline basic_istream<_CharT, _Traits>&
3680 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3682 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3685 using __format::_ChronoParts;
3686 auto __need = _ChronoParts::_Year | _ChronoParts::_Month;
3687 __detail::_Parser<> __p(__need);
3688 if (__p(__is, __fmt, __abbrev, __offset))
3689 __ym = year_month(__p._M_ymd.year(), __p._M_ymd.month());
3693 template<
typename _CharT,
typename _Traits>
3694 inline basic_ostream<_CharT, _Traits>&
3695 operator<<(basic_ostream<_CharT, _Traits>& __os,
3696 const year_month_day& __ymd)
3698 using _Ctx = __format::__format_context<_CharT>;
3699 using _Str = basic_string_view<_CharT>;
3700 _Str __s = _GLIBCXX_WIDEN(
"{:%F} is not a valid date");
3701 __os << std::vformat(__ymd.ok() ? __s.substr(0, 5) : __s,
3702 make_format_args<_Ctx>(__ymd));
3706 template<
typename _CharT,
typename _Traits,
3707 typename _Alloc = allocator<_CharT>>
3708 inline basic_istream<_CharT, _Traits>&
3710 year_month_day& __ymd,
3714 using __format::_ChronoParts;
3715 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3716 | _ChronoParts::_Day;
3717 __detail::_Parser<> __p(__need);
3718 if (__p(__is, __fmt, __abbrev, __offset))
3723 template<
typename _CharT,
typename _Traits>
3726 const year_month_day_last& __ymdl)
3731 __os2 << __ymdl.year();
3732 if constexpr (is_same_v<_CharT, char>)
3736 __os2 << __ymdl.month_day_last();
3737 __os << __os2.view();
3741 template<
typename _CharT,
typename _Traits>
3742 inline basic_ostream<_CharT, _Traits>&
3743 operator<<(basic_ostream<_CharT, _Traits>& __os,
3744 const year_month_weekday& __ymwd)
3748 basic_stringstream<_CharT> __os2;
3749 __os2.
imbue(__os.getloc());
3751 if constexpr (is_same_v<_CharT, char>)
3755 __os2 << __ymwd.year() << __slash << __ymwd.month() << __slash
3756 << __ymwd.weekday_indexed();
3757 __os << __os2.view();
3761 template<
typename _CharT,
typename _Traits>
3762 inline basic_ostream<_CharT, _Traits>&
3763 operator<<(basic_ostream<_CharT, _Traits>& __os,
3764 const year_month_weekday_last& __ymwdl)
3768 basic_stringstream<_CharT> __os2;
3769 __os2.imbue(__os.getloc());
3771 if constexpr (is_same_v<_CharT, char>)
3775 __os2 << __ymwdl.year() << __slash << __ymwdl.month() << __slash
3776 << __ymwdl.weekday_last();
3777 __os << __os2.view();
3781 template<
typename _CharT,
typename _Traits,
typename _Duration>
3782 inline basic_ostream<_CharT, _Traits>&
3783 operator<<(basic_ostream<_CharT, _Traits>& __os,
3786 return __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%T}"), __hms);
3789#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
3791 template<
typename _CharT,
typename _Traits>
3792 basic_ostream<_CharT, _Traits>&
3793 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_info& __i)
3795 return __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{}"), __i);
3799 template<
typename _CharT,
typename _Traits>
3800 basic_ostream<_CharT, _Traits>&
3801 operator<<(basic_ostream<_CharT, _Traits>& __os,
const local_info& __li)
3803 __os << __format::_Separators<_CharT>::_S_squares()[0];
3804 if (__li.result == local_info::unique)
3808 if (__li.result == local_info::nonexistent)
3809 __os << _GLIBCXX_WIDEN(
"nonexistent");
3811 __os << _GLIBCXX_WIDEN(
"ambiguous");
3812 __os << _GLIBCXX_WIDEN(
" local time between ") << __li.first;
3813 __os << _GLIBCXX_WIDEN(
" and ") << __li.second;
3815 __os << __format::_Separators<_CharT>::_S_squares()[1];
3819 template<
typename _CharT,
typename _Traits,
typename _Duration,
3820 typename _TimeZonePtr>
3821 inline basic_ostream<_CharT, _Traits>&
3822 operator<<(basic_ostream<_CharT, _Traits>& __os,
3823 const zoned_time<_Duration, _TimeZonePtr>& __t)
3825 __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T %Z}"), __t);
3830 template<
typename _CharT,
typename _Traits,
typename _Duration>
3831 requires (!treat_as_floating_point_v<typename _Duration::rep>)
3832 && ratio_less_v<typename _Duration::period, days::period>
3833 inline basic_ostream<_CharT, _Traits>&
3834 operator<<(basic_ostream<_CharT, _Traits>& __os,
3835 const sys_time<_Duration>& __tp)
3837 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __tp);
3841 template<
typename _CharT,
typename _Traits>
3842 inline basic_ostream<_CharT, _Traits>&
3843 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_days& __dp)
3845 __os << year_month_day{__dp};
3849 template<
typename _CharT,
typename _Traits,
typename _Duration,
3850 typename _Alloc = allocator<_CharT>>
3851 basic_istream<_CharT, _Traits>&
3852 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3853 sys_time<_Duration>& __tp,
3854 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3860 using __format::_ChronoParts;
3861 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3862 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
3863 __detail::_Parser_t<_Duration> __p(__need);
3864 if (__p(__is, __fmt, __abbrev, __offset))
3866 if (__p._M_is_leap_second)
3870 auto __st = __p._M_sys_days + __p._M_time - *__offset;
3871 __tp = __detail::__round<_Duration>(__st);
3877 template<
typename _CharT,
typename _Traits,
typename _Duration>
3878 inline basic_ostream<_CharT, _Traits>&
3879 operator<<(basic_ostream<_CharT, _Traits>& __os,
3880 const utc_time<_Duration>& __t)
3882 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
3886 template<
typename _CharT,
typename _Traits,
typename _Duration,
3887 typename _Alloc = allocator<_CharT>>
3888 inline basic_istream<_CharT, _Traits>&
3889 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3890 utc_time<_Duration>& __tp,
3891 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3897 using __format::_ChronoParts;
3898 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3899 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
3900 __detail::_Parser_t<_Duration> __p(__need);
3901 if (__p(__is, __fmt, __abbrev, __offset))
3905 auto __ut = utc_clock::from_sys(__p._M_sys_days) + __p._M_time
3907 __tp = __detail::__round<_Duration>(__ut);
3912 template<
typename _CharT,
typename _Traits,
typename _Duration>
3913 inline basic_ostream<_CharT, _Traits>&
3914 operator<<(basic_ostream<_CharT, _Traits>& __os,
3915 const tai_time<_Duration>& __t)
3917 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
3921 template<
typename _CharT,
typename _Traits,
typename _Duration,
3922 typename _Alloc = allocator<_CharT>>
3923 inline basic_istream<_CharT, _Traits>&
3924 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3925 tai_time<_Duration>& __tp,
3926 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3932 using __format::_ChronoParts;
3933 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3934 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
3935 __detail::_Parser_t<_Duration> __p(__need);
3936 if (__p(__is, __fmt, __abbrev, __offset))
3938 if (__p._M_is_leap_second)
3942 constexpr sys_days __epoch(-
days(4383));
3943 auto __d = __p._M_sys_days - __epoch + __p._M_time - *__offset;
3944 tai_time<common_type_t<_Duration, seconds>> __tt(__d);
3945 __tp = __detail::__round<_Duration>(__tt);
3951 template<
typename _CharT,
typename _Traits,
typename _Duration>
3952 inline basic_ostream<_CharT, _Traits>&
3953 operator<<(basic_ostream<_CharT, _Traits>& __os,
3954 const gps_time<_Duration>& __t)
3956 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
3960 template<
typename _CharT,
typename _Traits,
typename _Duration,
3961 typename _Alloc = allocator<_CharT>>
3962 inline basic_istream<_CharT, _Traits>&
3963 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3964 gps_time<_Duration>& __tp,
3965 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3971 using __format::_ChronoParts;
3972 auto __need = _ChronoParts::_YearMonthDay | _ChronoParts::_TimeOfDay;
3973 __detail::_Parser_t<_Duration> __p(__need);
3974 if (__p(__is, __fmt, __abbrev, __offset))
3976 if (__p._M_is_leap_second)
3980 constexpr sys_days __epoch(
days(3657));
3981 auto __d = __p._M_sys_days - __epoch + __p._M_time - *__offset;
3982 gps_time<common_type_t<_Duration, seconds>> __gt(__d);
3983 __tp = __detail::__round<_Duration>(__gt);
3989 template<
typename _CharT,
typename _Traits,
typename _Duration>
3990 inline basic_ostream<_CharT, _Traits>&
3991 operator<<(basic_ostream<_CharT, _Traits>& __os,
3992 const file_time<_Duration>& __t)
3994 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
3998 template<
typename _CharT,
typename _Traits,
typename _Duration,
3999 typename _Alloc = allocator<_CharT>>
4000 inline basic_istream<_CharT, _Traits>&
4001 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4002 file_time<_Duration>& __tp,
4003 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4006 sys_time<_Duration> __st;
4007 if (chrono::from_stream(__is, __fmt, __st, __abbrev, __offset))
4008 __tp = __detail::__round<_Duration>(file_clock::from_sys(__st));
4012 template<
typename _CharT,
typename _Traits,
typename _Duration>
4013 inline basic_ostream<_CharT, _Traits>&
4014 operator<<(basic_ostream<_CharT, _Traits>& __os,
4015 const local_time<_Duration>& __lt)
4018 requires requires(
const sys_time<_Duration>& __st) { __os << __st; }
4020 __os << sys_time<_Duration>{__lt.time_since_epoch()};
4024 template<
typename _CharT,
typename _Traits,
typename _Duration,
4025 typename _Alloc = allocator<_CharT>>
4026 basic_istream<_CharT, _Traits>&
4027 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4028 local_time<_Duration>& __tp,
4029 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4032 using __format::_ChronoParts;
4033 auto __need = _ChronoParts::_YearMonthDay | _ChronoParts::_TimeOfDay;
4034 __detail::_Parser_t<_Duration> __p(__need);
4035 if (__p(__is, __fmt, __abbrev, __offset))
4037 days __d = __p._M_sys_days.time_since_epoch();
4038 auto __t = local_days(__d) + __p._M_time;
4039 __tp = __detail::__round<_Duration>(__t);
4050 void from_stream() =
delete;
4052 template<
typename _Parsable,
typename _CharT,
4053 typename _Traits = std::char_traits<_CharT>,
4054 typename... _OptArgs>
4055 concept __parsable =
requires (basic_istream<_CharT, _Traits>& __is,
4056 const _CharT* __fmt, _Parsable& __tp,
4057 _OptArgs*... __args)
4058 { from_stream(__is, __fmt, __tp, __args...); };
4060 template<
typename _Parsable,
typename _CharT,
4061 typename _Traits = char_traits<_CharT>,
4062 typename _Alloc = allocator<_CharT>>
4066 using __string_type = basic_string<_CharT, _Traits, _Alloc>;
4069 _Parse(
const _CharT* __fmt, _Parsable& __tp,
4070 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4073 _M_abbrev(__abbrev), _M_offset(__offset)
4076 _Parse(_Parse&&) =
delete;
4077 _Parse& operator=(_Parse&&) =
delete;
4080 using __stream_type = basic_istream<_CharT, _Traits>;
4082 const _CharT*
const _M_fmt;
4083 _Parsable*
const _M_tp;
4084 __string_type*
const _M_abbrev;
4087 friend __stream_type&
4088 operator>>(__stream_type& __is, _Parse&& __p)
4091 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev,
4093 else if (__p._M_abbrev)
4094 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev);
4096 from_stream(__is, __p._M_fmt, *__p._M_tp);
4100 friend void operator>>(__stream_type&, _Parse&) =
delete;
4101 friend void operator>>(__stream_type&,
const _Parse&) =
delete;
4105 template<
typename _CharT, __detail::__parsable<_CharT> _Parsable>
4106 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4108 parse(
const _CharT* __fmt, _Parsable& __tp)
4109 {
return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp); }
4111 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4112 __detail::__parsable<_CharT, _Traits> _Parsable>
4115 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp)
4117 return __detail::_Parse<_Parsable, _CharT, _Traits>(__fmt.c_str(), __tp);
4120 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4121 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4122 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
4123 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4125 parse(
const _CharT* __fmt, _Parsable& __tp,
4126 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
4129 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
4133 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4134 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4135 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
4138 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
4139 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
4142 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
4146 template<
typename _CharT,
typename _Traits =
char_traits<_CharT>,
4147 typename _StrT = basic_
string<_CharT, _Traits>,
4148 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4149 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4151 parse(
const _CharT* __fmt, _Parsable& __tp,
minutes& __offset)
4153 return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp,
nullptr,
4157 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4158 typename _StrT = basic_string<_CharT, _Traits>,
4159 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4162 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
4165 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
4170 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4171 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4172 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4173 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4175 parse(
const _CharT* __fmt, _Parsable& __tp,
4176 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
4179 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
4184 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4185 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4186 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4189 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
4190 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
4193 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
4199 template<
typename _Duration>
4200 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4201 basic_istream<_CharT, _Traits>&
4202 __detail::_Parser<_Duration>::
4203 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4204 basic_string<_CharT, _Traits, _Alloc>* __abbrev,
4207 using sentry =
typename basic_istream<_CharT, _Traits>::sentry;
4209 if (sentry __cerb(__is,
true); __cerb)
4211 locale __loc = __is.getloc();
4216 struct _Stream_state
4219 _Stream_state(basic_istream<_CharT, _Traits>& __i)
4221 _M_flags(__i.flags(ios_base::
skipws | ios_base::
dec)),
4227 _M_is.flags(_M_flags);
4231 _Stream_state(_Stream_state&&) =
delete;
4233 basic_istream<_CharT, _Traits>& _M_is;
4234 ios_base::fmtflags _M_flags;
4244 auto __read_unsigned = [&] (
int __n) {
4245 return _S_read_unsigned(__is, __err, __n);
4250 auto __read_signed = [&] (
int __n) {
4251 return _S_read_signed(__is, __err, __n);
4255 auto __read_chr = [&__is, &__err] (_CharT __c) {
4256 return _S_read_chr(__is, __err, __c);
4259 using __format::_ChronoParts;
4260 _ChronoParts __parts{};
4262 const year __bad_y = --year::min();
4263 const month __bad_mon(255);
4264 const day __bad_day(255);
4265 const weekday __bad_wday(255);
4266 const hours __bad_h(-1);
4267 const minutes __bad_min(-9999);
4270 year __y = __bad_y, __yy = __bad_y;
4271 year __iso_y = __bad_y, __iso_yy = __bad_y;
4272 month __m = __bad_mon;
4273 day __d = __bad_day;
4274 weekday __wday = __bad_wday;
4275 hours __h = __bad_h, __h12 = __bad_h;
4277 _Duration __s = __bad_sec;
4279 int __iso_wk = -1, __sunday_wk = -1, __monday_wk = -1;
4281 int __dayofyear = -1;
4283 minutes __tz_offset = __bad_min;
4284 basic_string<_CharT, _Traits> __tz_abbr;
4286 if ((_M_need & _ChronoParts::_TimeOfDay) != 0
4287 && (_M_need & _ChronoParts::_Year) != 0)
4293 __parts = _ChronoParts::_TimeOfDay;
4300 bool __is_flag =
false;
4302 constexpr bool __is_floating
4303 = treat_as_floating_point_v<typename _Duration::rep>;
4322 _CharT __c = *__fmt++;
4329 else if (!__read_chr(__c)) [[unlikely]]
4340 if (__mod || __num) [[unlikely]]
4345 __tmget.get(__is, {}, __is, __err, &__tm,
4347 if (!__is_failed(__err))
4348 __wday = weekday(__tm.tm_wday);
4350 __parts |= _ChronoParts::_Weekday;
4356 if (__mod || __num) [[unlikely]]
4364 __tmget.get(__is, {}, __is, __err, &__tm,
4366 if (!__is_failed(__err))
4367 __m = month(__tm.tm_mon + 1);
4369 __parts |= _ChronoParts::_Month;
4373 if (__mod ==
'O' || __num) [[unlikely]]
4378 __tmget.get(__is, {}, __is, __err, &__tm,
4379 __fmt - 2 - (__mod ==
'E'), __fmt);
4380 if (!__is_failed(__err))
4382 __y = year(__tm.tm_year + 1900);
4383 __m = month(__tm.tm_mon + 1);
4384 __d = day(__tm.tm_mday);
4385 __h =
hours(__tm.tm_hour);
4390 __parts |= _ChronoParts::_DateTime;
4394 if (!__mod) [[likely]]
4396 auto __v = __read_signed(__num ? __num : 2);
4397 if (!__is_failed(__err))
4399 int __cmin = (int)year::min() / 100;
4400 int __cmax = (int)year::max() / 100;
4401 if (__cmin <= __v && __v <= __cmax)
4402 __century = __v * 100;
4407 else if (__mod ==
'E')
4410 __tmget.get(__is, {}, __is, __err, &__tm,
4412 if (!__is_failed(__err))
4413 __century = __tm.tm_year;
4422 if (!__mod) [[likely]]
4424 auto __v = __read_unsigned(__num ? __num : 2);
4425 if (!__is_failed(__err))
4428 else if (__mod ==
'O')
4431 __tmget.get(__is, {}, __is, __err, &__tm,
4433 if (!__is_failed(__err))
4434 __d = day(__tm.tm_mday);
4438 __parts |= _ChronoParts::_Day;
4442 if (__mod || __num) [[unlikely]]
4446 auto __month = __read_unsigned(2);
4448 auto __day = __read_unsigned(2);
4450 auto __year = __read_unsigned(2);
4451 if (__is_failed(__err))
4453 __y = year(__year + 1900 + 100 *
int(__year < 69));
4454 __m = month(__month);
4456 if (!year_month_day(__y, __m, __d).ok())
4458 __y = __yy = __iso_y = __iso_yy = __bad_y;
4464 __parts |= _ChronoParts::_Date;
4468 if (__mod) [[unlikely]]
4472 auto __year = __read_signed(__num ? __num : 4);
4474 auto __month = __read_unsigned(2);
4476 auto __day = __read_unsigned(2);
4477 if (__is_failed(__err))
4480 __m = month(__month);
4482 if (!year_month_day(__y, __m, __d).ok())
4484 __y = __yy = __iso_y = __iso_yy = __bad_y;
4490 __parts |= _ChronoParts::_Date;
4494 if (__mod) [[unlikely]]
4498 auto __val = __read_unsigned(__num ? __num : 2);
4499 if (__val >= 0 && __val <= 99)
4501 __iso_yy = year(__val);
4502 if (__century == -1)
4506 __iso_yy = __iso_y = __y = __yy = __bad_y;
4508 __parts |= _ChronoParts::_Year;
4512 if (__mod) [[unlikely]]
4515 __iso_y = year(__read_unsigned(__num ? __num : 4));
4516 __parts |= _ChronoParts::_Year;
4521 if (__mod ==
'E') [[unlikely]]
4523 else if (__mod ==
'O')
4528 __tmget.get(__is, {}, __is, __err, &__tm,
4530 if (!__is_failed(__err))
4534 __h12 =
hours(__tm.tm_hour);
4538 __h =
hours(__tm.tm_hour);
4547 auto __val = __read_unsigned(__num ? __num : 2);
4548 if (__c ==
'I' && __val >= 1 && __val <= 12)
4550 __h12 =
hours(__val);
4553 else if (__c ==
'H' && __val >= 0 && __val <= 23)
4560 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4565 __parts |= _ChronoParts::_TimeOfDay;
4569 if (__mod) [[unlikely]]
4571 else if (_M_need == _ChronoParts::_TimeOfDay)
4573 auto __val = __read_signed(__num ? __num : 3);
4574 if (!__is_failed(__err))
4577 __parts |= _ChronoParts::_TimeOfDay;
4582 __dayofyear = __read_unsigned(__num ? __num : 3);
4589 if (__mod ==
'E') [[unlikely]]
4591 else if (__mod ==
'O')
4594 __tmget.get(__is, {}, __is, __err, &__tm,
4596 if (!__is_failed(__err))
4597 __m = month(__tm.tm_mon + 1);
4601 auto __val = __read_unsigned(__num ? __num : 2);
4602 if (__val >= 1 && __val <= 12)
4607 __parts |= _ChronoParts::_Month;
4611 if (__mod ==
'E') [[unlikely]]
4613 else if (__mod ==
'O')
4616 __tmget.get(__is, {}, __is, __err, &__tm,
4618 if (!__is_failed(__err))
4623 auto __val = __read_unsigned(__num ? __num : 2);
4624 if (0 <= __val && __val < 60)
4628 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4633 __parts |= _ChronoParts::_TimeOfDay;
4643 const _CharT* __ampms[2];
4644 __tmpunct._M_am_pm(__ampms);
4645 int __n = 0, __which = 3;
4646 while (__which != 0)
4648 auto __i = __is.peek();
4649 if (_Traits::eq_int_type(__i, _Traits::eof()))
4659 else if (__ampms[0][__n + 1] == _CharT())
4670 else if (__ampms[1][__n + 1] == _CharT())
4681 if (__which == 0 || __which == 3)
4694 __tmget.get(__is, {}, __is, __err, &__tm,
4696 if (!__is_failed(__err))
4698 __h =
hours(__tm.tm_hour);
4703 __parts |= _ChronoParts::_TimeOfDay;
4708 if (__mod || __num) [[unlikely]]
4715 auto __val = __read_unsigned(2);
4716 if (__val == -1 || __val > 23) [[unlikely]]
4718 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4722 if (!__read_chr(
':')) [[unlikely]]
4726 __val = __read_unsigned(2);
4727 if (__val == -1 || __val > 60) [[unlikely]]
4729 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4737 __parts |= _ChronoParts::_TimeOfDay;
4740 else if (!__read_chr(
':')) [[unlikely]]
4746 if (__mod ==
'E') [[unlikely]]
4748 else if (__mod ==
'O')
4751 __tmget.get(__is, {}, __is, __err, &__tm,
4753 if (!__is_failed(__err))
4756 else if constexpr (_Duration::period::den == 1
4759 auto __val = __read_unsigned(__num ? __num : 2);
4760 if (0 <= __val && __val <= 59) [[likely]]
4764 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4771 basic_stringstream<_CharT> __buf;
4772 auto __digit = _S_try_read_digit(__is, __err);
4775 __buf.put(_CharT(
'0') + __digit);
4776 __digit = _S_try_read_digit(__is, __err);
4778 __buf.put(_CharT(
'0') + __digit);
4781 auto __i = __is.peek();
4782 if (_Traits::eq_int_type(__i, _Traits::eof()))
4790 __dp = __np.decimal_point();
4792 _CharT __c = _Traits::to_char_type(__i);
4798 = hh_mm_ss<_Duration>::fractional_width;
4801 __digit = _S_try_read_digit(__is, __err);
4803 __buf.put(_CharT(
'0') + __digit);
4811 if (!__is_failed(__err)) [[likely]]
4813 long double __val{};
4814#if __cpp_lib_to_chars
4816 auto __first = __str.data();
4817 auto __last = __first + __str.size();
4821 if ((
bool)ec || ptr != __last) [[unlikely]]
4829 if constexpr (__is_floating)
4836 __parts |= _ChronoParts::_TimeOfDay;
4841 if (__mod ==
'E') [[unlikely]]
4843 else if (__mod ==
'O')
4848 __tmget.get(__is, {}, __is, __err, &__tm,
4850 if (!__is_failed(__err))
4851 __wday = weekday(__tm.tm_wday);
4858 const int __lo = __c ==
'u' ? 1 : 0;
4859 const int __hi = __lo + 6;
4860 auto __val = __read_unsigned(__num ? __num : 1);
4861 if (__lo <= __val && __val <= __hi)
4862 __wday = weekday(__val);
4865 __wday = __bad_wday;
4869 __parts |= _ChronoParts::_Weekday;
4875 if (__mod ==
'E') [[unlikely]]
4877 else if (__mod ==
'O')
4879 if (__c ==
'V') [[unlikely]]
4889 const int __lo = __c ==
'V' ? 1 : 0;
4890 const int __hi = 53;
4891 auto __val = __read_unsigned(__num ? __num : 2);
4892 if (__lo <= __val && __val <= __hi)
4897 __sunday_wk = __val;
4903 __monday_wk = __val;
4908 __iso_wk = __sunday_wk = __monday_wk = -1;
4914 if (__mod ==
'O' || __num) [[unlikely]]
4919 __tmget.get(__is, {}, __is, __err, &__tm,
4920 __fmt - 2 - (__mod ==
'E'), __fmt);
4921 if (!__is_failed(__err))
4923 __y = year(__tm.tm_year + 1900);
4924 __m = month(__tm.tm_mon + 1);
4925 __d = day(__tm.tm_mday);
4928 __parts |= _ChronoParts::_Date;
4932 if (__mod ==
'O' || __num) [[unlikely]]
4937 __tmget.get(__is, {}, __is, __err, &__tm,
4938 __fmt - 2 - (__mod ==
'E'), __fmt);
4939 if (!__is_failed(__err))
4941 __h =
hours(__tm.tm_hour);
4946 __parts |= _ChronoParts::_TimeOfDay;
4950 if (__mod) [[unlikely]]
4953 __tmget.get(__is, {}, __is, __err, &__tm,
4955 if (!__is_failed(__err))
4957 int __cent = __tm.tm_year < 2000 ? 1900 : 2000;
4958 __yy = year(__tm.tm_year - __cent);
4959 if (__century == -1)
4965 auto __val = __read_unsigned(__num ? __num : 2);
4966 if (__val >= 0 && __val <= 99)
4969 if (__century == -1)
4970 __century = __val < 69 ? 2000 : 1900;
4973 __y = __yy = __iso_yy = __iso_y = __bad_y;
4975 __parts |= _ChronoParts::_Year;
4979 if (__mod ==
'O') [[unlikely]]
4981 else if (__mod ==
'E')
4984 __tmget.get(__is, {}, __is, __err, &__tm,
4986 if (!__is_failed(__err))
4987 __y = year(__tm.tm_year);
4991 auto __val = __read_unsigned(__num ? __num : 4);
4992 if (!__is_failed(__err))
4995 __parts |= _ChronoParts::_Year;
4999 if (__num) [[unlikely]]
5006 auto __i = __is.peek();
5007 if (_Traits::eq_int_type(__i, _Traits::eof()))
5012 _CharT __ic = _Traits::to_char_type(__i);
5013 const bool __neg = __ic == _CharT(
'-');
5014 if (__ic == _CharT(
'-') || __ic == _CharT(
'+'))
5021 __hh = __read_unsigned(2);
5026 __hh = 10 * _S_try_read_digit(__is, __err);
5027 __hh += _S_try_read_digit(__is, __err);
5030 if (__is_failed(__err))
5034 if (_Traits::eq_int_type(__i, _Traits::eof()))
5037 __tz_offset =
minutes(__hh * (__neg ? -60 : 60));
5040 __ic = _Traits::to_char_type(__i);
5042 bool __read_mm =
false;
5045 if (__ic == _GLIBCXX_WIDEN(
":")[0])
5052 else if (_CharT(
'0') <= __ic && __ic <= _CharT(
'9'))
5058 int_least32_t __mm = 0;
5061 __mm = 10 * _S_try_read_digit(__is, __err);
5062 __mm += _S_try_read_digit(__is, __err);
5065 if (!__is_failed(__err))
5067 auto __z = __hh * 60 + __mm;
5068 __tz_offset =
minutes(__neg ? -__z : __z);
5074 if (__mod || __num) [[unlikely]]
5078 basic_string_view<_CharT> __x = _GLIBCXX_WIDEN(
"_/-+");
5082 auto __i = __is.peek();
5083 if (!_Traits::eq_int_type(__i, _Traits::eof()))
5085 _CharT __a = _Traits::to_char_type(__i);
5087 || __x.find(__a) != __x.npos)
5089 __tz_abbr.push_back(__a);
5098 if (__tz_abbr.empty())
5104 if (__mod || __num) [[unlikely]]
5108 _CharT __i = __is.peek();
5109 if (_Traits::eq_int_type(__i, _Traits::eof()))
5111 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
5119 if (__mod || __num) [[unlikely]]
5123 _CharT __i = __is.peek();
5124 if (_Traits::eq_int_type(__i, _Traits::eof()))
5126 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
5132 if (__mod || __num) [[unlikely]]
5140 if (__mod || __num) [[unlikely]]
5149 if (_CharT(
'1') <= __c && __c <= _CharT(
'9'))
5151 if (!__mod) [[likely]]
5154 auto __end = __fmt + _Traits::length(__fmt);
5156 = __format::__parse_integer(__fmt - 1, __end);
5157 if (__ptr) [[likely]]
5168 if (__is_failed(__err)) [[unlikely]]
5178 if (__yy != __bad_y && __y == __bad_y)
5179 __y =
years(__century) + __yy;
5180 if (__iso_yy != __bad_y && __iso_y == __bad_y)
5181 __iso_y =
years(__century) + __iso_yy;
5184 bool __can_use_doy =
false;
5185 bool __can_use_iso_wk =
false;
5186 bool __can_use_sun_wk =
false;
5187 bool __can_use_mon_wk =
false;
5190 if (__y != __bad_y && __dayofyear >= 0)
5192 __can_use_doy =
true;
5193 __parts |= _ChronoParts::_Date;
5195 else if (__y != __bad_y && __wday != __bad_wday && __sunday_wk >= 0)
5197 __can_use_sun_wk =
true;
5198 __parts |= _ChronoParts::_Date;
5200 else if (__y != __bad_y && __wday != __bad_wday && __monday_wk >= 0)
5202 __can_use_mon_wk =
true;
5203 __parts |= _ChronoParts::_Date;
5205 else if (__iso_y != __bad_y && __wday != __bad_wday && __iso_wk > 0)
5208 __can_use_iso_wk =
true;
5209 __parts |= _ChronoParts::_Date;
5212 if (__is_failed(__err)) [[unlikely]]
5214 else if (__is_flag) [[unlikely]]
5216 else if ((_M_need & __parts) == _M_need) [[likely]]
5238 const bool __need_wday = (_M_need & _ChronoParts::_Weekday) != 0;
5242 const bool __need_time = (_M_need & _ChronoParts::_TimeOfDay) != 0;
5244 if (__need_wday && __wday != __bad_wday)
5246 else if ((_M_need & _ChronoParts::_Date) != 0)
5250 const bool __need_ymd = !__need_wday && !__need_time;
5252 if (((_M_need & _ChronoParts::_Year) != 0 && __y == __bad_y)
5253 || ((_M_need & _ChronoParts::_Month) != 0 && __m == __bad_mon)
5254 || ((_M_need & _ChronoParts::_Day) != 0 && __d == __bad_day))
5261 if ((0 < __dayofyear && __dayofyear <= 365)
5262 || (__dayofyear == 366 && __y.is_leap()))
5265 _M_sys_days = sys_days(__y/January/1)
5266 +
days(__dayofyear - 1);
5268 _M_ymd = year_month_day(_M_sys_days);
5273 else if (__can_use_iso_wk)
5281 const sys_days __jan4(__iso_y/January/4);
5282 weekday __wd1(__jan4 -
days(3));
5283 if (__wd1 != Thursday)
5284 if (__wd1 != Wednesday || !__iso_y.is_leap())
5288 if (!__is_failed(__err)) [[likely]]
5291 sys_days __w(Thursday[1]/January/__iso_y);
5293 __w -= Thursday - Monday;
5295 __w += __wday - Monday;
5299 _M_ymd = year_month_day(_M_sys_days);
5302 else if (__can_use_sun_wk)
5305 sys_days __wk1(__y/January/Sunday[1]);
5306 _M_sys_days = __wk1 +
weeks(__sunday_wk - 1)
5307 +
days(__wday.c_encoding());
5308 _M_ymd = year_month_day(_M_sys_days);
5309 if (_M_ymd.year() != __y) [[unlikely]]
5312 else if (__can_use_mon_wk)
5315 sys_days __wk1(__y/January/Monday[1]);
5316 _M_sys_days = __wk1 +
weeks(__monday_wk - 1)
5317 +
days(__wday.c_encoding() - 1);
5318 _M_ymd = year_month_day(_M_sys_days);
5319 if (_M_ymd.year() != __y) [[unlikely]]
5331 if ((_M_need & _ChronoParts::_Year) != 0)
5333 if (!__y.ok()) [[unlikely]]
5336 else if (__y == __bad_y)
5339 if ((_M_need & _ChronoParts::_Month) != 0)
5341 if (!__m.ok()) [[unlikely]]
5344 else if (__m == __bad_mon)
5347 if ((_M_need & _ChronoParts::_Day) != 0)
5349 if (__d < day(1) || __d > (__y/__m/last).day())
5352 else if (__d == __bad_day)
5355 if (year_month_day __ymd(__y, __m, __d); __ymd.ok())
5358 if (__need_wday || __need_time)
5359 _M_sys_days = sys_days(_M_ymd);
5366 _M_wd = weekday(_M_sys_days);
5372 if (__h == __bad_h && __h12 != __bad_h)
5376 else if (__ampm == 2)
5377 __h = __h12 ==
hours(12) ? __h12 : __h12 +
hours(12);
5382 auto __t = _M_time.zero();
5391 if (__min != __bad_min)
5397 if (__s != __bad_sec)
5401 _M_is_leap_second = __s >=
seconds(60);
5410 if (!__is_failed(__err)) [[likely]]
5412 if (__offset && __tz_offset != __bad_min)
5413 *__offset = __tz_offset;
5414 if (__abbrev && !__tz_abbr.empty())
5422 __is.setstate(__err);
5426#undef _GLIBCXX_WIDEN
5431_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.