30#ifndef _GLIBCXX_CHRONO_IO_H
31#define _GLIBCXX_CHRONO_IO_H 1
34#pragma GCC system_header
37#if __cplusplus >= 202002L
47namespace std _GLIBCXX_VISIBILITY(default)
49_GLIBCXX_BEGIN_NAMESPACE_VERSION
59#define _GLIBCXX_WIDEN_(C, S) ::std::__format::_Widen<C>(S, L##S)
60#define _GLIBCXX_WIDEN(S) _GLIBCXX_WIDEN_(_CharT, S)
62 template<
typename _Period,
typename _CharT>
64 __units_suffix()
noexcept
69#define _GLIBCXX_UNITS_SUFFIX(period, suffix) \
70 if constexpr (is_same_v<_Period, period>) \
71 return _GLIBCXX_WIDEN(suffix); \
74 _GLIBCXX_UNITS_SUFFIX(atto,
"as")
75 _GLIBCXX_UNITS_SUFFIX(femto,
"fs")
76 _GLIBCXX_UNITS_SUFFIX(pico,
"ps")
77 _GLIBCXX_UNITS_SUFFIX(nano,
"ns")
78 _GLIBCXX_UNITS_SUFFIX(milli,
"ms")
79#if _GLIBCXX_USE_ALT_MICROSECONDS_SUFFIX
82 _GLIBCXX_UNITS_SUFFIX(micro,
"\u00b5s")
84 _GLIBCXX_UNITS_SUFFIX(micro,
"us")
86 _GLIBCXX_UNITS_SUFFIX(centi,
"cs")
87 _GLIBCXX_UNITS_SUFFIX(deci,
"ds")
89 _GLIBCXX_UNITS_SUFFIX(deca,
"das")
90 _GLIBCXX_UNITS_SUFFIX(hecto,
"hs")
91 _GLIBCXX_UNITS_SUFFIX(kilo,
"ks")
92 _GLIBCXX_UNITS_SUFFIX(mega,
"Ms")
93 _GLIBCXX_UNITS_SUFFIX(giga,
"Gs")
94 _GLIBCXX_UNITS_SUFFIX(tera,
"Ts")
95 _GLIBCXX_UNITS_SUFFIX(tera,
"Ts")
96 _GLIBCXX_UNITS_SUFFIX(peta,
"Ps")
97 _GLIBCXX_UNITS_SUFFIX(exa,
"Es")
101#undef _GLIBCXX_UNITS_SUFFIX
105 template<
typename _Period,
typename _CharT,
typename _Out>
107 __fmt_units_suffix(_Out __out)
noexcept
109 if (
auto __s = __detail::__units_suffix<_Period, _CharT>(); __s.size())
110 return __format::__write(
std::move(__out), __s);
111 else if constexpr (_Period::den == 1)
112 return std::format_to(
std::move(__out), _GLIBCXX_WIDEN(
"[{}]s"),
113 (uintmax_t)_Period::num);
115 return std::format_to(
std::move(__out), _GLIBCXX_WIDEN(
"[{}/{}]s"),
116 (uintmax_t)_Period::num,
117 (uintmax_t)_Period::den);
126 template<
typename _CharT,
typename _Traits,
127 typename _Rep,
typename _Period>
133 using period =
typename _Period::type;
141 __detail::__fmt_units_suffix<period, _CharT>(_Out(__s));
151 template<
typename _Duration>
152 struct __local_time_fmt
154 local_time<_Duration> _M_time;
155 const string* _M_abbrev;
161 template<
typename _Duration>
162 using __local_time_fmt_for
163 = __local_time_fmt<common_type_t<_Duration, seconds>>;
176 template<
typename _Duration>
177 inline __detail::__local_time_fmt<_Duration>
179 const string* __abbrev =
nullptr,
180 const seconds* __offset_sec =
nullptr)
181 {
return {__time, __abbrev, __offset_sec}; }
189 [[noreturn,__gnu__::__always_inline__]]
191 __not_valid_for_duration()
192 { __throw_format_error(
"format error: chrono-format-spec not valid for "
193 "chrono::duration"); }
195 [[noreturn,__gnu__::__always_inline__]]
197 __invalid_chrono_spec()
198 { __throw_format_error(
"format error: chrono-format-spec not valid for "
204 enum class _ChronoParts :
unsigned short {
205 _None = 0, _TotalSeconds = 1u, _Subseconds = 1u << 2,
208 _EpochUnits = 1u << 3, _UnitSuffix = 1u << 4,
209 _EpochSeconds = _EpochUnits | _TotalSeconds,
212 _LocalDays = 1u << 5,
213 _LocalSeconds = _LocalDays | _TotalSeconds,
215 _Year = 1u << 6, _Month = 1u << 7, _Day = 1u << 8,
216 _Weekday = 1u << 9, _WeekdayIndex = 1u << 10, _DayOfYear = 1u << 11,
217 _IndexedWeekday = _Weekday | _WeekdayIndex,
218 _YearMonthDay = _Year | _Month | _Day,
219 _Date = _LocalDays | _YearMonthDay | _IndexedWeekday | _DayOfYear,
221 _HoursMinutesSeconds = 1u << 12,
222 _TimeOfDay = _HoursMinutesSeconds | _Subseconds,
223 _Time = _TimeOfDay | _TotalSeconds,
224 _EpochTime = _Time | _EpochUnits | _UnitSuffix,
225 _DateTime = _Date | _Time,
227 _ZoneAbbrev = 1u << 13, _ZoneOffset = 1u << 14,
228 _TimeZone = _ZoneAbbrev | _ZoneOffset,
229 _ZonedDateTime = _DateTime | _TimeZone,
232 [[__gnu__::__always_inline__]]
233 constexpr _ChronoParts
234 operator&(_ChronoParts __x, _ChronoParts __y)
noexcept
235 {
return static_cast<_ChronoParts
>((unsigned)__x & (unsigned)__y); }
237 [[__gnu__::__always_inline__]]
238 constexpr _ChronoParts&
239 operator&=(_ChronoParts& __x, _ChronoParts __y)
noexcept
240 {
return __x = __x & __y; }
242 [[__gnu__::__always_inline__]]
243 constexpr _ChronoParts
244 operator|(_ChronoParts __x, _ChronoParts __y)
noexcept
245 {
return static_cast<_ChronoParts
>((
unsigned short)__x | (
unsigned short)__y); }
247 [[__gnu__::__always_inline__]]
248 constexpr _ChronoParts&
249 operator|=(_ChronoParts& __x, _ChronoParts __y)
noexcept
250 {
return __x = __x | __y; }
253 [[__gnu__::__always_inline__]]
254 constexpr _ChronoParts
255 operator-(_ChronoParts __x, _ChronoParts __y)
noexcept
256 {
return static_cast<_ChronoParts
>((
unsigned short)__x & ~(
unsigned short)__y); }
259 [[__gnu__::__always_inline__]]
260 constexpr _ChronoParts&
261 operator-=(_ChronoParts& __x, _ChronoParts __y)
noexcept
262 {
return __x = __x - __y; }
264 [[__gnu__::__always_inline__]]
266 operator==(_ChronoParts __x,
decltype(
nullptr)) noexcept
267 {
return (
unsigned short)__x == 0; }
269 template<
typename _CharT>
270 struct _ChronoSpec : _Spec<_CharT>
281 unsigned _M_locale_specific : 1;
284 unsigned _M_needs_ok_check : 1;
286 unsigned _M_floating_point_rep : 1;
288 unsigned _M_custom_rep : 1;
289 unsigned _M_unused : 4;
292 _ChronoParts _M_needed;
293 basic_string_view<_CharT> _M_chrono_specs;
295 [[__gnu__::__always_inline__]]
297 _M_needs(_ChronoParts __parts)
const
298 {
return (_M_needed & __parts) != 0; }
301 template<
typename _CharT>
302 struct _ChronoFormats
304 using _String_view = basic_string_view<_CharT>;
309 {
return _GLIBCXX_WIDEN(
"%F %T %Z"); }
314 {
return _S_ftz().substr(0, 5); }
319 {
return _S_ftz().substr(0, 2); }
324 {
return _S_ftz().substr(3, 2); }
329 {
return _GLIBCXX_WIDEN(
"%Y/%b/%d"); }
334 {
return _S_ymd().substr(0, 5); }
339 {
return _S_ymd().substr(3); }
344 {
return _S_ymd().substr(0, 2); }
349 {
return _S_ymd().substr(3, 2); }
354 {
return _S_ymd().substr(6, 2); }
360 {
return _String_view(_GLIBCXX_WIDEN(
"%Y/%b/%a[%\0]"), 12); }
365 {
return _S_ymwi().substr(3); }
370 {
return _S_ymwi().substr(6); }
375 {
return _S_ymwi().substr(6, 2); }
380 {
return _GLIBCXX_WIDEN(
"%Y/%b/%a[last]"); }
385 {
return _S_ymwl().substr(3); }
390 {
return _S_ymwl().substr(6); }
395 {
return _GLIBCXX_WIDEN(
"%Y/%b/last"); }
400 {
return _S_yml().substr(3); }
403 template<
typename _CharT>
406 static constexpr unsigned _S_max_prec = 18;
407 using _Attoseconds = chrono::duration<__UINT_LEAST64_TYPE__, atto>;
410 = basic_format_context<_Sink_iter<_CharT>, _CharT>;
411 using _FormatArgs = basic_format_args<_FormatContext>;
412 static inline auto _S_args = std::make_format_args<_FormatContext>();
414 _ChronoData() =
default;
415 _ChronoData(_ChronoData&&) =
delete;
418 chrono::seconds _M_eseconds;
421 _Attoseconds _M_subseconds;
425 _FormatArgs _M_ereps = _S_args;
426 basic_string_view<_CharT> _M_unit_suffix;
429 chrono::local_seconds _M_lseconds;
430 chrono::local_days _M_ldays;
432 chrono::year _M_year;
433 chrono::month _M_month;
435 chrono::weekday _M_weekday;
436 unsigned char _M_weekday_index;
437 chrono::days _M_day_of_year;
440 chrono::hours _M_hours;
441 chrono::minutes _M_minutes;
442 chrono::seconds _M_seconds;
444 chrono::seconds _M_zone_offset;
445 basic_string_view<_CharT> _M_zone_abbrev;
446 const char* _M_zone_cstr =
"";
448 template<
typename _YearMonth>
449 [[__gnu__::__always_inline__]]
451 _M_fill_year_month(
const _YearMonth& __ym, _ChronoParts __parts)
453 _M_year = __ym.year();
454 __parts -= _ChronoParts::_Year;
455 _M_month = __ym.month();
456 __parts -= _ChronoParts::_Month;
460 [[__gnu__::__always_inline__]]
462 _M_fill_day(chrono::day __d, _ChronoParts __parts)
465 __parts -= _ChronoParts::_Day;
466 _M_weekday_index = ((unsigned)__d + 6u) / 7u;
467 __parts -= _ChronoParts::_WeekdayIndex;
471 [[__gnu__::__always_inline__]]
473 _M_fill_weekday(chrono::weekday_indexed __wi, _ChronoParts __parts)
475 _M_weekday = __wi.weekday();
476 __parts -= _ChronoParts::_Weekday;
477 _M_weekday_index = __wi.index();
478 __parts -= _ChronoParts::_WeekdayIndex;
483 [[__gnu__::__always_inline__]]
485 _M_fill_aux(chrono::local_days __ld, _ChronoParts __parts)
487 using namespace chrono;
488 if ((__parts & _ChronoParts::_Weekday) != 0)
489 _M_weekday = weekday(__ld);
490 __parts -= _ChronoParts::_Weekday;
491 if ((__parts & _ChronoParts::_DayOfYear) != 0)
494 _M_day_of_year = __ld - local_days(_M_year/January/0);
495 __parts -= _ChronoParts::_DayOfYear;
500 [[__gnu__::__always_inline__]]
502 _M_fill_ldays(chrono::local_days __ld, _ChronoParts __parts)
505 __parts -= _ChronoParts::_LocalDays;
506 return _M_fill_aux(__ld, __parts);
510 _M_fill_time(chrono::seconds __d)
512 chrono::hh_mm_ss<chrono::seconds> __hms(__d);
513 _M_hours = __hms.hours();
514 _M_minutes = __hms.minutes();
515 _M_seconds = __hms.seconds();
519 _M_fill_date_time(chrono::local_seconds __ls, _ChronoParts __parts)
521 _M_ldays = chrono::floor<chrono::days>(__ls);
522 __parts -= _ChronoParts::_LocalDays;
523 if ((__parts & _ChronoParts::_HoursMinutesSeconds) != 0)
524 _M_fill_time(_M_lseconds - _M_ldays);
526 if ((__parts & _ChronoParts::_Date) != 0)
528 const chrono::year_month_day __ymd(_M_ldays);
529 _M_fill_year_month(__ymd, __parts);
530 _M_fill_day(__ymd.day(), __parts);
531 _M_fill_aux(_M_ldays, __parts);
536 _M_fill_zone(
const char* __abbrev,
const wchar_t* __wabbrev)
538 if constexpr (is_same_v<_CharT, char>)
539 _M_zone_abbrev = __abbrev;
541 _M_zone_abbrev = __wabbrev;
542 _M_zone_cstr = __abbrev;
545 [[__gnu__::__always_inline__]]
548 { _M_fill_zone(
"UTC", L
"UTC"); }
552 template<
typename _CharT>
553 struct __formatter_chrono
555 using __string_view = basic_string_view<_CharT>;
556 using __string = basic_string<_CharT>;
558 __formatter_chrono() =
default;
561 __formatter_chrono(_ChronoSpec<_CharT> __spec) noexcept
565 constexpr typename basic_format_parse_context<_CharT>::iterator
566 _M_parse(basic_format_parse_context<_CharT>& __pc, _ChronoParts __parts,
567 const _ChronoSpec<_CharT>& __def)
569 auto __first = __pc.
begin();
570 auto __last = __pc.end();
572 _ChronoSpec<_CharT> __spec = __def;
574 auto __finalize = [
this, &__spec, &__def] {
575 using enum _ChronoParts;
576 _ChronoParts __checked
577 = __spec._M_debug ? _YearMonthDay|_IndexedWeekday
581 __spec._M_needs_ok_check
582 = __spec._M_needs(__def._M_needed & __checked);
586 auto __finished = [&] {
587 if (__first == __last || *__first ==
'}')
598 __first = __spec._M_parse_fill_and_align(__first, __last);
602 __first = __spec._M_parse_width(__first, __last, __pc);
608 if ((__parts & _ChronoParts::_EpochUnits) == 0
609 || !__spec._M_floating_point_rep)
610 __throw_format_error(
"format error: invalid precision for duration");
613 __first = _Spec<_CharT>()._M_parse_precision(__first, __last, __pc);
615 __spec._M_prec_kind = _WP_value;
620 __spec._M_localized =
false;
621 __first = __spec._M_parse_locale(__first, __last);
628 __string_view __str(__first, __last - __first);
629 auto __end = __str.find(
'}');
630 if (__end != __str.npos)
632 __str.remove_suffix(__str.length() - __end);
633 __last = __first + __end;
635 if (__str.find(
'{') != __str.npos)
636 __throw_format_error(
"chrono format error: '{' in chrono-specs");
642 __spec._M_debug =
false;
643 __spec._M_locale_specific =
false;
644 __spec._M_needed = _ChronoParts::_None;
645 __spec._M_chrono_specs = __string_view();
647 const auto __chrono_specs = __first++;
648 if (*__chrono_specs !=
'%')
649 __throw_format_error(
"chrono format error: no '%' at start of "
654 while (__first != __last)
656 enum _Mods { _Mod_none, _Mod_E, _Mod_O, _Mod_E_O };
657 _Mods __allowed_mods = _Mod_none;
659 _ChronoParts __needed = _ChronoParts::_None;
660 bool __locale_specific =
false;
662 _CharT __c = *__first++;
665 using enum _ChronoParts;
669 __locale_specific =
true;
675 __locale_specific =
true;
678 __needed = _Date|_HoursMinutesSeconds;
679 __allowed_mods = _Mod_E;
680 __locale_specific =
true;
684 __allowed_mods = _Mod_E;
689 __allowed_mods = _Mod_O;
693 __needed = _YearMonthDay;
698 __needed = _LocalDays|_Year|_DayOfYear|_Weekday;
702 __needed = _HoursMinutesSeconds;
703 __allowed_mods = _Mod_O;
706 __needed = __parts & _DayOfYear;
709 if (__needed == _None)
710 __needed = _HoursMinutesSeconds;
714 __allowed_mods = _Mod_O;
717 __needed = _HoursMinutesSeconds;
718 __allowed_mods = _Mod_O;
722 __locale_specific =
true;
725 __needed = _HoursMinutesSeconds;
728 __needed = _TimeOfDay;
731 __needed = _UnitSuffix;
734 __needed = _EpochUnits;
737 __needed = _TimeOfDay;
738 __allowed_mods = _Mod_O;
743 __allowed_mods = _Mod_O;
747 __needed = _DayOfYear|_Weekday;
748 __allowed_mods = _Mod_O;
752 __locale_specific =
true;
753 __allowed_mods = _Mod_E;
756 __needed = _HoursMinutesSeconds;
757 __locale_specific =
true;
758 __allowed_mods = _Mod_E;
762 __allowed_mods = _Mod_E_O;
766 __allowed_mods = _Mod_E;
769 __needed = _ZoneOffset;
770 __allowed_mods = _Mod_E_O;
773 __needed = _ZoneAbbrev;
781 if (__mod) [[unlikely]]
783 __allowed_mods = _Mod_none;
789 __throw_format_error(
"chrono format error: invalid specifier "
793 if ((__mod ==
'E' && !(__allowed_mods & _Mod_E))
794 || (__mod ==
'O' && !(__allowed_mods & _Mod_O)))
795 __throw_format_error(
"chrono format error: invalid modifier "
797 if (__mod && __c !=
'z')
798 __locale_specific =
true;
802 if (__locale_specific)
803 __needed -= _ChronoParts::_Subseconds;
805 if ((__parts & __needed) != __needed)
806 __throw_format_error(
"chrono format error: format argument does "
807 "not contain the information required by the "
809 __spec._M_needed |= __needed;
810 __spec._M_locale_specific |= __locale_specific;
813 size_t __pos = __string_view(__first, __last - __first).find(
'%');
818 if (__pos == __string_view::npos)
824 __first += __pos + 1;
829 if (__conv || __mod != _CharT())
830 __throw_format_error(
"chrono format error: unescaped '%' in "
833 __spec._M_chrono_specs
834 = __string_view(__chrono_specs, __first - __chrono_specs);
841 template<
typename _FormatContext>
842 typename _FormatContext::iterator
843 _M_format(
const _ChronoData<_CharT>& __t, _FormatContext& __fc)
const
845#if defined _GLIBCXX_USE_NL_LANGINFO_L && __CHAR_BIT__ == 8
849 if constexpr (is_same_v<_CharT, char>)
850 if constexpr (__unicode::__literal_encoding_is_utf8())
851 if (_M_spec._M_localized && _M_spec._M_locale_specific)
853 extern locale __with_encoding_conversion(
const locale&);
857 locale __loc = __fc.locale();
858 if (__loc != locale::classic())
859 __fc._M_loc = __with_encoding_conversion(__loc);
863 const size_t __padwidth = _M_spec._M_get_width(__fc);
865 return _M_format_to(__t, __fc.out(), __fc);
867 using _Out =
typename _FormatContext::iterator;
868 _Padding_sink<_Out, _CharT> __sink(__fc.out(), __padwidth);
869 _M_format_to(__t, __sink.out(), __fc);
870 return __sink._M_finish(_M_spec._M_align, _M_spec._M_fill);
873 _ChronoSpec<_CharT> _M_spec;
876 static constexpr const _CharT* _S_chars
877 = _GLIBCXX_WIDEN(
"0123456789.Lf:/ +-{}");
878 static constexpr _CharT _S_dot = _S_chars[10];
879 static constexpr _CharT _S_colon = _S_chars[13];
880 static constexpr _CharT _S_slash = _S_chars[14];
881 static constexpr _CharT _S_space = _S_chars[15];
882 static constexpr const _CharT* _S_fp_fmt = _S_chars + 11;
883 static constexpr const _CharT* _S_plus_minus = _S_chars + 16;
884 static constexpr const _CharT* _S_minus_empty_spec = _S_chars + 17;
885 static constexpr const _CharT* _S_empty_spec = _S_chars + 18;
887 [[__gnu__::__always_inline__]]
888 static _Dynamic_format_string<_CharT>
890 {
return _Dynamic_format_string<_CharT>(_S_empty_spec); }
892 static constexpr const _CharT* _S_weekdays[]
894 _GLIBCXX_WIDEN(
"Sunday"),
895 _GLIBCXX_WIDEN(
"Monday"),
896 _GLIBCXX_WIDEN(
"Tuesday"),
897 _GLIBCXX_WIDEN(
"Wednesday"),
898 _GLIBCXX_WIDEN(
"Thursday"),
899 _GLIBCXX_WIDEN(
"Friday"),
900 _GLIBCXX_WIDEN(
"Saturday"),
903 static constexpr const _CharT* _S_months[]
905 _GLIBCXX_WIDEN(
"January"),
906 _GLIBCXX_WIDEN(
"February"),
907 _GLIBCXX_WIDEN(
"March"),
908 _GLIBCXX_WIDEN(
"April"),
909 _GLIBCXX_WIDEN(
"May"),
910 _GLIBCXX_WIDEN(
"June"),
911 _GLIBCXX_WIDEN(
"July"),
912 _GLIBCXX_WIDEN(
"August"),
913 _GLIBCXX_WIDEN(
"September"),
914 _GLIBCXX_WIDEN(
"October"),
915 _GLIBCXX_WIDEN(
"November"),
916 _GLIBCXX_WIDEN(
"December"),
920 template<
typename _OutIter>
922 _M_write(_OutIter __out, [[maybe_unused]]
const locale& __loc,
923 __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);
1152 __out = _M_g_G_V(__t,
std::move(__out), __c);
1156 __out = _M_H_I(__t._M_hours, __print_sign(), __c);
1159 __out = _M_j(__t, __print_sign());
1162 __out = _M_m(__t._M_month,
std::move(__out));
1165 __out = _M_M(__t._M_minutes, __print_sign());
1168 __out = _M_p(__t._M_hours,
std::move(__out));
1171 __out = _M_q(__t._M_unit_suffix,
std::move(__out));
1174 __out = _M_Q(__t, __print_sign(), __fc);
1177 __out = _M_r(__t, __print_sign());
1181 __out = _M_R_X(__t, __print_sign(), __c !=
'R');
1184 __out = _M_T(__t, __print_sign(), __fc);
1187 __out = _M_S(__t, __print_sign(), __fc, __mod !=
'O');
1191 __out = _M_u_w(__t._M_weekday,
std::move(__out), __c);
1195 __out = _M_U_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;
1318 __yi = __builtin_abs(__yi);
1319 int __ci = __yi / 100;
1321 if (__conv ==
'C' && __is_neg && (__ci * 100) != __yi) [[unlikely]]
1324 if (__conv !=
'y' && __ci >= 100) [[unlikely]]
1326 using _FmtStr = _Dynamic_format_string<_CharT>;
1327 __string_view __fs = _S_minus_empty_spec + !__is_neg;
1328 __out = std::format_to(
std::move(__out), _FmtStr(__fs),
1329 __conv ==
'C' ? __ci : __yi);
1334 __buf[0] = _S_plus_minus[1];
1335 __string_view __sv(__buf + 3, __buf + 3);
1338 _S_fill_two_digits(__buf + 1, __ci);
1339 __sv = __string_view(__buf + !__is_neg, __buf + 3);
1343 _S_fill_two_digits(__buf + 3, __yi % 100);
1344 __sv = __string_view(__sv.data(), __buf + 5);
1346 __out = __format::__write(
std::move(__out), __sv);
1351 template<
typename _OutIter>
1353 _M_D_x(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1359 auto __di = (unsigned)__t._M_day;
1360 auto __mi = (unsigned)__t._M_month;
1361 auto __yi = __builtin_abs((
int)__t._M_year) % 100;
1363 if (__mi >= 100 || __di >= 100) [[unlikely]]
1365 using _FmtStr = _Dynamic_format_string<_CharT>;
1366 __string_view __fs = _GLIBCXX_WIDEN(
"{:02d}/{:02d}/{:02d}");
1367 __out = std::format_to(
std::move(__out), _FmtStr(__fs),
1373 __buf[2] = _S_slash;
1374 __buf[5] = _S_slash;
1375 __string_view __sv(__buf, __buf + 8);
1377 _S_fill_two_digits(__buf, __mi);
1378 _S_fill_two_digits(__buf + 3, __di);
1379 _S_fill_two_digits(__buf + 6, __yi);
1380 __out = __format::__write(
std::move(__out), __sv);
1385 template<
typename _OutIter>
1387 _M_d_e(chrono::day __d, _OutIter __out, _CharT __conv)
const
1394 unsigned __i = (unsigned)__d;
1397 auto __sv = _S_str_d2(__buf, __i);
1398 if (__conv == _CharT(
'e') && __i < 10)
1401 __buf[0] = _S_space;
1405 __out = __format::__write(
std::move(__out), __sv);
1409 template<
typename _OutIter>
1411 _M_F(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1413 auto __di = (unsigned)__t._M_day;
1414 auto __mi = (unsigned)__t._M_month;
1415 auto __yi = (int)__t._M_year;
1416 const bool __is_neg = __yi < 0;
1417 __yi = __builtin_abs(__yi);
1419 if (__yi >= 10000 || __mi >= 100 || __di >= 100) [[unlikely]]
1421 using _FmtStr = _Dynamic_format_string<_CharT>;
1423 = _GLIBCXX_WIDEN(
"-{:04d}-{:02d}-{:02d}") + !__is_neg;
1424 __out = std::format_to(
std::move(__out), _FmtStr(__fs),
1430 __buf[0] = _S_plus_minus[1];
1431 __buf[5] = _S_plus_minus[1];
1432 __buf[8] = _S_plus_minus[1];
1433 __string_view __sv(__buf + !__is_neg, __buf + 11);
1435 _S_fill_two_digits(__buf + 1, __yi / 100);
1436 _S_fill_two_digits(__buf + 3, __yi % 100);
1437 _S_fill_two_digits(__buf + 6, __mi);
1438 _S_fill_two_digits(__buf + 9, __di);
1439 __out = __format::__write(
std::move(__out), __sv);
1445 template<
typename _OutIter>
1447 _M_g_G_V(
const _ChronoData<_CharT>& __t, _OutIter __out,
1448 _CharT __conv)
const
1459 using namespace chrono;
1461 const days __offset = (__t._M_weekday - Monday) -
days(3);
1463 const local_days __ild = __t._M_ldays - __offset;
1465 days __idoy = __t._M_day_of_year - __offset;
1469 if (__idoy <=
days(0))
1470 __iyear = __t._M_year -
years(1);
1471 else if (__idoy <=
days(365))
1472 __iyear = __t._M_year;
1473 else if (__idoy ==
days(366) && __t._M_year.is_leap())
1474 __iyear = __t._M_year;
1475 else if (__idoy <=
days(730))
1476 __iyear = __t._M_year +
years(1);
1478 __iyear = year_month_day(__ild).year();
1481 return _M_C_y_Y(__iyear,
std::move(__out),
"yY"[__conv ==
'G']);
1483 if (__iyear != __t._M_year)
1484 __idoy = __ild - local_days(__iyear/January/0);
1486 const auto __wi = chrono::floor<weeks>(__idoy -
days(1)).count() + 1;
1487 return __format::__write(
std::move(__out), _S_two_digits(__wi));
1490 template<
typename _OutIter>
1492 _M_H_I(chrono::hours __h, _OutIter __out, _CharT __conv)
const
1499 int __i = __h.count();
1501 if (__conv == _CharT(
'I'))
1507 else if (__i >= 100) [[unlikely]]
1508 return std::format_to(
std::move(__out), _S_empty_fs(), __i);
1510 return __format::__write(
std::move(__out), _S_two_digits(__i));
1513 template<
typename _OutIter>
1515 _M_j(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1517 if (!_M_spec._M_needs(_ChronoParts::_DayOfYear))
1520 auto __d = chrono::floor<chrono::days>(__t._M_hours).count();
1521 return std::format_to(
std::move(__out), _S_empty_fs(), __d);
1524 auto __d = __t._M_day_of_year.count();
1525 if (__d >= 1000) [[unlikely]]
1526 return std::format_to(
std::move(__out), _S_empty_fs(), __d);
1529 return __format::__write(
std::move(__out), _S_str_d3(__buf, __d));
1532 template<
typename _OutIter>
1534 _M_m(chrono::month __m, _OutIter __out)
const
1538 auto __i = (unsigned)__m;
1539 if (__i == 0 && _M_spec._M_debug) [[unlikely]]
1541 return __format::__write(
std::move(__out), _S_digit(0));
1544 return __format::__write(
std::move(__out), _S_str_d2(__buf, __i));
1547 template<
typename _OutIter>
1549 _M_M(chrono::minutes __m, _OutIter __out)
const
1554 auto __i = __m.count();
1555 return __format::__write(
std::move(__out), _S_two_digits(__i));
1558 template<
typename _OutIter>
1560 _M_p(chrono::hours __h, _OutIter __out)
const
1565 _S_fill_ampm(__buf, __h);
1566 return __format::__write(
std::move(__out), __string_view(__buf, 2));
1569 template<
typename _OutIter>
1571 _M_q(__string_view __us, _OutIter __out)
const
1574 return __format::__write(
std::move(__out), __us);
1577 template<
typename _OutIter,
typename _FormatContext>
1579 _M_Q(
const _ChronoData<_CharT>& __t, _OutIter __out,
1580 _FormatContext&)
const
1583 return std::vformat_to(
std::move(__out), _S_empty_spec, __t._M_ereps);
1586 template<
typename _OutIter>
1588 _M_r(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1591 auto __hi = __t._M_hours.count() % 12;
1596 __buf[2] = _S_colon;
1597 __buf[5] = _S_colon;
1598 __buf[8] = _S_space;
1599 _S_fill_two_digits(__buf, __hi);
1600 _S_fill_two_digits(__buf + 3, __t._M_minutes.count());
1601 _S_fill_two_digits(__buf + 6, __t._M_seconds.count());
1602 _S_fill_ampm(__buf + 9, __t._M_hours);
1604 return __format::__write(
std::move(__out), __string_view(__buf, 11));
1607 template<
typename _OutIter>
1609 _M_R_X(
const _ChronoData<_CharT>& __t, _OutIter __out,
1616 auto __hi = __t._M_hours.count();
1619 __buf[2] = _S_colon;
1620 __buf[5] = _S_colon;
1621 __string_view __sv(__buf, 8);
1623 if (__hi >= 100) [[unlikely]]
1625 __out = std::format_to(
std::move(__out), _S_empty_fs(), __hi);
1626 __sv.remove_prefix(2);
1629 _S_fill_two_digits(__buf, __hi);
1631 _S_fill_two_digits(__buf + 3, __t._M_minutes.count());
1633 _S_fill_two_digits(__buf + 6, __t._M_seconds.count());
1635 __sv.remove_suffix(3);
1637 return __format::__write(
std::move(__out), __sv);
1640 template<
typename _OutIter,
typename _FormatContext>
1642 _M_S(
const _ChronoData<_CharT>& __t, _OutIter __out,
1643 _FormatContext& __ctx,
bool __subs =
true)
const
1647 auto __s = __t._M_seconds;
1649 __out = __format::__write(
std::move(__out),
1650 _S_two_digits(__s.count()));
1652 __out = _M_subsecs(__t,
std::move(__out), __ctx);
1656 template<
typename _OutIter,
typename _FormatContext>
1658 _M_subsecs(
const _ChronoData<_CharT>& __t, _OutIter __out,
1659 _FormatContext& __ctx)
const
1661 unsigned __prec = _M_spec._M_prec_kind != _WP_none
1662 ? _M_spec._M_get_precision(__ctx)
1667 _CharT __dot = _S_dot;
1668 if (_M_spec._M_localized) [[unlikely]]
1670 auto __loc = __ctx.locale();
1671 const auto& __np = use_facet<numpunct<_CharT>>(__loc);
1672 __dot = __np.decimal_point();
1677 if (_M_spec._M_floating_point_rep)
1679 _Str_sink<_CharT> __sink;
1680 if (_M_spec._M_localized && _M_spec._M_custom_rep) [[unlikely]]
1681 std::vformat_to(__sink.out(), __ctx.locale(),
1682 _GLIBCXX_WIDEN(
"{1:0.{2}Lf}"), __t._M_ereps);
1684 std::vformat_to(__sink.out(),
1685 _GLIBCXX_WIDEN(
"{1:0.{2}f}"), __t._M_ereps);
1687 auto __sv = __sink.view();
1689 __sv.remove_prefix(2);
1690 return __format::__write(
std::move(__out), __sv);
1693 constexpr unsigned __max_prec = _ChronoData<_CharT>::_S_max_prec;
1694 constexpr typename _ChronoData<_CharT>::_Attoseconds::rep __pow10t[]
1698 10'000u, 100'000u, 1000'000u,
1699 10'000'000u, 100'000'000u, 1000'000'000u,
1700 10'000'000'000u, 100'000'000'000u, 1000'000'000'000u,
1701 10'000'000'000'000u, 100'000'000'000'000u, 1000'000'000'000'000u,
1702 10'000'000'000'000'000u, 100'000'000'000'000'000u, 1000'000'000'000'000'000u,
1705 auto __subs = __t._M_subseconds.count();
1706 if (__prec < __max_prec)
1707 __subs /= __pow10t[__max_prec - __prec];
1708 else if (__prec > __max_prec)
1709 __prec = __max_prec;
1711 using _FmtStr = _Dynamic_format_string<_CharT>;
1712 return std::format_to(__out, _FmtStr(_GLIBCXX_WIDEN(
"{0:0{1}}")),
1718 template<
typename _OutIter,
typename _FormatContext>
1720 _M_T(
const _ChronoData<_CharT>& __t, _OutIter __out,
1721 _FormatContext& __ctx)
const
1724 __out = _M_R_X(__t,
std::move(__out),
true);
1725 return _M_subsecs(__t,
std::move(__out), __ctx);
1728 template<
typename _OutIter>
1730 _M_u_w(chrono::weekday __wd, _OutIter __out, _CharT __conv)
const
1736 unsigned __wdi = __conv ==
'u' ? __wd.iso_encoding()
1737 : __wd.c_encoding();
1739 return __format::__write(
std::move(__out), _S_str_d1(__buf, __wdi));
1742 template<
typename _OutIter>
1744 _M_U_W(
const _ChronoData<_CharT>& __t, _OutIter __out,
1745 _CharT __conv)
const
1752 using namespace chrono;
1753 const weekday __weekstart = __conv ==
'U' ? Sunday : Monday;
1754 const days __offset = __t._M_weekday - __weekstart;
1755 auto __weeks = chrono::floor<weeks>(__t._M_day_of_year - __offset -
days(1));
1756 return __format::__write(
std::move(__out), _S_two_digits(__weeks.count() + 1));
1759 template<
typename _OutIter>
1761 _M_z(chrono::seconds __ts, _OutIter __out,
bool __mod =
false)
const
1765 __string_view __zero
1766 = __mod ? _GLIBCXX_WIDEN(
"+00:00") : _GLIBCXX_WIDEN(
"+0000");
1767 return __format::__write(
std::move(__out), __zero);
1770 chrono::hh_mm_ss<chrono::seconds> __hms(__ts);
1771 unsigned __mo = 3 + __mod;
1774 __buf[0] = _S_plus_minus[__hms.is_negative()];
1775 __buf[3] = _S_colon;
1776 _S_fill_two_digits(__buf + 1, __hms.hours().count());
1777 _S_fill_two_digits(__buf + __mo, __hms.minutes().count());
1779 __string_view __sv(__buf, __mo + 2);
1780 return __format::__write(
std::move(__out), __sv);
1783 template<
typename _OutIter>
1785 _M_Z(__string_view __abbrev, _OutIter __out)
const
1786 {
return __format::__write(
std::move(__out), __abbrev); }
1791 static basic_string_view<_CharT>
1792 _S_digit(
int __n)
noexcept
1795 return { _GLIBCXX_WIDEN(
"0123456789999999") + (__n & 0xf), 1 };
1799 static basic_string_view<_CharT>
1800 _S_two_digits(
int __n)
noexcept
1803 _GLIBCXX_WIDEN(
"0001020304050607080910111213141516171819"
1804 "2021222324252627282930313233343536373839"
1805 "4041424344454647484950515253545556575859"
1806 "6061626364656667686970717273747576777879"
1807 "8081828384858687888990919293949596979899"
1808 "9999999999999999999999999999999999999999"
1809 "9999999999999999") + 2 * (__n & 0x7f),
1815 [[__gnu__::__always_inline__]]
1817 _S_fill_two_digits(_CharT* __buf,
unsigned __n)
1819 auto __sv = _S_two_digits(__n);
1825 [[__gnu__::__always_inline__]]
1827 _S_fill_ampm(_CharT* __buf, chrono::hours __h)
1829 auto __hi = __h.count();
1830 if (__hi >= 24) [[unlikely]]
1833 constexpr const _CharT* __apm = _GLIBCXX_WIDEN(
"APM");
1834 __buf[0] = __apm[__hi >= 12];
1835 __buf[1] = __apm[2];
1840 [[__gnu__::__always_inline__]]
1841 static basic_string_view<_CharT>
1842 _S_str_d1(span<_CharT, 3> __buf,
unsigned __n)
1844 if (__n < 10) [[likely]]
1845 return _S_digit(__n);
1846 return _S_str_d2(__buf, __n);
1851 [[__gnu__::__always_inline__]]
1852 static basic_string_view<_CharT>
1853 _S_str_d2(span<_CharT, 3> __buf,
unsigned __n)
1855 if (__n < 100) [[likely]]
1856 return _S_two_digits(__n);
1857 return _S_str_d3(__buf, __n);
1862 [[__gnu__::__always_inline__]]
1863 static basic_string_view<_CharT>
1864 _S_str_d3(span<_CharT, 3> __buf,
unsigned __n)
1866 _S_fill_two_digits(__buf.data(), __n / 10);
1867 __buf[2] = _S_chars[__n % 10];
1868 return __string_view(__buf.data(), 3);
1872 template<
typename _CharT>
1873 struct __formatter_duration :
private __formatter_chrono<_CharT>
1875 template<
typename _Rep,
typename _Period>
1876 constexpr static auto
1877 _S_subseconds(
const chrono::duration<_Rep, _Period>& __d)
1879 if constexpr (chrono::treat_as_floating_point_v<_Rep>)
1880 return chrono::duration<_Rep>(__d);
1881 else if constexpr (_Period::den == 1)
1882 return chrono::seconds(0);
1885 using _Attoseconds = _ChronoData<_CharT>::_Attoseconds;
1886 using _CRep = common_type_t<_Rep, typename _Attoseconds::rep>;
1887 chrono::duration<_CRep, _Period> __subs(__d.count());
1888 return chrono::duration_cast<_Attoseconds>(__subs);
1893 template<
typename _Duration>
1896 _S_spec_for(_ChronoParts __parts)
1898 using _Rep =
typename _Duration::rep;
1899 using enum _ChronoParts;
1901 _ChronoSpec<_CharT> __res{};
1902 __res._M_floating_point_rep = chrono::treat_as_floating_point_v<_Rep>;
1903 __res._M_custom_rep = !is_arithmetic_v<_Rep>;
1904 __res._M_prec = chrono::hh_mm_ss<_Duration>::fractional_width;
1905 if ((__parts & _TimeOfDay) != 0)
1906 __res._M_localized = __res._M_prec > 0 || __res._M_floating_point_rep;
1908 if ((__parts & _TimeOfDay) != 0)
1909 __res._M_needed |= _TimeOfDay;
1910 if ((__parts & _Date) != 0)
1911 __res._M_needed |= _YearMonthDay;
1912 if ((__parts & _ZoneAbbrev) != 0)
1913 __res._M_needed |= _ZoneAbbrev;
1917 case _ZonedDateTime:
1918 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ftz();
1921 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ft();
1924 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_f();
1927 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_t();
1932 __builtin_unreachable();
1937 template<
typename _Duration>
1942 using enum _ChronoParts;
1944 constexpr bool __stream_insertable =
1945 requires (basic_ostream<_CharT>& __os, chrono::sys_time<_Duration> __t)
1947 if constexpr (!__stream_insertable)
1948 return _S_spec_for<_Duration>(_None);
1949 else if constexpr (is_convertible_v<_Duration, chrono::days>)
1950 return _S_spec_for<_Duration>(_Date);
1952 return _S_spec_for<_Duration>(_DateTime);
1955 using __formatter_chrono<_CharT>::__formatter_chrono;
1956 using __formatter_chrono<_CharT>::_M_spec;
1958 template<
typename _Duration>
1959 constexpr typename basic_format_parse_context<_CharT>::iterator
1960 _M_parse(basic_format_parse_context<_CharT>& __pc, _ChronoParts __parts,
1961 const _ChronoSpec<_CharT>& __def)
1963 using _Rep =
typename _Duration::rep;
1964 using enum _ChronoParts;
1967 = __formatter_chrono<_CharT>::_M_parse(__pc, __parts, __def);
1970 _M_spec._M_needs_ok_check =
false;
1975 if constexpr (!is_floating_point_v<_Rep>)
1976 if constexpr (chrono::treat_as_floating_point_v<_Rep>)
1977 if (_M_spec._M_needs(_Subseconds|_EpochUnits)
1978 || _M_spec._M_prec_kind != _WP_none
1979 || _M_spec._M_prec_value > 0)
1981 constexpr const _CharT* __fs = _GLIBCXX_WIDEN(
"#02.5Lf");
1982 basic_format_parse_context<_CharT> __npc(__fs);
1983 formatter<_Rep, _CharT> __fmtter;
1984 __fmtter.parse(__npc);
1990 template<
typename _FormatContext>
1992 _M_locale(_FormatContext& __fc)
const
1994 if (!_M_spec._M_localized)
1997 return __fc.locale();
2001 template<
typename _Rep,
typename _Period,
typename _FormatContext>
2002 typename _FormatContext::iterator
2003 _M_format_to_ostream(
const chrono::duration<_Rep, _Period>& __d,
2005 _FormatContext& __fc)
const
2007 basic_ostringstream<_CharT> __os;
2008 __os.imbue(this->_M_locale(__fc));
2010 if (__is_neg) [[unlikely]]
2011 __os << this->_S_plus_minus[1];
2015 return __format::__write_padded_as_spec(__str, __str.size(),
2019 template<
typename _Rep1,
typename _Period1,
2020 typename _Rep2,
typename _Period2,
2021 typename _FormatContext>
2022 typename _FormatContext::iterator
2023 _M_format_units(_ChronoData<_CharT>& __cd,
2024 const chrono::duration<_Rep1, _Period1>& __ed,
2025 const chrono::duration<_Rep2, _Period2>& __ss,
2026 _FormatContext& __fc)
const
2028 __format::_Str_sink<_CharT> __suffix_store;
2029 constexpr auto _S_unit_suffix
2030 = chrono::__detail::__units_suffix<_Period1, _CharT>();
2031 if constexpr (!_S_unit_suffix.empty())
2032 __cd._M_unit_suffix = _S_unit_suffix;
2033 else if (_M_spec._M_needs(_ChronoParts::_UnitSuffix))
2036 __fmt_units_suffix<_Period1, _CharT>(__suffix_store.out());
2037 __cd._M_unit_suffix = __suffix_store.view();
2040 const auto __prec = _M_spec._M_prec_kind != _WP_none
2041 ? _M_spec._M_get_precision(__fc)
2044 using _ErasedContext =
typename _ChronoData<_CharT>::_FormatContext;
2047 auto __ereps = +__ed.count();
2048 if (!_M_spec._M_needs(_ChronoParts::_Subseconds))
2052 = std::make_format_args<_ErasedContext>(__ereps, __ssreps, __prec);
2053 __cd._M_ereps = __args_store;
2054 return this->_M_format(__cd, __fc);
2057 using _Attoseconds = _ChronoData<_CharT>::_Attoseconds;
2058 auto __nss = _S_subseconds(__ss);
2059 __cd._M_subseconds = chrono::duration_cast<_Attoseconds>(__nss);
2061 auto __ssreps = __nss.count();
2063 = std::make_format_args<_ErasedContext>(__ereps, __ssreps, __prec);
2064 __cd._M_ereps = __args_store;
2066 return this->_M_format(__cd, __fc);
2070 template<
typename _Rep1,
typename _Period1,
typename _FormatContext>
2071 typename _FormatContext::iterator
2072 _M_format_time_point(_ChronoData<_CharT>& __cd,
2073 const chrono::duration<_Rep1, _Period1>& __ed,
2074 _FormatContext& __fc)
const
2076 auto __parts = _M_spec._M_needed - _ChronoParts::_TotalSeconds;
2077 if ((__parts & _ChronoParts::_DateTime) != 0)
2078 __cd._M_fill_date_time(__cd._M_lseconds, __parts);
2079 return _M_format_units(__cd, __ed, __ed - __cd._M_eseconds, __fc);
2083#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2084 template<
typename _CharT>
2085 struct __formatter_chrono_info
2087 constexpr typename basic_format_parse_context<_CharT>::iterator
2088 parse(basic_format_parse_context<_CharT>& __pc)
2089 {
return _M_f._M_parse(__pc, _ChronoParts(), {}); }
2091 template<
typename _Info,
typename _Out>
2092 typename basic_format_context<_Out, _CharT>::iterator
2093 format(
const _Info& __i,
2094 basic_format_context<_Out, _CharT>& __fc)
const
2098 if (!_M_f._M_spec._M_chrono_specs.empty()) [[unlikely]]
2099 return _M_f._M_format(_ChronoData<_CharT>{}, __fc);
2101 const size_t __padwidth = _M_f._M_spec._M_get_width(__fc);
2102 if (__padwidth == 0)
2103 return _M_format_to(__fc.out(), __i);
2105 _Padding_sink<_Out, _CharT> __sink(__fc.out(), __padwidth);
2106 _M_format_to(__sink.out(), __i);
2107 return __sink._M_finish(_M_f._M_spec._M_align, _M_f._M_spec._M_fill);
2111 template<
typename _Out>
2113 _M_format_to(_Out __out,
const chrono::sys_info& __si)
const
2115 using _FmtStr = _Dynamic_format_string<_CharT>;
2119 constexpr auto* __fs
2120 = _GLIBCXX_WIDEN(
"[{0:%F %T},{1:%F %T},{2:%T},{3:%Q%q},{0:%Z}]");
2121 const chrono::local_seconds __lb(__si.begin.time_since_epoch());
2122 return std::format_to(
std::move(__out), _FmtStr(__fs),
2123 chrono::local_time_format(__lb, &__si.abbrev),
2124 __si.end, __si.offset, __si.save);
2127 template<
typename _Out>
2129 _M_format_to(_Out __out,
const chrono::local_info& __li)
const
2131 *__out = _Separators<_CharT>::_S_squares()[0];
2133 if (__li.result == chrono::local_info::unique)
2134 __out = _M_format_to(
std::move(__out), __li.first);
2137 basic_string_view<_CharT> __sv;
2138 if (__li.result == chrono::local_info::nonexistent)
2139 __sv =_GLIBCXX_WIDEN(
"nonexistent");
2141 __sv = _GLIBCXX_WIDEN(
"ambiguous");
2142 __out = __format::__write(
std::move(__out), __sv);
2144 __sv = _GLIBCXX_WIDEN(
" local time between ");
2145 __out = __format::__write(
std::move(__out), __sv);
2146 __out = _M_format_to(
std::move(__out), __li.first);
2148 __sv = _GLIBCXX_WIDEN(
" and ");
2149 __out = __format::__write(
std::move(__out), __sv);
2150 __out = _M_format_to(
std::move(__out), __li.second);
2152 *__out = _Separators<_CharT>::_S_squares()[1];
2157 __formatter_chrono<_CharT> _M_f;
2164 template<
typename _Rep,
typename _Period,
typename _CharT>
2165 requires __format::__formattable_impl<_Rep, _CharT>
2166 struct formatter<
chrono::duration<_Rep, _Period>, _CharT>
2168 constexpr typename basic_format_parse_context<_CharT>::iterator
2169 parse(basic_format_parse_context<_CharT>& __pc)
2171 using enum __format::_ChronoParts;
2172 return _M_f.template _M_parse<_Duration>(__pc, _EpochTime, __defSpec);
2175 template<
typename _Out>
2176 typename basic_format_context<_Out, _CharT>::iterator
2177 format(
const chrono::duration<_Rep, _Period>& __d,
2178 basic_format_context<_Out, _CharT>& __fc)
const
2180 if constexpr (numeric_limits<_Rep>::is_signed)
2181 if (__d < __d.zero()) [[unlikely]]
2183 if constexpr (is_integral_v<_Rep>)
2187 using _URep = make_unsigned_t<_Rep>;
2188 auto __ucnt = -
static_cast<_URep
>(__d.count());
2189 auto __ud = chrono::duration<_URep, _Period>(__ucnt);
2190 return _M_format(__ud,
true, __fc);
2193 return _M_format(-__d,
true, __fc);
2195 return _M_format(__d,
false, __fc);
2199 using _Duration = chrono::duration<_Rep, _Period>;
2201 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2203 using enum __format::_ChronoParts;
2204 auto __res = __format::__formatter_duration<_CharT>::
2205 template _S_spec_for<_Duration>(_None);
2206 __res._M_localized = !is_integral_v<_Rep>;
2208 if constexpr (is_integral_v<_Rep>)
2210 __res._M_needed = _EpochUnits|_UnitSuffix;
2211 __res._M_chrono_specs = _GLIBCXX_WIDEN(
"%Q%q");
2216 template<
typename _Rep2,
typename _Out>
2217 typename basic_format_context<_Out, _CharT>::iterator
2218 _M_format(
const chrono::duration<_Rep2, _Period>& __d,
2220 basic_format_context<_Out, _CharT>& __fc)
const
2222 using namespace chrono;
2223 using enum __format::_ChronoParts;
2224 if constexpr (!is_integral_v<_Rep>)
2225 if (_M_f._M_spec._M_chrono_specs.empty())
2226 return _M_f._M_format_to_ostream(__d, __is_neg, __fc);
2228 __format::_ChronoData<_CharT> __cd;
2229 __cd._M_is_neg = __is_neg;
2230 auto __ts = chrono::floor<chrono::seconds>(__d);
2231 __cd._M_eseconds = __ts;
2232 if (_M_f._M_spec._M_needs(_HoursMinutesSeconds))
2233 __cd._M_fill_time(__ts);
2234 return _M_f._M_format_units(__cd, __d, __d - __ts, __fc);
2237 __format::__formatter_duration<_CharT> _M_f{__defSpec};
2240#if __glibcxx_print >= 202406L
2243 template<
typename _Rep,
typename _Period>
2245 enable_nonlocking_formatter_optimization<chrono::duration<_Rep, _Period>>
2246 = is_arithmetic_v<_Rep>;
2249 template<__format::__
char _CharT>
2250 struct formatter<
chrono::day, _CharT>
2252 constexpr typename basic_format_parse_context<_CharT>::iterator
2253 parse(basic_format_parse_context<_CharT>& __pc)
2255 using enum __format::_ChronoParts;
2256 return _M_f._M_parse(__pc, _Day|_WeekdayIndex, __defSpec);
2259 template<
typename _Out>
2260 typename basic_format_context<_Out, _CharT>::iterator
2261 format(
const chrono::day& __t,
2262 basic_format_context<_Out, _CharT>& __fc)
const
2264 __format::_ChronoData<_CharT> __cd{};
2265 __cd._M_fill_day(__t, __defSpec._M_needed);
2266 return _M_f._M_format(__cd, __fc);
2270 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2272 using __format::_ChronoFormats;
2273 using enum __format::_ChronoParts;
2275 __format::_ChronoSpec<_CharT> __res{};
2276 __res._M_debug =
true;
2277 __res._M_needed = _Day;
2278 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_d();
2282 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2285#if __glibcxx_print >= 202406L
2287 inline constexpr bool
2288 enable_nonlocking_formatter_optimization<chrono::day> =
true;
2291 template<__format::__
char _CharT>
2292 struct formatter<
chrono::month, _CharT>
2294 constexpr typename basic_format_parse_context<_CharT>::iterator
2295 parse(basic_format_parse_context<_CharT>& __pc)
2297 using enum __format::_ChronoParts;
2298 return _M_f._M_parse(__pc, _Month, __defSpec);
2301 template<
typename _Out>
2302 typename basic_format_context<_Out, _CharT>::iterator
2303 format(
const chrono::month& __t,
2304 basic_format_context<_Out, _CharT>& __fc)
const
2306 __format::_ChronoData<_CharT> __cd{};
2307 __cd._M_month = __t;
2308 return _M_f._M_format(__cd, __fc);
2312 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2314 using __format::_ChronoFormats;
2315 using enum __format::_ChronoParts;
2317 __format::_ChronoSpec<_CharT> __res{};
2318 __res._M_debug =
true;
2319 __res._M_localized =
true;
2320 __res._M_locale_specific =
true;
2321 __res._M_needed = _Month;
2322 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_m();
2326 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2329#if __glibcxx_print >= 202406L
2331 inline constexpr bool
2332 enable_nonlocking_formatter_optimization<chrono::month> =
true;
2335 template<__format::__
char _CharT>
2336 struct formatter<
chrono::year, _CharT>
2338 constexpr typename basic_format_parse_context<_CharT>::iterator
2339 parse(basic_format_parse_context<_CharT>& __pc)
2341 using enum __format::_ChronoParts;
2342 return _M_f._M_parse(__pc, _Year, __defSpec);
2345 template<
typename _Out>
2346 typename basic_format_context<_Out, _CharT>::iterator
2347 format(
const chrono::year& __t,
2348 basic_format_context<_Out, _CharT>& __fc)
const
2350 __format::_ChronoData<_CharT> __cd{};
2352 return _M_f._M_format(__cd, __fc);
2356 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2358 using __format::_ChronoFormats;
2359 using enum __format::_ChronoParts;
2361 __format::_ChronoSpec<_CharT> __res{};
2362 __res._M_debug =
true;
2363 __res._M_needed = _Year;
2364 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_y();
2368 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2371#if __glibcxx_print >= 202406L
2373 inline constexpr bool
2374 enable_nonlocking_formatter_optimization<chrono::year> =
true;
2377 template<__format::__
char _CharT>
2378 struct formatter<
chrono::weekday, _CharT>
2380 constexpr typename basic_format_parse_context<_CharT>::iterator
2381 parse(basic_format_parse_context<_CharT>& __pc)
2383 using enum __format::_ChronoParts;
2384 return _M_f._M_parse(__pc, _Weekday, __defSpec);
2387 template<
typename _Out>
2388 typename basic_format_context<_Out, _CharT>::iterator
2389 format(
const chrono::weekday& __t,
2390 basic_format_context<_Out, _CharT>& __fc)
const
2392 __format::_ChronoData<_CharT> __cd{};
2393 __cd._M_weekday = __t;
2394 return _M_f._M_format(__cd, __fc);
2398 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2400 using __format::_ChronoFormats;
2401 using enum __format::_ChronoParts;
2403 __format::_ChronoSpec<_CharT> __res{};
2404 __res._M_debug =
true;
2405 __res._M_localized =
true;
2406 __res._M_locale_specific =
true;
2407 __res._M_needed = _Weekday;
2408 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_w();
2412 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2415#if __glibcxx_print >= 202406L
2417 inline constexpr bool
2418 enable_nonlocking_formatter_optimization<chrono::weekday> =
true;
2421 template<__format::__
char _CharT>
2422 struct formatter<
chrono::weekday_indexed, _CharT>
2424 constexpr typename basic_format_parse_context<_CharT>::iterator
2425 parse(basic_format_parse_context<_CharT>& __pc)
2427 using enum __format::_ChronoParts;
2428 return _M_f._M_parse(__pc, _IndexedWeekday, __defSpec);
2431 template<
typename _Out>
2432 typename basic_format_context<_Out, _CharT>::iterator
2433 format(
const chrono::weekday_indexed& __t,
2434 basic_format_context<_Out, _CharT>& __fc)
const
2436 __format::_ChronoData<_CharT> __cd{};
2437 __cd._M_fill_weekday(__t, __defSpec._M_needed);
2438 return _M_f._M_format(__cd, __fc);
2442 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2444 using __format::_ChronoFormats;
2445 using enum __format::_ChronoParts;
2447 __format::_ChronoSpec<_CharT> __res{};
2448 __res._M_debug =
true;
2449 __res._M_localized =
true;
2450 __res._M_locale_specific =
true;
2451 __res._M_needed = _IndexedWeekday;
2452 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_wi();
2456 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2459#if __glibcxx_print >= 202406L
2461 inline constexpr bool
2462 enable_nonlocking_formatter_optimization<chrono::weekday_indexed> =
true;
2465 template<__format::__
char _CharT>
2466 struct formatter<
chrono::weekday_last, _CharT>
2468 constexpr typename basic_format_parse_context<_CharT>::iterator
2469 parse(basic_format_parse_context<_CharT>& __pc)
2471 using enum __format::_ChronoParts;
2472 return _M_f._M_parse(__pc, _Weekday, __defSpec);
2475 template<
typename _Out>
2476 typename basic_format_context<_Out, _CharT>::iterator
2477 format(
const chrono::weekday_last& __t,
2478 basic_format_context<_Out, _CharT>& __fc)
const
2480 __format::_ChronoData<_CharT> __cd{};
2481 __cd._M_weekday = __t.weekday();
2482 return _M_f._M_format(__cd, __fc);
2486 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2488 using __format::_ChronoFormats;
2489 using enum __format::_ChronoParts;
2491 __format::_ChronoSpec<_CharT> __res{};
2492 __res._M_debug =
true;
2493 __res._M_localized =
true;
2494 __res._M_locale_specific =
true;
2495 __res._M_needed = _Weekday;
2496 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_wl();
2500 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2503#if __glibcxx_print >= 202406L
2505 inline constexpr bool
2506 enable_nonlocking_formatter_optimization<chrono::weekday_last> =
true;
2509 template<__format::__
char _CharT>
2510 struct formatter<
chrono::month_day, _CharT>
2512 constexpr typename basic_format_parse_context<_CharT>::iterator
2513 parse(basic_format_parse_context<_CharT>& __pc)
2515 using enum __format::_ChronoParts;
2516 return _M_f._M_parse(__pc, _Month|_Day|_WeekdayIndex, __defSpec);
2519 template<
typename _Out>
2520 typename basic_format_context<_Out, _CharT>::iterator
2521 format(
const chrono::month_day& __t,
2522 basic_format_context<_Out, _CharT>& __fc)
const
2524 __format::_ChronoData<_CharT> __cd{};
2525 __cd._M_month = __t.month();
2526 __cd._M_fill_day(__t.day(), __defSpec._M_needed);
2527 return _M_f._M_format(__cd, __fc);
2531 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2533 using __format::_ChronoFormats;
2534 using enum __format::_ChronoParts;
2536 __format::_ChronoSpec<_CharT> __res{};
2537 __res._M_debug =
true;
2538 __res._M_localized =
true;
2539 __res._M_locale_specific =
true;
2540 __res._M_needed = _Month|_Day;
2541 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_md();
2545 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2548#if __glibcxx_print >= 202406L
2550 inline constexpr bool
2551 enable_nonlocking_formatter_optimization<chrono::month_day> =
true;
2554 template<__format::__
char _CharT>
2555 struct formatter<
chrono::month_day_last, _CharT>
2557 constexpr typename basic_format_parse_context<_CharT>::iterator
2558 parse(basic_format_parse_context<_CharT>& __pc)
2560 using enum __format::_ChronoParts;
2561 return _M_f._M_parse(__pc, _Month, __defSpec);
2564 template<
typename _Out>
2565 typename basic_format_context<_Out, _CharT>::iterator
2566 format(
const chrono::month_day_last& __t,
2567 basic_format_context<_Out, _CharT>& __fc)
const
2569 __format::_ChronoData<_CharT> __cd{};
2570 __cd._M_month = __t.month();
2571 return _M_f._M_format(__cd, __fc);
2575 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2577 using __format::_ChronoFormats;
2578 using enum __format::_ChronoParts;
2580 __format::_ChronoSpec<_CharT> __res{};
2581 __res._M_debug =
true;
2582 __res._M_localized =
true;
2583 __res._M_locale_specific =
true;
2584 __res._M_needed = _Month;
2585 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ml();
2589 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2592#if __glibcxx_print >= 202406L
2594 inline constexpr bool
2595 enable_nonlocking_formatter_optimization<chrono::month_day_last> =
true;
2598 template<__format::__
char _CharT>
2599 struct formatter<
chrono::month_weekday, _CharT>
2601 constexpr typename basic_format_parse_context<_CharT>::iterator
2602 parse(basic_format_parse_context<_CharT>& __pc)
2604 using enum __format::_ChronoParts;
2605 return _M_f._M_parse(__pc, _Month|_IndexedWeekday, __defSpec);
2608 template<
typename _Out>
2609 typename basic_format_context<_Out, _CharT>::iterator
2610 format(
const chrono::month_weekday& __t,
2611 basic_format_context<_Out, _CharT>& __fc)
const
2613 __format::_ChronoData<_CharT> __cd{};
2614 __cd._M_month = __t.month();
2615 __cd._M_fill_weekday(__t.weekday_indexed(), __defSpec._M_needed);
2616 return _M_f._M_format(__cd, __fc);
2620 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2622 using __format::_ChronoFormats;
2623 using enum __format::_ChronoParts;
2625 __format::_ChronoSpec<_CharT> __res{};
2626 __res._M_debug =
true;
2627 __res._M_localized =
true;
2628 __res._M_locale_specific =
true;
2629 __res._M_needed = _Month|_IndexedWeekday;
2630 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_mwi();
2634 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2637#if __glibcxx_print >= 202406L
2639 inline constexpr bool
2640 enable_nonlocking_formatter_optimization<chrono::month_weekday> =
true;
2643 template<__format::__
char _CharT>
2644 struct formatter<
chrono::month_weekday_last, _CharT>
2646 constexpr typename basic_format_parse_context<_CharT>::iterator
2647 parse(basic_format_parse_context<_CharT>& __pc)
2649 using enum __format::_ChronoParts;
2650 return _M_f._M_parse(__pc, _Month|_Weekday, __defSpec);
2653 template<
typename _Out>
2654 typename basic_format_context<_Out, _CharT>::iterator
2655 format(
const chrono::month_weekday_last& __t,
2656 basic_format_context<_Out, _CharT>& __fc)
const
2658 __format::_ChronoData<_CharT> __cd{};
2659 __cd._M_month = __t.month();
2660 __cd._M_weekday = __t.weekday_last().weekday();
2661 return _M_f._M_format(__cd, __fc);
2665 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2667 using __format::_ChronoFormats;
2668 using enum __format::_ChronoParts;
2670 __format::_ChronoSpec<_CharT> __res{};
2671 __res._M_debug =
true;
2672 __res._M_localized =
true;
2673 __res._M_locale_specific =
true;
2674 __res._M_needed = _Month|_Weekday;
2675 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_mwl();
2679 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2682#if __glibcxx_print >= 202406L
2684 inline constexpr bool
2685 enable_nonlocking_formatter_optimization<chrono::month_weekday_last> =
true;
2688 template<__format::__
char _CharT>
2689 struct formatter<
chrono::year_month, _CharT>
2691 constexpr typename basic_format_parse_context<_CharT>::iterator
2692 parse(basic_format_parse_context<_CharT>& __pc)
2694 using enum __format::_ChronoParts;
2695 return _M_f._M_parse(__pc, _Year|_Month, __defSpec);
2698 template<
typename _Out>
2699 typename basic_format_context<_Out, _CharT>::iterator
2700 format(
const chrono::year_month& __t,
2701 basic_format_context<_Out, _CharT>& __fc)
const
2703 __format::_ChronoData<_CharT> __cd{};
2704 __cd._M_fill_year_month(__t, __defSpec._M_needed);
2705 return _M_f._M_format(__cd, __fc);
2709 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2711 using __format::_ChronoFormats;
2712 using enum __format::_ChronoParts;
2714 __format::_ChronoSpec<_CharT> __res{};
2715 __res._M_debug =
true;
2716 __res._M_localized =
true;
2717 __res._M_locale_specific =
true;
2718 __res._M_needed = _Year|_Month;
2719 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ym();
2723 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2726#if __glibcxx_print >= 202406L
2728 inline constexpr bool
2729 enable_nonlocking_formatter_optimization<chrono::year_month> =
true;
2732 template<__format::__
char _CharT>
2733 struct formatter<
chrono::year_month_day, _CharT>
2735 constexpr typename basic_format_parse_context<_CharT>::iterator
2736 parse(basic_format_parse_context<_CharT>& __pc)
2738 using enum __format::_ChronoParts;
2739 return _M_f._M_parse(__pc, _Date, __defSpec);
2742 template<
typename _Out>
2743 typename basic_format_context<_Out, _CharT>::iterator
2744 format(
const chrono::year_month_day& __t,
2745 basic_format_context<_Out, _CharT>& __fc)
const
2747 __format::_ChronoData<_CharT> __cd{};
2748 auto __parts = _M_f._M_spec._M_needed;
2749 __parts = __cd._M_fill_year_month(__t, __parts);
2750 __parts = __cd._M_fill_day(__t.day(), __parts);
2752 return _M_f._M_format(__cd, __fc);
2754 __cd._M_fill_ldays(chrono::local_days(__t), __parts);
2755 return _M_f._M_format(__cd, __fc);
2759 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2761 using __format::_ChronoFormats;
2762 using enum __format::_ChronoParts;
2764 __format::_ChronoSpec<_CharT> __res{};
2765 __res._M_debug =
true;
2766 __res._M_needed = _YearMonthDay;
2767 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_f();
2771 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2774#if __glibcxx_print >= 202406L
2776 inline constexpr bool
2777 enable_nonlocking_formatter_optimization<chrono::year_month_day> =
true;
2780 template<__format::__
char _CharT>
2781 struct formatter<
chrono::year_month_day_last, _CharT>
2783 constexpr typename basic_format_parse_context<_CharT>::iterator
2784 parse(basic_format_parse_context<_CharT>& __pc)
2786 using enum __format::_ChronoParts;
2787 return _M_f._M_parse(__pc, _Date, __defSpec);
2790 template<
typename _Out>
2791 typename basic_format_context<_Out, _CharT>::iterator
2792 format(
const chrono::year_month_day_last& __t,
2793 basic_format_context<_Out, _CharT>& __fc)
const
2795 using enum __format::_ChronoParts;
2797 __format::_ChronoData<_CharT> __cd{};
2798 auto __parts = _M_f._M_spec._M_needed;
2799 __parts = __cd._M_fill_year_month(__t, __parts);
2800 if (_M_f._M_spec._M_needs(_Day|_WeekdayIndex))
2801 __parts = __cd._M_fill_day(__t.day(), __parts);
2803 return _M_f._M_format(__cd, __fc);
2805 __cd._M_fill_ldays(chrono::local_days(__t), __parts);
2806 return _M_f._M_format(__cd, __fc);
2810 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2812 using __format::_ChronoFormats;
2813 using enum __format::_ChronoParts;
2815 __format::_ChronoSpec<_CharT> __res{};
2816 __res._M_debug =
true;
2817 __res._M_localized =
true;
2818 __res._M_locale_specific =
true;
2819 __res._M_needed = _Year|_Month;
2820 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_yml();
2824 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2827#if __glibcxx_print >= 202406L
2829 inline constexpr bool
2830 enable_nonlocking_formatter_optimization<chrono::year_month_day_last> =
true;
2833 template<__format::__
char _CharT>
2834 struct formatter<
chrono::year_month_weekday, _CharT>
2836 constexpr typename basic_format_parse_context<_CharT>::iterator
2837 parse(basic_format_parse_context<_CharT>& __pc)
2839 using enum __format::_ChronoParts;
2840 return _M_f._M_parse(__pc, _Date, __defSpec);
2843 template<
typename _Out>
2844 typename basic_format_context<_Out, _CharT>::iterator
2845 format(
const chrono::year_month_weekday& __t,
2846 basic_format_context<_Out, _CharT>& __fc)
const
2848 __format::_ChronoData<_CharT> __cd{};
2849 auto __parts = _M_f._M_spec._M_needed;
2850 __parts = __cd._M_fill_year_month(__t, __parts);
2851 __parts = __cd._M_fill_weekday(__t.weekday_indexed(), __parts);
2852 if (__t.index() == 0) [[unlikely]]
2855 __parts -= __format::_ChronoParts::_Day;
2857 return _M_f._M_format(__cd, __fc);
2859 chrono::local_days __ld(__t);
2860 __parts = __cd._M_fill_ldays(__ld, __parts);
2862 return _M_f._M_format(__cd, __fc);
2864 auto __dom = __ld - chrono::local_days(__t.year()/__t.month()/0);
2866 __cd._M_day = chrono::day(__dom.count());
2867 return _M_f._M_format(__cd, __fc);
2871 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2873 using __format::_ChronoFormats;
2874 using enum __format::_ChronoParts;
2876 __format::_ChronoSpec<_CharT> __res{};
2877 __res._M_debug =
true;
2878 __res._M_localized =
true;
2879 __res._M_locale_specific =
true;
2880 __res._M_needed = _Year|_Month|_IndexedWeekday;
2881 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ymwi();
2885 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2888#if __glibcxx_print >= 202406L
2890 inline constexpr bool
2891 enable_nonlocking_formatter_optimization<chrono::year_month_weekday> =
true;
2894 template<__format::__
char _CharT>
2895 struct formatter<
chrono::year_month_weekday_last, _CharT>
2897 constexpr typename basic_format_parse_context<_CharT>::iterator
2898 parse(basic_format_parse_context<_CharT>& __pc)
2900 using enum __format::_ChronoParts;
2901 return _M_f._M_parse(__pc, _Date, __defSpec);
2904 template<
typename _Out>
2905 typename basic_format_context<_Out, _CharT>::iterator
2906 format(
const chrono::year_month_weekday_last& __t,
2907 basic_format_context<_Out, _CharT>& __fc)
const
2909 __format::_ChronoData<_CharT> __cd{};
2910 auto __parts = _M_f._M_spec._M_needed;
2911 __parts = __cd._M_fill_year_month(__t, __parts);
2912 __cd._M_weekday = __t.weekday_last().weekday();
2913 __parts -= __format::_ChronoParts::_Weekday;
2915 return _M_f._M_format(__cd, __fc);
2917 chrono::local_days __ld(__t);
2918 __parts = __cd._M_fill_ldays(__ld, __parts);
2920 return _M_f._M_format(__cd, __fc);
2922 auto __dom = __ld - chrono::local_days(__t.year()/__t.month()/0);
2923 __cd._M_fill_day(chrono::day(__dom.count()), __parts);
2924 return _M_f._M_format(__cd, __fc);
2928 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2930 using __format::_ChronoFormats;
2931 using enum __format::_ChronoParts;
2933 __format::_ChronoSpec<_CharT> __res{};
2934 __res._M_debug =
true;
2935 __res._M_localized =
true;
2936 __res._M_locale_specific =
true;
2937 __res._M_needed = _Year|_Month|_Weekday;
2938 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ymwl();
2942 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2945#if __glibcxx_print >= 202406L
2947 inline constexpr bool
2948 enable_nonlocking_formatter_optimization<chrono::year_month_weekday_last> =
true;
2951 template<
typename _Rep,
typename _Period, __format::__
char _CharT>
2952 struct formatter<
chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>, _CharT>
2954 constexpr typename basic_format_parse_context<_CharT>::iterator
2955 parse(basic_format_parse_context<_CharT>& __pc)
2957 using enum __format::_ChronoParts;
2958 return _M_f.template _M_parse<_Precision>(__pc, _Time, __defSpec);
2961 template<
typename _Out>
2962 typename basic_format_context<_Out, _CharT>::iterator
2963 format(
const chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>& __t,
2964 basic_format_context<_Out, _CharT>& __fc)
const
2966 using enum __format::_ChronoParts;
2968 __format::_ChronoData<_CharT> __cd;
2969 __cd._M_is_neg = __t.is_negative();
2970 __cd._M_hours = __t.hours();
2971 __cd._M_minutes = __t.minutes();
2972 __cd._M_seconds = __t.seconds();
2977 if (_M_f._M_spec._M_needs(_EpochUnits))
2978 __d = __t.to_duration();
2979 if (_M_f._M_spec._M_needs(_TotalSeconds))
2981 = __cd._M_hours + __cd._M_minutes + __cd._M_seconds;
2982 return _M_f._M_format_units(__cd, __d, __t.subseconds(), __fc);
2987 =
typename chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>::precision;
2988 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
2989 __format::__formatter_duration<_CharT>::
2990 template _S_spec_for<_Precision>(__format::_ChronoParts::_Time);
2992 __format::__formatter_duration<_CharT> _M_f{__defSpec};
2995#if __glibcxx_print >= 202406L
2998 template<
typename _Duration>
3000 enable_nonlocking_formatter_optimization<chrono::hh_mm_ss<_Duration>>
3001 = enable_nonlocking_formatter_optimization<_Duration>;
3004#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
3005 template<__format::__
char _CharT>
3006 struct formatter<
chrono::sys_info, _CharT>
3008 constexpr typename basic_format_parse_context<_CharT>::iterator
3009 parse(basic_format_parse_context<_CharT>& __pc)
3010 {
return _M_f.parse(__pc); }
3012 template<
typename _Out>
3013 typename basic_format_context<_Out, _CharT>::iterator
3014 format(
const chrono::sys_info& __i,
3015 basic_format_context<_Out, _CharT>& __fc)
const
3016 {
return _M_f.format(__i, __fc); }
3019 __format::__formatter_chrono_info<_CharT> _M_f;
3022#if __glibcxx_print >= 202406L
3024 inline constexpr bool
3025 enable_nonlocking_formatter_optimization<chrono::sys_info> =
true;
3028 template<__format::__
char _CharT>
3029 struct formatter<
chrono::local_info, _CharT>
3031 constexpr typename basic_format_parse_context<_CharT>::iterator
3032 parse(basic_format_parse_context<_CharT>& __pc)
3033 {
return _M_f.parse(__pc); }
3035 template<
typename _Out>
3036 typename basic_format_context<_Out, _CharT>::iterator
3037 format(
const chrono::local_info& __i,
3038 basic_format_context<_Out, _CharT>& __fc)
const
3039 {
return _M_f.format(__i, __fc); }
3042 __format::__formatter_chrono_info<_CharT> _M_f;
3045#if __glibcxx_print >= 202406L
3047 inline constexpr bool
3048 enable_nonlocking_formatter_optimization<chrono::local_info> =
true;
3052 template<
typename _Duration, __format::__
char _CharT>
3053 struct formatter<
chrono::sys_time<_Duration>, _CharT>
3055 constexpr typename basic_format_parse_context<_CharT>::iterator
3056 parse(basic_format_parse_context<_CharT>& __pc)
3058 using enum __format::_ChronoParts;
3060 = _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3061 if constexpr (__defSpec._M_chrono_specs.empty())
3062 if (_M_f._M_spec._M_chrono_specs.empty())
3063 __format::__invalid_chrono_spec();
3067 template<
typename _Out>
3068 typename basic_format_context<_Out, _CharT>::iterator
3069 format(
const chrono::sys_time<_Duration>& __t,
3070 basic_format_context<_Out, _CharT>& __fc)
const
3072 __format::_ChronoData<_CharT> __cd{};
3073 __cd._M_fill_utc_zone();
3075 _Duration __ed = __t.time_since_epoch();
3076 __cd._M_eseconds = chrono::floor<chrono::seconds>(__ed);
3077 __cd._M_lseconds = chrono::local_seconds(__cd._M_eseconds);
3078 return _M_f._M_format_time_point(__cd, __ed, __fc);
3082 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3083 __format::__formatter_duration<_CharT>::template _S_spec_for_tp<_Duration>();
3085 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3088#if __glibcxx_print >= 202406L
3091 template<
typename _Duration>
3093 enable_nonlocking_formatter_optimization<chrono::sys_time<_Duration>>
3094 = enable_nonlocking_formatter_optimization<_Duration>;
3097 template<
typename _Duration, __format::__
char _CharT>
3098 struct formatter<
chrono::utc_time<_Duration>, _CharT>
3100 constexpr typename basic_format_parse_context<_CharT>::iterator
3101 parse(basic_format_parse_context<_CharT>& __pc)
3103 using enum __format::_ChronoParts;
3104 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3107 template<
typename _Out>
3108 typename basic_format_context<_Out, _CharT>::iterator
3109 format(
const chrono::utc_time<_Duration>& __t,
3110 basic_format_context<_Out, _CharT>& __fc)
const
3112 using __format::_ChronoParts;
3113 using namespace chrono;
3114 __format::_ChronoData<_CharT> __cd{};
3115 __cd._M_fill_utc_zone();
3117 _Duration __ed = __t.time_since_epoch();
3118 __cd._M_eseconds = chrono::floor<seconds>(__ed);
3122 const auto __li = chrono::get_leap_second_info(__t);
3123 __cd._M_lseconds = local_seconds(__cd._M_eseconds - __li.elapsed);
3124 auto __parts = _M_f._M_spec._M_needed - _ChronoParts::_TotalSeconds;
3125 if ((__parts & _ChronoParts::_DateTime) != 0)
3127 __cd._M_fill_date_time(__cd._M_lseconds, __parts);
3128 __cd._M_seconds +=
seconds(__li.is_leap_second);
3130 return _M_f._M_format_units(__cd, __ed, __ed - __cd._M_eseconds, __fc);
3134 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3135 __format::__formatter_duration<_CharT>::
3136 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3138 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3141#if __glibcxx_print >= 202406L
3144 template<
typename _Duration>
3146 enable_nonlocking_formatter_optimization<chrono::utc_time<_Duration>>
3147 = enable_nonlocking_formatter_optimization<_Duration>;
3150 template<
typename _Duration, __format::__
char _CharT>
3151 struct formatter<
chrono::tai_time<_Duration>, _CharT>
3153 constexpr typename basic_format_parse_context<_CharT>::iterator
3154 parse(basic_format_parse_context<_CharT>& __pc)
3156 using enum __format::_ChronoParts;
3157 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3160 template<
typename _Out>
3161 typename basic_format_context<_Out, _CharT>::iterator
3162 format(
const chrono::tai_time<_Duration>& __t,
3163 basic_format_context<_Out, _CharT>& __fc)
const
3165 using namespace chrono;
3166 __format::_ChronoData<_CharT> __cd{};
3167 __cd._M_fill_zone(
"TAI", L
"TAI");
3169 _Duration __ed = __t.time_since_epoch();
3170 __cd._M_eseconds = chrono::floor<seconds>(__ed);
3172 constexpr chrono::days __tai_offset = chrono::days(4383);
3173 __cd._M_lseconds = local_seconds(__cd._M_eseconds - __tai_offset);
3174 return _M_f._M_format_time_point(__cd, __ed, __fc);
3178 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3179 __format::__formatter_duration<_CharT>::
3180 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3182 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3185#if __glibcxx_print >= 202406L
3188 template<
typename _Duration>
3190 enable_nonlocking_formatter_optimization<chrono::tai_time<_Duration>>
3191 = enable_nonlocking_formatter_optimization<_Duration>;
3194 template<
typename _Duration, __format::__
char _CharT>
3195 struct formatter<
chrono::gps_time<_Duration>, _CharT>
3197 constexpr typename basic_format_parse_context<_CharT>::iterator
3198 parse(basic_format_parse_context<_CharT>& __pc)
3200 using enum __format::_ChronoParts;
3201 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3204 template<
typename _Out>
3205 typename basic_format_context<_Out, _CharT>::iterator
3206 format(
const chrono::gps_time<_Duration>& __t,
3207 basic_format_context<_Out, _CharT>& __fc)
const
3209 using namespace chrono;
3210 __format::_ChronoData<_CharT> __cd{};
3211 __cd._M_fill_zone(
"GPS", L
"GPS");
3213 _Duration __ed = __t.time_since_epoch();
3214 __cd._M_eseconds = chrono::floor<seconds>(__ed);
3216 constexpr chrono::days __gps_offset = chrono::days(3657);
3217 __cd._M_lseconds = local_seconds(__cd._M_eseconds + __gps_offset);
3218 return _M_f._M_format_time_point(__cd, __ed, __fc);
3222 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3223 __format::__formatter_duration<_CharT>::
3224 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3226 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3229#if __glibcxx_print >= 202406L
3232 template<
typename _Duration>
3234 enable_nonlocking_formatter_optimization<chrono::gps_time<_Duration>>
3235 = enable_nonlocking_formatter_optimization<_Duration>;
3238 template<
typename _Duration, __format::__
char _CharT>
3239 struct formatter<
chrono::file_time<_Duration>, _CharT>
3241 constexpr typename basic_format_parse_context<_CharT>::iterator
3242 parse(basic_format_parse_context<_CharT>& __pc)
3244 using enum __format::_ChronoParts;
3245 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3248 template<
typename _Out>
3249 typename basic_format_context<_Out, _CharT>::iterator
3250 format(
const chrono::file_time<_Duration>& __t,
3251 basic_format_context<_Out, _CharT>& __fc)
const
3253 using namespace chrono;
3254 __format::_ChronoData<_CharT> __cd{};
3255 __cd._M_fill_utc_zone();
3257 _Duration __ed = __t.time_since_epoch();
3258 __cd._M_eseconds = chrono::floor<seconds>(__ed);
3259 auto __st = chrono::clock_cast<system_clock>(__t);
3261 = local_seconds(chrono::floor<seconds>(__st.time_since_epoch()));
3262 return _M_f._M_format_time_point(__cd, __ed, __fc);
3266 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3267 __format::__formatter_duration<_CharT>::
3268 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3270 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3273#if __glibcxx_print >= 202406L
3276 template<
typename _Duration>
3278 enable_nonlocking_formatter_optimization<chrono::file_time<_Duration>>
3279 = enable_nonlocking_formatter_optimization<_Duration>;
3282 template<
typename _Duration, __format::__
char _CharT>
3283 struct formatter<
chrono::local_time<_Duration>, _CharT>
3285 constexpr typename basic_format_parse_context<_CharT>::iterator
3286 parse(basic_format_parse_context<_CharT>& __pc)
3288 using enum __format::_ChronoParts;
3290 = _M_f.template _M_parse<_Duration>(__pc, _DateTime, __defSpec);
3291 if constexpr (__defSpec._M_chrono_specs.empty())
3292 if (_M_f._M_spec._M_chrono_specs.empty())
3293 __format::__invalid_chrono_spec();
3297 template<
typename _Out>
3298 typename basic_format_context<_Out, _CharT>::iterator
3299 format(
const chrono::local_time<_Duration>& __lt,
3300 basic_format_context<_Out, _CharT>& __fc)
const
3302 __format::_ChronoData<_CharT> __cd{};
3303 _Duration __ed = __lt.time_since_epoch();
3304 __cd._M_lseconds = chrono::floor<chrono::seconds>(__lt);
3305 __cd._M_eseconds = __cd._M_lseconds.time_since_epoch();
3306 return _M_f._M_format_time_point(__cd, __ed, __fc);
3310 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3311 __format::__formatter_duration<_CharT>::template _S_spec_for_tp<_Duration>();
3313 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3316#if __glibcxx_print >= 202406L
3319 template<
typename _Duration>
3321 enable_nonlocking_formatter_optimization<chrono::local_time<_Duration>>
3322 = enable_nonlocking_formatter_optimization<_Duration>;
3325 template<
typename _Duration, __format::__
char _CharT>
3326 struct formatter<
chrono::__detail::__local_time_fmt<_Duration>, _CharT>
3328 constexpr typename basic_format_parse_context<_CharT>::iterator
3329 parse(basic_format_parse_context<_CharT>& __pc)
3331 using enum __format::_ChronoParts;
3332 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3335 template<
typename _Out>
3336 typename basic_format_context<_Out, _CharT>::iterator
3337 format(
const chrono::__detail::__local_time_fmt<_Duration>& __zt,
3338 basic_format_context<_Out, _CharT>& __fc)
const
3340 using enum __format::_ChronoParts;
3341 __format::_ChronoData<_CharT> __cd{};
3343 if (_M_f._M_spec._M_needs(_ZoneOffset))
3345 if (!__zt._M_offset_sec)
3346 std::__throw_format_error(
"format error: no timezone available for %z");
3347 __cd._M_zone_offset = *__zt._M_offset_sec;
3350 basic_string<_CharT> __zone_store;
3351 if (_M_f._M_spec._M_needs(_ZoneAbbrev))
3353 if (!__zt._M_abbrev)
3354 std::__throw_format_error(
"format error: no timezone available for %Z");
3356 __cd._M_zone_cstr = __zt._M_abbrev->data();
3357 if constexpr (is_same_v<_CharT, char>)
3358 __cd._M_zone_abbrev = *__zt._M_abbrev;
3362 __zone_store.resize(__zt._M_abbrev->size());
3363 auto& __ct = use_facet<ctype<_CharT>>(_M_f._M_locale(__fc));
3364 __ct.widen(__zt._M_abbrev->data(),
3365 __zt._M_abbrev->data() + __zt._M_abbrev->size(),
3366 __zone_store.data());
3367 __cd._M_zone_abbrev = __zone_store;
3371 _Duration __ed = __zt._M_time.time_since_epoch();
3372 __cd._M_lseconds = chrono::floor<chrono::seconds>(__zt._M_time);
3373 __cd._M_eseconds = __cd._M_lseconds.time_since_epoch();
3374 return _M_f._M_format_time_point(__cd, __ed, __fc);
3378 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3379 __format::__formatter_duration<_CharT>::
3380 template _S_spec_for<_Duration>(__format::_ChronoParts::_ZonedDateTime);
3382 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3385#if __glibcxx_print >= 202406L
3388 template<
typename _Duration>
3390 enable_nonlocking_formatter_optimization<
3391 chrono::__detail::__local_time_fmt<_Duration>>
3392 = enable_nonlocking_formatter_optimization<_Duration>;
3395#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
3396 template<
typename _Duration,
typename _TimeZonePtr, __format::__
char _CharT>
3397 struct formatter<
chrono::zoned_time<_Duration, _TimeZonePtr>, _CharT>
3398 : formatter<chrono::__detail::__local_time_fmt_for<_Duration>, _CharT>
3400 template<
typename _Out>
3401 typename basic_format_context<_Out, _CharT>::iterator
3402 format(
const chrono::zoned_time<_Duration, _TimeZonePtr>& __tp,
3403 basic_format_context<_Out, _CharT>& __fc)
const
3405 using _Ltf = chrono::__detail::__local_time_fmt_for<_Duration>;
3406 using _Base = formatter<_Ltf, _CharT>;
3407 const chrono::sys_info __info = __tp.get_info();
3408 const auto __lf = chrono::local_time_format(__tp.get_local_time(),
3411 return _Base::format(__lf, __fc);
3415#if __glibcxx_print >= 202406L
3418 template<
typename _Duration>
3420 enable_nonlocking_formatter_optimization<
3421 chrono::zoned_time<_Duration, const chrono::time_zone*>>
3422 = enable_nonlocking_formatter_optimization<_Duration>;
3434 template<
typename _Duration = seconds>
3437 static_assert(is_same_v<common_type_t<_Duration, seconds>, _Duration>);
3440 _Parser(__format::_ChronoParts __need) : _M_need(__need) { }
3442 _Parser(_Parser&&) =
delete;
3443 void operator=(_Parser&&) =
delete;
3445 _Duration _M_time{};
3446 sys_days _M_sys_days{};
3447 year_month_day _M_ymd{};
3449 __format::_ChronoParts _M_need;
3450 unsigned _M_is_leap_second : 1 {};
3451 unsigned _M_reserved : 15 {};
3453 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3454 basic_istream<_CharT, _Traits>&
3455 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3456 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3457 minutes* __offset =
nullptr);
3462 template<
typename _CharT,
typename _Traits>
3463 static int_least32_t
3464 _S_read_unsigned(basic_istream<_CharT, _Traits>& __is,
3465 ios_base::iostate& __err,
int __n)
3467 int_least32_t __val = _S_try_read_digit(__is, __err);
3468 if (__val == -1) [[unlikely]]
3469 __err |= ios_base::failbit;
3474 for (
int __i = 1; __i < __n1; ++__i)
3475 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
3481 while (__n1++ < __n) [[unlikely]]
3482 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
3484 if (__builtin_mul_overflow(__val, 10, &__val)
3485 || __builtin_add_overflow(__val, __dig, &__val))
3487 __err |= ios_base::failbit;
3497 template<
typename _CharT,
typename _Traits>
3498 static int_least32_t
3499 _S_read_signed(basic_istream<_CharT, _Traits>& __is,
3500 ios_base::iostate& __err,
int __n)
3502 auto __sign = __is.peek();
3503 if (__sign ==
'-' || __sign ==
'+')
3505 int_least32_t __val = _S_read_unsigned(__is, __err, __n);
3506 if (__err & ios_base::failbit)
3508 if (__sign ==
'-') [[unlikely]]
3516 template<
typename _CharT,
typename _Traits>
3517 static int_least32_t
3518 _S_try_read_digit(basic_istream<_CharT, _Traits>& __is,
3519 ios_base::iostate& __err)
3521 int_least32_t __val = -1;
3522 auto __i = __is.peek();
3523 if (!_Traits::eq_int_type(__i, _Traits::eof())) [[likely]]
3525 _CharT __c = _Traits::to_char_type(__i);
3526 if (_CharT(
'0') <= __c && __c <= _CharT(
'9')) [[likely]]
3529 __val = __c - _CharT(
'0');
3533 __err |= ios_base::eofbit;
3539 template<
typename _CharT,
typename _Traits>
3541 _S_read_chr(basic_istream<_CharT, _Traits>& __is,
3542 ios_base::iostate& __err, _CharT __c)
3544 auto __i = __is.peek();
3545 if (_Traits::eq_int_type(__i, _Traits::eof()))
3546 __err |= ios_base::eofbit;
3547 else if (_Traits::to_char_type(__i) == __c) [[likely]]
3552 __err |= ios_base::failbit;
3557 template<
typename _Duration>
3558 using _Parser_t = _Parser<common_type_t<_Duration, seconds>>;
3560 template<
typename _Duration>
3564 if constexpr (_Duration::period::den == 1)
3566 switch (_Duration::period::num)
3568 case minutes::period::num:
3569 case hours::period::num:
3570 case days::period::num:
3571 case weeks::period::num:
3572 case years::period::num:
3589 template<
typename _ToDur,
typename _Tp>
3591 __round(
const _Tp& __t)
3593 if constexpr (__is_duration_v<_Tp>)
3595 if constexpr (treat_as_floating_point_v<typename _Tp::rep>)
3597 else if constexpr (__detail::__use_floor<_ToDur>())
3604 static_assert(__is_time_point_v<_Tp>);
3605 using _Tpt = time_point<typename _Tp::clock, _ToDur>;
3606 return _Tpt(__detail::__round<_ToDur>(__t.time_since_epoch()));
3613 template<
typename _CharT,
typename _Traits,
typename _Rep,
typename _Period,
3614 typename _Alloc = allocator<_CharT>>
3615 inline basic_istream<_CharT, _Traits>&
3616 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3618 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3621 auto __need = __format::_ChronoParts::_TimeOfDay;
3622 __detail::_Parser_t<duration<_Rep, _Period>> __p(__need);
3623 if (__p(__is, __fmt, __abbrev, __offset))
3624 __d = __detail::__round<duration<_Rep, _Period>>(__p._M_time);
3628 template<
typename _CharT,
typename _Traits>
3629 inline basic_ostream<_CharT, _Traits>&
3630 operator<<(basic_ostream<_CharT, _Traits>& __os,
const day& __d)
3632 using _Ctx = __format::__format_context<_CharT>;
3633 using _Str = basic_string_view<_CharT>;
3634 _Str __s = _GLIBCXX_WIDEN(
"{:02d} is not a valid day");
3636 __s = __s.substr(0, 6);
3637 auto __u = (unsigned)__d;
3638 __os << std::vformat(__s, make_format_args<_Ctx>(__u));
3642 template<
typename _CharT,
typename _Traits,
3643 typename _Alloc = allocator<_CharT>>
3644 inline basic_istream<_CharT, _Traits>&
3645 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3647 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3650 __detail::_Parser<> __p(__format::_ChronoParts::_Day);
3651 if (__p(__is, __fmt, __abbrev, __offset))
3652 __d = __p._M_ymd.day();
3656 template<
typename _CharT,
typename _Traits>
3657 inline basic_ostream<_CharT, _Traits>&
3658 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month& __m)
3660 using _Ctx = __format::__format_context<_CharT>;
3661 using _Str = basic_string_view<_CharT>;
3662 _Str __s = _GLIBCXX_WIDEN(
"{:L%b}{} is not a valid month");
3664 __os << std::vformat(__os.getloc(), __s.substr(0, 6),
3665 make_format_args<_Ctx>(__m));
3668 auto __u = (unsigned)__m;
3669 __os << std::vformat(__s.substr(6), make_format_args<_Ctx>(__u));
3674 template<
typename _CharT,
typename _Traits,
3675 typename _Alloc = allocator<_CharT>>
3676 inline basic_istream<_CharT, _Traits>&
3677 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3679 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3682 __detail::_Parser<> __p(__format::_ChronoParts::_Month);
3683 if (__p(__is, __fmt, __abbrev, __offset))
3684 __m = __p._M_ymd.month();
3688 template<
typename _CharT,
typename _Traits>
3689 inline basic_ostream<_CharT, _Traits>&
3690 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year& __y)
3692 using _Ctx = __format::__format_context<_CharT>;
3693 using _Str = basic_string_view<_CharT>;
3694 _Str __s = _GLIBCXX_WIDEN(
"-{:04d} is not a valid year");
3696 __s = __s.substr(0, 7);
3698 if (__i >= 0) [[likely]]
3699 __s.remove_prefix(1);
3702 __os << std::vformat(__s, make_format_args<_Ctx>(__i));
3706 template<
typename _CharT,
typename _Traits,
3707 typename _Alloc = allocator<_CharT>>
3708 inline basic_istream<_CharT, _Traits>&
3709 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3711 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3714 __detail::_Parser<> __p(__format::_ChronoParts::_Year);
3715 if (__p(__is, __fmt, __abbrev, __offset))
3716 __y = __p._M_ymd.year();
3720 template<
typename _CharT,
typename _Traits>
3721 inline basic_ostream<_CharT, _Traits>&
3722 operator<<(basic_ostream<_CharT, _Traits>& __os,
const weekday& __wd)
3724 using _Ctx = __format::__format_context<_CharT>;
3725 using _Str = basic_string_view<_CharT>;
3726 _Str __s = _GLIBCXX_WIDEN(
"{:L%a}{} is not a valid weekday");
3728 __os << std::vformat(__os.getloc(), __s.substr(0, 6),
3729 make_format_args<_Ctx>(__wd));
3732 auto __c = __wd.c_encoding();
3733 __os << std::vformat(__s.substr(6), make_format_args<_Ctx>(__c));
3738 template<
typename _CharT,
typename _Traits,
3739 typename _Alloc = allocator<_CharT>>
3740 inline basic_istream<_CharT, _Traits>&
3741 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3743 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3746 __detail::_Parser<> __p(__format::_ChronoParts::_Weekday);
3747 if (__p(__is, __fmt, __abbrev, __offset))
3752 template<
typename _CharT,
typename _Traits>
3753 inline basic_ostream<_CharT, _Traits>&
3754 operator<<(basic_ostream<_CharT, _Traits>& __os,
3755 const weekday_indexed& __wdi)
3760 basic_stringstream<_CharT> __os2;
3761 __os2.imbue(__os.getloc());
3762 __os2 << __wdi.weekday();
3763 const auto __i = __wdi.index();
3764 basic_string_view<_CharT> __s
3765 = _GLIBCXX_WIDEN(
"[ is not a valid index]");
3767 __os2 << std::format(_GLIBCXX_WIDEN(
"{}"), __i);
3768 if (__i >= 1 && __i <= 5)
3769 __os2 << __s.back();
3771 __os2 << __s.substr(1);
3772 __os << __os2.view();
3776 template<
typename _CharT,
typename _Traits>
3777 inline basic_ostream<_CharT, _Traits>&
3778 operator<<(basic_ostream<_CharT, _Traits>& __os,
3779 const weekday_last& __wdl)
3782 basic_stringstream<_CharT> __os2;
3783 __os2.imbue(__os.getloc());
3784 __os2 << __wdl.weekday() << _GLIBCXX_WIDEN(
"[last]");
3785 __os << __os2.view();
3789 template<
typename _CharT,
typename _Traits>
3790 inline basic_ostream<_CharT, _Traits>&
3791 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month_day& __md)
3794 basic_stringstream<_CharT> __os2;
3795 __os2.imbue(__os.getloc());
3796 __os2 << __md.month();
3797 if constexpr (is_same_v<_CharT, char>)
3801 __os2 << __md.day();
3802 __os << __os2.view();
3806 template<
typename _CharT,
typename _Traits,
3807 typename _Alloc = allocator<_CharT>>
3808 inline basic_istream<_CharT, _Traits>&
3809 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3811 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3814 using __format::_ChronoParts;
3815 auto __need = _ChronoParts::_Month | _ChronoParts::_Day;
3816 __detail::_Parser<> __p(__need);
3817 if (__p(__is, __fmt, __abbrev, __offset))
3818 __md = month_day(__p._M_ymd.month(), __p._M_ymd.day());
3822 template<
typename _CharT,
typename _Traits>
3823 inline basic_ostream<_CharT, _Traits>&
3824 operator<<(basic_ostream<_CharT, _Traits>& __os,
3825 const month_day_last& __mdl)
3828 basic_stringstream<_CharT> __os2;
3829 __os2.imbue(__os.getloc());
3830 __os2 << __mdl.month() << _GLIBCXX_WIDEN(
"/last");
3831 __os << __os2.view();
3835 template<
typename _CharT,
typename _Traits>
3836 inline basic_ostream<_CharT, _Traits>&
3837 operator<<(basic_ostream<_CharT, _Traits>& __os,
3838 const month_weekday& __mwd)
3841 basic_stringstream<_CharT> __os2;
3842 __os2.imbue(__os.getloc());
3843 __os2 << __mwd.month();
3844 if constexpr (is_same_v<_CharT, char>)
3848 __os2 << __mwd.weekday_indexed();
3849 __os << __os2.view();
3853 template<
typename _CharT,
typename _Traits>
3854 inline basic_ostream<_CharT, _Traits>&
3855 operator<<(basic_ostream<_CharT, _Traits>& __os,
3856 const month_weekday_last& __mwdl)
3859 basic_stringstream<_CharT> __os2;
3860 __os2.imbue(__os.getloc());
3861 __os2 << __mwdl.month();
3862 if constexpr (is_same_v<_CharT, char>)
3866 __os2 << __mwdl.weekday_last();
3867 __os << __os2.view();
3871 template<
typename _CharT,
typename _Traits>
3872 inline basic_ostream<_CharT, _Traits>&
3873 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year_month& __ym)
3876 basic_stringstream<_CharT> __os2;
3877 __os2.imbue(__os.getloc());
3878 __os2 << __ym.year();
3879 if constexpr (is_same_v<_CharT, char>)
3883 __os2 << __ym.month();
3884 __os << __os2.view();
3888 template<
typename _CharT,
typename _Traits,
3889 typename _Alloc = allocator<_CharT>>
3890 inline basic_istream<_CharT, _Traits>&
3891 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3893 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3896 using __format::_ChronoParts;
3897 auto __need = _ChronoParts::_Year | _ChronoParts::_Month;
3898 __detail::_Parser<> __p(__need);
3899 if (__p(__is, __fmt, __abbrev, __offset))
3900 __ym = year_month(__p._M_ymd.year(), __p._M_ymd.month());
3904 template<
typename _CharT,
typename _Traits>
3905 inline basic_ostream<_CharT, _Traits>&
3906 operator<<(basic_ostream<_CharT, _Traits>& __os,
3907 const year_month_day& __ymd)
3909 using _Ctx = __format::__format_context<_CharT>;
3910 using _Str = basic_string_view<_CharT>;
3911 _Str __s = _GLIBCXX_WIDEN(
"{:%F} is not a valid date");
3912 __os << std::vformat(__ymd.ok() ? __s.substr(0, 5) : __s,
3913 make_format_args<_Ctx>(__ymd));
3917 template<
typename _CharT,
typename _Traits,
3918 typename _Alloc = allocator<_CharT>>
3919 inline basic_istream<_CharT, _Traits>&
3921 year_month_day& __ymd,
3925 using __format::_ChronoParts;
3926 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3927 | _ChronoParts::_Day;
3928 __detail::_Parser<> __p(__need);
3929 if (__p(__is, __fmt, __abbrev, __offset))
3934 template<
typename _CharT,
typename _Traits>
3937 const year_month_day_last& __ymdl)
3942 __os2 << __ymdl.year();
3943 if constexpr (is_same_v<_CharT, char>)
3947 __os2 << __ymdl.month_day_last();
3948 __os << __os2.view();
3952 template<
typename _CharT,
typename _Traits>
3953 inline basic_ostream<_CharT, _Traits>&
3954 operator<<(basic_ostream<_CharT, _Traits>& __os,
3955 const year_month_weekday& __ymwd)
3959 basic_stringstream<_CharT> __os2;
3960 __os2.
imbue(__os.getloc());
3962 if constexpr (is_same_v<_CharT, char>)
3966 __os2 << __ymwd.year() << __slash << __ymwd.month() << __slash
3967 << __ymwd.weekday_indexed();
3968 __os << __os2.view();
3972 template<
typename _CharT,
typename _Traits>
3973 inline basic_ostream<_CharT, _Traits>&
3974 operator<<(basic_ostream<_CharT, _Traits>& __os,
3975 const year_month_weekday_last& __ymwdl)
3979 basic_stringstream<_CharT> __os2;
3980 __os2.imbue(__os.getloc());
3982 if constexpr (is_same_v<_CharT, char>)
3986 __os2 << __ymwdl.year() << __slash << __ymwdl.month() << __slash
3987 << __ymwdl.weekday_last();
3988 __os << __os2.view();
3992 template<
typename _CharT,
typename _Traits,
typename _Duration>
3993 inline basic_ostream<_CharT, _Traits>&
3994 operator<<(basic_ostream<_CharT, _Traits>& __os,
3997 return __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%T}"), __hms);
4000#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
4002 template<
typename _CharT,
typename _Traits>
4003 basic_ostream<_CharT, _Traits>&
4004 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_info& __i)
4006 return __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{}"), __i);
4010 template<
typename _CharT,
typename _Traits>
4011 basic_ostream<_CharT, _Traits>&
4012 operator<<(basic_ostream<_CharT, _Traits>& __os,
const local_info& __li)
4014 __os << __format::_Separators<_CharT>::_S_squares()[0];
4015 if (__li.result == local_info::unique)
4019 if (__li.result == local_info::nonexistent)
4020 __os << _GLIBCXX_WIDEN(
"nonexistent");
4022 __os << _GLIBCXX_WIDEN(
"ambiguous");
4023 __os << _GLIBCXX_WIDEN(
" local time between ") << __li.first;
4024 __os << _GLIBCXX_WIDEN(
" and ") << __li.second;
4026 __os << __format::_Separators<_CharT>::_S_squares()[1];
4030 template<
typename _CharT,
typename _Traits,
typename _Duration,
4031 typename _TimeZonePtr>
4032 inline basic_ostream<_CharT, _Traits>&
4033 operator<<(basic_ostream<_CharT, _Traits>& __os,
4034 const zoned_time<_Duration, _TimeZonePtr>& __t)
4036 __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T %Z}"), __t);
4041 template<
typename _CharT,
typename _Traits,
typename _Duration>
4042 requires (!treat_as_floating_point_v<typename _Duration::rep>)
4043 && ratio_less_v<typename _Duration::period, days::period>
4044 inline basic_ostream<_CharT, _Traits>&
4045 operator<<(basic_ostream<_CharT, _Traits>& __os,
4046 const sys_time<_Duration>& __tp)
4048 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __tp);
4052 template<
typename _CharT,
typename _Traits>
4053 inline basic_ostream<_CharT, _Traits>&
4054 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_days& __dp)
4056 __os << year_month_day{__dp};
4060 template<
typename _CharT,
typename _Traits,
typename _Duration,
4061 typename _Alloc = allocator<_CharT>>
4062 basic_istream<_CharT, _Traits>&
4063 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4064 sys_time<_Duration>& __tp,
4065 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4071 using __format::_ChronoParts;
4072 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
4073 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
4074 __detail::_Parser_t<_Duration> __p(__need);
4075 if (__p(__is, __fmt, __abbrev, __offset))
4077 if (__p._M_is_leap_second)
4081 auto __st = __p._M_sys_days + __p._M_time - *__offset;
4082 __tp = __detail::__round<_Duration>(__st);
4088 template<
typename _CharT,
typename _Traits,
typename _Duration>
4089 inline basic_ostream<_CharT, _Traits>&
4090 operator<<(basic_ostream<_CharT, _Traits>& __os,
4091 const utc_time<_Duration>& __t)
4093 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
4097 template<
typename _CharT,
typename _Traits,
typename _Duration,
4098 typename _Alloc = allocator<_CharT>>
4099 inline basic_istream<_CharT, _Traits>&
4100 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4101 utc_time<_Duration>& __tp,
4102 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4108 using __format::_ChronoParts;
4109 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
4110 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
4111 __detail::_Parser_t<_Duration> __p(__need);
4112 if (__p(__is, __fmt, __abbrev, __offset))
4116 auto __ut = utc_clock::from_sys(__p._M_sys_days) + __p._M_time
4118 __tp = __detail::__round<_Duration>(__ut);
4123 template<
typename _CharT,
typename _Traits,
typename _Duration>
4124 inline basic_ostream<_CharT, _Traits>&
4125 operator<<(basic_ostream<_CharT, _Traits>& __os,
4126 const tai_time<_Duration>& __t)
4128 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
4132 template<
typename _CharT,
typename _Traits,
typename _Duration,
4133 typename _Alloc = allocator<_CharT>>
4134 inline basic_istream<_CharT, _Traits>&
4135 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4136 tai_time<_Duration>& __tp,
4137 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4143 using __format::_ChronoParts;
4144 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
4145 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
4146 __detail::_Parser_t<_Duration> __p(__need);
4147 if (__p(__is, __fmt, __abbrev, __offset))
4149 if (__p._M_is_leap_second)
4153 constexpr sys_days __epoch(-
days(4383));
4154 auto __d = __p._M_sys_days - __epoch + __p._M_time - *__offset;
4155 tai_time<common_type_t<_Duration, seconds>> __tt(__d);
4156 __tp = __detail::__round<_Duration>(__tt);
4162 template<
typename _CharT,
typename _Traits,
typename _Duration>
4163 inline basic_ostream<_CharT, _Traits>&
4164 operator<<(basic_ostream<_CharT, _Traits>& __os,
4165 const gps_time<_Duration>& __t)
4167 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
4171 template<
typename _CharT,
typename _Traits,
typename _Duration,
4172 typename _Alloc = allocator<_CharT>>
4173 inline basic_istream<_CharT, _Traits>&
4174 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4175 gps_time<_Duration>& __tp,
4176 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4182 using __format::_ChronoParts;
4183 auto __need = _ChronoParts::_YearMonthDay | _ChronoParts::_TimeOfDay;
4184 __detail::_Parser_t<_Duration> __p(__need);
4185 if (__p(__is, __fmt, __abbrev, __offset))
4187 if (__p._M_is_leap_second)
4191 constexpr sys_days __epoch(
days(3657));
4192 auto __d = __p._M_sys_days - __epoch + __p._M_time - *__offset;
4193 gps_time<common_type_t<_Duration, seconds>> __gt(__d);
4194 __tp = __detail::__round<_Duration>(__gt);
4200 template<
typename _CharT,
typename _Traits,
typename _Duration>
4201 inline basic_ostream<_CharT, _Traits>&
4202 operator<<(basic_ostream<_CharT, _Traits>& __os,
4203 const file_time<_Duration>& __t)
4205 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
4209 template<
typename _CharT,
typename _Traits,
typename _Duration,
4210 typename _Alloc = allocator<_CharT>>
4211 inline basic_istream<_CharT, _Traits>&
4212 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4213 file_time<_Duration>& __tp,
4214 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4217 sys_time<_Duration> __st;
4218 if (chrono::from_stream(__is, __fmt, __st, __abbrev, __offset))
4219 __tp = __detail::__round<_Duration>(file_clock::from_sys(__st));
4223 template<
typename _CharT,
typename _Traits,
typename _Duration>
4224 inline basic_ostream<_CharT, _Traits>&
4225 operator<<(basic_ostream<_CharT, _Traits>& __os,
4226 const local_time<_Duration>& __lt)
4229 requires requires(
const sys_time<_Duration>& __st) { __os << __st; }
4231 __os << sys_time<_Duration>{__lt.time_since_epoch()};
4235 template<
typename _CharT,
typename _Traits,
typename _Duration,
4236 typename _Alloc = allocator<_CharT>>
4237 basic_istream<_CharT, _Traits>&
4238 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4239 local_time<_Duration>& __tp,
4240 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4243 using __format::_ChronoParts;
4244 auto __need = _ChronoParts::_YearMonthDay | _ChronoParts::_TimeOfDay;
4245 __detail::_Parser_t<_Duration> __p(__need);
4246 if (__p(__is, __fmt, __abbrev, __offset))
4248 days __d = __p._M_sys_days.time_since_epoch();
4249 auto __t = local_days(__d) + __p._M_time;
4250 __tp = __detail::__round<_Duration>(__t);
4261 void from_stream() =
delete;
4263 template<
typename _Parsable,
typename _CharT,
4264 typename _Traits = std::char_traits<_CharT>,
4265 typename... _OptArgs>
4266 concept __parsable =
requires (basic_istream<_CharT, _Traits>& __is,
4267 const _CharT* __fmt, _Parsable& __tp,
4268 _OptArgs*... __args)
4269 { from_stream(__is, __fmt, __tp, __args...); };
4271 template<
typename _Parsable,
typename _CharT,
4272 typename _Traits = char_traits<_CharT>,
4273 typename _Alloc = allocator<_CharT>>
4277 using __string_type = basic_string<_CharT, _Traits, _Alloc>;
4280 _Parse(
const _CharT* __fmt, _Parsable& __tp,
4281 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4284 _M_abbrev(__abbrev), _M_offset(__offset)
4287 _Parse(_Parse&&) =
delete;
4288 _Parse& operator=(_Parse&&) =
delete;
4291 using __stream_type = basic_istream<_CharT, _Traits>;
4293 const _CharT*
const _M_fmt;
4294 _Parsable*
const _M_tp;
4295 __string_type*
const _M_abbrev;
4298 friend __stream_type&
4299 operator>>(__stream_type& __is, _Parse&& __p)
4302 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev,
4304 else if (__p._M_abbrev)
4305 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev);
4307 from_stream(__is, __p._M_fmt, *__p._M_tp);
4311 friend void operator>>(__stream_type&, _Parse&) =
delete;
4312 friend void operator>>(__stream_type&,
const _Parse&) =
delete;
4316 template<
typename _CharT, __detail::__parsable<_CharT> _Parsable>
4317 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4319 parse(
const _CharT* __fmt, _Parsable& __tp)
4320 {
return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp); }
4322 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4323 __detail::__parsable<_CharT, _Traits> _Parsable>
4326 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp)
4328 return __detail::_Parse<_Parsable, _CharT, _Traits>(__fmt.c_str(), __tp);
4331 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4332 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4333 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
4334 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4336 parse(
const _CharT* __fmt, _Parsable& __tp,
4337 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
4340 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
4344 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4345 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4346 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
4349 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
4350 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
4353 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
4357 template<
typename _CharT,
typename _Traits =
char_traits<_CharT>,
4358 typename _StrT = basic_
string<_CharT, _Traits>,
4359 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4360 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4362 parse(
const _CharT* __fmt, _Parsable& __tp,
minutes& __offset)
4364 return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp,
nullptr,
4368 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4369 typename _StrT = basic_string<_CharT, _Traits>,
4370 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4373 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
4376 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
4381 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4382 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4383 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4384 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4386 parse(
const _CharT* __fmt, _Parsable& __tp,
4387 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
4390 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
4395 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4396 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4397 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4400 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
4401 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
4404 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
4410 template<
typename _Duration>
4411 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4412 basic_istream<_CharT, _Traits>&
4413 __detail::_Parser<_Duration>::
4414 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4415 basic_string<_CharT, _Traits, _Alloc>* __abbrev,
4418 using sentry =
typename basic_istream<_CharT, _Traits>::sentry;
4420 if (sentry __cerb(__is,
true); __cerb)
4422 locale __loc = __is.getloc();
4427 struct _Stream_state
4430 _Stream_state(basic_istream<_CharT, _Traits>& __i)
4432 _M_flags(__i.flags(ios_base::
skipws | ios_base::
dec)),
4438 _M_is.flags(_M_flags);
4442 _Stream_state(_Stream_state&&) =
delete;
4444 basic_istream<_CharT, _Traits>& _M_is;
4445 ios_base::fmtflags _M_flags;
4455 auto __read_unsigned = [&] (
int __n) {
4456 return _S_read_unsigned(__is, __err, __n);
4461 auto __read_signed = [&] (
int __n) {
4462 return _S_read_signed(__is, __err, __n);
4466 auto __read_chr = [&__is, &__err] (_CharT __c) {
4467 return _S_read_chr(__is, __err, __c);
4470 using __format::_ChronoParts;
4471 _ChronoParts __parts{};
4473 const year __bad_y = --year::min();
4474 const month __bad_mon(255);
4475 const day __bad_day(255);
4476 const weekday __bad_wday(255);
4477 const hours __bad_h(-1);
4478 const minutes __bad_min(-9999);
4481 year __y = __bad_y, __yy = __bad_y;
4482 year __iso_y = __bad_y, __iso_yy = __bad_y;
4483 month __m = __bad_mon;
4484 day __d = __bad_day;
4485 weekday __wday = __bad_wday;
4486 hours __h = __bad_h, __h12 = __bad_h;
4488 _Duration __s = __bad_sec;
4490 int __iso_wk = -1, __sunday_wk = -1, __monday_wk = -1;
4492 int __dayofyear = -1;
4494 minutes __tz_offset = __bad_min;
4495 basic_string<_CharT, _Traits> __tz_abbr;
4497 if ((_M_need & _ChronoParts::_TimeOfDay) != 0
4498 && (_M_need & _ChronoParts::_Year) != 0)
4504 __parts = _ChronoParts::_TimeOfDay;
4511 bool __is_flag =
false;
4513 constexpr bool __is_floating
4514 = treat_as_floating_point_v<typename _Duration::rep>;
4533 _CharT __c = *__fmt++;
4540 else if (!__read_chr(__c)) [[unlikely]]
4551 if (__mod || __num) [[unlikely]]
4556 __tmget.get(__is, {}, __is, __err, &__tm,
4558 if (!__is_failed(__err))
4559 __wday = weekday(__tm.tm_wday);
4561 __parts |= _ChronoParts::_Weekday;
4567 if (__mod || __num) [[unlikely]]
4575 __tmget.get(__is, {}, __is, __err, &__tm,
4577 if (!__is_failed(__err))
4578 __m = month(__tm.tm_mon + 1);
4580 __parts |= _ChronoParts::_Month;
4584 if (__mod ==
'O' || __num) [[unlikely]]
4589 __tmget.get(__is, {}, __is, __err, &__tm,
4590 __fmt - 2 - (__mod ==
'E'), __fmt);
4591 if (!__is_failed(__err))
4593 __y = year(__tm.tm_year + 1900);
4594 __m = month(__tm.tm_mon + 1);
4595 __d = day(__tm.tm_mday);
4596 __h =
hours(__tm.tm_hour);
4601 __parts |= _ChronoParts::_DateTime;
4605 if (!__mod) [[likely]]
4607 auto __v = __read_signed(__num ? __num : 2);
4608 if (!__is_failed(__err))
4610 int __cmin = (int)year::min() / 100;
4611 int __cmax = (int)year::max() / 100;
4612 if (__cmin <= __v && __v <= __cmax)
4613 __century = __v * 100;
4618 else if (__mod ==
'E')
4621 __tmget.get(__is, {}, __is, __err, &__tm,
4623 if (!__is_failed(__err))
4624 __century = __tm.tm_year;
4633 if (!__mod) [[likely]]
4635 auto __v = __read_unsigned(__num ? __num : 2);
4636 if (!__is_failed(__err))
4639 else if (__mod ==
'O')
4642 __tmget.get(__is, {}, __is, __err, &__tm,
4644 if (!__is_failed(__err))
4645 __d = day(__tm.tm_mday);
4649 __parts |= _ChronoParts::_Day;
4653 if (__mod || __num) [[unlikely]]
4657 auto __month = __read_unsigned(2);
4659 auto __day = __read_unsigned(2);
4661 auto __year = __read_unsigned(2);
4662 if (__is_failed(__err))
4664 __y = year(__year + 1900 + 100 *
int(__year < 69));
4665 __m = month(__month);
4667 if (!year_month_day(__y, __m, __d).ok())
4669 __y = __yy = __iso_y = __iso_yy = __bad_y;
4675 __parts |= _ChronoParts::_Date;
4679 if (__mod) [[unlikely]]
4683 auto __year = __read_signed(__num ? __num : 4);
4685 auto __month = __read_unsigned(2);
4687 auto __day = __read_unsigned(2);
4688 if (__is_failed(__err))
4691 __m = month(__month);
4693 if (!year_month_day(__y, __m, __d).ok())
4695 __y = __yy = __iso_y = __iso_yy = __bad_y;
4701 __parts |= _ChronoParts::_Date;
4705 if (__mod) [[unlikely]]
4709 auto __val = __read_unsigned(__num ? __num : 2);
4710 if (__val >= 0 && __val <= 99)
4712 __iso_yy = year(__val);
4713 if (__century == -1)
4717 __iso_yy = __iso_y = __y = __yy = __bad_y;
4719 __parts |= _ChronoParts::_Year;
4723 if (__mod) [[unlikely]]
4726 __iso_y = year(__read_unsigned(__num ? __num : 4));
4727 __parts |= _ChronoParts::_Year;
4732 if (__mod ==
'E') [[unlikely]]
4734 else if (__mod ==
'O')
4739 __tmget.get(__is, {}, __is, __err, &__tm,
4741 if (!__is_failed(__err))
4745 __h12 =
hours(__tm.tm_hour);
4749 __h =
hours(__tm.tm_hour);
4758 auto __val = __read_unsigned(__num ? __num : 2);
4759 if (__c ==
'I' && __val >= 1 && __val <= 12)
4761 __h12 =
hours(__val);
4764 else if (__c ==
'H' && __val >= 0 && __val <= 23)
4771 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4776 __parts |= _ChronoParts::_TimeOfDay;
4780 if (__mod) [[unlikely]]
4782 else if (_M_need == _ChronoParts::_TimeOfDay)
4784 auto __val = __read_signed(__num ? __num : 3);
4785 if (!__is_failed(__err))
4788 __parts |= _ChronoParts::_TimeOfDay;
4793 __dayofyear = __read_unsigned(__num ? __num : 3);
4800 if (__mod ==
'E') [[unlikely]]
4802 else if (__mod ==
'O')
4805 __tmget.get(__is, {}, __is, __err, &__tm,
4807 if (!__is_failed(__err))
4808 __m = month(__tm.tm_mon + 1);
4812 auto __val = __read_unsigned(__num ? __num : 2);
4813 if (__val >= 1 && __val <= 12)
4818 __parts |= _ChronoParts::_Month;
4822 if (__mod ==
'E') [[unlikely]]
4824 else if (__mod ==
'O')
4827 __tmget.get(__is, {}, __is, __err, &__tm,
4829 if (!__is_failed(__err))
4834 auto __val = __read_unsigned(__num ? __num : 2);
4835 if (0 <= __val && __val < 60)
4839 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4844 __parts |= _ChronoParts::_TimeOfDay;
4854 const _CharT* __ampms[2];
4855 __tmpunct._M_am_pm(__ampms);
4856 int __n = 0, __which = 3;
4857 while (__which != 0)
4859 auto __i = __is.peek();
4860 if (_Traits::eq_int_type(__i, _Traits::eof()))
4870 else if (__ampms[0][__n + 1] == _CharT())
4881 else if (__ampms[1][__n + 1] == _CharT())
4892 if (__which == 0 || __which == 3)
4905 __tmget.get(__is, {}, __is, __err, &__tm,
4907 if (!__is_failed(__err))
4909 __h =
hours(__tm.tm_hour);
4914 __parts |= _ChronoParts::_TimeOfDay;
4919 if (__mod || __num) [[unlikely]]
4926 auto __val = __read_unsigned(2);
4927 if (__val == -1 || __val > 23) [[unlikely]]
4929 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4933 if (!__read_chr(
':')) [[unlikely]]
4937 __val = __read_unsigned(2);
4938 if (__val == -1 || __val > 60) [[unlikely]]
4940 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4948 __parts |= _ChronoParts::_TimeOfDay;
4951 else if (!__read_chr(
':')) [[unlikely]]
4957 if (__mod ==
'E') [[unlikely]]
4959 else if (__mod ==
'O')
4962 __tmget.get(__is, {}, __is, __err, &__tm,
4964 if (!__is_failed(__err))
4967 else if constexpr (_Duration::period::den == 1
4970 auto __val = __read_unsigned(__num ? __num : 2);
4971 if (0 <= __val && __val <= 59) [[likely]]
4975 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4983 auto __digit = _S_try_read_digit(__is, __err);
4986 __buf.put(
'0' + __digit);
4987 __digit = _S_try_read_digit(__is, __err);
4989 __buf.put(
'0' + __digit);
4992 auto __i = __is.peek();
4993 if (_Traits::eq_int_type(__i, _Traits::eof()))
5001 __dp = __np.decimal_point();
5003 _CharT __c = _Traits::to_char_type(__i);
5009 = hh_mm_ss<_Duration>::fractional_width;
5012 __digit = _S_try_read_digit(__is, __err);
5014 __buf.put(
'0' + __digit);
5022 if (!__is_failed(__err)) [[likely]]
5024 long double __val{};
5025#if __cpp_lib_to_chars
5027 auto __first = __str.data();
5028 auto __last = __first + __str.size();
5032 if ((
bool)ec || ptr != __last) [[unlikely]]
5040 if constexpr (__is_floating)
5047 __parts |= _ChronoParts::_TimeOfDay;
5052 if (__mod ==
'E') [[unlikely]]
5054 else if (__mod ==
'O')
5059 __tmget.get(__is, {}, __is, __err, &__tm,
5061 if (!__is_failed(__err))
5062 __wday = weekday(__tm.tm_wday);
5069 const int __lo = __c ==
'u' ? 1 : 0;
5070 const int __hi = __lo + 6;
5071 auto __val = __read_unsigned(__num ? __num : 1);
5072 if (__lo <= __val && __val <= __hi)
5073 __wday = weekday(__val);
5076 __wday = __bad_wday;
5080 __parts |= _ChronoParts::_Weekday;
5086 if (__mod ==
'E') [[unlikely]]
5088 else if (__mod ==
'O')
5090 if (__c ==
'V') [[unlikely]]
5100 const int __lo = __c ==
'V' ? 1 : 0;
5101 const int __hi = 53;
5102 auto __val = __read_unsigned(__num ? __num : 2);
5103 if (__lo <= __val && __val <= __hi)
5108 __sunday_wk = __val;
5114 __monday_wk = __val;
5119 __iso_wk = __sunday_wk = __monday_wk = -1;
5125 if (__mod ==
'O' || __num) [[unlikely]]
5130 __tmget.get(__is, {}, __is, __err, &__tm,
5131 __fmt - 2 - (__mod ==
'E'), __fmt);
5132 if (!__is_failed(__err))
5134 __y = year(__tm.tm_year + 1900);
5135 __m = month(__tm.tm_mon + 1);
5136 __d = day(__tm.tm_mday);
5139 __parts |= _ChronoParts::_Date;
5143 if (__mod ==
'O' || __num) [[unlikely]]
5148 __tmget.get(__is, {}, __is, __err, &__tm,
5149 __fmt - 2 - (__mod ==
'E'), __fmt);
5150 if (!__is_failed(__err))
5152 __h =
hours(__tm.tm_hour);
5157 __parts |= _ChronoParts::_TimeOfDay;
5161 if (__mod) [[unlikely]]
5164 __tmget.get(__is, {}, __is, __err, &__tm,
5166 if (!__is_failed(__err))
5168 int __cent = __tm.tm_year < 2000 ? 1900 : 2000;
5169 __yy = year(__tm.tm_year - __cent);
5170 if (__century == -1)
5176 auto __val = __read_unsigned(__num ? __num : 2);
5177 if (__val >= 0 && __val <= 99)
5180 if (__century == -1)
5181 __century = __val < 69 ? 2000 : 1900;
5184 __y = __yy = __iso_yy = __iso_y = __bad_y;
5186 __parts |= _ChronoParts::_Year;
5190 if (__mod ==
'O') [[unlikely]]
5192 else if (__mod ==
'E')
5195 __tmget.get(__is, {}, __is, __err, &__tm,
5197 if (!__is_failed(__err))
5198 __y = year(__tm.tm_year);
5202 auto __val = __read_unsigned(__num ? __num : 4);
5203 if (!__is_failed(__err))
5206 __parts |= _ChronoParts::_Year;
5210 if (__num) [[unlikely]]
5217 auto __i = __is.peek();
5218 if (_Traits::eq_int_type(__i, _Traits::eof()))
5223 _CharT __ic = _Traits::to_char_type(__i);
5224 const bool __neg = __ic == _CharT(
'-');
5225 if (__ic == _CharT(
'-') || __ic == _CharT(
'+'))
5232 __hh = __read_unsigned(2);
5237 __hh = 10 * _S_try_read_digit(__is, __err);
5238 __hh += _S_try_read_digit(__is, __err);
5241 if (__is_failed(__err))
5245 if (_Traits::eq_int_type(__i, _Traits::eof()))
5248 __tz_offset =
minutes(__hh * (__neg ? -60 : 60));
5251 __ic = _Traits::to_char_type(__i);
5253 bool __read_mm =
false;
5256 if (__ic == _GLIBCXX_WIDEN(
":")[0])
5263 else if (_CharT(
'0') <= __ic && __ic <= _CharT(
'9'))
5269 int_least32_t __mm = 0;
5272 __mm = 10 * _S_try_read_digit(__is, __err);
5273 __mm += _S_try_read_digit(__is, __err);
5276 if (!__is_failed(__err))
5278 auto __z = __hh * 60 + __mm;
5279 __tz_offset =
minutes(__neg ? -__z : __z);
5285 if (__mod || __num) [[unlikely]]
5289 basic_string_view<_CharT> __x = _GLIBCXX_WIDEN(
"_/-+");
5293 auto __i = __is.peek();
5294 if (!_Traits::eq_int_type(__i, _Traits::eof()))
5296 _CharT __a = _Traits::to_char_type(__i);
5298 || __x.find(__a) != __x.npos)
5300 __tz_abbr.push_back(__a);
5309 if (__tz_abbr.empty())
5315 if (__mod || __num) [[unlikely]]
5319 _CharT __i = __is.peek();
5320 if (_Traits::eq_int_type(__i, _Traits::eof()))
5322 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
5330 if (__mod || __num) [[unlikely]]
5334 _CharT __i = __is.peek();
5335 if (_Traits::eq_int_type(__i, _Traits::eof()))
5337 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
5343 if (__mod || __num) [[unlikely]]
5351 if (__mod || __num) [[unlikely]]
5360 if (_CharT(
'1') <= __c && __c <= _CharT(
'9'))
5362 if (!__mod) [[likely]]
5365 auto __end = __fmt + _Traits::length(__fmt);
5367 = __format::__parse_integer(__fmt - 1, __end);
5368 if (__ptr) [[likely]]
5379 if (__is_failed(__err)) [[unlikely]]
5389 if (__yy != __bad_y && __y == __bad_y)
5390 __y =
years(__century) + __yy;
5391 if (__iso_yy != __bad_y && __iso_y == __bad_y)
5392 __iso_y =
years(__century) + __iso_yy;
5395 bool __can_use_doy =
false;
5396 bool __can_use_iso_wk =
false;
5397 bool __can_use_sun_wk =
false;
5398 bool __can_use_mon_wk =
false;
5401 if (__y != __bad_y && __dayofyear >= 0)
5403 __can_use_doy =
true;
5404 __parts |= _ChronoParts::_Date;
5406 else if (__y != __bad_y && __wday != __bad_wday && __sunday_wk >= 0)
5408 __can_use_sun_wk =
true;
5409 __parts |= _ChronoParts::_Date;
5411 else if (__y != __bad_y && __wday != __bad_wday && __monday_wk >= 0)
5413 __can_use_mon_wk =
true;
5414 __parts |= _ChronoParts::_Date;
5416 else if (__iso_y != __bad_y && __wday != __bad_wday && __iso_wk > 0)
5419 __can_use_iso_wk =
true;
5420 __parts |= _ChronoParts::_Date;
5423 if (__is_failed(__err)) [[unlikely]]
5425 else if (__is_flag) [[unlikely]]
5427 else if ((_M_need & __parts) == _M_need) [[likely]]
5449 const bool __need_wday = (_M_need & _ChronoParts::_Weekday) != 0;
5453 const bool __need_time = (_M_need & _ChronoParts::_TimeOfDay) != 0;
5455 if (__need_wday && __wday != __bad_wday)
5457 else if ((_M_need & _ChronoParts::_Date) != 0)
5461 const bool __need_ymd = !__need_wday && !__need_time;
5463 if (((_M_need & _ChronoParts::_Year) != 0 && __y == __bad_y)
5464 || ((_M_need & _ChronoParts::_Month) != 0 && __m == __bad_mon)
5465 || ((_M_need & _ChronoParts::_Day) != 0 && __d == __bad_day))
5472 if ((0 < __dayofyear && __dayofyear <= 365)
5473 || (__dayofyear == 366 && __y.is_leap()))
5476 _M_sys_days = sys_days(__y/January/1)
5477 +
days(__dayofyear - 1);
5479 _M_ymd = year_month_day(_M_sys_days);
5484 else if (__can_use_iso_wk)
5492 const sys_days __jan4(__iso_y/January/4);
5493 weekday __wd1(__jan4 -
days(3));
5494 if (__wd1 != Thursday)
5495 if (__wd1 != Wednesday || !__iso_y.is_leap())
5499 if (!__is_failed(__err)) [[likely]]
5502 sys_days __w(Thursday[1]/January/__iso_y);
5504 __w -= Thursday - Monday;
5506 __w += __wday - Monday;
5510 _M_ymd = year_month_day(_M_sys_days);
5513 else if (__can_use_sun_wk)
5516 sys_days __wk1(__y/January/Sunday[1]);
5517 _M_sys_days = __wk1 +
weeks(__sunday_wk - 1)
5518 +
days(__wday.c_encoding());
5519 _M_ymd = year_month_day(_M_sys_days);
5520 if (_M_ymd.year() != __y) [[unlikely]]
5523 else if (__can_use_mon_wk)
5526 sys_days __wk1(__y/January/Monday[1]);
5527 _M_sys_days = __wk1 +
weeks(__monday_wk - 1)
5528 +
days(__wday.c_encoding() - 1);
5529 _M_ymd = year_month_day(_M_sys_days);
5530 if (_M_ymd.year() != __y) [[unlikely]]
5542 if ((_M_need & _ChronoParts::_Year) != 0)
5544 if (!__y.ok()) [[unlikely]]
5547 else if (__y == __bad_y)
5550 if ((_M_need & _ChronoParts::_Month) != 0)
5552 if (!__m.ok()) [[unlikely]]
5555 else if (__m == __bad_mon)
5558 if ((_M_need & _ChronoParts::_Day) != 0)
5560 if (__d < day(1) || __d > (__y/__m/last).day())
5563 else if (__d == __bad_day)
5566 if (year_month_day __ymd(__y, __m, __d); __ymd.ok())
5569 if (__need_wday || __need_time)
5570 _M_sys_days = sys_days(_M_ymd);
5577 _M_wd = weekday(_M_sys_days);
5583 if (__h == __bad_h && __h12 != __bad_h)
5587 else if (__ampm == 2)
5588 __h = __h12 ==
hours(12) ? __h12 : __h12 +
hours(12);
5593 auto __t = _M_time.zero();
5602 if (__min != __bad_min)
5608 if (__s != __bad_sec)
5612 _M_is_leap_second = __s >=
seconds(60);
5621 if (!__is_failed(__err)) [[likely]]
5623 if (__offset && __tz_offset != __bad_min)
5624 *__offset = __tz_offset;
5625 if (__abbrev && !__tz_abbr.empty())
5633 __is.setstate(__err);
5637#undef _GLIBCXX_WIDEN
5642_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.
basic_stringstream< char > stringstream
Class for char mixed input and output memory streams.
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).
ios_base & fixed(ios_base &__base)
Calls base.setf(ios_base::fixed, ios_base::floatfield).
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 integer 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.