30#ifndef _GLIBCXX_CHRONO_IO_H
31#define _GLIBCXX_CHRONO_IO_H 1
34#pragma GCC system_header
37#if __cplusplus >= 202002L
48namespace std _GLIBCXX_VISIBILITY(default)
50_GLIBCXX_BEGIN_NAMESPACE_VERSION
60#define _GLIBCXX_WIDEN_(C, S) ::std::__format::_Widen<C>(S, L##S)
61#define _GLIBCXX_WIDEN(S) _GLIBCXX_WIDEN_(_CharT, S)
63 template<
typename _Period,
typename _CharT>
65 __units_suffix()
noexcept
70#define _GLIBCXX_UNITS_SUFFIX(period, suffix) \
71 if constexpr (is_same_v<_Period, period>) \
72 return _GLIBCXX_WIDEN(suffix); \
75 _GLIBCXX_UNITS_SUFFIX(atto,
"as")
76 _GLIBCXX_UNITS_SUFFIX(femto,
"fs")
77 _GLIBCXX_UNITS_SUFFIX(pico,
"ps")
78 _GLIBCXX_UNITS_SUFFIX(nano,
"ns")
79 _GLIBCXX_UNITS_SUFFIX(milli,
"ms")
80#if _GLIBCXX_USE_ALT_MICROSECONDS_SUFFIX
83 _GLIBCXX_UNITS_SUFFIX(micro,
"\u00b5s")
85 _GLIBCXX_UNITS_SUFFIX(micro,
"us")
87 _GLIBCXX_UNITS_SUFFIX(centi,
"cs")
88 _GLIBCXX_UNITS_SUFFIX(deci,
"ds")
90 _GLIBCXX_UNITS_SUFFIX(deca,
"das")
91 _GLIBCXX_UNITS_SUFFIX(hecto,
"hs")
92 _GLIBCXX_UNITS_SUFFIX(kilo,
"ks")
93 _GLIBCXX_UNITS_SUFFIX(mega,
"Ms")
94 _GLIBCXX_UNITS_SUFFIX(giga,
"Gs")
95 _GLIBCXX_UNITS_SUFFIX(tera,
"Ts")
96 _GLIBCXX_UNITS_SUFFIX(tera,
"Ts")
97 _GLIBCXX_UNITS_SUFFIX(peta,
"Ps")
98 _GLIBCXX_UNITS_SUFFIX(exa,
"Es")
102#undef _GLIBCXX_UNITS_SUFFIX
106 template<
typename _Period,
typename _CharT,
typename _Out>
108 __fmt_units_suffix(_Out __out)
noexcept
110 if (
auto __s = __detail::__units_suffix<_Period, _CharT>(); __s.size())
111 return __format::__write(
std::move(__out), __s);
112 else if constexpr (_Period::den == 1)
113 return std::format_to(
std::move(__out), _GLIBCXX_WIDEN(
"[{}]s"),
114 (uintmax_t)_Period::num);
116 return std::format_to(
std::move(__out), _GLIBCXX_WIDEN(
"[{}/{}]s"),
117 (uintmax_t)_Period::num,
118 (uintmax_t)_Period::den);
127 template<
typename _CharT,
typename _Traits,
128 typename _Rep,
typename _Period>
134 using period =
typename _Period::type;
142 __detail::__fmt_units_suffix<period, _CharT>(_Out(__s));
152 template<
typename _Duration>
153 struct __local_time_fmt
155 local_time<_Duration> _M_time;
156 const string* _M_abbrev;
162 template<
typename _Duration>
163 using __local_time_fmt_for
164 = __local_time_fmt<common_type_t<_Duration, seconds>>;
177 template<
typename _Duration>
178 inline __detail::__local_time_fmt<_Duration>
180 const string* __abbrev =
nullptr,
181 const seconds* __offset_sec =
nullptr)
182 {
return {__time, __abbrev, __offset_sec}; }
190 [[noreturn,__gnu__::__always_inline__]]
192 __not_valid_for_duration()
193 { __throw_format_error(
"format error: chrono-format-spec not valid for "
194 "chrono::duration"); }
196 [[noreturn,__gnu__::__always_inline__]]
198 __invalid_chrono_spec()
199 { __throw_format_error(
"format error: chrono-format-spec not valid for "
205 enum class _ChronoParts :
unsigned short {
206 _None = 0, _TotalSeconds = 1u, _Subseconds = 1u << 2,
209 _EpochUnits = 1u << 3, _UnitSuffix = 1u << 4,
210 _EpochSeconds = _EpochUnits | _TotalSeconds,
213 _LocalDays = 1u << 5,
214 _LocalSeconds = _LocalDays | _TotalSeconds,
216 _Year = 1u << 6, _Month = 1u << 7, _Day = 1u << 8,
217 _Weekday = 1u << 9, _WeekdayIndex = 1u << 10, _DayOfYear = 1u << 11,
218 _IndexedWeekday = _Weekday | _WeekdayIndex,
219 _YearMonthDay = _Year | _Month | _Day,
220 _Date = _LocalDays | _YearMonthDay | _IndexedWeekday | _DayOfYear,
222 _HoursMinutesSeconds = 1u << 12,
223 _TimeOfDay = _HoursMinutesSeconds | _Subseconds,
224 _Time = _TimeOfDay | _TotalSeconds,
225 _EpochTime = _Time | _EpochUnits | _UnitSuffix,
226 _DateTime = _Date | _Time,
228 _ZoneAbbrev = 1u << 13, _ZoneOffset = 1u << 14,
229 _TimeZone = _ZoneAbbrev | _ZoneOffset,
230 _ZonedDateTime = _DateTime | _TimeZone,
233 [[__gnu__::__always_inline__]]
234 constexpr _ChronoParts
235 operator&(_ChronoParts __x, _ChronoParts __y)
noexcept
236 {
return static_cast<_ChronoParts
>((unsigned)__x & (unsigned)__y); }
238 [[__gnu__::__always_inline__]]
239 constexpr _ChronoParts&
240 operator&=(_ChronoParts& __x, _ChronoParts __y)
noexcept
241 {
return __x = __x & __y; }
243 [[__gnu__::__always_inline__]]
244 constexpr _ChronoParts
245 operator|(_ChronoParts __x, _ChronoParts __y)
noexcept
246 {
return static_cast<_ChronoParts
>((
unsigned short)__x | (
unsigned short)__y); }
248 [[__gnu__::__always_inline__]]
249 constexpr _ChronoParts&
250 operator|=(_ChronoParts& __x, _ChronoParts __y)
noexcept
251 {
return __x = __x | __y; }
254 [[__gnu__::__always_inline__]]
255 constexpr _ChronoParts
256 operator-(_ChronoParts __x, _ChronoParts __y)
noexcept
257 {
return static_cast<_ChronoParts
>((
unsigned short)__x & ~(
unsigned short)__y); }
260 [[__gnu__::__always_inline__]]
261 constexpr _ChronoParts&
262 operator-=(_ChronoParts& __x, _ChronoParts __y)
noexcept
263 {
return __x = __x - __y; }
265 [[__gnu__::__always_inline__]]
267 operator==(_ChronoParts __x,
decltype(
nullptr)) noexcept
268 {
return (
unsigned short)__x == 0; }
270 template<
typename _CharT>
271 struct _ChronoSpec : _Spec<_CharT>
282 unsigned _M_locale_specific : 1;
285 unsigned _M_needs_ok_check : 1;
287 unsigned _M_floating_point_rep : 1;
289 unsigned _M_custom_rep : 1;
290 unsigned _M_unused : 4;
293 _ChronoParts _M_needed;
294 basic_string_view<_CharT> _M_chrono_specs;
296 [[__gnu__::__always_inline__]]
298 _M_needs(_ChronoParts __parts)
const
299 {
return (_M_needed & __parts) != 0; }
302 template<
typename _CharT>
303 struct _ChronoFormats
305 using _String_view = basic_string_view<_CharT>;
310 {
return _GLIBCXX_WIDEN(
"%F %T %Z"); }
315 {
return _S_ftz().substr(0, 5); }
320 {
return _S_ftz().substr(0, 2); }
325 {
return _S_ftz().substr(3, 2); }
330 {
return _GLIBCXX_WIDEN(
"%Y/%b/%d"); }
335 {
return _S_ymd().substr(0, 5); }
340 {
return _S_ymd().substr(3); }
345 {
return _S_ymd().substr(0, 2); }
350 {
return _S_ymd().substr(3, 2); }
355 {
return _S_ymd().substr(6, 2); }
361 {
return _String_view(_GLIBCXX_WIDEN(
"%Y/%b/%a[%\0]"), 12); }
366 {
return _S_ymwi().substr(3); }
371 {
return _S_ymwi().substr(6); }
376 {
return _S_ymwi().substr(6, 2); }
381 {
return _GLIBCXX_WIDEN(
"%Y/%b/%a[last]"); }
386 {
return _S_ymwl().substr(3); }
391 {
return _S_ymwl().substr(6); }
396 {
return _GLIBCXX_WIDEN(
"%Y/%b/last"); }
401 {
return _S_yml().substr(3); }
404 template<
typename _CharT>
407 static constexpr unsigned _S_max_prec = 18;
408 using _Attoseconds = chrono::duration<__UINT_LEAST64_TYPE__, atto>;
411 = basic_format_context<_Sink_iter<_CharT>, _CharT>;
412 using _FormatArgs = basic_format_args<_FormatContext>;
413 static inline auto _S_args = std::make_format_args<_FormatContext>();
415 _ChronoData() =
default;
416 _ChronoData(_ChronoData&&) =
delete;
419 chrono::seconds _M_eseconds;
422 _Attoseconds _M_subseconds;
426 _FormatArgs _M_ereps = _S_args;
427 basic_string_view<_CharT> _M_unit_suffix;
430 chrono::local_seconds _M_lseconds;
431 chrono::local_days _M_ldays;
433 chrono::year _M_year;
434 chrono::month _M_month;
436 chrono::weekday _M_weekday;
437 unsigned char _M_weekday_index;
438 chrono::days _M_day_of_year;
441 chrono::hours _M_hours;
442 chrono::minutes _M_minutes;
443 chrono::seconds _M_seconds;
445 chrono::seconds _M_zone_offset;
446 basic_string_view<_CharT> _M_zone_abbrev;
447 const char* _M_zone_cstr =
"";
449 template<
typename _YearMonth>
450 [[__gnu__::__always_inline__]]
452 _M_fill_year_month(
const _YearMonth& __ym, _ChronoParts __parts)
454 _M_year = __ym.year();
455 __parts -= _ChronoParts::_Year;
456 _M_month = __ym.month();
457 __parts -= _ChronoParts::_Month;
461 [[__gnu__::__always_inline__]]
463 _M_fill_day(chrono::day __d, _ChronoParts __parts)
466 __parts -= _ChronoParts::_Day;
467 _M_weekday_index = ((unsigned)__d + 6u) % 7u;
468 __parts -= _ChronoParts::_WeekdayIndex;
472 [[__gnu__::__always_inline__]]
474 _M_fill_weekday(chrono::weekday_indexed __wi, _ChronoParts __parts)
476 _M_weekday = __wi.weekday();
477 __parts -= _ChronoParts::_Weekday;
478 _M_weekday_index = __wi.index();
479 __parts -= _ChronoParts::_WeekdayIndex;
483 [[__gnu__::__always_inline__]]
485 _M_fill_aux(chrono::local_days __ld, _ChronoParts __parts)
487 using namespace chrono;
488 if ((__parts & _ChronoParts::_Weekday) != 0)
489 _M_weekday = weekday(__ld);
490 __parts -= _ChronoParts::_Weekday;
491 if ((__parts & _ChronoParts::_DayOfYear) != 0)
494 _M_day_of_year = __ld - local_days(_M_year/January/0);
495 __parts -= _ChronoParts::_DayOfYear;
499 [[__gnu__::__always_inline__]]
501 _M_fill_ldays(chrono::local_days __ld, _ChronoParts __parts)
504 __parts -= _ChronoParts::_LocalDays;
505 return _M_fill_aux(__ld, __parts);
509 _M_fill_time(chrono::seconds __d)
511 chrono::hh_mm_ss<chrono::seconds> __hms(__d);
512 _M_hours = __hms.hours();
513 _M_minutes = __hms.minutes();
514 _M_seconds = __hms.seconds();
518 _M_fill_date_time(chrono::local_seconds __ls, _ChronoParts __parts)
520 _M_ldays = chrono::floor<chrono::days>(__ls);
521 __parts -= _ChronoParts::_LocalDays;
522 if ((__parts & _ChronoParts::_HoursMinutesSeconds) != 0)
523 _M_fill_time(_M_lseconds - _M_ldays);
525 if ((__parts & _ChronoParts::_Date) != 0)
527 const chrono::year_month_day __ymd(_M_ldays);
528 _M_fill_year_month(__ymd, __parts);
529 _M_fill_day(__ymd.day(), __parts);
530 _M_fill_aux(_M_ldays, __parts);
535 _M_fill_zone(
const char* __abbrev,
const wchar_t* __wabbrev)
537 if constexpr (is_same_v<_CharT, char>)
538 _M_zone_abbrev = __abbrev;
540 _M_zone_abbrev = __wabbrev;
541 _M_zone_cstr = __abbrev;
544 [[__gnu__::__always_inline__]]
547 { _M_fill_zone(
"UTC", L
"UTC"); }
551 template<
typename _CharT>
552 struct __formatter_chrono
554 using __string_view = basic_string_view<_CharT>;
555 using __string = basic_string<_CharT>;
557 __formatter_chrono() =
default;
560 __formatter_chrono(_ChronoSpec<_CharT> __spec) noexcept
564 template<
typename _ParseContext>
565 constexpr typename _ParseContext::iterator
566 _M_parse(_ParseContext& __pc, _ChronoParts __parts,
567 const _ChronoSpec<_CharT>& __def)
569 auto __first = __pc.
begin();
570 auto __last = __pc.end();
572 _ChronoSpec<_CharT> __spec = __def;
574 auto __finalize = [
this, &__spec, &__def] {
575 using enum _ChronoParts;
576 _ChronoParts __checked
577 = __spec._M_debug ? _YearMonthDay|_IndexedWeekday
581 __spec._M_needs_ok_check
582 = __spec._M_needs(__def._M_needed & __checked);
586 auto __finished = [&] {
587 if (__first == __last || *__first ==
'}')
598 __first = __spec._M_parse_fill_and_align(__first, __last);
602 __first = __spec._M_parse_width(__first, __last, __pc);
608 if ((__parts & _ChronoParts::_EpochUnits) == 0
609 || !__spec._M_floating_point_rep)
610 __throw_format_error(
"format error: invalid precision for duration");
613 __first = _Spec<_CharT>()._M_parse_precision(__first, __last, __pc);
615 __spec._M_prec_kind = _WP_value;
620 __spec._M_localized =
false;
621 __first = __spec._M_parse_locale(__first, __last);
628 __string_view __str(__first, __last - __first);
629 auto __end = __str.find(
'}');
630 if (__end != __str.npos)
632 __str.remove_suffix(__str.length() - __end);
633 __last = __first + __end;
635 if (__str.find(
'{') != __str.npos)
636 __throw_format_error(
"chrono format error: '{' in chrono-specs");
642 __spec._M_debug =
false;
643 __spec._M_locale_specific =
false;
644 __spec._M_needed = _ChronoParts::_None;
645 __spec._M_chrono_specs = __string_view();
647 const auto __chrono_specs = __first++;
648 if (*__chrono_specs !=
'%')
649 __throw_format_error(
"chrono format error: no '%' at start of "
654 while (__first != __last)
656 enum _Mods { _Mod_none, _Mod_E, _Mod_O, _Mod_E_O };
657 _Mods __allowed_mods = _Mod_none;
659 _ChronoParts __needed = _ChronoParts::_None;
660 bool __locale_specific =
false;
662 _CharT __c = *__first++;
665 using enum _ChronoParts;
669 __locale_specific =
true;
675 __locale_specific =
true;
678 __needed = _Date|_HoursMinutesSeconds;
679 __allowed_mods = _Mod_E;
680 __locale_specific =
true;
684 __allowed_mods = _Mod_E;
689 __allowed_mods = _Mod_O;
693 __needed = _YearMonthDay;
697 __needed = _LocalDays|_Weekday;
701 __needed = _HoursMinutesSeconds;
702 __allowed_mods = _Mod_O;
705 __needed = __parts & _DayOfYear;
708 if (__needed == _None)
709 __needed = _HoursMinutesSeconds;
713 __allowed_mods = _Mod_O;
716 __needed = _HoursMinutesSeconds;
717 __allowed_mods = _Mod_O;
721 __locale_specific =
true;
724 __needed = _HoursMinutesSeconds;
727 __needed = _TimeOfDay;
730 __needed = _UnitSuffix;
733 __needed = _EpochUnits;
736 __needed = _TimeOfDay;
737 __allowed_mods = _Mod_O;
742 __allowed_mods = _Mod_O;
747 __needed = _LocalDays|_Year|_DayOfYear|_Weekday;
748 __allowed_mods = _Mod_O;
752 __locale_specific =
true;
753 __allowed_mods = _Mod_E;
756 __needed = _HoursMinutesSeconds;
757 __locale_specific =
true;
758 __allowed_mods = _Mod_E;
762 __allowed_mods = _Mod_E_O;
766 __allowed_mods = _Mod_E;
769 __needed = _ZoneOffset;
770 __allowed_mods = _Mod_E_O;
773 __needed = _ZoneAbbrev;
781 if (__mod) [[unlikely]]
783 __allowed_mods = _Mod_none;
789 __throw_format_error(
"chrono format error: invalid "
790 " specifier in chrono-specs");
793 if ((__mod ==
'E' && !(__allowed_mods & _Mod_E))
794 || (__mod ==
'O' && !(__allowed_mods & _Mod_O)))
795 __throw_format_error(
"chrono format error: invalid "
796 " modifier in chrono-specs");
797 if (__mod && __c !=
'z')
798 __locale_specific =
true;
802 if (__locale_specific)
803 __needed -= _ChronoParts::_Subseconds;
805 if ((__parts & __needed) != __needed)
806 __throw_format_error(
"chrono format error: format argument "
807 "does not contain the information "
808 "required by the chrono-specs");
809 __spec._M_needed |= __needed;
810 __spec._M_locale_specific |= __locale_specific;
813 size_t __pos = __string_view(__first, __last - __first).find(
'%');
818 if (__pos == __string_view::npos)
824 __first += __pos + 1;
829 if (__conv || __mod != _CharT())
830 __throw_format_error(
"chrono format error: unescaped '%' in "
833 __spec._M_chrono_specs
834 = __string_view(__chrono_specs, __first - __chrono_specs);
841 template<
typename _FormatContext>
842 typename _FormatContext::iterator
843 _M_format(
const _ChronoData<_CharT>& __t, _FormatContext& __fc)
const
845#if defined _GLIBCXX_USE_NL_LANGINFO_L && __CHAR_BIT__ == 8
849 if constexpr (is_same_v<_CharT, char>)
850 if constexpr (__unicode::__literal_encoding_is_utf8())
851 if (_M_spec._M_localized && _M_spec._M_locale_specific)
853 extern locale __with_encoding_conversion(
const locale&);
857 locale __loc = __fc.locale();
858 if (__loc != locale::classic())
859 __fc._M_loc = __with_encoding_conversion(__loc);
863 const size_t __padwidth = _M_spec._M_get_width(__fc);
865 return _M_format_to(__t, __fc.out(), __fc);
867 using _Out =
typename _FormatContext::iterator;
868 _Padding_sink<_Out, _CharT> __sink(__fc.out(), __padwidth);
869 _M_format_to(__t, __sink.out(), __fc);
870 return __sink._M_finish(_M_spec._M_align, _M_spec._M_fill);
874 _ChronoSpec<_CharT> _M_spec;
877 static constexpr const _CharT* _S_chars
878 = _GLIBCXX_WIDEN(
"0123456789.Lf:/ +-{}");
879 static constexpr _CharT _S_dot = _S_chars[10];
880 static constexpr _CharT _S_colon = _S_chars[13];
881 static constexpr _CharT _S_slash = _S_chars[14];
882 static constexpr _CharT _S_space = _S_chars[15];
883 static constexpr const _CharT* _S_fp_fmt = _S_chars + 11;
884 static constexpr const _CharT* _S_plus_minus = _S_chars + 16;
885 static constexpr const _CharT* _S_minus_empty_spec = _S_chars + 17;
886 static constexpr const _CharT* _S_empty_spec = _S_chars + 18;
888 [[__gnu__::__always_inline__]]
889 static _Runtime_format_string<_CharT>
891 {
return _Runtime_format_string<_CharT>(_S_empty_spec); }
893 static constexpr const _CharT* _S_weekdays[]
895 _GLIBCXX_WIDEN(
"Sunday"),
896 _GLIBCXX_WIDEN(
"Monday"),
897 _GLIBCXX_WIDEN(
"Tuesday"),
898 _GLIBCXX_WIDEN(
"Wednesday"),
899 _GLIBCXX_WIDEN(
"Thursday"),
900 _GLIBCXX_WIDEN(
"Friday"),
901 _GLIBCXX_WIDEN(
"Saturday"),
904 static constexpr const _CharT* _S_months[]
906 _GLIBCXX_WIDEN(
"January"),
907 _GLIBCXX_WIDEN(
"February"),
908 _GLIBCXX_WIDEN(
"March"),
909 _GLIBCXX_WIDEN(
"April"),
910 _GLIBCXX_WIDEN(
"May"),
911 _GLIBCXX_WIDEN(
"June"),
912 _GLIBCXX_WIDEN(
"July"),
913 _GLIBCXX_WIDEN(
"August"),
914 _GLIBCXX_WIDEN(
"September"),
915 _GLIBCXX_WIDEN(
"October"),
916 _GLIBCXX_WIDEN(
"November"),
917 _GLIBCXX_WIDEN(
"December"),
921 template<
typename _OutIter>
923 _M_write(_OutIter __out,
const locale& __loc, __string_view __s)
const
925#if defined _GLIBCXX_USE_NL_LANGINFO_L && __CHAR_BIT__ == 8
930 if constexpr (is_same_v<_CharT, char>)
931 if constexpr (__unicode::__literal_encoding_is_utf8())
932 if (_M_spec._M_localized && _M_spec._M_locale_specific
933 && __loc != locale::classic())
936 __locale_encoding_to_utf8(
const locale&, string_view,
void*);
938 __s = __locale_encoding_to_utf8(__loc, __s, &__buf);
941 return __format::__write(
std::move(__out), __s);
944 [[__gnu__::__always_inline__]]
946 _S_localized_spec(_CharT __conv, _CharT __mod)
970 template<
typename _Iter>
972 _M_locale_fmt(_Iter __out,
const locale& __loc,
const struct tm& __tm,
973 char __fmt,
char __mod)
const
975 basic_ostringstream<_CharT> __os;
977 const auto& __tp = use_facet<time_put<_CharT>>(__loc);
978 __tp.put(__os, __os, _S_space, &__tm, __fmt, __mod);
980 __out = _M_write(
std::move(__out), __loc, __os.view());
985 _M_check_ok(
const _ChronoData<_CharT>& __t, _CharT& __conv)
const
987 if (!_M_spec._M_debug)
993 if (!__t._M_weekday.ok()) [[unlikely]]
994 __throw_format_error(
"format error: invalid weekday");
999 if (!__t._M_month.ok()) [[unlikely]]
1000 __throw_format_error(
"format error: invalid month");
1005 return __string_view();
1012 if (__t._M_weekday_index < 1 || __t._M_weekday_index > 5) [[unlikely]]
1013 return _GLIBCXX_WIDEN(
"index");
1017 if (!__t._M_weekday.ok()) [[unlikely]]
1020 return _GLIBCXX_WIDEN(
"weekday");
1026 if (!__t._M_month.ok()) [[unlikely]]
1029 return _GLIBCXX_WIDEN(
"month");
1034 if (!__t._M_day.ok()) [[unlikely]]
1035 return _GLIBCXX_WIDEN(
"day");
1038 if (!(__t._M_year/__t._M_month/__t._M_day).ok()) [[unlikely]]
1039 return _GLIBCXX_WIDEN(
"date");
1042 if (!__t._M_year.ok()) [[unlikely]]
1043 return _GLIBCXX_WIDEN(
"year");
1048 return __string_view();
1051 template<
typename _OutIter,
typename _FormatContext>
1053 _M_format_to(
const _ChronoData<_CharT>& __t, _OutIter __out,
1054 _FormatContext& __fc)
const
1056 auto __first = _M_spec._M_chrono_specs.begin();
1057 const auto __last = _M_spec._M_chrono_specs.end();
1059 auto __print_sign = [__is_neg = __t._M_is_neg, &__out] ()
mutable {
1062 *__out++ = _S_plus_minus[1];
1069 bool __use_locale_fmt =
false;
1070 if (_M_spec._M_localized && _M_spec._M_locale_specific)
1071 if (__fc.locale() != locale::classic())
1073 __use_locale_fmt =
true;
1075 __tm.tm_year = (int)__t._M_year - 1900;
1076 __tm.tm_yday = __t._M_day_of_year.count();
1077 __tm.tm_mon = (unsigned)__t._M_month - 1;
1078 __tm.tm_mday = (unsigned)__t._M_day;
1079 __tm.tm_wday = __t._M_weekday.c_encoding();
1080 __tm.tm_hour = __t._M_hours.count();
1081 __tm.tm_min = __t._M_minutes.count();
1082 __tm.tm_sec = __t._M_seconds.count();
1090#ifdef _GLIBCXX_USE_STRUCT_TM_TM_ZONE
1093 if (__t._M_zone_cstr)
1094 __tm.tm_zone =
const_cast<char*
>(__t._M_zone_cstr);
1099 constexpr const _CharT* __literals = _GLIBCXX_WIDEN(
"\n\t%");
1106 _CharT __c = *__first++;
1107 __string_view __invalid;
1108 if (_M_spec._M_needs_ok_check)
1109 __invalid = _M_check_ok(__t, __c);
1111 if (__invalid.empty() &&__use_locale_fmt
1112 && _S_localized_spec(__c, __mod)) [[unlikely]]
1113 __out = _M_locale_fmt(
std::move(__out), __fc.locale(),
1119 __out = _M_wi(__t._M_weekday_index,
std::move(__out));
1123 __out = _M_a_A(__t._M_weekday,
std::move(__out), __c ==
'A');
1128 __out = _M_b_B(__t._M_month,
std::move(__out), __c ==
'B');
1136 __out = _M_C_y_Y(__t._M_year,
std::move(__out), __c);
1140 __out = _M_d_e(__t._M_day,
std::move(__out), __c);
1151 __out = _M_g_G(__t,
std::move(__out), __c ==
'G');
1155 __out = _M_H_I(__t._M_hours, __print_sign(), __c);
1158 __out = _M_j(__t, __print_sign());
1161 __out = _M_m(__t._M_month,
std::move(__out));
1164 __out = _M_M(__t._M_minutes, __print_sign());
1167 __out = _M_p(__t._M_hours,
std::move(__out));
1170 __out = _M_q(__t._M_unit_suffix,
std::move(__out));
1173 __out = _M_Q(__t, __print_sign(), __fc);
1176 __out = _M_r(__t, __print_sign());
1180 __out = _M_R_X(__t, __print_sign(), __c !=
'R');
1183 __out = _M_T(__t, __print_sign(), __fc);
1186 __out = _M_S(__t, __print_sign(), __fc, __mod !=
'O');
1190 __out = _M_u_w(__t._M_weekday,
std::move(__out), __c);
1195 __out = _M_U_V_W(__t,
std::move(__out), __c);
1198 __out = _M_z(__t._M_zone_offset,
std::move(__out), (
bool)__mod);
1201 __out = _M_Z(__t._M_zone_abbrev,
std::move(__out));
1204 *__out++ = __literals[0];
1207 *__out++ = __literals[1];
1210 *__out++ = __literals[2];
1221 if (!__invalid.empty())
1223 constexpr __string_view __pref = _GLIBCXX_WIDEN(
" is not a valid ");
1224 __out = __format::__write(
std::move(__out), __pref);
1225 __out = __format::__write(
std::move(__out), __invalid);
1230 __string_view __str(__first, __last - __first);
1231 size_t __pos = __str.find(
'%');
1236 if (__pos == __str.npos)
1240 __str.remove_suffix(__str.length() - __pos);
1241 __first += __pos + 1;
1243 __out = __format::__write(
std::move(__out), __str);
1246 while (__first != __last);
1250 template<
typename _OutIter>
1252 _M_wi(
unsigned __wi, _OutIter __out)
const
1256 __out = __format::__write(
std::move(__out), _S_str_d1(__buf, __wi));
1260 template<
typename _OutIter>
1262 _M_a_A(chrono::weekday __wd, _OutIter __out,
bool __full)
const
1266 __string_view __str = _S_weekdays[__wd.c_encoding()];
1268 __str = __str.substr(0, 3);
1269 return __format::__write(
std::move(__out), __str);
1272 template<
typename _OutIter>
1274 _M_b_B(chrono::month __m, _OutIter __out,
bool __full)
const
1278 __string_view __str = _S_months[(unsigned)__m - 1];
1280 __str = __str.substr(0, 3);
1281 return __format::__write(
std::move(__out), __str);
1284 template<
typename _OutIter>
1286 _M_c(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1291 __out = _M_a_A(__t._M_weekday,
std::move(__out),
false);
1293 __out = _M_b_B(__t._M_month,
std::move(++__out),
false);
1295 __out = _M_d_e(__t._M_day,
std::move(++__out),
'e');
1297 __out = _M_R_X(__t,
std::move(++__out),
true);
1299 return _M_C_y_Y(__t._M_year,
std::move(++__out),
'Y');
1302 template<
typename _OutIter>
1304 _M_C_y_Y(chrono::year __y, _OutIter __out, _CharT __conv)
const
1314 int __yi = (int)__y;
1315 const bool __is_neg = __yi < 0;
1316 __yi = __builtin_abs(__yi);
1317 int __ci = __yi / 100;
1319 if (__conv ==
'C' && __is_neg && (__ci * 100) != __yi) [[unlikely]]
1322 if (__conv !=
'y' && __ci >= 100) [[unlikely]]
1324 using _FmtStr = _Runtime_format_string<_CharT>;
1325 __string_view __fs = _S_minus_empty_spec + !__is_neg;
1326 __out = std::format_to(
std::move(__out), _FmtStr(__fs),
1327 __conv ==
'C' ? __ci : __yi);
1332 __buf[0] = _S_plus_minus[1];
1333 __string_view __sv(__buf + 3, __buf + 3);
1336 _S_fill_two_digits(__buf + 1, __ci);
1337 __sv = __string_view(__buf + !__is_neg, __buf + 3);
1341 _S_fill_two_digits(__buf + 3, __yi % 100);
1342 __sv = __string_view(__sv.data(), __buf + 5);
1344 __out = __format::__write(
std::move(__out), __sv);
1349 template<
typename _OutIter>
1351 _M_D_x(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1357 auto __di = (unsigned)__t._M_day;
1358 auto __mi = (unsigned)__t._M_month;
1359 auto __yi = __builtin_abs((
int)__t._M_year) % 100;
1361 if (__mi >= 100 || __di >= 100) [[unlikely]]
1363 using _FmtStr = _Runtime_format_string<_CharT>;
1364 __string_view __fs = _GLIBCXX_WIDEN(
"{:02d}/{:02d}/{:02d}");
1365 __out = std::format_to(
std::move(__out), _FmtStr(__fs),
1371 __buf[2] = _S_slash;
1372 __buf[5] = _S_slash;
1373 __string_view __sv(__buf, __buf + 8);
1375 _S_fill_two_digits(__buf, __mi);
1376 _S_fill_two_digits(__buf + 3, __di);
1377 _S_fill_two_digits(__buf + 6, __yi);
1378 __out = __format::__write(
std::move(__out), __sv);
1383 template<
typename _OutIter>
1385 _M_d_e(chrono::day __d, _OutIter __out, _CharT __conv)
const
1392 unsigned __i = (unsigned)__d;
1395 auto __sv = _S_str_d2(__buf, __i);
1396 if (__conv == _CharT(
'e') && __i < 10)
1399 __buf[0] = _S_space;
1403 __out = __format::__write(
std::move(__out), __sv);
1407 template<
typename _OutIter>
1409 _M_F(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1411 auto __di = (unsigned)__t._M_day;
1412 auto __mi = (unsigned)__t._M_month;
1413 auto __yi = (int)__t._M_year;
1414 const bool __is_neg = __yi < 0;
1415 __yi = __builtin_abs(__yi);
1417 if (__yi >= 10000 || __mi >= 100 || __di >= 100) [[unlikely]]
1419 using _FmtStr = _Runtime_format_string<_CharT>;
1421 = _GLIBCXX_WIDEN(
"-{:04d}-{:02d}-{:02d}") + !__is_neg;
1422 __out = std::format_to(
std::move(__out), _FmtStr(__fs),
1428 __buf[0] = _S_plus_minus[1];
1429 __buf[5] = _S_plus_minus[1];
1430 __buf[8] = _S_plus_minus[1];
1431 __string_view __sv(__buf + !__is_neg, __buf + 11);
1433 _S_fill_two_digits(__buf + 1, __yi / 100);
1434 _S_fill_two_digits(__buf + 3, __yi % 100);
1435 _S_fill_two_digits(__buf + 6, __mi);
1436 _S_fill_two_digits(__buf + 9, __di);
1437 __out = __format::__write(
std::move(__out), __sv);
1443 template<
typename _OutIter>
1445 _M_g_G(
const _ChronoData<_CharT>& __t, _OutIter __out,
1450 using namespace chrono;
1451 auto __d = __t._M_ldays;
1453 __d -= (__t._M_weekday - Monday) -
days(3);
1455 year __y = year_month_day(__d).year();
1456 return _M_C_y_Y(__y,
std::move(__out),
"yY"[__full]);
1459 template<
typename _OutIter>
1461 _M_H_I(chrono::hours __h, _OutIter __out, _CharT __conv)
const
1468 int __i = __h.count();
1470 if (__conv == _CharT(
'I'))
1476 else if (__i >= 100) [[unlikely]]
1477 return std::format_to(
std::move(__out), _S_empty_fs(), __i);
1479 return __format::__write(
std::move(__out), _S_two_digits(__i));
1482 template<
typename _OutIter>
1484 _M_j(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1486 if (!_M_spec._M_needs(_ChronoParts::_DayOfYear))
1489 auto __d = chrono::floor<chrono::days>(__t._M_hours).count();
1490 return std::format_to(
std::move(__out), _S_empty_fs(), __d);
1493 auto __d = __t._M_day_of_year.count();
1494 if (__d >= 1000) [[unlikely]]
1495 return std::format_to(
std::move(__out), _S_empty_fs(), __d);
1498 return __format::__write(
std::move(__out), _S_str_d3(__buf, __d));
1501 template<
typename _OutIter>
1503 _M_m(chrono::month __m, _OutIter __out)
const
1507 auto __i = (unsigned)__m;
1508 if (__i == 0 && _M_spec._M_debug) [[unlikely]]
1510 return __format::__write(
std::move(__out), _S_digit(0));
1513 return __format::__write(
std::move(__out), _S_str_d2(__buf, __i));
1516 template<
typename _OutIter>
1518 _M_M(chrono::minutes __m, _OutIter __out)
const
1523 auto __i = __m.count();
1524 return __format::__write(
std::move(__out), _S_two_digits(__i));
1527 template<
typename _OutIter>
1529 _M_p(chrono::hours __h, _OutIter __out)
const
1534 _S_fill_ampm(__buf, __h);
1535 return __format::__write(
std::move(__out), __string_view(__buf, 2));
1538 template<
typename _OutIter>
1540 _M_q(__string_view __us, _OutIter __out)
const
1543 return __format::__write(
std::move(__out), __us);
1546 template<
typename _OutIter,
typename _FormatContext>
1548 _M_Q(
const _ChronoData<_CharT>& __t, _OutIter __out,
1549 _FormatContext&)
const
1552 return std::vformat_to(
std::move(__out), _S_empty_spec, __t._M_ereps);
1555 template<
typename _OutIter>
1557 _M_r(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1560 auto __hi = __t._M_hours.count() % 12;
1565 __buf[2] = _S_colon;
1566 __buf[5] = _S_colon;
1567 __buf[8] = _S_space;
1568 _S_fill_two_digits(__buf, __hi);
1569 _S_fill_two_digits(__buf + 3, __t._M_minutes.count());
1570 _S_fill_two_digits(__buf + 6, __t._M_seconds.count());
1571 _S_fill_ampm(__buf + 9, __t._M_hours);
1573 return __format::__write(
std::move(__out), __string_view(__buf, 11));
1576 template<
typename _OutIter>
1578 _M_R_X(
const _ChronoData<_CharT>& __t, _OutIter __out,
1585 auto __hi = __t._M_hours.count();
1588 __buf[2] = _S_colon;
1589 __buf[5] = _S_colon;
1590 __string_view __sv(__buf, 8);
1592 if (__hi >= 100) [[unlikely]]
1594 __out = std::format_to(
std::move(__out), _S_empty_fs(), __hi);
1595 __sv.remove_prefix(2);
1598 _S_fill_two_digits(__buf, __hi);
1600 _S_fill_two_digits(__buf + 3, __t._M_minutes.count());
1602 _S_fill_two_digits(__buf + 6, __t._M_seconds.count());
1604 __sv.remove_suffix(3);
1606 return __format::__write(
std::move(__out), __sv);
1609 template<
typename _OutIter,
typename _FormatContext>
1611 _M_S(
const _ChronoData<_CharT>& __t, _OutIter __out,
1612 _FormatContext& __ctx,
bool __subs =
true)
const
1616 auto __s = __t._M_seconds;
1618 __out = __format::__write(
std::move(__out),
1619 _S_two_digits(__s.count()));
1621 __out = _M_subsecs(__t,
std::move(__out), __ctx);
1625 template<
typename _OutIter,
typename _FormatContext>
1627 _M_subsecs(
const _ChronoData<_CharT>& __t, _OutIter __out,
1628 _FormatContext& __ctx)
const
1630 unsigned __prec = _M_spec._M_prec_kind != _WP_none
1631 ? _M_spec._M_get_precision(__ctx)
1636 _CharT __dot = _S_dot;
1637 if (_M_spec._M_localized) [[unlikely]]
1639 auto __loc = __ctx.locale();
1640 const auto& __np = use_facet<numpunct<_CharT>>(__loc);
1641 __dot = __np.decimal_point();
1646 if (_M_spec._M_floating_point_rep)
1648 _Str_sink<_CharT> __sink;
1649 if (_M_spec._M_localized && _M_spec._M_custom_rep) [[unlikely]]
1650 std::vformat_to(__sink.out(), __ctx.locale(),
1651 _GLIBCXX_WIDEN(
"{1:0.{2}Lf}"), __t._M_ereps);
1653 std::vformat_to(__sink.out(),
1654 _GLIBCXX_WIDEN(
"{1:0.{2}f}"), __t._M_ereps);
1656 auto __sv = __sink.view();
1658 __sv.remove_prefix(2);
1659 return __format::__write(
std::move(__out), __sv);
1662 constexpr unsigned __max_prec = _ChronoData<_CharT>::_S_max_prec;
1663 constexpr typename _ChronoData<_CharT>::_Attoseconds::rep __pow10t[]
1667 10'000u, 100'000u, 1000'000u,
1668 10'000'000u, 100'000'000u, 1000'000'000u,
1669 10'000'000'000u, 100'000'000'000u, 1000'000'000'000u,
1670 10'000'000'000'000u, 100'000'000'000'000u, 1000'000'000'000'000u,
1671 10'000'000'000'000'000u, 100'000'000'000'000'000u, 1000'000'000'000'000'000u,
1674 auto __subs = __t._M_subseconds.count();
1675 if (__prec < __max_prec)
1676 __subs /= __pow10t[__max_prec - __prec];
1677 else if (__prec > __max_prec)
1678 __prec = __max_prec;
1680 using _FmtStr = _Runtime_format_string<_CharT>;
1681 return std::format_to(__out, _FmtStr(_GLIBCXX_WIDEN(
"{0:0{1}}")),
1687 template<
typename _OutIter,
typename _FormatContext>
1689 _M_T(
const _ChronoData<_CharT>& __t, _OutIter __out,
1690 _FormatContext& __ctx)
const
1693 __out = _M_R_X(__t,
std::move(__out),
true);
1694 return _M_subsecs(__t,
std::move(__out), __ctx);
1697 template<
typename _OutIter>
1699 _M_u_w(chrono::weekday __wd, _OutIter __out, _CharT __conv)
const
1705 unsigned __wdi = __conv ==
'u' ? __wd.iso_encoding()
1706 : __wd.c_encoding();
1708 return __format::__write(
std::move(__out), _S_str_d1(__buf, __wdi));
1711 template<
typename _OutIter>
1713 _M_U_V_W(
const _ChronoData<_CharT>& __t, _OutIter __out,
1714 _CharT __conv)
const
1722 using namespace chrono;
1724 auto __d = __t._M_ldays;
1729 __d -= (__t._M_weekday - Monday) -
days(3);
1732 __first = local_days(year_month_day(__d).year()/January/1);
1736 const weekday __weekstart = __conv ==
'U' ? Sunday : Monday;
1737 __first = local_days(__t._M_year/January/__weekstart[1]);
1739 auto __weeks = chrono::floor<weeks>(__d - __first);
1740 __string_view __sv = _S_two_digits(__weeks.count() + 1);
1741 return __format::__write(
std::move(__out), __sv);
1744 template<
typename _OutIter>
1746 _M_z(chrono::seconds __ts, _OutIter __out,
bool __mod =
false)
const
1750 __string_view __zero
1751 = __mod ? _GLIBCXX_WIDEN(
"+00:00") : _GLIBCXX_WIDEN(
"+0000");
1752 return __format::__write(
std::move(__out), __zero);
1755 chrono::hh_mm_ss<chrono::seconds> __hms(__ts);
1756 unsigned __mo = 3 + __mod;
1759 __buf[0] = _S_plus_minus[__hms.is_negative()];
1760 __buf[3] = _S_colon;
1761 _S_fill_two_digits(__buf + 1, __hms.hours().count());
1762 _S_fill_two_digits(__buf + __mo, __hms.minutes().count());
1764 __string_view __sv(__buf, __mo + 2);
1765 return __format::__write(
std::move(__out), __sv);
1768 template<
typename _OutIter>
1770 _M_Z(__string_view __abbrev, _OutIter __out)
const
1771 {
return __format::__write(
std::move(__out), __abbrev); }
1776 static basic_string_view<_CharT>
1777 _S_digit(
int __n)
noexcept
1780 return { _GLIBCXX_WIDEN(
"0123456789999999") + (__n & 0xf), 1 };
1784 static basic_string_view<_CharT>
1785 _S_two_digits(
int __n)
noexcept
1788 _GLIBCXX_WIDEN(
"0001020304050607080910111213141516171819"
1789 "2021222324252627282930313233343536373839"
1790 "4041424344454647484950515253545556575859"
1791 "6061626364656667686970717273747576777879"
1792 "8081828384858687888990919293949596979899"
1793 "9999999999999999999999999999999999999999"
1794 "9999999999999999") + 2 * (__n & 0x7f),
1800 [[__gnu__::__always_inline__]]
1802 _S_fill_two_digits(_CharT* __buf,
unsigned __n)
1804 auto __sv = _S_two_digits(__n);
1810 [[__gnu__::__always_inline__]]
1812 _S_fill_ampm(_CharT* __buf, chrono::hours __h)
1814 auto __hi = __h.count();
1815 if (__hi >= 24) [[unlikely]]
1818 constexpr const _CharT* __apm = _GLIBCXX_WIDEN(
"APM");
1819 __buf[0] = __apm[__hi >= 12];
1820 __buf[1] = __apm[2];
1825 [[__gnu__::__always_inline__]]
1826 static basic_string_view<_CharT>
1827 _S_str_d1(span<_CharT, 3> __buf,
unsigned __n)
1829 if (__n < 10) [[likely]]
1830 return _S_digit(__n);
1831 return _S_str_d2(__buf, __n);
1836 [[__gnu__::__always_inline__]]
1837 static basic_string_view<_CharT>
1838 _S_str_d2(span<_CharT, 3> __buf,
unsigned __n)
1840 if (__n < 100) [[likely]]
1841 return _S_two_digits(__n);
1842 return _S_str_d3(__buf, __n);
1847 [[__gnu__::__always_inline__]]
1848 static basic_string_view<_CharT>
1849 _S_str_d3(span<_CharT, 3> __buf,
unsigned __n)
1851 _S_fill_two_digits(__buf.data(), __n / 10);
1852 __buf[2] = _S_chars[__n % 10];
1853 return __string_view(__buf.data(), 3);
1857 template<
typename _CharT>
1858 struct __formatter_duration :
private __formatter_chrono<_CharT>
1860 template<
typename _Rep,
typename _Period>
1861 constexpr static auto
1862 _S_subseconds(
const chrono::duration<_Rep, _Period>& __d)
1864 if constexpr (chrono::treat_as_floating_point_v<_Rep>)
1865 return chrono::duration<_Rep>(__d);
1866 else if constexpr (_Period::den == 1)
1867 return chrono::seconds(0);
1870 using _Attoseconds = _ChronoData<_CharT>::_Attoseconds;
1871 using _CRep = common_type_t<_Rep, typename _Attoseconds::rep>;
1872 chrono::duration<_CRep, _Period> subs(__d.count());
1873 return chrono::duration_cast<_Attoseconds>(subs);
1878 template<
typename _Duration>
1881 _S_spec_for(_ChronoParts __parts)
1883 using _Rep =
typename _Duration::rep;
1884 using enum _ChronoParts;
1886 _ChronoSpec<_CharT> __res{};
1887 __res._M_floating_point_rep = chrono::treat_as_floating_point_v<_Rep>;
1888 __res._M_custom_rep = !is_arithmetic_v<_Rep>;
1889 __res._M_prec = chrono::hh_mm_ss<_Duration>::fractional_width;
1890 if ((__parts & _TimeOfDay) != 0)
1891 __res._M_localized = __res._M_prec > 0 || __res._M_floating_point_rep;
1893 if ((__parts & _TimeOfDay) != 0)
1894 __res._M_needed |= _TimeOfDay;
1895 if ((__parts & _Date) != 0)
1896 __res._M_needed |= _YearMonthDay;
1897 if ((__parts & _ZoneAbbrev) != 0)
1898 __res._M_needed |= _ZoneAbbrev;
1902 case _ZonedDateTime:
1903 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ftz();
1906 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ft();
1909 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_f();
1912 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_t();
1917 __builtin_unreachable();
1922 using __formatter_chrono<_CharT>::__formatter_chrono;
1923 using __formatter_chrono<_CharT>::_M_spec;
1925 template<
typename _Duration,
typename _ParseContext>
1926 constexpr typename _ParseContext::iterator
1927 _M_parse(_ParseContext& __pc, _ChronoParts __parts,
1928 const _ChronoSpec<_CharT>& __def = {})
1930 using _Rep =
typename _Duration::rep;
1931 using enum _ChronoParts;
1934 = __formatter_chrono<_CharT>::_M_parse(__pc, __parts, __def);
1937 _M_spec._M_needs_ok_check =
false;
1942 if constexpr (!is_floating_point_v<_Rep>)
1943 if constexpr (chrono::treat_as_floating_point_v<_Rep>)
1944 if (_M_spec._M_needs(_Subseconds|_EpochUnits)
1945 || _M_spec._M_prec_kind != _WP_none
1946 || _M_spec._M_prec_value > 0)
1948 constexpr const _CharT* __fs = _GLIBCXX_WIDEN(
"#02.5Lf");
1949 basic_format_parse_context<_CharT> __npc(__fs);
1950 formatter<_Rep, _CharT> __fmtter;
1951 __fmtter.parse(__npc);
1957 template<
typename _FormatContext>
1959 _M_locale(_FormatContext& __fc)
const
1961 if (!_M_spec._M_localized)
1964 return __fc.locale();
1968 template<
typename _Rep,
typename _Period,
typename _FormatContext>
1969 typename _FormatContext::iterator
1970 _M_format_to_ostream(
const chrono::duration<_Rep, _Period>& __d,
1972 _FormatContext& __fc)
const
1974 basic_ostringstream<_CharT> __os;
1975 __os.imbue(this->_M_locale(__fc));
1977 if (__is_neg) [[unlikely]]
1978 __os << this->_S_plus_minus[1];
1982 return __format::__write_padded_as_spec(__str, __str.size(),
1986 template<
typename _Rep1,
typename _Period1,
1987 typename _Rep2,
typename _Period2,
1988 typename _FormatContext>
1989 typename _FormatContext::iterator
1990 _M_format_units(_ChronoData<_CharT>& __cd,
1991 const chrono::duration<_Rep1, _Period1>& __ed,
1992 const chrono::duration<_Rep2, _Period2>& __ss,
1993 _FormatContext& __fc)
const
1995 __format::_Str_sink<_CharT> __suffix_store;
1996 constexpr auto _S_unit_suffix
1997 = chrono::__detail::__units_suffix<_Period1, _CharT>();
1998 if constexpr (!_S_unit_suffix.empty())
1999 __cd._M_unit_suffix = _S_unit_suffix;
2000 else if (_M_spec._M_needs(_ChronoParts::_UnitSuffix))
2003 __fmt_units_suffix<_Period1, _CharT>(__suffix_store.out());
2004 __cd._M_unit_suffix = __suffix_store.view();
2007 const auto __prec = _M_spec._M_prec_kind != _WP_none
2008 ? _M_spec._M_get_precision(__fc)
2011 using _ErasedContext =
typename _ChronoData<_CharT>::_FormatContext;
2014 auto __ereps = +__ed.count();
2015 if (!_M_spec._M_needs(_ChronoParts::_Subseconds))
2019 = std::make_format_args<_ErasedContext>(__ereps, __ssreps, __prec);
2020 __cd._M_ereps = __args_store;
2021 return this->_M_format(__cd, __fc);
2024 using _Attoseconds = _ChronoData<_CharT>::_Attoseconds;
2025 auto __nss = _S_subseconds(__ss);
2026 __cd._M_subseconds = chrono::duration_cast<_Attoseconds>(__nss);
2028 auto __ssreps = __nss.count();
2030 = std::make_format_args<_ErasedContext>(__ereps, __ssreps, __prec);
2031 __cd._M_ereps = __args_store;
2033 return this->_M_format(__cd, __fc);
2037 template<
typename _Rep1,
typename _Period1,
typename _FormatContext>
2038 typename _FormatContext::iterator
2039 _M_format_time_point(_ChronoData<_CharT>& __cd,
2040 const chrono::duration<_Rep1, _Period1>& __ed,
2041 _FormatContext& __fc)
const
2043 auto __parts = _M_spec._M_needed - _ChronoParts::_TotalSeconds;
2044 if ((__parts & _ChronoParts::_DateTime) != 0)
2045 __cd._M_fill_date_time(__cd._M_lseconds, __parts);
2046 return _M_format_units(__cd, __ed, __ed - __cd._M_eseconds, __fc);
2050#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2051 template<
typename _CharT>
2052 struct __formatter_chrono_info
2054 constexpr typename basic_format_parse_context<_CharT>::iterator
2055 parse(basic_format_parse_context<_CharT>& __pc)
2056 {
return _M_f._M_parse(__pc, _ChronoParts(), {}); }
2058 template<
typename _Info,
typename _Out>
2059 typename basic_format_context<_Out, _CharT>::iterator
2060 format(
const _Info& __i,
2061 basic_format_context<_Out, _CharT>& __fc)
const
2065 if (!_M_f._M_spec._M_chrono_specs.empty()) [[unlikely]]
2066 return _M_f._M_format(_ChronoData<_CharT>{}, __fc);
2068 const size_t __padwidth = _M_f._M_spec._M_get_width(__fc);
2069 if (__padwidth == 0)
2070 return _M_format_to(__fc.out(), __i);
2072 _Padding_sink<_Out, _CharT> __sink(__fc.out(), __padwidth);
2073 _M_format_to(__sink.out(), __i);
2074 return __sink._M_finish(_M_f._M_spec._M_align, _M_f._M_spec._M_fill);
2078 template<
typename _Out>
2080 _M_format_to(_Out __out,
const chrono::sys_info& __si)
const
2082 using _FmtStr = _Runtime_format_string<_CharT>;
2086 constexpr auto* __fs
2087 = _GLIBCXX_WIDEN(
"[{0:%F %T},{1:%F %T},{2:%T},{3:%Q%q},{0:%Z}]");
2088 const chrono::local_seconds __lb(__si.begin.time_since_epoch());
2089 return std::format_to(
std::move(__out), _FmtStr(__fs),
2090 chrono::local_time_format(__lb, &__si.abbrev),
2091 __si.end, __si.offset, __si.save);
2094 template<
typename _Out>
2096 _M_format_to(_Out __out,
const chrono::local_info& __li)
const
2098 *__out = _Separators<_CharT>::_S_squares()[0];
2100 if (__li.result == chrono::local_info::unique)
2101 __out = _M_format_to(
std::move(__out), __li.first);
2104 basic_string_view<_CharT> __sv;
2105 if (__li.result == chrono::local_info::nonexistent)
2106 __sv =_GLIBCXX_WIDEN(
"nonexistent");
2108 __sv = _GLIBCXX_WIDEN(
"ambiguous");
2109 __out = __format::__write(
std::move(__out), __sv);
2111 __sv = _GLIBCXX_WIDEN(
" local time between ");
2112 __out = __format::__write(
std::move(__out), __sv);
2113 __out = _M_format_to(
std::move(__out), __li.first);
2115 __sv = _GLIBCXX_WIDEN(
" and ");
2116 __out = __format::__write(
std::move(__out), __sv);
2117 __out = _M_format_to(
std::move(__out), __li.second);
2119 *__out = _Separators<_CharT>::_S_squares()[1];
2124 __formatter_chrono<_CharT> _M_f;
2131 template<
typename _Rep,
typename _Period,
typename _CharT>
2132 requires __format::__formattable_impl<_Rep, _CharT>
2133 struct formatter<
chrono::duration<_Rep, _Period>, _CharT>
2135 constexpr typename basic_format_parse_context<_CharT>::iterator
2136 parse(basic_format_parse_context<_CharT>& __pc)
2138 using enum __format::_ChronoParts;
2139 return _M_f.template _M_parse<_Duration>(__pc, _EpochTime, __defSpec);
2142 template<
typename _Out>
2143 typename basic_format_context<_Out, _CharT>::iterator
2144 format(
const chrono::duration<_Rep, _Period>& __d,
2145 basic_format_context<_Out, _CharT>& __fc)
const
2147 if constexpr (numeric_limits<_Rep>::is_signed)
2148 if (__d < __d.zero()) [[unlikely]]
2150 if constexpr (is_integral_v<_Rep>)
2154 using _URep = make_unsigned_t<_Rep>;
2155 auto __ucnt = -
static_cast<_URep
>(__d.count());
2156 auto __ud = chrono::duration<_URep, _Period>(__ucnt);
2157 return _M_format(__ud,
true, __fc);
2160 return _M_format(-__d,
true, __fc);
2162 return _M_format(__d,
false, __fc);
2166 using _Duration = chrono::duration<_Rep, _Period>;
2168 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2170 using enum __format::_ChronoParts;
2171 auto __res = __format::__formatter_duration<_CharT>::
2172 template _S_spec_for<_Duration>(_None);
2173 __res._M_localized = !is_integral_v<_Rep>;
2175 if constexpr (is_integral_v<_Rep>)
2177 __res._M_needed = _EpochUnits|_UnitSuffix;
2178 __res._M_chrono_specs = _GLIBCXX_WIDEN(
"%Q%q");
2183 template<
typename _Rep2,
typename _Out>
2184 typename basic_format_context<_Out, _CharT>::iterator
2185 _M_format(
const chrono::duration<_Rep2, _Period>& __d,
2187 basic_format_context<_Out, _CharT>& __fc)
const
2189 using namespace chrono;
2190 using enum __format::_ChronoParts;
2191 if constexpr (!is_integral_v<_Rep>)
2192 if (_M_f._M_spec._M_chrono_specs.empty())
2193 return _M_f._M_format_to_ostream(__d, __is_neg, __fc);
2195 __format::_ChronoData<_CharT> __cd;
2196 __cd._M_is_neg = __is_neg;
2197 auto __ts = chrono::floor<chrono::seconds>(__d);
2198 __cd._M_eseconds = __ts;
2199 if (_M_f._M_spec._M_needs(_HoursMinutesSeconds))
2200 __cd._M_fill_time(__ts);
2201 return _M_f._M_format_units(__cd, __d, __d - __ts, __fc);
2204 __format::__formatter_duration<_CharT> _M_f{__defSpec};
2207 template<__format::__
char _CharT>
2208 struct formatter<
chrono::day, _CharT>
2210 constexpr typename basic_format_parse_context<_CharT>::iterator
2211 parse(basic_format_parse_context<_CharT>& __pc)
2213 using enum __format::_ChronoParts;
2214 return _M_f._M_parse(__pc, _Day|_WeekdayIndex, __defSpec);
2217 template<
typename _Out>
2218 typename basic_format_context<_Out, _CharT>::iterator
2219 format(
const chrono::day& __t,
2220 basic_format_context<_Out, _CharT>& __fc)
const
2222 __format::_ChronoData<_CharT> __cd{};
2223 __cd._M_fill_day(__t, __defSpec._M_needed);
2224 return _M_f._M_format(__cd, __fc);
2228 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2230 using __format::_ChronoFormats;
2231 using enum __format::_ChronoParts;
2233 __format::_ChronoSpec<_CharT> __res{};
2234 __res._M_debug =
true;
2235 __res._M_needed = _Day;
2236 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_d();
2240 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2243 template<__format::__
char _CharT>
2244 struct formatter<
chrono::month, _CharT>
2246 constexpr typename basic_format_parse_context<_CharT>::iterator
2247 parse(basic_format_parse_context<_CharT>& __pc)
2249 using enum __format::_ChronoParts;
2250 return _M_f._M_parse(__pc, _Month, __defSpec);
2253 template<
typename _Out>
2254 typename basic_format_context<_Out, _CharT>::iterator
2255 format(
const chrono::month& __t,
2256 basic_format_context<_Out, _CharT>& __fc)
const
2258 __format::_ChronoData<_CharT> __cd{};
2259 __cd._M_month = __t;
2260 return _M_f._M_format(__cd, __fc);
2264 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2266 using __format::_ChronoFormats;
2267 using enum __format::_ChronoParts;
2269 __format::_ChronoSpec<_CharT> __res{};
2270 __res._M_debug =
true;
2271 __res._M_localized =
true;
2272 __res._M_locale_specific =
true;
2273 __res._M_needed = _Month;
2274 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_m();
2278 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2281 template<__format::__
char _CharT>
2282 struct formatter<
chrono::year, _CharT>
2284 constexpr typename basic_format_parse_context<_CharT>::iterator
2285 parse(basic_format_parse_context<_CharT>& __pc)
2287 using enum __format::_ChronoParts;
2288 return _M_f._M_parse(__pc, _Year, __defSpec);
2291 template<
typename _Out>
2292 typename basic_format_context<_Out, _CharT>::iterator
2293 format(
const chrono::year& __t,
2294 basic_format_context<_Out, _CharT>& __fc)
const
2296 __format::_ChronoData<_CharT> __cd{};
2298 return _M_f._M_format(__cd, __fc);
2302 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2304 using __format::_ChronoFormats;
2305 using enum __format::_ChronoParts;
2307 __format::_ChronoSpec<_CharT> __res{};
2308 __res._M_debug =
true;
2309 __res._M_needed = _Year;
2310 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_y();
2314 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2317 template<__format::__
char _CharT>
2318 struct formatter<
chrono::weekday, _CharT>
2320 constexpr typename basic_format_parse_context<_CharT>::iterator
2321 parse(basic_format_parse_context<_CharT>& __pc)
2323 using enum __format::_ChronoParts;
2324 return _M_f._M_parse(__pc, _Weekday, __defSpec);
2327 template<
typename _Out>
2328 typename basic_format_context<_Out, _CharT>::iterator
2329 format(
const chrono::weekday& __t,
2330 basic_format_context<_Out, _CharT>& __fc)
const
2332 __format::_ChronoData<_CharT> __cd{};
2333 __cd._M_weekday = __t;
2334 return _M_f._M_format(__cd, __fc);
2338 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2340 using __format::_ChronoFormats;
2341 using enum __format::_ChronoParts;
2343 __format::_ChronoSpec<_CharT> __res{};
2344 __res._M_debug =
true;
2345 __res._M_localized =
true;
2346 __res._M_locale_specific =
true;
2347 __res._M_needed = _Weekday;
2348 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_w();
2352 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2355 template<__format::__
char _CharT>
2356 struct formatter<
chrono::weekday_indexed, _CharT>
2358 constexpr typename basic_format_parse_context<_CharT>::iterator
2359 parse(basic_format_parse_context<_CharT>& __pc)
2361 using enum __format::_ChronoParts;
2362 return _M_f._M_parse(__pc, _IndexedWeekday, __defSpec);
2365 template<
typename _Out>
2366 typename basic_format_context<_Out, _CharT>::iterator
2367 format(
const chrono::weekday_indexed& __t,
2368 basic_format_context<_Out, _CharT>& __fc)
const
2370 __format::_ChronoData<_CharT> __cd{};
2371 __cd._M_fill_weekday(__t, __defSpec._M_needed);
2372 return _M_f._M_format(__cd, __fc);
2376 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2378 using __format::_ChronoFormats;
2379 using enum __format::_ChronoParts;
2381 __format::_ChronoSpec<_CharT> __res{};
2382 __res._M_debug =
true;
2383 __res._M_localized =
true;
2384 __res._M_locale_specific =
true;
2385 __res._M_needed = _IndexedWeekday;
2386 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_wi();
2390 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2393 template<__format::__
char _CharT>
2394 struct formatter<
chrono::weekday_last, _CharT>
2396 constexpr typename basic_format_parse_context<_CharT>::iterator
2397 parse(basic_format_parse_context<_CharT>& __pc)
2399 using enum __format::_ChronoParts;
2400 return _M_f._M_parse(__pc, _Weekday, __defSpec);
2403 template<
typename _Out>
2404 typename basic_format_context<_Out, _CharT>::iterator
2405 format(
const chrono::weekday_last& __t,
2406 basic_format_context<_Out, _CharT>& __fc)
const
2408 __format::_ChronoData<_CharT> __cd{};
2409 __cd._M_weekday = __t.weekday();
2410 return _M_f._M_format(__cd, __fc);
2414 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2416 using __format::_ChronoFormats;
2417 using enum __format::_ChronoParts;
2419 __format::_ChronoSpec<_CharT> __res{};
2420 __res._M_debug =
true;
2421 __res._M_localized =
true;
2422 __res._M_locale_specific =
true;
2423 __res._M_needed = _Weekday;
2424 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_wl();
2428 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2431 template<__format::__
char _CharT>
2432 struct formatter<
chrono::month_day, _CharT>
2434 constexpr typename basic_format_parse_context<_CharT>::iterator
2435 parse(basic_format_parse_context<_CharT>& __pc)
2437 using enum __format::_ChronoParts;
2438 return _M_f._M_parse(__pc, _Month|_Day|_WeekdayIndex, __defSpec);
2441 template<
typename _Out>
2442 typename basic_format_context<_Out, _CharT>::iterator
2443 format(
const chrono::month_day& __t,
2444 basic_format_context<_Out, _CharT>& __fc)
const
2446 __format::_ChronoData<_CharT> __cd{};
2447 __cd._M_month = __t.month();
2448 __cd._M_fill_day(__t.day(), __defSpec._M_needed);
2449 return _M_f._M_format(__cd, __fc);
2453 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2455 using __format::_ChronoFormats;
2456 using enum __format::_ChronoParts;
2458 __format::_ChronoSpec<_CharT> __res{};
2459 __res._M_debug =
true;
2460 __res._M_localized =
true;
2461 __res._M_locale_specific =
true;
2462 __res._M_needed = _Month|_Day;
2463 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_md();
2467 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2470 template<__format::__
char _CharT>
2471 struct formatter<
chrono::month_day_last, _CharT>
2473 constexpr typename basic_format_parse_context<_CharT>::iterator
2474 parse(basic_format_parse_context<_CharT>& __pc)
2476 using enum __format::_ChronoParts;
2477 return _M_f._M_parse(__pc, _Month, __defSpec);
2480 template<
typename _Out>
2481 typename basic_format_context<_Out, _CharT>::iterator
2482 format(
const chrono::month_day_last& __t,
2483 basic_format_context<_Out, _CharT>& __fc)
const
2485 __format::_ChronoData<_CharT> __cd{};
2486 __cd._M_month = __t.month();
2487 return _M_f._M_format(__cd, __fc);
2491 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2493 using __format::_ChronoFormats;
2494 using enum __format::_ChronoParts;
2496 __format::_ChronoSpec<_CharT> __res{};
2497 __res._M_debug =
true;
2498 __res._M_localized =
true;
2499 __res._M_locale_specific =
true;
2500 __res._M_needed = _Month;
2501 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ml();
2505 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2508 template<__format::__
char _CharT>
2509 struct formatter<
chrono::month_weekday, _CharT>
2511 constexpr typename basic_format_parse_context<_CharT>::iterator
2512 parse(basic_format_parse_context<_CharT>& __pc)
2514 using enum __format::_ChronoParts;
2515 return _M_f._M_parse(__pc, _Month|_IndexedWeekday, __defSpec);
2518 template<
typename _Out>
2519 typename basic_format_context<_Out, _CharT>::iterator
2520 format(
const chrono::month_weekday& __t,
2521 basic_format_context<_Out, _CharT>& __fc)
const
2523 __format::_ChronoData<_CharT> __cd{};
2524 __cd._M_month = __t.month();
2525 __cd._M_fill_weekday(__t.weekday_indexed(), __defSpec._M_needed);
2526 return _M_f._M_format(__cd, __fc);
2530 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2532 using __format::_ChronoFormats;
2533 using enum __format::_ChronoParts;
2535 __format::_ChronoSpec<_CharT> __res{};
2536 __res._M_debug =
true;
2537 __res._M_localized =
true;
2538 __res._M_locale_specific =
true;
2539 __res._M_needed = _Month|_IndexedWeekday;
2540 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_mwi();
2544 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2547 template<__format::__
char _CharT>
2548 struct formatter<
chrono::month_weekday_last, _CharT>
2550 constexpr typename basic_format_parse_context<_CharT>::iterator
2551 parse(basic_format_parse_context<_CharT>& __pc)
2553 using enum __format::_ChronoParts;
2554 return _M_f._M_parse(__pc, _Month|_Weekday, __defSpec);
2557 template<
typename _Out>
2558 typename basic_format_context<_Out, _CharT>::iterator
2559 format(
const chrono::month_weekday_last& __t,
2560 basic_format_context<_Out, _CharT>& __fc)
const
2562 __format::_ChronoData<_CharT> __cd{};
2563 __cd._M_month = __t.month();
2564 __cd._M_weekday = __t.weekday_last().weekday();
2565 return _M_f._M_format(__cd, __fc);
2569 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2571 using __format::_ChronoFormats;
2572 using enum __format::_ChronoParts;
2574 __format::_ChronoSpec<_CharT> __res{};
2575 __res._M_debug =
true;
2576 __res._M_localized =
true;
2577 __res._M_locale_specific =
true;
2578 __res._M_needed = _Month|_Weekday;
2579 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_mwl();
2583 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2586 template<__format::__
char _CharT>
2587 struct formatter<
chrono::year_month, _CharT>
2589 constexpr typename basic_format_parse_context<_CharT>::iterator
2590 parse(basic_format_parse_context<_CharT>& __pc)
2592 using enum __format::_ChronoParts;
2593 return _M_f._M_parse(__pc, _Year|_Month, __defSpec);
2596 template<
typename _Out>
2597 typename basic_format_context<_Out, _CharT>::iterator
2598 format(
const chrono::year_month& __t,
2599 basic_format_context<_Out, _CharT>& __fc)
const
2601 __format::_ChronoData<_CharT> __cd{};
2602 __cd._M_fill_year_month(__t, __defSpec._M_needed);
2603 return _M_f._M_format(__cd, __fc);
2607 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2609 using __format::_ChronoFormats;
2610 using enum __format::_ChronoParts;
2612 __format::_ChronoSpec<_CharT> __res{};
2613 __res._M_debug =
true;
2614 __res._M_localized =
true;
2615 __res._M_locale_specific =
true;
2616 __res._M_needed = _Year|_Month;
2617 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ym();
2621 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2624 template<__format::__
char _CharT>
2625 struct formatter<
chrono::year_month_day, _CharT>
2627 constexpr typename basic_format_parse_context<_CharT>::iterator
2628 parse(basic_format_parse_context<_CharT>& __pc)
2630 using enum __format::_ChronoParts;
2631 return _M_f._M_parse(__pc, _Date, __defSpec);
2634 template<
typename _Out>
2635 typename basic_format_context<_Out, _CharT>::iterator
2636 format(
const chrono::year_month_day& __t,
2637 basic_format_context<_Out, _CharT>& __fc)
const
2639 __format::_ChronoData<_CharT> __cd{};
2640 auto __parts = _M_f._M_spec._M_needed;
2641 __parts = __cd._M_fill_year_month(__t, __parts);
2642 __parts = __cd._M_fill_day(__t.day(), __parts);
2644 return _M_f._M_format(__cd, __fc);
2646 chrono::local_days __ld(__t);
2647 __cd._M_fill_ldays(__ld, __parts);
2648 return _M_f._M_format(__cd, __fc);
2652 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2654 using __format::_ChronoFormats;
2655 using enum __format::_ChronoParts;
2657 __format::_ChronoSpec<_CharT> __res{};
2658 __res._M_debug =
true;
2659 __res._M_needed = _YearMonthDay;
2660 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_f();
2664 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2667 template<__format::__
char _CharT>
2668 struct formatter<
chrono::year_month_day_last, _CharT>
2670 constexpr typename basic_format_parse_context<_CharT>::iterator
2671 parse(basic_format_parse_context<_CharT>& __pc)
2673 using enum __format::_ChronoParts;
2674 return _M_f._M_parse(__pc, _Date, __defSpec);
2677 template<
typename _Out>
2678 typename basic_format_context<_Out, _CharT>::iterator
2679 format(
const chrono::year_month_day_last& __t,
2680 basic_format_context<_Out, _CharT>& __fc)
const
2682 __format::_ChronoData<_CharT> __cd{};
2683 auto __parts = _M_f._M_spec._M_needed;
2684 __parts = __cd._M_fill_year_month(__t, __parts);
2686 return _M_f._M_format(__cd, __fc);
2688 chrono::local_days __ld(__t);
2689 __parts = __cd._M_fill_ldays(__ld, __parts);
2691 return _M_f._M_format(__cd, __fc);
2693 chrono::year_month_day __ymd(__ld);
2694 __cd._M_fill_day(__ymd.day(), __parts);
2695 return _M_f._M_format(__cd, __fc);
2699 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2701 using __format::_ChronoFormats;
2702 using enum __format::_ChronoParts;
2704 __format::_ChronoSpec<_CharT> __res{};
2705 __res._M_debug =
true;
2706 __res._M_localized =
true;
2707 __res._M_locale_specific =
true;
2708 __res._M_needed = _Year|_Month;
2709 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_yml();
2713 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2716 template<__format::__
char _CharT>
2717 struct formatter<
chrono::year_month_weekday, _CharT>
2719 constexpr typename basic_format_parse_context<_CharT>::iterator
2720 parse(basic_format_parse_context<_CharT>& __pc)
2722 using enum __format::_ChronoParts;
2723 return _M_f._M_parse(__pc, _Date, __defSpec);
2726 template<
typename _Out>
2727 typename basic_format_context<_Out, _CharT>::iterator
2728 format(
const chrono::year_month_weekday& __t,
2729 basic_format_context<_Out, _CharT>& __fc)
const
2731 __format::_ChronoData<_CharT> __cd{};
2732 auto __parts = _M_f._M_spec._M_needed;
2733 __parts = __cd._M_fill_year_month(__t, __parts);
2734 __parts = __cd._M_fill_weekday(__t.weekday_indexed(), __parts);
2736 return _M_f._M_format(__cd, __fc);
2738 chrono::local_days __ld(__t);
2739 __parts = __cd._M_fill_ldays(__ld, __parts);
2741 return _M_f._M_format(__cd, __fc);
2743 chrono::year_month_day __ymd(__ld);
2745 __cd._M_day = __ymd.day();
2746 return _M_f._M_format(__cd, __fc);
2750 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2752 using __format::_ChronoFormats;
2753 using enum __format::_ChronoParts;
2755 __format::_ChronoSpec<_CharT> __res{};
2756 __res._M_debug =
true;
2757 __res._M_localized =
true;
2758 __res._M_locale_specific =
true;
2759 __res._M_needed = _Year|_Month|_IndexedWeekday;
2760 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ymwi();
2764 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2767 template<__format::__
char _CharT>
2768 struct formatter<
chrono::year_month_weekday_last, _CharT>
2770 constexpr typename basic_format_parse_context<_CharT>::iterator
2771 parse(basic_format_parse_context<_CharT>& __pc)
2773 using enum __format::_ChronoParts;
2774 return _M_f._M_parse(__pc, _Date, __defSpec);
2777 template<
typename _Out>
2778 typename basic_format_context<_Out, _CharT>::iterator
2779 format(
const chrono::year_month_weekday_last& __t,
2780 basic_format_context<_Out, _CharT>& __fc)
const
2782 __format::_ChronoData<_CharT> __cd{};
2783 auto __parts = _M_f._M_spec._M_needed;
2784 __parts = __cd._M_fill_year_month(__t, __parts);
2785 __cd._M_weekday = __t.weekday_last().weekday();
2786 __parts -= __format::_ChronoParts::_Weekday;
2788 return _M_f._M_format(__cd, __fc);
2790 chrono::local_days __ld(__t);
2791 __parts = __cd._M_fill_ldays(__ld, __parts);
2793 return _M_f._M_format(__cd, __fc);
2795 chrono::year_month_day __ymd(__ld);
2796 __cd._M_fill_day(__ymd.day(), __parts);
2797 return _M_f._M_format(__cd, __fc);
2801 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2803 using __format::_ChronoFormats;
2804 using enum __format::_ChronoParts;
2806 __format::_ChronoSpec<_CharT> __res{};
2807 __res._M_debug =
true;
2808 __res._M_localized =
true;
2809 __res._M_locale_specific =
true;
2810 __res._M_needed = _Year|_Month|_Weekday;
2811 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ymwl();
2815 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2818 template<
typename _Rep,
typename _Period, __format::__
char _CharT>
2819 struct formatter<
chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>, _CharT>
2821 constexpr typename basic_format_parse_context<_CharT>::iterator
2822 parse(basic_format_parse_context<_CharT>& __pc)
2824 using enum __format::_ChronoParts;
2825 return _M_f.template _M_parse<_Precision>(__pc, _Time, __defSpec);
2828 template<
typename _Out>
2829 typename basic_format_context<_Out, _CharT>::iterator
2830 format(
const chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>& __t,
2831 basic_format_context<_Out, _CharT>& __fc)
const
2833 using enum __format::_ChronoParts;
2835 __format::_ChronoData<_CharT> __cd;
2836 __cd._M_is_neg = __t.is_negative();
2837 __cd._M_hours = __t.hours();
2838 __cd._M_minutes = __t.minutes();
2839 __cd._M_seconds = __t.seconds();
2844 if (_M_f._M_spec._M_needs(_EpochUnits))
2845 __d = __t.to_duration();
2846 if (_M_f._M_spec._M_needs(_TotalSeconds))
2848 = __cd._M_hours + __cd._M_minutes + __cd._M_seconds;
2849 return _M_f._M_format_units(__cd, __d, __t.subseconds(), __fc);
2854 =
typename chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>::precision;
2855 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
2856 __format::__formatter_duration<_CharT>::
2857 template _S_spec_for<_Precision>(__format::_ChronoParts::_Time);
2859 __format::__formatter_duration<_CharT> _M_f{__defSpec};
2862#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2863 template<__format::__
char _CharT>
2864 struct formatter<
chrono::sys_info, _CharT>
2866 constexpr typename basic_format_parse_context<_CharT>::iterator
2867 parse(basic_format_parse_context<_CharT>& __pc)
2868 {
return _M_f.parse(__pc); }
2870 template<
typename _Out>
2871 typename basic_format_context<_Out, _CharT>::iterator
2872 format(
const chrono::sys_info& __i,
2873 basic_format_context<_Out, _CharT>& __fc)
const
2874 {
return _M_f.format(__i, __fc); }
2877 __format::__formatter_chrono_info<_CharT> _M_f;
2880 template<__format::__
char _CharT>
2881 struct formatter<
chrono::local_info, _CharT>
2883 constexpr typename basic_format_parse_context<_CharT>::iterator
2884 parse(basic_format_parse_context<_CharT>& __pc)
2885 {
return _M_f.parse(__pc); }
2887 template<
typename _Out>
2888 typename basic_format_context<_Out, _CharT>::iterator
2889 format(
const chrono::local_info& __i,
2890 basic_format_context<_Out, _CharT>& __fc)
const
2891 {
return _M_f.format(__i, __fc); }
2894 __format::__formatter_chrono_info<_CharT> _M_f;
2898 template<
typename _Duration, __format::__
char _CharT>
2899 struct formatter<
chrono::sys_time<_Duration>, _CharT>
2901 constexpr typename basic_format_parse_context<_CharT>::iterator
2902 parse(basic_format_parse_context<_CharT>& __pc)
2904 using enum __format::_ChronoParts;
2906 = _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
2907 if constexpr (!__stream_insertable)
2908 if (_M_f._M_spec._M_chrono_specs.empty())
2909 __format::__invalid_chrono_spec();
2913 template<
typename _Out>
2914 typename basic_format_context<_Out, _CharT>::iterator
2915 format(
const chrono::sys_time<_Duration>& __t,
2916 basic_format_context<_Out, _CharT>& __fc)
const
2918 __format::_ChronoData<_CharT> __cd{};
2919 __cd._M_fill_utc_zone();
2921 _Duration __ed = __t.time_since_epoch();
2922 __cd._M_eseconds = chrono::floor<chrono::seconds>(__ed);
2923 __cd._M_lseconds = chrono::local_seconds(__cd._M_eseconds);
2924 return _M_f._M_format_time_point(__cd, __ed, __fc);
2928 static constexpr bool __stream_insertable
2929 =
requires (basic_ostream<_CharT>& __os,
2930 chrono::sys_time<_Duration> __t) { __os << __t; };
2932 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2934 using enum __format::_ChronoParts;
2935 __format::_ChronoParts __needed = _DateTime;
2936 if constexpr (!__stream_insertable)
2938 else if constexpr (is_convertible_v<_Duration, chrono::days>)
2940 return __format::__formatter_duration<_CharT>::
2941 template _S_spec_for<_Duration>(__needed);
2944 __format::__formatter_duration<_CharT> _M_f{__defSpec};
2947 template<
typename _Duration, __format::__
char _CharT>
2948 struct formatter<
chrono::utc_time<_Duration>, _CharT>
2949 : __format::__formatter_chrono<_CharT>
2951 constexpr typename basic_format_parse_context<_CharT>::iterator
2952 parse(basic_format_parse_context<_CharT>& __pc)
2954 using enum __format::_ChronoParts;
2955 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
2958 template<
typename _Out>
2959 typename basic_format_context<_Out, _CharT>::iterator
2960 format(
const chrono::utc_time<_Duration>& __t,
2961 basic_format_context<_Out, _CharT>& __fc)
const
2963 using __format::_ChronoParts;
2964 using namespace chrono;
2965 __format::_ChronoData<_CharT> __cd{};
2966 __cd._M_fill_utc_zone();
2968 _Duration __ed = __t.time_since_epoch();
2969 __cd._M_eseconds = chrono::floor<seconds>(__ed);
2973 const auto __li = chrono::get_leap_second_info(__t);
2974 __cd._M_lseconds = local_seconds(__cd._M_eseconds - __li.elapsed);
2975 auto __parts = _M_f._M_spec._M_needed - _ChronoParts::_TotalSeconds;
2976 if ((__parts & _ChronoParts::_DateTime) != 0)
2978 __cd._M_fill_date_time(__cd._M_lseconds, __parts);
2979 __cd._M_seconds +=
seconds(__li.is_leap_second);
2981 return _M_f._M_format_units(__cd, __ed, __ed - __cd._M_eseconds, __fc);
2985 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
2986 __format::__formatter_duration<_CharT>::
2987 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
2989 __format::__formatter_duration<_CharT> _M_f{__defSpec};
2992 template<
typename _Duration, __format::__
char _CharT>
2993 struct formatter<
chrono::tai_time<_Duration>, _CharT>
2994 : __format::__formatter_chrono<_CharT>
2996 constexpr typename basic_format_parse_context<_CharT>::iterator
2997 parse(basic_format_parse_context<_CharT>& __pc)
2999 using enum __format::_ChronoParts;
3000 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3003 template<
typename _Out>
3004 typename basic_format_context<_Out, _CharT>::iterator
3005 format(
const chrono::tai_time<_Duration>& __t,
3006 basic_format_context<_Out, _CharT>& __fc)
const
3008 using namespace chrono;
3009 __format::_ChronoData<_CharT> __cd{};
3010 __cd._M_fill_zone(
"TAI", L
"TAI");
3012 _Duration __ed = __t.time_since_epoch();
3013 __cd._M_eseconds = chrono::floor<seconds>(__ed);
3015 constexpr chrono::days __tai_offset = chrono::days(4383);
3016 __cd._M_lseconds = local_seconds(__cd._M_eseconds - __tai_offset);
3017 return _M_f._M_format_time_point(__cd, __ed, __fc);
3021 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3022 __format::__formatter_duration<_CharT>::
3023 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3025 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3028 template<
typename _Duration, __format::__
char _CharT>
3029 struct formatter<
chrono::gps_time<_Duration>, _CharT>
3030 : __format::__formatter_chrono<_CharT>
3032 constexpr typename basic_format_parse_context<_CharT>::iterator
3033 parse(basic_format_parse_context<_CharT>& __pc)
3035 using enum __format::_ChronoParts;
3036 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3039 template<
typename _Out>
3040 typename basic_format_context<_Out, _CharT>::iterator
3041 format(
const chrono::gps_time<_Duration>& __t,
3042 basic_format_context<_Out, _CharT>& __fc)
const
3044 using namespace chrono;
3045 __format::_ChronoData<_CharT> __cd{};
3046 __cd._M_fill_zone(
"GPS", L
"GPS");
3048 _Duration __ed = __t.time_since_epoch();
3049 __cd._M_eseconds = chrono::floor<seconds>(__ed);
3051 constexpr chrono::days __gps_offset = chrono::days(3657);
3052 __cd._M_lseconds = local_seconds(__cd._M_eseconds + __gps_offset);
3053 return _M_f._M_format_time_point(__cd, __ed, __fc);
3057 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3058 __format::__formatter_duration<_CharT>::
3059 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3061 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3064 template<
typename _Duration, __format::__
char _CharT>
3065 struct formatter<
chrono::file_time<_Duration>, _CharT>
3067 constexpr typename basic_format_parse_context<_CharT>::iterator
3068 parse(basic_format_parse_context<_CharT>& __pc)
3070 using enum __format::_ChronoParts;
3071 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3074 template<
typename _Out>
3075 typename basic_format_context<_Out, _CharT>::iterator
3076 format(
const chrono::file_time<_Duration>& __t,
3077 basic_format_context<_Out, _CharT>& __fc)
const
3079 using namespace chrono;
3080 __format::_ChronoData<_CharT> __cd{};
3081 __cd._M_fill_utc_zone();
3083 _Duration __ed = __t.time_since_epoch();
3084 __cd._M_eseconds = chrono::floor<seconds>(__ed);
3085 auto __st = chrono::clock_cast<system_clock>(__t);
3087 = local_seconds(chrono::floor<seconds>(__st.time_since_epoch()));
3088 return _M_f._M_format_time_point(__cd, __ed, __fc);
3092 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3093 __format::__formatter_duration<_CharT>::
3094 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3096 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3099 template<
typename _Duration, __format::__
char _CharT>
3100 struct formatter<
chrono::local_time<_Duration>, _CharT>
3102 constexpr typename basic_format_parse_context<_CharT>::iterator
3103 parse(basic_format_parse_context<_CharT>& __pc)
3105 using enum __format::_ChronoParts;
3106 return _M_f.template _M_parse<_Duration>(__pc, _DateTime, __defSpec);
3109 template<
typename _Out>
3110 typename basic_format_context<_Out, _CharT>::iterator
3111 format(
const chrono::local_time<_Duration>& __lt,
3112 basic_format_context<_Out, _CharT>& __fc)
const
3114 __format::_ChronoData<_CharT> __cd{};
3115 _Duration __ed = __lt.time_since_epoch();
3116 __cd._M_lseconds = chrono::floor<chrono::seconds>(__lt);
3117 __cd._M_eseconds = __cd._M_lseconds.time_since_epoch();
3118 return _M_f._M_format_time_point(__cd, __ed, __fc);
3122 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
3124 using enum __format::_ChronoParts;
3125 __format::_ChronoParts __needed = _DateTime;
3126 if constexpr (is_convertible_v<_Duration, chrono::days>)
3128 return __format::__formatter_duration<_CharT>::
3129 template _S_spec_for<_Duration>(__needed);
3132 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3135 template<
typename _Duration, __format::__
char _CharT>
3136 struct formatter<
chrono::__detail::__local_time_fmt<_Duration>, _CharT>
3138 constexpr typename basic_format_parse_context<_CharT>::iterator
3139 parse(basic_format_parse_context<_CharT>& __pc)
3141 using enum __format::_ChronoParts;
3142 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3145 template<
typename _Out>
3146 typename basic_format_context<_Out, _CharT>::iterator
3147 format(
const chrono::__detail::__local_time_fmt<_Duration>& __zt,
3148 basic_format_context<_Out, _CharT>& __fc)
const
3150 using enum __format::_ChronoParts;
3151 __format::_ChronoData<_CharT> __cd{};
3153 if (_M_f._M_spec._M_needs(_ZoneOffset))
3155 if (!__zt._M_offset_sec)
3156 std::__throw_format_error(
"format error: no timezone available for %z");
3157 __cd._M_zone_offset = *__zt._M_offset_sec;
3160 basic_string<_CharT> __zone_store;
3161 if (_M_f._M_spec._M_needs(_ZoneAbbrev))
3163 if (!__zt._M_abbrev)
3164 std::__throw_format_error(
"format error: no timezone available for %Z");
3166 __cd._M_zone_cstr = __zt._M_abbrev->data();
3167 if constexpr (is_same_v<_CharT, char>)
3168 __cd._M_zone_abbrev = *__zt._M_abbrev;
3172 __zone_store.resize(__zt._M_abbrev->size());
3173 auto& __ct = use_facet<ctype<_CharT>>(_M_f._M_locale(__fc));
3174 __ct.widen(__zt._M_abbrev->data(),
3175 __zt._M_abbrev->data() + __zt._M_abbrev->size(),
3176 __zone_store.data());
3177 __cd._M_zone_abbrev = __zone_store;
3181 _Duration __ed = __zt._M_time.time_since_epoch();
3182 __cd._M_lseconds = chrono::floor<chrono::seconds>(__zt._M_time);
3183 __cd._M_eseconds = __cd._M_lseconds.time_since_epoch();
3184 return _M_f._M_format_time_point(__cd, __ed, __fc);
3188 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3189 __format::__formatter_duration<_CharT>::
3190 template _S_spec_for<_Duration>(__format::_ChronoParts::_ZonedDateTime);
3192 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3195#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
3196 template<
typename _Duration,
typename _TimeZonePtr, __format::__
char _CharT>
3197 struct formatter<
chrono::zoned_time<_Duration, _TimeZonePtr>, _CharT>
3198 : formatter<chrono::__detail::__local_time_fmt_for<_Duration>, _CharT>
3200 template<
typename _Out>
3201 typename basic_format_context<_Out, _CharT>::iterator
3202 format(
const chrono::zoned_time<_Duration, _TimeZonePtr>& __tp,
3203 basic_format_context<_Out, _CharT>& __fc)
const
3205 using _Ltf = chrono::__detail::__local_time_fmt_for<_Duration>;
3206 using _Base = formatter<_Ltf, _CharT>;
3207 const chrono::sys_info __info = __tp.get_info();
3208 const auto __lf = chrono::local_time_format(__tp.get_local_time(),
3211 return _Base::format(__lf, __fc);
3224 template<
typename _Duration = seconds>
3227 static_assert(is_same_v<common_type_t<_Duration, seconds>, _Duration>);
3230 _Parser(__format::_ChronoParts __need) : _M_need(__need) { }
3232 _Parser(_Parser&&) =
delete;
3233 void operator=(_Parser&&) =
delete;
3235 _Duration _M_time{};
3236 sys_days _M_sys_days{};
3237 year_month_day _M_ymd{};
3239 __format::_ChronoParts _M_need;
3240 unsigned _M_is_leap_second : 1 {};
3241 unsigned _M_reserved : 15 {};
3243 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3244 basic_istream<_CharT, _Traits>&
3245 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3246 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3247 minutes* __offset =
nullptr);
3252 template<
typename _CharT,
typename _Traits>
3253 static int_least32_t
3254 _S_read_unsigned(basic_istream<_CharT, _Traits>& __is,
3255 ios_base::iostate& __err,
int __n)
3257 int_least32_t __val = _S_try_read_digit(__is, __err);
3258 if (__val == -1) [[unlikely]]
3259 __err |= ios_base::failbit;
3264 for (
int __i = 1; __i < __n1; ++__i)
3265 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
3271 while (__n1++ < __n) [[unlikely]]
3272 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
3274 if (__builtin_mul_overflow(__val, 10, &__val)
3275 || __builtin_add_overflow(__val, __dig, &__val))
3277 __err |= ios_base::failbit;
3287 template<
typename _CharT,
typename _Traits>
3288 static int_least32_t
3289 _S_read_signed(basic_istream<_CharT, _Traits>& __is,
3290 ios_base::iostate& __err,
int __n)
3292 auto __sign = __is.peek();
3293 if (__sign ==
'-' || __sign ==
'+')
3295 int_least32_t __val = _S_read_unsigned(__is, __err, __n);
3296 if (__err & ios_base::failbit)
3298 if (__sign ==
'-') [[unlikely]]
3306 template<
typename _CharT,
typename _Traits>
3307 static int_least32_t
3308 _S_try_read_digit(basic_istream<_CharT, _Traits>& __is,
3309 ios_base::iostate& __err)
3311 int_least32_t __val = -1;
3312 auto __i = __is.peek();
3313 if (!_Traits::eq_int_type(__i, _Traits::eof())) [[likely]]
3315 _CharT __c = _Traits::to_char_type(__i);
3316 if (_CharT(
'0') <= __c && __c <= _CharT(
'9')) [[likely]]
3319 __val = __c - _CharT(
'0');
3323 __err |= ios_base::eofbit;
3329 template<
typename _CharT,
typename _Traits>
3331 _S_read_chr(basic_istream<_CharT, _Traits>& __is,
3332 ios_base::iostate& __err, _CharT __c)
3334 auto __i = __is.peek();
3335 if (_Traits::eq_int_type(__i, _Traits::eof()))
3336 __err |= ios_base::eofbit;
3337 else if (_Traits::to_char_type(__i) == __c) [[likely]]
3342 __err |= ios_base::failbit;
3347 template<
typename _Duration>
3348 using _Parser_t = _Parser<common_type_t<_Duration, seconds>>;
3350 template<
typename _Duration>
3354 if constexpr (_Duration::period::den == 1)
3356 switch (_Duration::period::num)
3358 case minutes::period::num:
3359 case hours::period::num:
3360 case days::period::num:
3361 case weeks::period::num:
3362 case years::period::num:
3379 template<
typename _ToDur,
typename _Tp>
3381 __round(
const _Tp& __t)
3383 if constexpr (__is_duration_v<_Tp>)
3385 if constexpr (treat_as_floating_point_v<typename _Tp::rep>)
3387 else if constexpr (__detail::__use_floor<_ToDur>())
3394 static_assert(__is_time_point_v<_Tp>);
3395 using _Tpt = time_point<typename _Tp::clock, _ToDur>;
3396 return _Tpt(__detail::__round<_ToDur>(__t.time_since_epoch()));
3403 template<
typename _CharT,
typename _Traits,
typename _Rep,
typename _Period,
3404 typename _Alloc = allocator<_CharT>>
3405 inline basic_istream<_CharT, _Traits>&
3406 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3408 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3411 auto __need = __format::_ChronoParts::_TimeOfDay;
3412 __detail::_Parser_t<duration<_Rep, _Period>> __p(__need);
3413 if (__p(__is, __fmt, __abbrev, __offset))
3414 __d = __detail::__round<duration<_Rep, _Period>>(__p._M_time);
3418 template<
typename _CharT,
typename _Traits>
3419 inline basic_ostream<_CharT, _Traits>&
3420 operator<<(basic_ostream<_CharT, _Traits>& __os,
const day& __d)
3422 using _Ctx = __format::__format_context<_CharT>;
3423 using _Str = basic_string_view<_CharT>;
3424 _Str __s = _GLIBCXX_WIDEN(
"{:02d} is not a valid day");
3426 __s = __s.substr(0, 6);
3427 auto __u = (unsigned)__d;
3428 __os << std::vformat(__s, make_format_args<_Ctx>(__u));
3432 template<
typename _CharT,
typename _Traits,
3433 typename _Alloc = allocator<_CharT>>
3434 inline basic_istream<_CharT, _Traits>&
3435 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3437 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3440 __detail::_Parser<> __p(__format::_ChronoParts::_Day);
3441 if (__p(__is, __fmt, __abbrev, __offset))
3442 __d = __p._M_ymd.day();
3446 template<
typename _CharT,
typename _Traits>
3447 inline basic_ostream<_CharT, _Traits>&
3448 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month& __m)
3450 using _Ctx = __format::__format_context<_CharT>;
3451 using _Str = basic_string_view<_CharT>;
3452 _Str __s = _GLIBCXX_WIDEN(
"{:L%b}{} is not a valid month");
3454 __os << std::vformat(__os.getloc(), __s.substr(0, 6),
3455 make_format_args<_Ctx>(__m));
3458 auto __u = (unsigned)__m;
3459 __os << std::vformat(__s.substr(6), make_format_args<_Ctx>(__u));
3464 template<
typename _CharT,
typename _Traits,
3465 typename _Alloc = allocator<_CharT>>
3466 inline basic_istream<_CharT, _Traits>&
3467 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3469 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3472 __detail::_Parser<> __p(__format::_ChronoParts::_Month);
3473 if (__p(__is, __fmt, __abbrev, __offset))
3474 __m = __p._M_ymd.month();
3478 template<
typename _CharT,
typename _Traits>
3479 inline basic_ostream<_CharT, _Traits>&
3480 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year& __y)
3482 using _Ctx = __format::__format_context<_CharT>;
3483 using _Str = basic_string_view<_CharT>;
3484 _Str __s = _GLIBCXX_WIDEN(
"-{:04d} is not a valid year");
3486 __s = __s.substr(0, 7);
3488 if (__i >= 0) [[likely]]
3489 __s.remove_prefix(1);
3492 __os << std::vformat(__s, make_format_args<_Ctx>(__i));
3496 template<
typename _CharT,
typename _Traits,
3497 typename _Alloc = allocator<_CharT>>
3498 inline basic_istream<_CharT, _Traits>&
3499 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3501 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3504 __detail::_Parser<> __p(__format::_ChronoParts::_Year);
3505 if (__p(__is, __fmt, __abbrev, __offset))
3506 __y = __p._M_ymd.year();
3510 template<
typename _CharT,
typename _Traits>
3511 inline basic_ostream<_CharT, _Traits>&
3512 operator<<(basic_ostream<_CharT, _Traits>& __os,
const weekday& __wd)
3514 using _Ctx = __format::__format_context<_CharT>;
3515 using _Str = basic_string_view<_CharT>;
3516 _Str __s = _GLIBCXX_WIDEN(
"{:L%a}{} is not a valid weekday");
3518 __os << std::vformat(__os.getloc(), __s.substr(0, 6),
3519 make_format_args<_Ctx>(__wd));
3522 auto __c = __wd.c_encoding();
3523 __os << std::vformat(__s.substr(6), make_format_args<_Ctx>(__c));
3528 template<
typename _CharT,
typename _Traits,
3529 typename _Alloc = allocator<_CharT>>
3530 inline basic_istream<_CharT, _Traits>&
3531 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3533 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3536 __detail::_Parser<> __p(__format::_ChronoParts::_Weekday);
3537 if (__p(__is, __fmt, __abbrev, __offset))
3542 template<
typename _CharT,
typename _Traits>
3543 inline basic_ostream<_CharT, _Traits>&
3544 operator<<(basic_ostream<_CharT, _Traits>& __os,
3545 const weekday_indexed& __wdi)
3550 basic_stringstream<_CharT> __os2;
3551 __os2.imbue(__os.getloc());
3552 __os2 << __wdi.weekday();
3553 const auto __i = __wdi.index();
3554 basic_string_view<_CharT> __s
3555 = _GLIBCXX_WIDEN(
"[ is not a valid index]");
3557 __os2 << std::format(_GLIBCXX_WIDEN(
"{}"), __i);
3558 if (__i >= 1 && __i <= 5)
3559 __os2 << __s.back();
3561 __os2 << __s.substr(1);
3562 __os << __os2.view();
3566 template<
typename _CharT,
typename _Traits>
3567 inline basic_ostream<_CharT, _Traits>&
3568 operator<<(basic_ostream<_CharT, _Traits>& __os,
3569 const weekday_last& __wdl)
3572 basic_stringstream<_CharT> __os2;
3573 __os2.imbue(__os.getloc());
3574 __os2 << __wdl.weekday() << _GLIBCXX_WIDEN(
"[last]");
3575 __os << __os2.view();
3579 template<
typename _CharT,
typename _Traits>
3580 inline basic_ostream<_CharT, _Traits>&
3581 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month_day& __md)
3584 basic_stringstream<_CharT> __os2;
3585 __os2.imbue(__os.getloc());
3586 __os2 << __md.month();
3587 if constexpr (is_same_v<_CharT, char>)
3591 __os2 << __md.day();
3592 __os << __os2.view();
3596 template<
typename _CharT,
typename _Traits,
3597 typename _Alloc = allocator<_CharT>>
3598 inline basic_istream<_CharT, _Traits>&
3599 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3601 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3604 using __format::_ChronoParts;
3605 auto __need = _ChronoParts::_Month | _ChronoParts::_Day;
3606 __detail::_Parser<> __p(__need);
3607 if (__p(__is, __fmt, __abbrev, __offset))
3608 __md = month_day(__p._M_ymd.month(), __p._M_ymd.day());
3612 template<
typename _CharT,
typename _Traits>
3613 inline basic_ostream<_CharT, _Traits>&
3614 operator<<(basic_ostream<_CharT, _Traits>& __os,
3615 const month_day_last& __mdl)
3618 basic_stringstream<_CharT> __os2;
3619 __os2.imbue(__os.getloc());
3620 __os2 << __mdl.month() << _GLIBCXX_WIDEN(
"/last");
3621 __os << __os2.view();
3625 template<
typename _CharT,
typename _Traits>
3626 inline basic_ostream<_CharT, _Traits>&
3627 operator<<(basic_ostream<_CharT, _Traits>& __os,
3628 const month_weekday& __mwd)
3631 basic_stringstream<_CharT> __os2;
3632 __os2.imbue(__os.getloc());
3633 __os2 << __mwd.month();
3634 if constexpr (is_same_v<_CharT, char>)
3638 __os2 << __mwd.weekday_indexed();
3639 __os << __os2.view();
3643 template<
typename _CharT,
typename _Traits>
3644 inline basic_ostream<_CharT, _Traits>&
3645 operator<<(basic_ostream<_CharT, _Traits>& __os,
3646 const month_weekday_last& __mwdl)
3649 basic_stringstream<_CharT> __os2;
3650 __os2.imbue(__os.getloc());
3651 __os2 << __mwdl.month();
3652 if constexpr (is_same_v<_CharT, char>)
3656 __os2 << __mwdl.weekday_last();
3657 __os << __os2.view();
3661 template<
typename _CharT,
typename _Traits>
3662 inline basic_ostream<_CharT, _Traits>&
3663 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year_month& __ym)
3666 basic_stringstream<_CharT> __os2;
3667 __os2.imbue(__os.getloc());
3668 __os2 << __ym.year();
3669 if constexpr (is_same_v<_CharT, char>)
3673 __os2 << __ym.month();
3674 __os << __os2.view();
3678 template<
typename _CharT,
typename _Traits,
3679 typename _Alloc = allocator<_CharT>>
3680 inline basic_istream<_CharT, _Traits>&
3681 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3683 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3686 using __format::_ChronoParts;
3687 auto __need = _ChronoParts::_Year | _ChronoParts::_Month;
3688 __detail::_Parser<> __p(__need);
3689 if (__p(__is, __fmt, __abbrev, __offset))
3690 __ym = year_month(__p._M_ymd.year(), __p._M_ymd.month());
3694 template<
typename _CharT,
typename _Traits>
3695 inline basic_ostream<_CharT, _Traits>&
3696 operator<<(basic_ostream<_CharT, _Traits>& __os,
3697 const year_month_day& __ymd)
3699 using _Ctx = __format::__format_context<_CharT>;
3700 using _Str = basic_string_view<_CharT>;
3701 _Str __s = _GLIBCXX_WIDEN(
"{:%F} is not a valid date");
3702 __os << std::vformat(__ymd.ok() ? __s.substr(0, 5) : __s,
3703 make_format_args<_Ctx>(__ymd));
3707 template<
typename _CharT,
typename _Traits,
3708 typename _Alloc = allocator<_CharT>>
3709 inline basic_istream<_CharT, _Traits>&
3711 year_month_day& __ymd,
3715 using __format::_ChronoParts;
3716 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3717 | _ChronoParts::_Day;
3718 __detail::_Parser<> __p(__need);
3719 if (__p(__is, __fmt, __abbrev, __offset))
3724 template<
typename _CharT,
typename _Traits>
3727 const year_month_day_last& __ymdl)
3732 __os2 << __ymdl.year();
3733 if constexpr (is_same_v<_CharT, char>)
3737 __os2 << __ymdl.month_day_last();
3738 __os << __os2.view();
3742 template<
typename _CharT,
typename _Traits>
3743 inline basic_ostream<_CharT, _Traits>&
3744 operator<<(basic_ostream<_CharT, _Traits>& __os,
3745 const year_month_weekday& __ymwd)
3749 basic_stringstream<_CharT> __os2;
3750 __os2.
imbue(__os.getloc());
3752 if constexpr (is_same_v<_CharT, char>)
3756 __os2 << __ymwd.year() << __slash << __ymwd.month() << __slash
3757 << __ymwd.weekday_indexed();
3758 __os << __os2.view();
3762 template<
typename _CharT,
typename _Traits>
3763 inline basic_ostream<_CharT, _Traits>&
3764 operator<<(basic_ostream<_CharT, _Traits>& __os,
3765 const year_month_weekday_last& __ymwdl)
3769 basic_stringstream<_CharT> __os2;
3770 __os2.imbue(__os.getloc());
3772 if constexpr (is_same_v<_CharT, char>)
3776 __os2 << __ymwdl.year() << __slash << __ymwdl.month() << __slash
3777 << __ymwdl.weekday_last();
3778 __os << __os2.view();
3782 template<
typename _CharT,
typename _Traits,
typename _Duration>
3783 inline basic_ostream<_CharT, _Traits>&
3784 operator<<(basic_ostream<_CharT, _Traits>& __os,
3787 return __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%T}"), __hms);
3790#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
3792 template<
typename _CharT,
typename _Traits>
3793 basic_ostream<_CharT, _Traits>&
3794 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_info& __i)
3796 return __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{}"), __i);
3800 template<
typename _CharT,
typename _Traits>
3801 basic_ostream<_CharT, _Traits>&
3802 operator<<(basic_ostream<_CharT, _Traits>& __os,
const local_info& __li)
3804 __os << __format::_Separators<_CharT>::_S_squares()[0];
3805 if (__li.result == local_info::unique)
3809 if (__li.result == local_info::nonexistent)
3810 __os << _GLIBCXX_WIDEN(
"nonexistent");
3812 __os << _GLIBCXX_WIDEN(
"ambiguous");
3813 __os << _GLIBCXX_WIDEN(
" local time between ") << __li.first;
3814 __os << _GLIBCXX_WIDEN(
" and ") << __li.second;
3816 __os << __format::_Separators<_CharT>::_S_squares()[1];
3820 template<
typename _CharT,
typename _Traits,
typename _Duration,
3821 typename _TimeZonePtr>
3822 inline basic_ostream<_CharT, _Traits>&
3823 operator<<(basic_ostream<_CharT, _Traits>& __os,
3824 const zoned_time<_Duration, _TimeZonePtr>& __t)
3826 __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T %Z}"), __t);
3831 template<
typename _CharT,
typename _Traits,
typename _Duration>
3832 requires (!treat_as_floating_point_v<typename _Duration::rep>)
3833 && ratio_less_v<typename _Duration::period, days::period>
3834 inline basic_ostream<_CharT, _Traits>&
3835 operator<<(basic_ostream<_CharT, _Traits>& __os,
3836 const sys_time<_Duration>& __tp)
3838 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __tp);
3842 template<
typename _CharT,
typename _Traits>
3843 inline basic_ostream<_CharT, _Traits>&
3844 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_days& __dp)
3846 __os << year_month_day{__dp};
3850 template<
typename _CharT,
typename _Traits,
typename _Duration,
3851 typename _Alloc = allocator<_CharT>>
3852 basic_istream<_CharT, _Traits>&
3853 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3854 sys_time<_Duration>& __tp,
3855 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3861 using __format::_ChronoParts;
3862 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3863 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
3864 __detail::_Parser_t<_Duration> __p(__need);
3865 if (__p(__is, __fmt, __abbrev, __offset))
3867 if (__p._M_is_leap_second)
3871 auto __st = __p._M_sys_days + __p._M_time - *__offset;
3872 __tp = __detail::__round<_Duration>(__st);
3878 template<
typename _CharT,
typename _Traits,
typename _Duration>
3879 inline basic_ostream<_CharT, _Traits>&
3880 operator<<(basic_ostream<_CharT, _Traits>& __os,
3881 const utc_time<_Duration>& __t)
3883 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
3887 template<
typename _CharT,
typename _Traits,
typename _Duration,
3888 typename _Alloc = allocator<_CharT>>
3889 inline basic_istream<_CharT, _Traits>&
3890 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3891 utc_time<_Duration>& __tp,
3892 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3898 using __format::_ChronoParts;
3899 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3900 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
3901 __detail::_Parser_t<_Duration> __p(__need);
3902 if (__p(__is, __fmt, __abbrev, __offset))
3906 auto __ut = utc_clock::from_sys(__p._M_sys_days) + __p._M_time
3908 __tp = __detail::__round<_Duration>(__ut);
3913 template<
typename _CharT,
typename _Traits,
typename _Duration>
3914 inline basic_ostream<_CharT, _Traits>&
3915 operator<<(basic_ostream<_CharT, _Traits>& __os,
3916 const tai_time<_Duration>& __t)
3918 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
3922 template<
typename _CharT,
typename _Traits,
typename _Duration,
3923 typename _Alloc = allocator<_CharT>>
3924 inline basic_istream<_CharT, _Traits>&
3925 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3926 tai_time<_Duration>& __tp,
3927 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3933 using __format::_ChronoParts;
3934 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3935 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
3936 __detail::_Parser_t<_Duration> __p(__need);
3937 if (__p(__is, __fmt, __abbrev, __offset))
3939 if (__p._M_is_leap_second)
3943 constexpr sys_days __epoch(-
days(4383));
3944 auto __d = __p._M_sys_days - __epoch + __p._M_time - *__offset;
3945 tai_time<common_type_t<_Duration, seconds>> __tt(__d);
3946 __tp = __detail::__round<_Duration>(__tt);
3952 template<
typename _CharT,
typename _Traits,
typename _Duration>
3953 inline basic_ostream<_CharT, _Traits>&
3954 operator<<(basic_ostream<_CharT, _Traits>& __os,
3955 const gps_time<_Duration>& __t)
3957 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
3961 template<
typename _CharT,
typename _Traits,
typename _Duration,
3962 typename _Alloc = allocator<_CharT>>
3963 inline basic_istream<_CharT, _Traits>&
3964 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3965 gps_time<_Duration>& __tp,
3966 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3972 using __format::_ChronoParts;
3973 auto __need = _ChronoParts::_YearMonthDay | _ChronoParts::_TimeOfDay;
3974 __detail::_Parser_t<_Duration> __p(__need);
3975 if (__p(__is, __fmt, __abbrev, __offset))
3977 if (__p._M_is_leap_second)
3981 constexpr sys_days __epoch(
days(3657));
3982 auto __d = __p._M_sys_days - __epoch + __p._M_time - *__offset;
3983 gps_time<common_type_t<_Duration, seconds>> __gt(__d);
3984 __tp = __detail::__round<_Duration>(__gt);
3990 template<
typename _CharT,
typename _Traits,
typename _Duration>
3991 inline basic_ostream<_CharT, _Traits>&
3992 operator<<(basic_ostream<_CharT, _Traits>& __os,
3993 const file_time<_Duration>& __t)
3995 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
3999 template<
typename _CharT,
typename _Traits,
typename _Duration,
4000 typename _Alloc = allocator<_CharT>>
4001 inline basic_istream<_CharT, _Traits>&
4002 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4003 file_time<_Duration>& __tp,
4004 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4007 sys_time<_Duration> __st;
4008 if (chrono::from_stream(__is, __fmt, __st, __abbrev, __offset))
4009 __tp = __detail::__round<_Duration>(file_clock::from_sys(__st));
4013 template<
typename _CharT,
typename _Traits,
typename _Duration>
4014 inline basic_ostream<_CharT, _Traits>&
4015 operator<<(basic_ostream<_CharT, _Traits>& __os,
4016 const local_time<_Duration>& __lt)
4018 __os << sys_time<_Duration>{__lt.time_since_epoch()};
4022 template<
typename _CharT,
typename _Traits,
typename _Duration,
4023 typename _Alloc = allocator<_CharT>>
4024 basic_istream<_CharT, _Traits>&
4025 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4026 local_time<_Duration>& __tp,
4027 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4030 using __format::_ChronoParts;
4031 auto __need = _ChronoParts::_YearMonthDay | _ChronoParts::_TimeOfDay;
4032 __detail::_Parser_t<_Duration> __p(__need);
4033 if (__p(__is, __fmt, __abbrev, __offset))
4035 days __d = __p._M_sys_days.time_since_epoch();
4036 auto __t = local_days(__d) + __p._M_time;
4037 __tp = __detail::__round<_Duration>(__t);
4048 void from_stream() =
delete;
4050 template<
typename _Parsable,
typename _CharT,
4051 typename _Traits = std::char_traits<_CharT>,
4052 typename... _OptArgs>
4053 concept __parsable =
requires (basic_istream<_CharT, _Traits>& __is,
4054 const _CharT* __fmt, _Parsable& __tp,
4055 _OptArgs*... __args)
4056 { from_stream(__is, __fmt, __tp, __args...); };
4058 template<
typename _Parsable,
typename _CharT,
4059 typename _Traits = char_traits<_CharT>,
4060 typename _Alloc = allocator<_CharT>>
4064 using __string_type = basic_string<_CharT, _Traits, _Alloc>;
4067 _Parse(
const _CharT* __fmt, _Parsable& __tp,
4068 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4071 _M_abbrev(__abbrev), _M_offset(__offset)
4074 _Parse(_Parse&&) =
delete;
4075 _Parse& operator=(_Parse&&) =
delete;
4078 using __stream_type = basic_istream<_CharT, _Traits>;
4080 const _CharT*
const _M_fmt;
4081 _Parsable*
const _M_tp;
4082 __string_type*
const _M_abbrev;
4085 friend __stream_type&
4086 operator>>(__stream_type& __is, _Parse&& __p)
4089 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev,
4091 else if (__p._M_abbrev)
4092 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev);
4094 from_stream(__is, __p._M_fmt, *__p._M_tp);
4098 friend void operator>>(__stream_type&, _Parse&) =
delete;
4099 friend void operator>>(__stream_type&,
const _Parse&) =
delete;
4103 template<
typename _CharT, __detail::__parsable<_CharT> _Parsable>
4104 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4106 parse(
const _CharT* __fmt, _Parsable& __tp)
4107 {
return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp); }
4109 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4110 __detail::__parsable<_CharT, _Traits> _Parsable>
4113 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp)
4115 return __detail::_Parse<_Parsable, _CharT, _Traits>(__fmt.c_str(), __tp);
4118 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4119 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4120 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
4121 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4123 parse(
const _CharT* __fmt, _Parsable& __tp,
4124 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
4127 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
4131 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4132 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4133 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
4136 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
4137 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
4140 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
4144 template<
typename _CharT,
typename _Traits =
char_traits<_CharT>,
4145 typename _StrT = basic_
string<_CharT, _Traits>,
4146 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4147 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4149 parse(
const _CharT* __fmt, _Parsable& __tp,
minutes& __offset)
4151 return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp,
nullptr,
4155 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4156 typename _StrT = basic_string<_CharT, _Traits>,
4157 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4160 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
4163 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
4168 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4169 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4170 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4171 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4173 parse(
const _CharT* __fmt, _Parsable& __tp,
4174 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
4177 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
4182 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4183 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4184 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4187 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
4188 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
4191 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
4197 template<
typename _Duration>
4198 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4199 basic_istream<_CharT, _Traits>&
4200 __detail::_Parser<_Duration>::
4201 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4202 basic_string<_CharT, _Traits, _Alloc>* __abbrev,
4205 using sentry =
typename basic_istream<_CharT, _Traits>::sentry;
4207 if (sentry __cerb(__is,
true); __cerb)
4209 locale __loc = __is.getloc();
4214 struct _Stream_state
4217 _Stream_state(basic_istream<_CharT, _Traits>& __i)
4219 _M_flags(__i.flags(ios_base::
skipws | ios_base::
dec)),
4225 _M_is.flags(_M_flags);
4229 _Stream_state(_Stream_state&&) =
delete;
4231 basic_istream<_CharT, _Traits>& _M_is;
4232 ios_base::fmtflags _M_flags;
4242 auto __read_unsigned = [&] (
int __n) {
4243 return _S_read_unsigned(__is, __err, __n);
4248 auto __read_signed = [&] (
int __n) {
4249 return _S_read_signed(__is, __err, __n);
4253 auto __read_chr = [&__is, &__err] (_CharT __c) {
4254 return _S_read_chr(__is, __err, __c);
4257 using __format::_ChronoParts;
4258 _ChronoParts __parts{};
4260 const year __bad_y = --year::min();
4261 const month __bad_mon(255);
4262 const day __bad_day(255);
4263 const weekday __bad_wday(255);
4264 const hours __bad_h(-1);
4265 const minutes __bad_min(-9999);
4268 year __y = __bad_y, __yy = __bad_y;
4269 year __iso_y = __bad_y, __iso_yy = __bad_y;
4270 month __m = __bad_mon;
4271 day __d = __bad_day;
4272 weekday __wday = __bad_wday;
4273 hours __h = __bad_h, __h12 = __bad_h;
4275 _Duration __s = __bad_sec;
4277 int __iso_wk = -1, __sunday_wk = -1, __monday_wk = -1;
4279 int __dayofyear = -1;
4281 minutes __tz_offset = __bad_min;
4282 basic_string<_CharT, _Traits> __tz_abbr;
4284 if ((_M_need & _ChronoParts::_TimeOfDay) != 0
4285 && (_M_need & _ChronoParts::_Year) != 0)
4291 __parts = _ChronoParts::_TimeOfDay;
4298 bool __is_flag =
false;
4300 constexpr bool __is_floating
4301 = treat_as_floating_point_v<typename _Duration::rep>;
4320 _CharT __c = *__fmt++;
4327 else if (!__read_chr(__c)) [[unlikely]]
4338 if (__mod || __num) [[unlikely]]
4343 __tmget.get(__is, {}, __is, __err, &__tm,
4345 if (!__is_failed(__err))
4346 __wday = weekday(__tm.tm_wday);
4348 __parts |= _ChronoParts::_Weekday;
4354 if (__mod || __num) [[unlikely]]
4362 __tmget.get(__is, {}, __is, __err, &__tm,
4364 if (!__is_failed(__err))
4365 __m = month(__tm.tm_mon + 1);
4367 __parts |= _ChronoParts::_Month;
4371 if (__mod ==
'O' || __num) [[unlikely]]
4376 __tmget.get(__is, {}, __is, __err, &__tm,
4377 __fmt - 2 - (__mod ==
'E'), __fmt);
4378 if (!__is_failed(__err))
4380 __y = year(__tm.tm_year + 1900);
4381 __m = month(__tm.tm_mon + 1);
4382 __d = day(__tm.tm_mday);
4383 __h =
hours(__tm.tm_hour);
4388 __parts |= _ChronoParts::_DateTime;
4392 if (!__mod) [[likely]]
4394 auto __v = __read_signed(__num ? __num : 2);
4395 if (!__is_failed(__err))
4397 int __cmin = (int)year::min() / 100;
4398 int __cmax = (int)year::max() / 100;
4399 if (__cmin <= __v && __v <= __cmax)
4400 __century = __v * 100;
4405 else if (__mod ==
'E')
4408 __tmget.get(__is, {}, __is, __err, &__tm,
4410 if (!__is_failed(__err))
4411 __century = __tm.tm_year;
4420 if (!__mod) [[likely]]
4422 auto __v = __read_unsigned(__num ? __num : 2);
4423 if (!__is_failed(__err))
4426 else if (__mod ==
'O')
4429 __tmget.get(__is, {}, __is, __err, &__tm,
4431 if (!__is_failed(__err))
4432 __d = day(__tm.tm_mday);
4436 __parts |= _ChronoParts::_Day;
4440 if (__mod || __num) [[unlikely]]
4444 auto __month = __read_unsigned(2);
4446 auto __day = __read_unsigned(2);
4448 auto __year = __read_unsigned(2);
4449 if (__is_failed(__err))
4451 __y = year(__year + 1900 + 100 *
int(__year < 69));
4452 __m = month(__month);
4454 if (!year_month_day(__y, __m, __d).ok())
4456 __y = __yy = __iso_y = __iso_yy = __bad_y;
4462 __parts |= _ChronoParts::_Date;
4466 if (__mod) [[unlikely]]
4470 auto __year = __read_signed(__num ? __num : 4);
4472 auto __month = __read_unsigned(2);
4474 auto __day = __read_unsigned(2);
4475 if (__is_failed(__err))
4478 __m = month(__month);
4480 if (!year_month_day(__y, __m, __d).ok())
4482 __y = __yy = __iso_y = __iso_yy = __bad_y;
4488 __parts |= _ChronoParts::_Date;
4492 if (__mod) [[unlikely]]
4496 auto __val = __read_unsigned(__num ? __num : 2);
4497 if (__val >= 0 && __val <= 99)
4499 __iso_yy = year(__val);
4500 if (__century == -1)
4504 __iso_yy = __iso_y = __y = __yy = __bad_y;
4506 __parts |= _ChronoParts::_Year;
4510 if (__mod) [[unlikely]]
4513 __iso_y = year(__read_unsigned(__num ? __num : 4));
4514 __parts |= _ChronoParts::_Year;
4519 if (__mod ==
'E') [[unlikely]]
4521 else if (__mod ==
'O')
4526 __tmget.get(__is, {}, __is, __err, &__tm,
4528 if (!__is_failed(__err))
4532 __h12 =
hours(__tm.tm_hour);
4536 __h =
hours(__tm.tm_hour);
4545 auto __val = __read_unsigned(__num ? __num : 2);
4546 if (__c ==
'I' && __val >= 1 && __val <= 12)
4548 __h12 =
hours(__val);
4551 else if (__c ==
'H' && __val >= 0 && __val <= 23)
4558 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4563 __parts |= _ChronoParts::_TimeOfDay;
4567 if (__mod) [[unlikely]]
4569 else if (_M_need == _ChronoParts::_TimeOfDay)
4571 auto __val = __read_signed(__num ? __num : 3);
4572 if (!__is_failed(__err))
4575 __parts |= _ChronoParts::_TimeOfDay;
4580 __dayofyear = __read_unsigned(__num ? __num : 3);
4587 if (__mod ==
'E') [[unlikely]]
4589 else if (__mod ==
'O')
4592 __tmget.get(__is, {}, __is, __err, &__tm,
4594 if (!__is_failed(__err))
4595 __m = month(__tm.tm_mon + 1);
4599 auto __val = __read_unsigned(__num ? __num : 2);
4600 if (__val >= 1 && __val <= 12)
4605 __parts |= _ChronoParts::_Month;
4609 if (__mod ==
'E') [[unlikely]]
4611 else if (__mod ==
'O')
4614 __tmget.get(__is, {}, __is, __err, &__tm,
4616 if (!__is_failed(__err))
4621 auto __val = __read_unsigned(__num ? __num : 2);
4622 if (0 <= __val && __val < 60)
4626 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4631 __parts |= _ChronoParts::_TimeOfDay;
4641 const _CharT* __ampms[2];
4642 __tmpunct._M_am_pm(__ampms);
4643 int __n = 0, __which = 3;
4644 while (__which != 0)
4646 auto __i = __is.peek();
4647 if (_Traits::eq_int_type(__i, _Traits::eof()))
4657 else if (__ampms[0][__n + 1] == _CharT())
4668 else if (__ampms[1][__n + 1] == _CharT())
4679 if (__which == 0 || __which == 3)
4692 __tmget.get(__is, {}, __is, __err, &__tm,
4694 if (!__is_failed(__err))
4696 __h =
hours(__tm.tm_hour);
4701 __parts |= _ChronoParts::_TimeOfDay;
4706 if (__mod || __num) [[unlikely]]
4713 auto __val = __read_unsigned(2);
4714 if (__val == -1 || __val > 23) [[unlikely]]
4716 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4720 if (!__read_chr(
':')) [[unlikely]]
4724 __val = __read_unsigned(2);
4725 if (__val == -1 || __val > 60) [[unlikely]]
4727 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4735 __parts |= _ChronoParts::_TimeOfDay;
4738 else if (!__read_chr(
':')) [[unlikely]]
4744 if (__mod ==
'E') [[unlikely]]
4746 else if (__mod ==
'O')
4749 __tmget.get(__is, {}, __is, __err, &__tm,
4751 if (!__is_failed(__err))
4754 else if constexpr (_Duration::period::den == 1
4757 auto __val = __read_unsigned(__num ? __num : 2);
4758 if (0 <= __val && __val <= 59) [[likely]]
4762 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4769 basic_stringstream<_CharT> __buf;
4770 auto __digit = _S_try_read_digit(__is, __err);
4773 __buf.put(_CharT(
'0') + __digit);
4774 __digit = _S_try_read_digit(__is, __err);
4776 __buf.put(_CharT(
'0') + __digit);
4779 auto __i = __is.peek();
4780 if (_Traits::eq_int_type(__i, _Traits::eof()))
4788 __dp = __np.decimal_point();
4790 _CharT __c = _Traits::to_char_type(__i);
4796 = hh_mm_ss<_Duration>::fractional_width;
4799 __digit = _S_try_read_digit(__is, __err);
4801 __buf.put(_CharT(
'0') + __digit);
4809 if (!__is_failed(__err)) [[likely]]
4811 long double __val{};
4812#if __cpp_lib_to_chars
4814 auto __first = __str.data();
4815 auto __last = __first + __str.size();
4819 if ((
bool)ec || ptr != __last) [[unlikely]]
4827 if constexpr (__is_floating)
4834 __parts |= _ChronoParts::_TimeOfDay;
4839 if (__mod ==
'E') [[unlikely]]
4841 else if (__mod ==
'O')
4846 __tmget.get(__is, {}, __is, __err, &__tm,
4848 if (!__is_failed(__err))
4849 __wday = weekday(__tm.tm_wday);
4856 const int __lo = __c ==
'u' ? 1 : 0;
4857 const int __hi = __lo + 6;
4858 auto __val = __read_unsigned(__num ? __num : 1);
4859 if (__lo <= __val && __val <= __hi)
4860 __wday = weekday(__val);
4863 __wday = __bad_wday;
4867 __parts |= _ChronoParts::_Weekday;
4873 if (__mod ==
'E') [[unlikely]]
4875 else if (__mod ==
'O')
4877 if (__c ==
'V') [[unlikely]]
4887 const int __lo = __c ==
'V' ? 1 : 0;
4888 const int __hi = 53;
4889 auto __val = __read_unsigned(__num ? __num : 2);
4890 if (__lo <= __val && __val <= __hi)
4895 __sunday_wk = __val;
4901 __monday_wk = __val;
4906 __iso_wk = __sunday_wk = __monday_wk = -1;
4912 if (__mod ==
'O' || __num) [[unlikely]]
4917 __tmget.get(__is, {}, __is, __err, &__tm,
4918 __fmt - 2 - (__mod ==
'E'), __fmt);
4919 if (!__is_failed(__err))
4921 __y = year(__tm.tm_year + 1900);
4922 __m = month(__tm.tm_mon + 1);
4923 __d = day(__tm.tm_mday);
4926 __parts |= _ChronoParts::_Date;
4930 if (__mod ==
'O' || __num) [[unlikely]]
4935 __tmget.get(__is, {}, __is, __err, &__tm,
4936 __fmt - 2 - (__mod ==
'E'), __fmt);
4937 if (!__is_failed(__err))
4939 __h =
hours(__tm.tm_hour);
4944 __parts |= _ChronoParts::_TimeOfDay;
4948 if (__mod) [[unlikely]]
4951 __tmget.get(__is, {}, __is, __err, &__tm,
4953 if (!__is_failed(__err))
4955 int __cent = __tm.tm_year < 2000 ? 1900 : 2000;
4956 __yy = year(__tm.tm_year - __cent);
4957 if (__century == -1)
4963 auto __val = __read_unsigned(__num ? __num : 2);
4964 if (__val >= 0 && __val <= 99)
4967 if (__century == -1)
4968 __century = __val < 69 ? 2000 : 1900;
4971 __y = __yy = __iso_yy = __iso_y = __bad_y;
4973 __parts |= _ChronoParts::_Year;
4977 if (__mod ==
'O') [[unlikely]]
4979 else if (__mod ==
'E')
4982 __tmget.get(__is, {}, __is, __err, &__tm,
4984 if (!__is_failed(__err))
4985 __y = year(__tm.tm_year);
4989 auto __val = __read_unsigned(__num ? __num : 4);
4990 if (!__is_failed(__err))
4993 __parts |= _ChronoParts::_Year;
4997 if (__num) [[unlikely]]
5004 auto __i = __is.peek();
5005 if (_Traits::eq_int_type(__i, _Traits::eof()))
5010 _CharT __ic = _Traits::to_char_type(__i);
5011 const bool __neg = __ic == _CharT(
'-');
5012 if (__ic == _CharT(
'-') || __ic == _CharT(
'+'))
5019 __hh = __read_unsigned(2);
5024 __hh = 10 * _S_try_read_digit(__is, __err);
5025 __hh += _S_try_read_digit(__is, __err);
5028 if (__is_failed(__err))
5032 if (_Traits::eq_int_type(__i, _Traits::eof()))
5035 __tz_offset =
minutes(__hh * (__neg ? -60 : 60));
5038 __ic = _Traits::to_char_type(__i);
5040 bool __read_mm =
false;
5043 if (__ic == _GLIBCXX_WIDEN(
":")[0])
5050 else if (_CharT(
'0') <= __ic && __ic <= _CharT(
'9'))
5056 int_least32_t __mm = 0;
5059 __mm = 10 * _S_try_read_digit(__is, __err);
5060 __mm += _S_try_read_digit(__is, __err);
5063 if (!__is_failed(__err))
5065 auto __z = __hh * 60 + __mm;
5066 __tz_offset =
minutes(__neg ? -__z : __z);
5072 if (__mod || __num) [[unlikely]]
5076 basic_string_view<_CharT> __x = _GLIBCXX_WIDEN(
"_/-+");
5080 auto __i = __is.peek();
5081 if (!_Traits::eq_int_type(__i, _Traits::eof()))
5083 _CharT __a = _Traits::to_char_type(__i);
5085 || __x.find(__a) != __x.npos)
5087 __tz_abbr.push_back(__a);
5096 if (__tz_abbr.empty())
5102 if (__mod || __num) [[unlikely]]
5106 _CharT __i = __is.peek();
5107 if (_Traits::eq_int_type(__i, _Traits::eof()))
5109 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
5117 if (__mod || __num) [[unlikely]]
5121 _CharT __i = __is.peek();
5122 if (_Traits::eq_int_type(__i, _Traits::eof()))
5124 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
5130 if (__mod || __num) [[unlikely]]
5138 if (__mod || __num) [[unlikely]]
5147 if (_CharT(
'1') <= __c && __c <= _CharT(
'9'))
5149 if (!__mod) [[likely]]
5152 auto __end = __fmt + _Traits::length(__fmt);
5154 = __format::__parse_integer(__fmt - 1, __end);
5155 if (__ptr) [[likely]]
5166 if (__is_failed(__err)) [[unlikely]]
5176 if (__yy != __bad_y && __y == __bad_y)
5177 __y =
years(__century) + __yy;
5178 if (__iso_yy != __bad_y && __iso_y == __bad_y)
5179 __iso_y =
years(__century) + __iso_yy;
5182 bool __can_use_doy =
false;
5183 bool __can_use_iso_wk =
false;
5184 bool __can_use_sun_wk =
false;
5185 bool __can_use_mon_wk =
false;
5188 if (__y != __bad_y && __dayofyear >= 0)
5190 __can_use_doy =
true;
5191 __parts |= _ChronoParts::_Date;
5193 else if (__y != __bad_y && __wday != __bad_wday && __sunday_wk >= 0)
5195 __can_use_sun_wk =
true;
5196 __parts |= _ChronoParts::_Date;
5198 else if (__y != __bad_y && __wday != __bad_wday && __monday_wk >= 0)
5200 __can_use_mon_wk =
true;
5201 __parts |= _ChronoParts::_Date;
5203 else if (__iso_y != __bad_y && __wday != __bad_wday && __iso_wk > 0)
5206 __can_use_iso_wk =
true;
5207 __parts |= _ChronoParts::_Date;
5210 if (__is_failed(__err)) [[unlikely]]
5212 else if (__is_flag) [[unlikely]]
5214 else if ((_M_need & __parts) == _M_need) [[likely]]
5236 const bool __need_wday = (_M_need & _ChronoParts::_Weekday) != 0;
5240 const bool __need_time = (_M_need & _ChronoParts::_TimeOfDay) != 0;
5242 if (__need_wday && __wday != __bad_wday)
5244 else if ((_M_need & _ChronoParts::_Date) != 0)
5248 const bool __need_ymd = !__need_wday && !__need_time;
5250 if (((_M_need & _ChronoParts::_Year) != 0 && __y == __bad_y)
5251 || ((_M_need & _ChronoParts::_Month) != 0 && __m == __bad_mon)
5252 || ((_M_need & _ChronoParts::_Day) != 0 && __d == __bad_day))
5259 if ((0 < __dayofyear && __dayofyear <= 365)
5260 || (__dayofyear == 366 && __y.is_leap()))
5263 _M_sys_days = sys_days(__y/January/1)
5264 +
days(__dayofyear - 1);
5266 _M_ymd = year_month_day(_M_sys_days);
5271 else if (__can_use_iso_wk)
5279 const sys_days __jan4(__iso_y/January/4);
5280 weekday __wd1(__jan4 -
days(3));
5281 if (__wd1 != Thursday)
5282 if (__wd1 != Wednesday || !__iso_y.is_leap())
5286 if (!__is_failed(__err)) [[likely]]
5289 sys_days __w(Thursday[1]/January/__iso_y);
5291 __w -= Thursday - Monday;
5293 __w += __wday - Monday;
5297 _M_ymd = year_month_day(_M_sys_days);
5300 else if (__can_use_sun_wk)
5303 sys_days __wk1(__y/January/Sunday[1]);
5304 _M_sys_days = __wk1 +
weeks(__sunday_wk - 1)
5305 +
days(__wday.c_encoding());
5306 _M_ymd = year_month_day(_M_sys_days);
5307 if (_M_ymd.year() != __y) [[unlikely]]
5310 else if (__can_use_mon_wk)
5313 sys_days __wk1(__y/January/Monday[1]);
5314 _M_sys_days = __wk1 +
weeks(__monday_wk - 1)
5315 +
days(__wday.c_encoding() - 1);
5316 _M_ymd = year_month_day(_M_sys_days);
5317 if (_M_ymd.year() != __y) [[unlikely]]
5329 if ((_M_need & _ChronoParts::_Year) != 0)
5331 if (!__y.ok()) [[unlikely]]
5334 else if (__y == __bad_y)
5337 if ((_M_need & _ChronoParts::_Month) != 0)
5339 if (!__m.ok()) [[unlikely]]
5342 else if (__m == __bad_mon)
5345 if ((_M_need & _ChronoParts::_Day) != 0)
5347 if (__d < day(1) || __d > (__y/__m/last).day())
5350 else if (__d == __bad_day)
5353 if (year_month_day __ymd(__y, __m, __d); __ymd.ok())
5356 if (__need_wday || __need_time)
5357 _M_sys_days = sys_days(_M_ymd);
5364 _M_wd = weekday(_M_sys_days);
5370 if (__h == __bad_h && __h12 != __bad_h)
5374 else if (__ampm == 2)
5375 __h = __h12 ==
hours(12) ? __h12 : __h12 +
hours(12);
5380 auto __t = _M_time.zero();
5389 if (__min != __bad_min)
5395 if (__s != __bad_sec)
5399 _M_is_leap_second = __s >=
seconds(60);
5408 if (!__is_failed(__err)) [[likely]]
5410 if (__offset && __tz_offset != __bad_min)
5411 *__offset = __tz_offset;
5412 if (__abbrev && !__tz_abbr.empty())
5420 __is.setstate(__err);
5424#undef _GLIBCXX_WIDEN
5429_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.