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;
888 [[__gnu__::__always_inline__]]
889 static _Dynamic_format_string<_CharT>
891 {
return _Dynamic_format_string<_CharT>(_S_empty_spec); }
894 static constexpr const _CharT* _S_weekdays[]
896 _GLIBCXX_WIDEN(
"Sunday"),
897 _GLIBCXX_WIDEN(
"Monday"),
898 _GLIBCXX_WIDEN(
"Tuesday"),
899 _GLIBCXX_WIDEN(
"Wednesday"),
900 _GLIBCXX_WIDEN(
"Thursday"),
901 _GLIBCXX_WIDEN(
"Friday"),
902 _GLIBCXX_WIDEN(
"Saturday"),
905 static constexpr const _CharT* _S_months[]
907 _GLIBCXX_WIDEN(
"January"),
908 _GLIBCXX_WIDEN(
"February"),
909 _GLIBCXX_WIDEN(
"March"),
910 _GLIBCXX_WIDEN(
"April"),
911 _GLIBCXX_WIDEN(
"May"),
912 _GLIBCXX_WIDEN(
"June"),
913 _GLIBCXX_WIDEN(
"July"),
914 _GLIBCXX_WIDEN(
"August"),
915 _GLIBCXX_WIDEN(
"September"),
916 _GLIBCXX_WIDEN(
"October"),
917 _GLIBCXX_WIDEN(
"November"),
918 _GLIBCXX_WIDEN(
"December"),
922 template<
typename _OutIter>
924 _M_write(_OutIter __out, [[maybe_unused]]
const locale& __loc,
925 __string_view __s)
const
927#if defined _GLIBCXX_USE_NL_LANGINFO_L && __CHAR_BIT__ == 8
932 if constexpr (is_same_v<_CharT, char>)
933 if constexpr (__unicode::__literal_encoding_is_utf8())
934 if (_M_spec._M_localized && _M_spec._M_locale_specific
935 && __loc != locale::classic())
938 __locale_encoding_to_utf8(
const locale&, string_view,
void*);
940 __s = __locale_encoding_to_utf8(__loc, __s, &__buf);
943 return __format::__write(
std::move(__out), __s);
946 [[__gnu__::__always_inline__]]
948 _S_localized_spec(_CharT __conv, _CharT __mod)
972 template<
typename _Iter>
974 _M_locale_fmt(_Iter __out,
const locale& __loc,
const struct tm& __tm,
975 char __fmt,
char __mod)
const
977 basic_ostringstream<_CharT> __os;
979 const auto& __tp = use_facet<time_put<_CharT>>(__loc);
980 __tp.put(__os, __os, _S_space, &__tm, __fmt, __mod);
982 __out = _M_write(
std::move(__out), __loc, __os.view());
987 _M_check_ok(
const _ChronoData<_CharT>& __t, _CharT& __conv)
const
989 if (!_M_spec._M_debug)
995 if (!__t._M_weekday.ok()) [[unlikely]]
996 __throw_format_error(
"format error: invalid weekday");
1001 if (!__t._M_month.ok()) [[unlikely]]
1002 __throw_format_error(
"format error: invalid month");
1007 return __string_view();
1014 if (__t._M_weekday_index < 1 || __t._M_weekday_index > 5) [[unlikely]]
1015 return _GLIBCXX_WIDEN(
"index");
1019 if (!__t._M_weekday.ok()) [[unlikely]]
1022 return _GLIBCXX_WIDEN(
"weekday");
1028 if (!__t._M_month.ok()) [[unlikely]]
1031 return _GLIBCXX_WIDEN(
"month");
1036 if (!__t._M_day.ok()) [[unlikely]]
1037 return _GLIBCXX_WIDEN(
"day");
1040 if (!(__t._M_year/__t._M_month/__t._M_day).ok()) [[unlikely]]
1041 return _GLIBCXX_WIDEN(
"date");
1044 if (!__t._M_year.ok()) [[unlikely]]
1045 return _GLIBCXX_WIDEN(
"year");
1050 return __string_view();
1053 template<
typename _OutIter,
typename _FormatContext>
1055 _M_format_to(
const _ChronoData<_CharT>& __t, _OutIter __out,
1056 _FormatContext& __fc)
const
1058 auto __first = _M_spec._M_chrono_specs.begin();
1059 const auto __last = _M_spec._M_chrono_specs.end();
1061 auto __print_sign = [__is_neg = __t._M_is_neg, &__out] ()
mutable {
1064 *__out++ = _S_plus_minus[1];
1071 bool __use_locale_fmt =
false;
1072 if (_M_spec._M_localized && _M_spec._M_locale_specific)
1073 if (__fc.locale() != locale::classic())
1075 __use_locale_fmt =
true;
1077 __tm.tm_year = (int)__t._M_year - 1900;
1078 __tm.tm_yday = __t._M_day_of_year.count();
1079 __tm.tm_mon = (unsigned)__t._M_month - 1;
1080 __tm.tm_mday = (unsigned)__t._M_day;
1081 __tm.tm_wday = __t._M_weekday.c_encoding();
1082 __tm.tm_hour = __t._M_hours.count();
1083 __tm.tm_min = __t._M_minutes.count();
1084 __tm.tm_sec = __t._M_seconds.count();
1092#ifdef _GLIBCXX_USE_STRUCT_TM_TM_ZONE
1095 if (__t._M_zone_cstr)
1096 __tm.tm_zone =
const_cast<char*
>(__t._M_zone_cstr);
1101 constexpr const _CharT* __literals = _GLIBCXX_WIDEN(
"\n\t%");
1108 _CharT __c = *__first++;
1109 __string_view __invalid;
1110 if (_M_spec._M_needs_ok_check)
1111 __invalid = _M_check_ok(__t, __c);
1113 if (__invalid.empty() &&__use_locale_fmt
1114 && _S_localized_spec(__c, __mod)) [[unlikely]]
1115 __out = _M_locale_fmt(
std::move(__out), __fc.locale(),
1121 __out = _M_wi(__t._M_weekday_index,
std::move(__out));
1125 __out = _M_a_A(__t._M_weekday,
std::move(__out), __c ==
'A');
1130 __out = _M_b_B(__t._M_month,
std::move(__out), __c ==
'B');
1138 __out = _M_C_y_Y(__t._M_year,
std::move(__out), __c);
1142 __out = _M_d_e(__t._M_day,
std::move(__out), __c);
1154 __out = _M_g_G_V(__t,
std::move(__out), __c);
1158 __out = _M_H_I(__t._M_hours, __print_sign(), __c);
1161 __out = _M_j(__t, __print_sign());
1164 __out = _M_m(__t._M_month,
std::move(__out));
1167 __out = _M_M(__t._M_minutes, __print_sign());
1170 __out = _M_p(__t._M_hours,
std::move(__out));
1173 __out = _M_q(__t._M_unit_suffix,
std::move(__out));
1176 __out = _M_Q(__t, __print_sign(), __fc);
1179 __out = _M_r(__t, __print_sign());
1183 __out = _M_R_X(__t, __print_sign(), __c !=
'R');
1186 __out = _M_T(__t, __print_sign(), __fc);
1189 __out = _M_S(__t, __print_sign(), __fc, __mod !=
'O');
1193 __out = _M_u_w(__t._M_weekday,
std::move(__out), __c);
1197 __out = _M_U_W(__t,
std::move(__out), __c);
1200 __out = _M_z(__t._M_zone_offset,
std::move(__out), (
bool)__mod);
1203 __out = _M_Z(__t._M_zone_abbrev,
std::move(__out));
1206 *__out++ = __literals[0];
1209 *__out++ = __literals[1];
1212 *__out++ = __literals[2];
1223 if (!__invalid.empty())
1225 constexpr __string_view __pref = _GLIBCXX_WIDEN(
" is not a valid ");
1226 __out = __format::__write(
std::move(__out), __pref);
1227 __out = __format::__write(
std::move(__out), __invalid);
1232 __string_view __str(__first, __last - __first);
1233 size_t __pos = __str.find(
'%');
1238 if (__pos == __str.npos)
1242 __str.remove_suffix(__str.length() - __pos);
1243 __first += __pos + 1;
1245 __out = __format::__write(
std::move(__out), __str);
1248 while (__first != __last);
1252 template<
typename _OutIter>
1254 _M_wi(
unsigned __wi, _OutIter __out)
const
1258 __out = __format::__write(
std::move(__out), _S_str_d1(__buf, __wi));
1262 template<
typename _OutIter>
1264 _M_a_A(chrono::weekday __wd, _OutIter __out,
bool __full)
const
1268 __string_view __str = _S_weekdays[__wd.c_encoding()];
1270 __str = __str.substr(0, 3);
1271 return __format::__write(
std::move(__out), __str);
1274 template<
typename _OutIter>
1276 _M_b_B(chrono::month __m, _OutIter __out,
bool __full)
const
1280 __string_view __str = _S_months[(unsigned)__m - 1];
1282 __str = __str.substr(0, 3);
1283 return __format::__write(
std::move(__out), __str);
1286 template<
typename _OutIter>
1288 _M_c(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1293 __out = _M_a_A(__t._M_weekday,
std::move(__out),
false);
1295 __out = _M_b_B(__t._M_month,
std::move(++__out),
false);
1297 __out = _M_d_e(__t._M_day,
std::move(++__out),
'e');
1299 __out = _M_R_X(__t,
std::move(++__out),
true);
1301 return _M_C_y_Y(__t._M_year,
std::move(++__out),
'Y');
1304 template<
typename _OutIter>
1306 _M_C_y_Y(chrono::year __y, _OutIter __out, _CharT __conv)
const
1316 int __yi = (int)__y;
1317 const bool __is_neg = __yi < 0;
1320 __yi = __builtin_abs(__yi);
1321 int __ci = __yi / 100;
1323 if (__conv ==
'C' && __is_neg && (__ci * 100) != __yi) [[unlikely]]
1326 if (__conv !=
'y' && __ci >= 100) [[unlikely]]
1328 using _FmtStr = _Dynamic_format_string<_CharT>;
1329 __string_view __fs = _S_minus_empty_spec + !__is_neg;
1330 __out = std::format_to(
std::move(__out), _FmtStr(__fs),
1331 __conv ==
'C' ? __ci : __yi);
1336 __buf[0] = _S_plus_minus[1];
1337 __string_view __sv(__buf + 3, __buf + 3);
1340 _S_fill_two_digits(__buf + 1, __ci);
1341 __sv = __string_view(__buf + !__is_neg, __buf + 3);
1345 _S_fill_two_digits(__buf + 3, __yi % 100);
1346 __sv = __string_view(__sv.data(), __buf + 5);
1348 __out = __format::__write(
std::move(__out), __sv);
1353 template<
typename _OutIter>
1355 _M_D_x(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1361 auto __di = (unsigned)__t._M_day;
1362 auto __mi = (unsigned)__t._M_month;
1363 auto __yi = __builtin_abs((
int)__t._M_year) % 100;
1365 if (__mi >= 100 || __di >= 100) [[unlikely]]
1367 using _FmtStr = _Dynamic_format_string<_CharT>;
1368 __string_view __fs = _GLIBCXX_WIDEN(
"{:02d}/{:02d}/{:02d}");
1369 __out = std::format_to(
std::move(__out), _FmtStr(__fs),
1375 __buf[2] = _S_slash;
1376 __buf[5] = _S_slash;
1377 __string_view __sv(__buf, __buf + 8);
1379 _S_fill_two_digits(__buf, __mi);
1380 _S_fill_two_digits(__buf + 3, __di);
1381 _S_fill_two_digits(__buf + 6, __yi);
1382 __out = __format::__write(
std::move(__out), __sv);
1387 template<
typename _OutIter>
1389 _M_d_e(chrono::day __d, _OutIter __out, _CharT __conv)
const
1396 unsigned __i = (unsigned)__d;
1399 auto __sv = _S_str_d2(__buf, __i);
1400 if (__conv == _CharT(
'e') && __i < 10)
1403 __buf[0] = _S_space;
1407 __out = __format::__write(
std::move(__out), __sv);
1411 template<
typename _OutIter>
1413 _M_F(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1415 auto __di = (unsigned)__t._M_day;
1416 auto __mi = (unsigned)__t._M_month;
1417 auto __yi = (int)__t._M_year;
1418 const bool __is_neg = __yi < 0;
1419 __yi = __builtin_abs(__yi);
1421 if (__yi >= 10000 || __mi >= 100 || __di >= 100) [[unlikely]]
1423 using _FmtStr = _Dynamic_format_string<_CharT>;
1425 = _GLIBCXX_WIDEN(
"-{:04d}-{:02d}-{:02d}") + !__is_neg;
1426 __out = std::format_to(
std::move(__out), _FmtStr(__fs),
1432 __buf[0] = _S_plus_minus[1];
1433 __buf[5] = _S_plus_minus[1];
1434 __buf[8] = _S_plus_minus[1];
1435 __string_view __sv(__buf + !__is_neg, __buf + 11);
1437 _S_fill_two_digits(__buf + 1, __yi / 100);
1438 _S_fill_two_digits(__buf + 3, __yi % 100);
1439 _S_fill_two_digits(__buf + 6, __mi);
1440 _S_fill_two_digits(__buf + 9, __di);
1441 __out = __format::__write(
std::move(__out), __sv);
1447 template<
typename _OutIter>
1449 _M_g_G_V(
const _ChronoData<_CharT>& __t, _OutIter __out,
1450 _CharT __conv)
const
1461 using namespace chrono;
1463 const days __offset = (__t._M_weekday - Monday) -
days(3);
1465 const local_days __ild = __t._M_ldays - __offset;
1467 days __idoy = __t._M_day_of_year - __offset;
1471 if (__idoy <=
days(0))
1472 __iyear = __t._M_year -
years(1);
1473 else if (__idoy <=
days(365))
1474 __iyear = __t._M_year;
1475 else if (__idoy ==
days(366) && __t._M_year.is_leap())
1476 __iyear = __t._M_year;
1477 else if (__idoy <=
days(730))
1478 __iyear = __t._M_year +
years(1);
1480 __iyear = year_month_day(__ild).year();
1483 return _M_C_y_Y(__iyear,
std::move(__out),
"yY"[__conv ==
'G']);
1485 if (__iyear != __t._M_year)
1486 __idoy = __ild - local_days(__iyear/January/0);
1488 const auto __wi = chrono::floor<weeks>(__idoy -
days(1)).count() + 1;
1489 return __format::__write(
std::move(__out), _S_two_digits(__wi));
1492 template<
typename _OutIter>
1494 _M_H_I(chrono::hours __h, _OutIter __out, _CharT __conv)
const
1501 int __i = __h.count();
1503 if (__conv == _CharT(
'I'))
1509 else if (__i >= 100) [[unlikely]]
1510 return std::format_to(
std::move(__out), _S_empty_fs(), __i);
1512 return __format::__write(
std::move(__out), _S_two_digits(__i));
1515 template<
typename _OutIter>
1517 _M_j(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1519 if (!_M_spec._M_needs(_ChronoParts::_DayOfYear))
1522 auto __d = chrono::floor<chrono::days>(__t._M_hours).count();
1523 return std::format_to(
std::move(__out), _S_empty_fs(), __d);
1526 auto __d = __t._M_day_of_year.count();
1527 if (__d >= 1000) [[unlikely]]
1528 return std::format_to(
std::move(__out), _S_empty_fs(), __d);
1531 return __format::__write(
std::move(__out), _S_str_d3(__buf, __d));
1534 template<
typename _OutIter>
1536 _M_m(chrono::month __m, _OutIter __out)
const
1540 auto __i = (unsigned)__m;
1541 if (__i == 0 && _M_spec._M_debug) [[unlikely]]
1543 return __format::__write(
std::move(__out), _S_digit(0));
1546 return __format::__write(
std::move(__out), _S_str_d2(__buf, __i));
1549 template<
typename _OutIter>
1551 _M_M(chrono::minutes __m, _OutIter __out)
const
1556 auto __i = __m.count();
1557 return __format::__write(
std::move(__out), _S_two_digits(__i));
1560 template<
typename _OutIter>
1562 _M_p(chrono::hours __h, _OutIter __out)
const
1567 _S_fill_ampm(__buf, __h);
1568 return __format::__write(
std::move(__out), __string_view(__buf, 2));
1571 template<
typename _OutIter>
1573 _M_q(__string_view __us, _OutIter __out)
const
1576 return __format::__write(
std::move(__out), __us);
1579 template<
typename _OutIter,
typename _FormatContext>
1581 _M_Q(
const _ChronoData<_CharT>& __t, _OutIter __out,
1582 _FormatContext&)
const
1585 return std::vformat_to(
std::move(__out), _S_empty_spec, __t._M_ereps);
1588 template<
typename _OutIter>
1590 _M_r(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1593 auto __hi = __t._M_hours.count() % 12;
1598 __buf[2] = _S_colon;
1599 __buf[5] = _S_colon;
1600 __buf[8] = _S_space;
1601 _S_fill_two_digits(__buf, __hi);
1602 _S_fill_two_digits(__buf + 3, __t._M_minutes.count());
1603 _S_fill_two_digits(__buf + 6, __t._M_seconds.count());
1604 _S_fill_ampm(__buf + 9, __t._M_hours);
1606 return __format::__write(
std::move(__out), __string_view(__buf, 11));
1609 template<
typename _OutIter>
1611 _M_R_X(
const _ChronoData<_CharT>& __t, _OutIter __out,
1618 auto __hi = __t._M_hours.count();
1621 __buf[2] = _S_colon;
1622 __buf[5] = _S_colon;
1623 __string_view __sv(__buf, 8);
1625 if (__hi >= 100) [[unlikely]]
1627 __out = std::format_to(
std::move(__out), _S_empty_fs(), __hi);
1628 __sv.remove_prefix(2);
1631 _S_fill_two_digits(__buf, __hi);
1633 _S_fill_two_digits(__buf + 3, __t._M_minutes.count());
1635 _S_fill_two_digits(__buf + 6, __t._M_seconds.count());
1637 __sv.remove_suffix(3);
1639 return __format::__write(
std::move(__out), __sv);
1642 template<
typename _OutIter,
typename _FormatContext>
1644 _M_S(
const _ChronoData<_CharT>& __t, _OutIter __out,
1645 _FormatContext& __ctx,
bool __subs =
true)
const
1649 auto __s = __t._M_seconds;
1651 __out = __format::__write(
std::move(__out),
1652 _S_two_digits(__s.count()));
1654 __out = _M_subsecs(__t,
std::move(__out), __ctx);
1658 template<
typename _OutIter,
typename _FormatContext>
1659 [[__gnu__::__always_inline__]]
1661 _M_subsecs(
const _ChronoData<_CharT>& __t, _OutIter __out,
1662 _FormatContext& __ctx)
const
1664 unsigned __prec = _M_spec._M_prec_kind != _WP_none
1665 ? _M_spec._M_get_precision(__ctx)
1670 _CharT __dot = _S_dot;
1671 if (_M_spec._M_localized) [[unlikely]]
1673 auto __loc = __ctx.locale();
1674 const auto& __np = use_facet<numpunct<_CharT>>(__loc);
1675 __dot = __np.decimal_point();
1680 if (_M_spec._M_floating_point_rep)
1682 _Str_sink<_CharT> __sink;
1683 if (_M_spec._M_localized && _M_spec._M_custom_rep) [[unlikely]]
1684 std::vformat_to(__sink.out(), __ctx.locale(),
1685 _GLIBCXX_WIDEN(
"{1:0.{2}Lf}"), __t._M_ereps);
1687 std::vformat_to(__sink.out(),
1688 _GLIBCXX_WIDEN(
"{1:0.{2}f}"), __t._M_ereps);
1690 auto __sv = __sink.view();
1692 __sv.remove_prefix(2);
1693 return __format::__write(
std::move(__out), __sv);
1696 constexpr unsigned __max_prec = _ChronoData<_CharT>::_S_max_prec;
1697 constexpr typename _ChronoData<_CharT>::_Attoseconds::rep __pow10t[]
1701 10'000u, 100'000u, 1000'000u,
1702 10'000'000u, 100'000'000u, 1000'000'000u,
1703 10'000'000'000u, 100'000'000'000u, 1000'000'000'000u,
1704 10'000'000'000'000u, 100'000'000'000'000u, 1000'000'000'000'000u,
1705 10'000'000'000'000'000u, 100'000'000'000'000'000u, 1000'000'000'000'000'000u,
1708 auto __subs = __t._M_subseconds.count();
1709 if (__prec < __max_prec)
1710 __subs /= __pow10t[__max_prec - __prec];
1711 else if (__prec > __max_prec)
1712 __prec = __max_prec;
1714 using _FmtStr = _Dynamic_format_string<_CharT>;
1715 return std::format_to(__out, _FmtStr(_GLIBCXX_WIDEN(
"{0:0{1}}")),
1721 template<
typename _OutIter,
typename _FormatContext>
1723 _M_T(
const _ChronoData<_CharT>& __t, _OutIter __out,
1724 _FormatContext& __ctx)
const
1727 __out = _M_R_X(__t,
std::move(__out),
true);
1728 return _M_subsecs(__t,
std::move(__out), __ctx);
1731 template<
typename _OutIter>
1733 _M_u_w(chrono::weekday __wd, _OutIter __out, _CharT __conv)
const
1739 unsigned __wdi = __conv ==
'u' ? __wd.iso_encoding()
1740 : __wd.c_encoding();
1742 return __format::__write(
std::move(__out), _S_str_d1(__buf, __wdi));
1745 template<
typename _OutIter>
1747 _M_U_W(
const _ChronoData<_CharT>& __t, _OutIter __out,
1748 _CharT __conv)
const
1755 using namespace chrono;
1756 const weekday __weekstart = __conv ==
'U' ? Sunday : Monday;
1757 const days __offset = __t._M_weekday - __weekstart;
1758 auto __weeks = chrono::floor<weeks>(__t._M_day_of_year - __offset -
days(1));
1759 return __format::__write(
std::move(__out), _S_two_digits(__weeks.count() + 1));
1762 template<
typename _OutIter>
1764 _M_z(chrono::seconds __ts, _OutIter __out,
bool __mod =
false)
const
1768 __string_view __zero
1769 = __mod ? _GLIBCXX_WIDEN(
"+00:00") : _GLIBCXX_WIDEN(
"+0000");
1770 return __format::__write(
std::move(__out), __zero);
1773 chrono::hh_mm_ss<chrono::seconds> __hms(__ts);
1774 unsigned __mo = 3 + __mod;
1777 __buf[0] = _S_plus_minus[__hms.is_negative()];
1778 __buf[3] = _S_colon;
1779 _S_fill_two_digits(__buf + 1, __hms.hours().count());
1780 _S_fill_two_digits(__buf + __mo, __hms.minutes().count());
1782 __string_view __sv(__buf, __mo + 2);
1783 return __format::__write(
std::move(__out), __sv);
1786 template<
typename _OutIter>
1788 _M_Z(__string_view __abbrev, _OutIter __out)
const
1789 {
return __format::__write(
std::move(__out), __abbrev); }
1794 static basic_string_view<_CharT>
1795 _S_digit(
int __n)
noexcept
1798 return { _GLIBCXX_WIDEN(
"0123456789999999") + (__n & 0xf), 1 };
1802 static basic_string_view<_CharT>
1803 _S_two_digits(
int __n)
noexcept
1806 _GLIBCXX_WIDEN(
"0001020304050607080910111213141516171819"
1807 "2021222324252627282930313233343536373839"
1808 "4041424344454647484950515253545556575859"
1809 "6061626364656667686970717273747576777879"
1810 "8081828384858687888990919293949596979899"
1811 "9999999999999999999999999999999999999999"
1812 "9999999999999999") + 2 * (__n & 0x7f),
1818 [[__gnu__::__always_inline__]]
1820 _S_fill_two_digits(_CharT* __buf,
unsigned __n)
1822 auto __sv = _S_two_digits(__n);
1828 [[__gnu__::__always_inline__]]
1830 _S_fill_ampm(_CharT* __buf, chrono::hours __h)
1832 auto __hi = __h.count();
1833 if (__hi >= 24) [[unlikely]]
1836 constexpr const _CharT* __apm = _GLIBCXX_WIDEN(
"APM");
1837 __buf[0] = __apm[__hi >= 12];
1838 __buf[1] = __apm[2];
1843 [[__gnu__::__always_inline__]]
1844 static basic_string_view<_CharT>
1845 _S_str_d1(span<_CharT, 3> __buf,
unsigned __n)
1847 if (__n < 10) [[likely]]
1848 return _S_digit(__n);
1849 return _S_str_d2(__buf, __n);
1854 [[__gnu__::__always_inline__]]
1855 static basic_string_view<_CharT>
1856 _S_str_d2(span<_CharT, 3> __buf,
unsigned __n)
1858 if (__n < 100) [[likely]]
1859 return _S_two_digits(__n);
1860 return _S_str_d3(__buf, __n);
1865 [[__gnu__::__always_inline__]]
1866 static basic_string_view<_CharT>
1867 _S_str_d3(span<_CharT, 3> __buf,
unsigned __n)
1869 _S_fill_two_digits(__buf.data(), __n / 10);
1870 __buf[2] = _S_chars[__n % 10];
1871 return __string_view(__buf.data(), 3);
1875 template<
typename _CharT>
1876 struct __formatter_duration :
private __formatter_chrono<_CharT>
1878 template<
typename _Rep,
typename _Period>
1879 constexpr static auto
1880 _S_subseconds(
const chrono::duration<_Rep, _Period>& __d)
1882 if constexpr (chrono::treat_as_floating_point_v<_Rep>)
1883 return chrono::duration<_Rep>(__d);
1884 else if constexpr (_Period::den == 1)
1885 return chrono::seconds(0);
1888 using _Attoseconds = _ChronoData<_CharT>::_Attoseconds;
1889 using _CRep = common_type_t<_Rep, typename _Attoseconds::rep>;
1890 chrono::duration<_CRep, _Period> __subs(__d.count());
1891 return chrono::duration_cast<_Attoseconds>(__subs);
1896 template<
typename _Duration>
1899 _S_spec_for(_ChronoParts __parts)
1901 using _Rep =
typename _Duration::rep;
1902 using enum _ChronoParts;
1904 _ChronoSpec<_CharT> __res{};
1905 __res._M_floating_point_rep = chrono::treat_as_floating_point_v<_Rep>;
1906 __res._M_custom_rep = !is_arithmetic_v<_Rep>;
1907 __res._M_prec = chrono::hh_mm_ss<_Duration>::fractional_width;
1908 if ((__parts & _TimeOfDay) != 0)
1909 __res._M_localized = __res._M_prec > 0 || __res._M_floating_point_rep;
1911 if ((__parts & _TimeOfDay) != 0)
1912 __res._M_needed |= _TimeOfDay;
1913 if ((__parts & _Date) != 0)
1914 __res._M_needed |= _YearMonthDay;
1915 if ((__parts & _ZoneAbbrev) != 0)
1916 __res._M_needed |= _ZoneAbbrev;
1920 case _ZonedDateTime:
1921 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ftz();
1924 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ft();
1927 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_f();
1930 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_t();
1935 __builtin_unreachable();
1940 template<
typename _Duration>
1945 using enum _ChronoParts;
1947 constexpr bool __stream_insertable =
1948 requires (basic_ostream<_CharT>& __os, chrono::sys_time<_Duration> __t)
1950 if constexpr (!__stream_insertable)
1951 return _S_spec_for<_Duration>(_None);
1952 else if constexpr (is_convertible_v<_Duration, chrono::days>)
1953 return _S_spec_for<_Duration>(_Date);
1955 return _S_spec_for<_Duration>(_DateTime);
1958 using __formatter_chrono<_CharT>::__formatter_chrono;
1959 using __formatter_chrono<_CharT>::_M_spec;
1961 template<
typename _Duration>
1962 constexpr typename basic_format_parse_context<_CharT>::iterator
1963 _M_parse(basic_format_parse_context<_CharT>& __pc, _ChronoParts __parts,
1964 const _ChronoSpec<_CharT>& __def)
1966 using _Rep =
typename _Duration::rep;
1967 using enum _ChronoParts;
1970 = __formatter_chrono<_CharT>::_M_parse(__pc, __parts, __def);
1973 _M_spec._M_needs_ok_check =
false;
1978 if constexpr (!is_floating_point_v<_Rep>)
1979 if constexpr (chrono::treat_as_floating_point_v<_Rep>)
1980 if (_M_spec._M_needs(_Subseconds|_EpochUnits)
1981 || _M_spec._M_prec_kind != _WP_none
1982 || _M_spec._M_prec_value > 0)
1984 constexpr const _CharT* __fs = _GLIBCXX_WIDEN(
"#02.5Lf");
1985 basic_format_parse_context<_CharT> __npc(__fs);
1986 formatter<_Rep, _CharT> __fmtter;
1987 __fmtter.parse(__npc);
1993 template<
typename _FormatContext>
1995 _M_locale(_FormatContext& __fc)
const
1997 if (!_M_spec._M_localized)
2000 return __fc.locale();
2004 template<
typename _Rep,
typename _Period,
typename _FormatContext>
2005 typename _FormatContext::iterator
2006 _M_format_to_ostream(
const chrono::duration<_Rep, _Period>& __d,
2008 _FormatContext& __fc)
const
2010 basic_ostringstream<_CharT> __os;
2011 __os.imbue(this->_M_locale(__fc));
2013 if (__is_neg) [[unlikely]]
2014 __os << this->_S_plus_minus[1];
2018 return __format::__write_padded_as_spec(__str, __str.size(),
2022 template<
typename _Rep1,
typename _Period1,
2023 typename _Rep2,
typename _Period2,
2024 typename _FormatContext>
2025 typename _FormatContext::iterator
2026 _M_format_units(_ChronoData<_CharT>& __cd,
2027 const chrono::duration<_Rep1, _Period1>& __ed,
2028 const chrono::duration<_Rep2, _Period2>& __ss,
2029 _FormatContext& __fc)
const
2031 __format::_Str_sink<_CharT> __suffix_store;
2032 constexpr auto _S_unit_suffix
2033 = chrono::__detail::__units_suffix<_Period1, _CharT>();
2034 if constexpr (!_S_unit_suffix.empty())
2035 __cd._M_unit_suffix = _S_unit_suffix;
2036 else if (_M_spec._M_needs(_ChronoParts::_UnitSuffix))
2039 __fmt_units_suffix<_Period1, _CharT>(__suffix_store.out());
2040 __cd._M_unit_suffix = __suffix_store.view();
2043 const auto __prec = _M_spec._M_prec_kind != _WP_none
2044 ? _M_spec._M_get_precision(__fc)
2047 using _ErasedContext =
typename _ChronoData<_CharT>::_FormatContext;
2050 auto __ereps = +__ed.count();
2051 if (!_M_spec._M_needs(_ChronoParts::_Subseconds))
2055 = std::make_format_args<_ErasedContext>(__ereps, __ssreps, __prec);
2056 __cd._M_ereps = __args_store;
2057 return this->_M_format(__cd, __fc);
2060 using _Attoseconds = _ChronoData<_CharT>::_Attoseconds;
2061 auto __nss = _S_subseconds(__ss);
2062 __cd._M_subseconds = chrono::duration_cast<_Attoseconds>(__nss);
2064 auto __ssreps = __nss.count();
2066 = std::make_format_args<_ErasedContext>(__ereps, __ssreps, __prec);
2067 __cd._M_ereps = __args_store;
2069 return this->_M_format(__cd, __fc);
2073 template<
typename _Rep1,
typename _Period1,
typename _FormatContext>
2074 typename _FormatContext::iterator
2075 _M_format_time_point(_ChronoData<_CharT>& __cd,
2076 const chrono::duration<_Rep1, _Period1>& __ed,
2077 _FormatContext& __fc)
const
2079 auto __parts = _M_spec._M_needed - _ChronoParts::_TotalSeconds;
2080 if ((__parts & _ChronoParts::_DateTime) != 0)
2081 __cd._M_fill_date_time(__cd._M_lseconds, __parts);
2082 return _M_format_units(__cd, __ed, __ed - __cd._M_eseconds, __fc);
2086#if __glibcxx_chrono >= 201803L
2087 template<
typename _CharT>
2088 struct __formatter_chrono_info
2090 constexpr typename basic_format_parse_context<_CharT>::iterator
2091 parse(basic_format_parse_context<_CharT>& __pc)
2092 {
return _M_f._M_parse(__pc, _ChronoParts(), {}); }
2094 template<
typename _Info,
typename _Out>
2095 typename basic_format_context<_Out, _CharT>::iterator
2096 format(
const _Info& __i,
2097 basic_format_context<_Out, _CharT>& __fc)
const
2101 if (!_M_f._M_spec._M_chrono_specs.empty()) [[unlikely]]
2102 return _M_f._M_format(_ChronoData<_CharT>{}, __fc);
2104 const size_t __padwidth = _M_f._M_spec._M_get_width(__fc);
2105 if (__padwidth == 0)
2106 return _M_format_to(__fc.out(), __i);
2108 _Padding_sink<_Out, _CharT> __sink(__fc.out(), __padwidth);
2109 _M_format_to(__sink.out(), __i);
2110 return __sink._M_finish(_M_f._M_spec._M_align, _M_f._M_spec._M_fill);
2114 template<
typename _Out>
2116 _M_format_to(_Out __out,
const chrono::sys_info& __si)
const
2118 using _FmtStr = _Dynamic_format_string<_CharT>;
2122 constexpr auto* __fs
2123 = _GLIBCXX_WIDEN(
"[{0:%F %T},{1:%F %T},{2:%T},{3:%Q%q},{0:%Z}]");
2124 const chrono::local_seconds __lb(__si.begin.time_since_epoch());
2125 return std::format_to(
std::move(__out), _FmtStr(__fs),
2126 chrono::local_time_format(__lb, &__si.abbrev),
2127 __si.end, __si.offset, __si.save);
2130 template<
typename _Out>
2132 _M_format_to(_Out __out,
const chrono::local_info& __li)
const
2134 *__out = _Separators<_CharT>::_S_squares()[0];
2136 if (__li.result == chrono::local_info::unique)
2137 __out = _M_format_to(
std::move(__out), __li.first);
2140 basic_string_view<_CharT> __sv;
2141 if (__li.result == chrono::local_info::nonexistent)
2142 __sv =_GLIBCXX_WIDEN(
"nonexistent");
2144 __sv = _GLIBCXX_WIDEN(
"ambiguous");
2145 __out = __format::__write(
std::move(__out), __sv);
2147 __sv = _GLIBCXX_WIDEN(
" local time between ");
2148 __out = __format::__write(
std::move(__out), __sv);
2149 __out = _M_format_to(
std::move(__out), __li.first);
2151 __sv = _GLIBCXX_WIDEN(
" and ");
2152 __out = __format::__write(
std::move(__out), __sv);
2153 __out = _M_format_to(
std::move(__out), __li.second);
2155 *__out = _Separators<_CharT>::_S_squares()[1];
2160 __formatter_chrono<_CharT> _M_f;
2167 template<
typename _Rep,
typename _Period,
typename _CharT>
2168 requires __format::__formattable_impl<_Rep, _CharT>
2169 struct formatter<
chrono::duration<_Rep, _Period>, _CharT>
2171 constexpr typename basic_format_parse_context<_CharT>::iterator
2172 parse(basic_format_parse_context<_CharT>& __pc)
2174 using enum __format::_ChronoParts;
2175 return _M_f.template _M_parse<_Duration>(__pc, _EpochTime, __defSpec);
2178 template<
typename _Out>
2179 typename basic_format_context<_Out, _CharT>::iterator
2180 format(
const chrono::duration<_Rep, _Period>& __d,
2181 basic_format_context<_Out, _CharT>& __fc)
const
2183 if constexpr (numeric_limits<_Rep>::is_signed)
2184 if (__d < __d.zero()) [[unlikely]]
2186 if constexpr (is_integral_v<_Rep>)
2190 using _URep = make_unsigned_t<_Rep>;
2191 auto __ucnt = -
static_cast<_URep
>(__d.count());
2192 auto __ud = chrono::duration<_URep, _Period>(__ucnt);
2193 return _M_format(__ud,
true, __fc);
2196 return _M_format(-__d,
true, __fc);
2198 return _M_format(__d,
false, __fc);
2202 using _Duration = chrono::duration<_Rep, _Period>;
2204 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2206 using enum __format::_ChronoParts;
2207 auto __res = __format::__formatter_duration<_CharT>::
2208 template _S_spec_for<_Duration>(_None);
2209 __res._M_localized = !is_integral_v<_Rep>;
2211 if constexpr (is_integral_v<_Rep>)
2213 __res._M_needed = _EpochUnits|_UnitSuffix;
2214 __res._M_chrono_specs = _GLIBCXX_WIDEN(
"%Q%q");
2219 template<
typename _Rep2,
typename _Out>
2220 typename basic_format_context<_Out, _CharT>::iterator
2221 _M_format(
const chrono::duration<_Rep2, _Period>& __d,
2223 basic_format_context<_Out, _CharT>& __fc)
const
2225 using namespace chrono;
2226 using enum __format::_ChronoParts;
2227 if constexpr (!is_integral_v<_Rep>)
2228 if (_M_f._M_spec._M_chrono_specs.empty())
2229 return _M_f._M_format_to_ostream(__d, __is_neg, __fc);
2231 __format::_ChronoData<_CharT> __cd;
2232 __cd._M_is_neg = __is_neg;
2233 auto __ts = chrono::floor<chrono::seconds>(__d);
2234 __cd._M_eseconds = __ts;
2235 if (_M_f._M_spec._M_needs(_HoursMinutesSeconds))
2236 __cd._M_fill_time(__ts);
2237 return _M_f._M_format_units(__cd, __d, __d - __ts, __fc);
2240 __format::__formatter_duration<_CharT> _M_f{__defSpec};
2243#if __glibcxx_print >= 202406L
2246 template<
typename _Rep,
typename _Period>
2248 enable_nonlocking_formatter_optimization<chrono::duration<_Rep, _Period>>
2249 = is_arithmetic_v<_Rep>;
2252 template<__format::__
char _CharT>
2253 struct formatter<
chrono::day, _CharT>
2255 constexpr typename basic_format_parse_context<_CharT>::iterator
2256 parse(basic_format_parse_context<_CharT>& __pc)
2258 using enum __format::_ChronoParts;
2259 return _M_f._M_parse(__pc, _Day|_WeekdayIndex, __defSpec);
2262 template<
typename _Out>
2263 typename basic_format_context<_Out, _CharT>::iterator
2264 format(
const chrono::day& __t,
2265 basic_format_context<_Out, _CharT>& __fc)
const
2267 __format::_ChronoData<_CharT> __cd{};
2268 __cd._M_fill_day(__t, __defSpec._M_needed);
2269 return _M_f._M_format(__cd, __fc);
2273 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2275 using __format::_ChronoFormats;
2276 using enum __format::_ChronoParts;
2278 __format::_ChronoSpec<_CharT> __res{};
2279 __res._M_debug =
true;
2280 __res._M_needed = _Day;
2281 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_d();
2285 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2288#if __glibcxx_print >= 202406L
2290 inline constexpr bool
2291 enable_nonlocking_formatter_optimization<chrono::day> =
true;
2294 template<__format::__
char _CharT>
2295 struct formatter<
chrono::month, _CharT>
2297 constexpr typename basic_format_parse_context<_CharT>::iterator
2298 parse(basic_format_parse_context<_CharT>& __pc)
2300 using enum __format::_ChronoParts;
2301 return _M_f._M_parse(__pc, _Month, __defSpec);
2304 template<
typename _Out>
2305 typename basic_format_context<_Out, _CharT>::iterator
2306 format(
const chrono::month& __t,
2307 basic_format_context<_Out, _CharT>& __fc)
const
2309 __format::_ChronoData<_CharT> __cd{};
2310 __cd._M_month = __t;
2311 return _M_f._M_format(__cd, __fc);
2315 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2317 using __format::_ChronoFormats;
2318 using enum __format::_ChronoParts;
2320 __format::_ChronoSpec<_CharT> __res{};
2321 __res._M_debug =
true;
2322 __res._M_localized =
true;
2323 __res._M_locale_specific =
true;
2324 __res._M_needed = _Month;
2325 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_m();
2329 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2332#if __glibcxx_print >= 202406L
2334 inline constexpr bool
2335 enable_nonlocking_formatter_optimization<chrono::month> =
true;
2338 template<__format::__
char _CharT>
2339 struct formatter<
chrono::year, _CharT>
2341 constexpr typename basic_format_parse_context<_CharT>::iterator
2342 parse(basic_format_parse_context<_CharT>& __pc)
2344 using enum __format::_ChronoParts;
2345 return _M_f._M_parse(__pc, _Year, __defSpec);
2348 template<
typename _Out>
2349 typename basic_format_context<_Out, _CharT>::iterator
2350 format(
const chrono::year& __t,
2351 basic_format_context<_Out, _CharT>& __fc)
const
2353 __format::_ChronoData<_CharT> __cd{};
2355 return _M_f._M_format(__cd, __fc);
2359 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2361 using __format::_ChronoFormats;
2362 using enum __format::_ChronoParts;
2364 __format::_ChronoSpec<_CharT> __res{};
2365 __res._M_debug =
true;
2366 __res._M_needed = _Year;
2367 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_y();
2371 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2374#if __glibcxx_print >= 202406L
2376 inline constexpr bool
2377 enable_nonlocking_formatter_optimization<chrono::year> =
true;
2380 template<__format::__
char _CharT>
2381 struct formatter<
chrono::weekday, _CharT>
2383 constexpr typename basic_format_parse_context<_CharT>::iterator
2384 parse(basic_format_parse_context<_CharT>& __pc)
2386 using enum __format::_ChronoParts;
2387 return _M_f._M_parse(__pc, _Weekday, __defSpec);
2390 template<
typename _Out>
2391 typename basic_format_context<_Out, _CharT>::iterator
2392 format(
const chrono::weekday& __t,
2393 basic_format_context<_Out, _CharT>& __fc)
const
2395 __format::_ChronoData<_CharT> __cd{};
2396 __cd._M_weekday = __t;
2397 return _M_f._M_format(__cd, __fc);
2401 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2403 using __format::_ChronoFormats;
2404 using enum __format::_ChronoParts;
2406 __format::_ChronoSpec<_CharT> __res{};
2407 __res._M_debug =
true;
2408 __res._M_localized =
true;
2409 __res._M_locale_specific =
true;
2410 __res._M_needed = _Weekday;
2411 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_w();
2415 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2418#if __glibcxx_print >= 202406L
2420 inline constexpr bool
2421 enable_nonlocking_formatter_optimization<chrono::weekday> =
true;
2424 template<__format::__
char _CharT>
2425 struct formatter<
chrono::weekday_indexed, _CharT>
2427 constexpr typename basic_format_parse_context<_CharT>::iterator
2428 parse(basic_format_parse_context<_CharT>& __pc)
2430 using enum __format::_ChronoParts;
2431 return _M_f._M_parse(__pc, _IndexedWeekday, __defSpec);
2434 template<
typename _Out>
2435 typename basic_format_context<_Out, _CharT>::iterator
2436 format(
const chrono::weekday_indexed& __t,
2437 basic_format_context<_Out, _CharT>& __fc)
const
2439 __format::_ChronoData<_CharT> __cd{};
2440 __cd._M_fill_weekday(__t, __defSpec._M_needed);
2441 return _M_f._M_format(__cd, __fc);
2445 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2447 using __format::_ChronoFormats;
2448 using enum __format::_ChronoParts;
2450 __format::_ChronoSpec<_CharT> __res{};
2451 __res._M_debug =
true;
2452 __res._M_localized =
true;
2453 __res._M_locale_specific =
true;
2454 __res._M_needed = _IndexedWeekday;
2455 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_wi();
2459 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2462#if __glibcxx_print >= 202406L
2464 inline constexpr bool
2465 enable_nonlocking_formatter_optimization<chrono::weekday_indexed> =
true;
2468 template<__format::__
char _CharT>
2469 struct formatter<
chrono::weekday_last, _CharT>
2471 constexpr typename basic_format_parse_context<_CharT>::iterator
2472 parse(basic_format_parse_context<_CharT>& __pc)
2474 using enum __format::_ChronoParts;
2475 return _M_f._M_parse(__pc, _Weekday, __defSpec);
2478 template<
typename _Out>
2479 typename basic_format_context<_Out, _CharT>::iterator
2480 format(
const chrono::weekday_last& __t,
2481 basic_format_context<_Out, _CharT>& __fc)
const
2483 __format::_ChronoData<_CharT> __cd{};
2484 __cd._M_weekday = __t.weekday();
2485 return _M_f._M_format(__cd, __fc);
2489 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2491 using __format::_ChronoFormats;
2492 using enum __format::_ChronoParts;
2494 __format::_ChronoSpec<_CharT> __res{};
2495 __res._M_debug =
true;
2496 __res._M_localized =
true;
2497 __res._M_locale_specific =
true;
2498 __res._M_needed = _Weekday;
2499 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_wl();
2503 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2506#if __glibcxx_print >= 202406L
2508 inline constexpr bool
2509 enable_nonlocking_formatter_optimization<chrono::weekday_last> =
true;
2512 template<__format::__
char _CharT>
2513 struct formatter<
chrono::month_day, _CharT>
2515 constexpr typename basic_format_parse_context<_CharT>::iterator
2516 parse(basic_format_parse_context<_CharT>& __pc)
2518 using enum __format::_ChronoParts;
2519 return _M_f._M_parse(__pc, _Month|_Day|_WeekdayIndex, __defSpec);
2522 template<
typename _Out>
2523 typename basic_format_context<_Out, _CharT>::iterator
2524 format(
const chrono::month_day& __t,
2525 basic_format_context<_Out, _CharT>& __fc)
const
2527 __format::_ChronoData<_CharT> __cd{};
2528 __cd._M_month = __t.month();
2529 __cd._M_fill_day(__t.day(), __defSpec._M_needed);
2530 return _M_f._M_format(__cd, __fc);
2534 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2536 using __format::_ChronoFormats;
2537 using enum __format::_ChronoParts;
2539 __format::_ChronoSpec<_CharT> __res{};
2540 __res._M_debug =
true;
2541 __res._M_localized =
true;
2542 __res._M_locale_specific =
true;
2543 __res._M_needed = _Month|_Day;
2544 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_md();
2548 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2551#if __glibcxx_print >= 202406L
2553 inline constexpr bool
2554 enable_nonlocking_formatter_optimization<chrono::month_day> =
true;
2557 template<__format::__
char _CharT>
2558 struct formatter<
chrono::month_day_last, _CharT>
2560 constexpr typename basic_format_parse_context<_CharT>::iterator
2561 parse(basic_format_parse_context<_CharT>& __pc)
2563 using enum __format::_ChronoParts;
2564 return _M_f._M_parse(__pc, _Month, __defSpec);
2567 template<
typename _Out>
2568 typename basic_format_context<_Out, _CharT>::iterator
2569 format(
const chrono::month_day_last& __t,
2570 basic_format_context<_Out, _CharT>& __fc)
const
2572 __format::_ChronoData<_CharT> __cd{};
2573 __cd._M_month = __t.month();
2574 return _M_f._M_format(__cd, __fc);
2578 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2580 using __format::_ChronoFormats;
2581 using enum __format::_ChronoParts;
2583 __format::_ChronoSpec<_CharT> __res{};
2584 __res._M_debug =
true;
2585 __res._M_localized =
true;
2586 __res._M_locale_specific =
true;
2587 __res._M_needed = _Month;
2588 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ml();
2592 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2595#if __glibcxx_print >= 202406L
2597 inline constexpr bool
2598 enable_nonlocking_formatter_optimization<chrono::month_day_last> =
true;
2601 template<__format::__
char _CharT>
2602 struct formatter<
chrono::month_weekday, _CharT>
2604 constexpr typename basic_format_parse_context<_CharT>::iterator
2605 parse(basic_format_parse_context<_CharT>& __pc)
2607 using enum __format::_ChronoParts;
2608 return _M_f._M_parse(__pc, _Month|_IndexedWeekday, __defSpec);
2611 template<
typename _Out>
2612 typename basic_format_context<_Out, _CharT>::iterator
2613 format(
const chrono::month_weekday& __t,
2614 basic_format_context<_Out, _CharT>& __fc)
const
2616 __format::_ChronoData<_CharT> __cd{};
2617 __cd._M_month = __t.month();
2618 __cd._M_fill_weekday(__t.weekday_indexed(), __defSpec._M_needed);
2619 return _M_f._M_format(__cd, __fc);
2623 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2625 using __format::_ChronoFormats;
2626 using enum __format::_ChronoParts;
2628 __format::_ChronoSpec<_CharT> __res{};
2629 __res._M_debug =
true;
2630 __res._M_localized =
true;
2631 __res._M_locale_specific =
true;
2632 __res._M_needed = _Month|_IndexedWeekday;
2633 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_mwi();
2637 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2640#if __glibcxx_print >= 202406L
2642 inline constexpr bool
2643 enable_nonlocking_formatter_optimization<chrono::month_weekday> =
true;
2646 template<__format::__
char _CharT>
2647 struct formatter<
chrono::month_weekday_last, _CharT>
2649 constexpr typename basic_format_parse_context<_CharT>::iterator
2650 parse(basic_format_parse_context<_CharT>& __pc)
2652 using enum __format::_ChronoParts;
2653 return _M_f._M_parse(__pc, _Month|_Weekday, __defSpec);
2656 template<
typename _Out>
2657 typename basic_format_context<_Out, _CharT>::iterator
2658 format(
const chrono::month_weekday_last& __t,
2659 basic_format_context<_Out, _CharT>& __fc)
const
2661 __format::_ChronoData<_CharT> __cd{};
2662 __cd._M_month = __t.month();
2663 __cd._M_weekday = __t.weekday_last().weekday();
2664 return _M_f._M_format(__cd, __fc);
2668 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2670 using __format::_ChronoFormats;
2671 using enum __format::_ChronoParts;
2673 __format::_ChronoSpec<_CharT> __res{};
2674 __res._M_debug =
true;
2675 __res._M_localized =
true;
2676 __res._M_locale_specific =
true;
2677 __res._M_needed = _Month|_Weekday;
2678 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_mwl();
2682 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2685#if __glibcxx_print >= 202406L
2687 inline constexpr bool
2688 enable_nonlocking_formatter_optimization<chrono::month_weekday_last> =
true;
2691 template<__format::__
char _CharT>
2692 struct formatter<
chrono::year_month, _CharT>
2694 constexpr typename basic_format_parse_context<_CharT>::iterator
2695 parse(basic_format_parse_context<_CharT>& __pc)
2697 using enum __format::_ChronoParts;
2698 return _M_f._M_parse(__pc, _Year|_Month, __defSpec);
2701 template<
typename _Out>
2702 typename basic_format_context<_Out, _CharT>::iterator
2703 format(
const chrono::year_month& __t,
2704 basic_format_context<_Out, _CharT>& __fc)
const
2706 __format::_ChronoData<_CharT> __cd{};
2707 __cd._M_fill_year_month(__t, __defSpec._M_needed);
2708 return _M_f._M_format(__cd, __fc);
2712 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2714 using __format::_ChronoFormats;
2715 using enum __format::_ChronoParts;
2717 __format::_ChronoSpec<_CharT> __res{};
2718 __res._M_debug =
true;
2719 __res._M_localized =
true;
2720 __res._M_locale_specific =
true;
2721 __res._M_needed = _Year|_Month;
2722 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ym();
2726 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2729#if __glibcxx_print >= 202406L
2731 inline constexpr bool
2732 enable_nonlocking_formatter_optimization<chrono::year_month> =
true;
2735 template<__format::__
char _CharT>
2736 struct formatter<
chrono::year_month_day, _CharT>
2738 constexpr typename basic_format_parse_context<_CharT>::iterator
2739 parse(basic_format_parse_context<_CharT>& __pc)
2741 using enum __format::_ChronoParts;
2742 return _M_f._M_parse(__pc, _Date, __defSpec);
2745 template<
typename _Out>
2746 typename basic_format_context<_Out, _CharT>::iterator
2747 format(
const chrono::year_month_day& __t,
2748 basic_format_context<_Out, _CharT>& __fc)
const
2750 __format::_ChronoData<_CharT> __cd{};
2751 auto __parts = _M_f._M_spec._M_needed;
2752 __parts = __cd._M_fill_year_month(__t, __parts);
2753 __parts = __cd._M_fill_day(__t.day(), __parts);
2755 return _M_f._M_format(__cd, __fc);
2757 __cd._M_fill_ldays(chrono::local_days(__t), __parts);
2758 return _M_f._M_format(__cd, __fc);
2762 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2764 using __format::_ChronoFormats;
2765 using enum __format::_ChronoParts;
2767 __format::_ChronoSpec<_CharT> __res{};
2768 __res._M_debug =
true;
2769 __res._M_needed = _YearMonthDay;
2770 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_f();
2774 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2777#if __glibcxx_print >= 202406L
2779 inline constexpr bool
2780 enable_nonlocking_formatter_optimization<chrono::year_month_day> =
true;
2783 template<__format::__
char _CharT>
2784 struct formatter<
chrono::year_month_day_last, _CharT>
2786 constexpr typename basic_format_parse_context<_CharT>::iterator
2787 parse(basic_format_parse_context<_CharT>& __pc)
2789 using enum __format::_ChronoParts;
2790 return _M_f._M_parse(__pc, _Date, __defSpec);
2793 template<
typename _Out>
2794 typename basic_format_context<_Out, _CharT>::iterator
2795 format(
const chrono::year_month_day_last& __t,
2796 basic_format_context<_Out, _CharT>& __fc)
const
2798 using enum __format::_ChronoParts;
2800 __format::_ChronoData<_CharT> __cd{};
2801 auto __parts = _M_f._M_spec._M_needed;
2802 __parts = __cd._M_fill_year_month(__t, __parts);
2803 if (_M_f._M_spec._M_needs(_Day|_WeekdayIndex))
2804 __parts = __cd._M_fill_day(__t.day(), __parts);
2806 return _M_f._M_format(__cd, __fc);
2808 __cd._M_fill_ldays(chrono::local_days(__t), __parts);
2809 return _M_f._M_format(__cd, __fc);
2813 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2815 using __format::_ChronoFormats;
2816 using enum __format::_ChronoParts;
2818 __format::_ChronoSpec<_CharT> __res{};
2819 __res._M_debug =
true;
2820 __res._M_localized =
true;
2821 __res._M_locale_specific =
true;
2822 __res._M_needed = _Year|_Month;
2823 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_yml();
2827 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2830#if __glibcxx_print >= 202406L
2832 inline constexpr bool
2833 enable_nonlocking_formatter_optimization<chrono::year_month_day_last> =
true;
2836 template<__format::__
char _CharT>
2837 struct formatter<
chrono::year_month_weekday, _CharT>
2839 constexpr typename basic_format_parse_context<_CharT>::iterator
2840 parse(basic_format_parse_context<_CharT>& __pc)
2842 using enum __format::_ChronoParts;
2843 return _M_f._M_parse(__pc, _Date, __defSpec);
2846 template<
typename _Out>
2847 typename basic_format_context<_Out, _CharT>::iterator
2848 format(
const chrono::year_month_weekday& __t,
2849 basic_format_context<_Out, _CharT>& __fc)
const
2851 __format::_ChronoData<_CharT> __cd{};
2852 auto __parts = _M_f._M_spec._M_needed;
2853 __parts = __cd._M_fill_year_month(__t, __parts);
2854 __parts = __cd._M_fill_weekday(__t.weekday_indexed(), __parts);
2855 if (__t.index() == 0) [[unlikely]]
2858 __parts -= __format::_ChronoParts::_Day;
2860 return _M_f._M_format(__cd, __fc);
2862 chrono::local_days __ld(__t);
2863 __parts = __cd._M_fill_ldays(__ld, __parts);
2865 return _M_f._M_format(__cd, __fc);
2867 auto __dom = __ld - chrono::local_days(__t.year()/__t.month()/0);
2869 __cd._M_day = chrono::day(__dom.count());
2870 return _M_f._M_format(__cd, __fc);
2874 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2876 using __format::_ChronoFormats;
2877 using enum __format::_ChronoParts;
2879 __format::_ChronoSpec<_CharT> __res{};
2880 __res._M_debug =
true;
2881 __res._M_localized =
true;
2882 __res._M_locale_specific =
true;
2883 __res._M_needed = _Year|_Month|_IndexedWeekday;
2884 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ymwi();
2888 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2891#if __glibcxx_print >= 202406L
2893 inline constexpr bool
2894 enable_nonlocking_formatter_optimization<chrono::year_month_weekday> =
true;
2897 template<__format::__
char _CharT>
2898 struct formatter<
chrono::year_month_weekday_last, _CharT>
2900 constexpr typename basic_format_parse_context<_CharT>::iterator
2901 parse(basic_format_parse_context<_CharT>& __pc)
2903 using enum __format::_ChronoParts;
2904 return _M_f._M_parse(__pc, _Date, __defSpec);
2907 template<
typename _Out>
2908 typename basic_format_context<_Out, _CharT>::iterator
2909 format(
const chrono::year_month_weekday_last& __t,
2910 basic_format_context<_Out, _CharT>& __fc)
const
2912 __format::_ChronoData<_CharT> __cd{};
2913 auto __parts = _M_f._M_spec._M_needed;
2914 __parts = __cd._M_fill_year_month(__t, __parts);
2915 __cd._M_weekday = __t.weekday_last().weekday();
2916 __parts -= __format::_ChronoParts::_Weekday;
2918 return _M_f._M_format(__cd, __fc);
2920 chrono::local_days __ld(__t);
2921 __parts = __cd._M_fill_ldays(__ld, __parts);
2923 return _M_f._M_format(__cd, __fc);
2925 auto __dom = __ld - chrono::local_days(__t.year()/__t.month()/0);
2926 __cd._M_fill_day(chrono::day(__dom.count()), __parts);
2927 return _M_f._M_format(__cd, __fc);
2931 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2933 using __format::_ChronoFormats;
2934 using enum __format::_ChronoParts;
2936 __format::_ChronoSpec<_CharT> __res{};
2937 __res._M_debug =
true;
2938 __res._M_localized =
true;
2939 __res._M_locale_specific =
true;
2940 __res._M_needed = _Year|_Month|_Weekday;
2941 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ymwl();
2945 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2948#if __glibcxx_print >= 202406L
2950 inline constexpr bool
2951 enable_nonlocking_formatter_optimization<chrono::year_month_weekday_last> =
true;
2954 template<
typename _Rep,
typename _Period, __format::__
char _CharT>
2955 struct formatter<
chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>, _CharT>
2957 constexpr typename basic_format_parse_context<_CharT>::iterator
2958 parse(basic_format_parse_context<_CharT>& __pc)
2960 using enum __format::_ChronoParts;
2961 return _M_f.template _M_parse<_Precision>(__pc, _Time, __defSpec);
2964 template<
typename _Out>
2965 typename basic_format_context<_Out, _CharT>::iterator
2966 format(
const chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>& __t,
2967 basic_format_context<_Out, _CharT>& __fc)
const
2969 using enum __format::_ChronoParts;
2971 __format::_ChronoData<_CharT> __cd;
2972 __cd._M_is_neg = __t.is_negative();
2973 __cd._M_hours = __t.hours();
2974 __cd._M_minutes = __t.minutes();
2975 __cd._M_seconds = __t.seconds();
2980 if (_M_f._M_spec._M_needs(_EpochUnits))
2981 __d = __t.to_duration();
2982 if (_M_f._M_spec._M_needs(_TotalSeconds))
2984 = __cd._M_hours + __cd._M_minutes + __cd._M_seconds;
2985 return _M_f._M_format_units(__cd, __d, __t.subseconds(), __fc);
2990 =
typename chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>::precision;
2991 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
2992 __format::__formatter_duration<_CharT>::
2993 template _S_spec_for<_Precision>(__format::_ChronoParts::_Time);
2995 __format::__formatter_duration<_CharT> _M_f{__defSpec};
2998#if __glibcxx_print >= 202406L
3001 template<
typename _Duration>
3003 enable_nonlocking_formatter_optimization<chrono::hh_mm_ss<_Duration>>
3004 = enable_nonlocking_formatter_optimization<_Duration>;
3007#if __glibcxx_chrono >= 201803L
3008 template<__format::__
char _CharT>
3009 struct formatter<
chrono::sys_info, _CharT>
3011 constexpr typename basic_format_parse_context<_CharT>::iterator
3012 parse(basic_format_parse_context<_CharT>& __pc)
3013 {
return _M_f.parse(__pc); }
3015 template<
typename _Out>
3016 typename basic_format_context<_Out, _CharT>::iterator
3017 format(
const chrono::sys_info& __i,
3018 basic_format_context<_Out, _CharT>& __fc)
const
3019 {
return _M_f.format(__i, __fc); }
3022 __format::__formatter_chrono_info<_CharT> _M_f;
3025#if __glibcxx_print >= 202406L
3027 inline constexpr bool
3028 enable_nonlocking_formatter_optimization<chrono::sys_info> =
true;
3031 template<__format::__
char _CharT>
3032 struct formatter<
chrono::local_info, _CharT>
3034 constexpr typename basic_format_parse_context<_CharT>::iterator
3035 parse(basic_format_parse_context<_CharT>& __pc)
3036 {
return _M_f.parse(__pc); }
3038 template<
typename _Out>
3039 typename basic_format_context<_Out, _CharT>::iterator
3040 format(
const chrono::local_info& __i,
3041 basic_format_context<_Out, _CharT>& __fc)
const
3042 {
return _M_f.format(__i, __fc); }
3045 __format::__formatter_chrono_info<_CharT> _M_f;
3048#if __glibcxx_print >= 202406L
3050 inline constexpr bool
3051 enable_nonlocking_formatter_optimization<chrono::local_info> =
true;
3055 template<
typename _Duration, __format::__
char _CharT>
3056 struct formatter<
chrono::sys_time<_Duration>, _CharT>
3058 constexpr typename basic_format_parse_context<_CharT>::iterator
3059 parse(basic_format_parse_context<_CharT>& __pc)
3061 using enum __format::_ChronoParts;
3063 = _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3064 if constexpr (__defSpec._M_chrono_specs.empty())
3065 if (_M_f._M_spec._M_chrono_specs.empty())
3066 __format::__invalid_chrono_spec();
3070 template<
typename _Out>
3071 typename basic_format_context<_Out, _CharT>::iterator
3072 format(
const chrono::sys_time<_Duration>& __t,
3073 basic_format_context<_Out, _CharT>& __fc)
const
3075 __format::_ChronoData<_CharT> __cd{};
3076 __cd._M_fill_utc_zone();
3078 _Duration __ed = __t.time_since_epoch();
3079 __cd._M_eseconds = chrono::floor<chrono::seconds>(__ed);
3080 __cd._M_lseconds = chrono::local_seconds(__cd._M_eseconds);
3081 return _M_f._M_format_time_point(__cd, __ed, __fc);
3085 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3086 __format::__formatter_duration<_CharT>::template _S_spec_for_tp<_Duration>();
3088 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3091#if __glibcxx_print >= 202406L
3094 template<
typename _Duration>
3096 enable_nonlocking_formatter_optimization<chrono::sys_time<_Duration>>
3097 = enable_nonlocking_formatter_optimization<_Duration>;
3100 template<
typename _Duration, __format::__
char _CharT>
3101 struct formatter<
chrono::utc_time<_Duration>, _CharT>
3103 constexpr typename basic_format_parse_context<_CharT>::iterator
3104 parse(basic_format_parse_context<_CharT>& __pc)
3106 using enum __format::_ChronoParts;
3107 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3110 template<
typename _Out>
3111 typename basic_format_context<_Out, _CharT>::iterator
3112 format(
const chrono::utc_time<_Duration>& __t,
3113 basic_format_context<_Out, _CharT>& __fc)
const
3115 using __format::_ChronoParts;
3116 using namespace chrono;
3117 __format::_ChronoData<_CharT> __cd{};
3118 __cd._M_fill_utc_zone();
3120 _Duration __ed = __t.time_since_epoch();
3121 __cd._M_eseconds = chrono::floor<seconds>(__ed);
3125 const auto __li = chrono::get_leap_second_info(__t);
3126 __cd._M_lseconds = local_seconds(__cd._M_eseconds - __li.elapsed);
3127 auto __parts = _M_f._M_spec._M_needed - _ChronoParts::_TotalSeconds;
3128 if ((__parts & _ChronoParts::_DateTime) != 0)
3130 __cd._M_fill_date_time(__cd._M_lseconds, __parts);
3131 __cd._M_seconds +=
seconds(__li.is_leap_second);
3133 return _M_f._M_format_units(__cd, __ed, __ed - __cd._M_eseconds, __fc);
3137 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3138 __format::__formatter_duration<_CharT>::
3139 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3141 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3144#if __glibcxx_print >= 202406L
3147 template<
typename _Duration>
3149 enable_nonlocking_formatter_optimization<chrono::utc_time<_Duration>>
3150 = enable_nonlocking_formatter_optimization<_Duration>;
3153 template<
typename _Duration, __format::__
char _CharT>
3154 struct formatter<
chrono::tai_time<_Duration>, _CharT>
3156 constexpr typename basic_format_parse_context<_CharT>::iterator
3157 parse(basic_format_parse_context<_CharT>& __pc)
3159 using enum __format::_ChronoParts;
3160 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3163 template<
typename _Out>
3164 typename basic_format_context<_Out, _CharT>::iterator
3165 format(
const chrono::tai_time<_Duration>& __t,
3166 basic_format_context<_Out, _CharT>& __fc)
const
3168 using namespace chrono;
3169 __format::_ChronoData<_CharT> __cd{};
3170 __cd._M_fill_zone(
"TAI", L
"TAI");
3172 _Duration __ed = __t.time_since_epoch();
3173 __cd._M_eseconds = chrono::floor<seconds>(__ed);
3175 constexpr chrono::days __tai_offset = chrono::days(4383);
3176 __cd._M_lseconds = local_seconds(__cd._M_eseconds - __tai_offset);
3177 return _M_f._M_format_time_point(__cd, __ed, __fc);
3181 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3182 __format::__formatter_duration<_CharT>::
3183 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3185 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3188#if __glibcxx_print >= 202406L
3191 template<
typename _Duration>
3193 enable_nonlocking_formatter_optimization<chrono::tai_time<_Duration>>
3194 = enable_nonlocking_formatter_optimization<_Duration>;
3197 template<
typename _Duration, __format::__
char _CharT>
3198 struct formatter<
chrono::gps_time<_Duration>, _CharT>
3200 constexpr typename basic_format_parse_context<_CharT>::iterator
3201 parse(basic_format_parse_context<_CharT>& __pc)
3203 using enum __format::_ChronoParts;
3204 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3207 template<
typename _Out>
3208 typename basic_format_context<_Out, _CharT>::iterator
3209 format(
const chrono::gps_time<_Duration>& __t,
3210 basic_format_context<_Out, _CharT>& __fc)
const
3212 using namespace chrono;
3213 __format::_ChronoData<_CharT> __cd{};
3214 __cd._M_fill_zone(
"GPS", L
"GPS");
3216 _Duration __ed = __t.time_since_epoch();
3217 __cd._M_eseconds = chrono::floor<seconds>(__ed);
3219 constexpr chrono::days __gps_offset = chrono::days(3657);
3220 __cd._M_lseconds = local_seconds(__cd._M_eseconds + __gps_offset);
3221 return _M_f._M_format_time_point(__cd, __ed, __fc);
3225 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3226 __format::__formatter_duration<_CharT>::
3227 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3229 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3232#if __glibcxx_print >= 202406L
3235 template<
typename _Duration>
3237 enable_nonlocking_formatter_optimization<chrono::gps_time<_Duration>>
3238 = enable_nonlocking_formatter_optimization<_Duration>;
3241 template<
typename _Duration, __format::__
char _CharT>
3242 struct formatter<
chrono::file_time<_Duration>, _CharT>
3244 constexpr typename basic_format_parse_context<_CharT>::iterator
3245 parse(basic_format_parse_context<_CharT>& __pc)
3247 using enum __format::_ChronoParts;
3248 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3251 template<
typename _Out>
3252 typename basic_format_context<_Out, _CharT>::iterator
3253 format(
const chrono::file_time<_Duration>& __t,
3254 basic_format_context<_Out, _CharT>& __fc)
const
3256 using namespace chrono;
3257 __format::_ChronoData<_CharT> __cd{};
3258 __cd._M_fill_utc_zone();
3260 _Duration __ed = __t.time_since_epoch();
3261 __cd._M_eseconds = chrono::floor<seconds>(__ed);
3262 auto __st = chrono::clock_cast<system_clock>(__t);
3264 = local_seconds(chrono::floor<seconds>(__st.time_since_epoch()));
3265 return _M_f._M_format_time_point(__cd, __ed, __fc);
3269 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3270 __format::__formatter_duration<_CharT>::
3271 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3273 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3276#if __glibcxx_print >= 202406L
3279 template<
typename _Duration>
3281 enable_nonlocking_formatter_optimization<chrono::file_time<_Duration>>
3282 = enable_nonlocking_formatter_optimization<_Duration>;
3285 template<
typename _Duration, __format::__
char _CharT>
3286 struct formatter<
chrono::local_time<_Duration>, _CharT>
3288 constexpr typename basic_format_parse_context<_CharT>::iterator
3289 parse(basic_format_parse_context<_CharT>& __pc)
3291 using enum __format::_ChronoParts;
3293 = _M_f.template _M_parse<_Duration>(__pc, _DateTime, __defSpec);
3294 if constexpr (__defSpec._M_chrono_specs.empty())
3295 if (_M_f._M_spec._M_chrono_specs.empty())
3296 __format::__invalid_chrono_spec();
3300 template<
typename _Out>
3301 typename basic_format_context<_Out, _CharT>::iterator
3302 format(
const chrono::local_time<_Duration>& __lt,
3303 basic_format_context<_Out, _CharT>& __fc)
const
3305 __format::_ChronoData<_CharT> __cd{};
3306 _Duration __ed = __lt.time_since_epoch();
3307 __cd._M_lseconds = chrono::floor<chrono::seconds>(__lt);
3308 __cd._M_eseconds = __cd._M_lseconds.time_since_epoch();
3309 return _M_f._M_format_time_point(__cd, __ed, __fc);
3313 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3314 __format::__formatter_duration<_CharT>::template _S_spec_for_tp<_Duration>();
3316 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3319#if __glibcxx_print >= 202406L
3322 template<
typename _Duration>
3324 enable_nonlocking_formatter_optimization<chrono::local_time<_Duration>>
3325 = enable_nonlocking_formatter_optimization<_Duration>;
3328 template<
typename _Duration, __format::__
char _CharT>
3329 struct formatter<
chrono::__detail::__local_time_fmt<_Duration>, _CharT>
3331 constexpr typename basic_format_parse_context<_CharT>::iterator
3332 parse(basic_format_parse_context<_CharT>& __pc)
3334 using enum __format::_ChronoParts;
3335 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3338 template<
typename _Out>
3339 typename basic_format_context<_Out, _CharT>::iterator
3340 format(
const chrono::__detail::__local_time_fmt<_Duration>& __zt,
3341 basic_format_context<_Out, _CharT>& __fc)
const
3343 using enum __format::_ChronoParts;
3344 __format::_ChronoData<_CharT> __cd{};
3346 if (_M_f._M_spec._M_needs(_ZoneOffset))
3348 if (!__zt._M_offset_sec)
3349 std::__throw_format_error(
"format error: no timezone available for %z");
3350 __cd._M_zone_offset = *__zt._M_offset_sec;
3353 basic_string<_CharT> __zone_store;
3354 if (_M_f._M_spec._M_needs(_ZoneAbbrev))
3356 if (!__zt._M_abbrev)
3357 std::__throw_format_error(
"format error: no timezone available for %Z");
3359 __cd._M_zone_cstr = __zt._M_abbrev->data();
3360 if constexpr (is_same_v<_CharT, char>)
3361 __cd._M_zone_abbrev = *__zt._M_abbrev;
3365 __zone_store.resize(__zt._M_abbrev->size());
3366 auto& __ct = use_facet<ctype<_CharT>>(_M_f._M_locale(__fc));
3367 __ct.widen(__zt._M_abbrev->data(),
3368 __zt._M_abbrev->data() + __zt._M_abbrev->size(),
3369 __zone_store.data());
3370 __cd._M_zone_abbrev = __zone_store;
3374 _Duration __ed = __zt._M_time.time_since_epoch();
3375 __cd._M_lseconds = chrono::floor<chrono::seconds>(__zt._M_time);
3376 __cd._M_eseconds = __cd._M_lseconds.time_since_epoch();
3377 return _M_f._M_format_time_point(__cd, __ed, __fc);
3381 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3382 __format::__formatter_duration<_CharT>::
3383 template _S_spec_for<_Duration>(__format::_ChronoParts::_ZonedDateTime);
3385 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3388#if __glibcxx_print >= 202406L
3391 template<
typename _Duration>
3393 enable_nonlocking_formatter_optimization<
3394 chrono::__detail::__local_time_fmt<_Duration>>
3395 = enable_nonlocking_formatter_optimization<_Duration>;
3398#if __glibcxx_chrono >= 201803L
3399 template<
typename _Duration,
typename _TimeZonePtr, __format::__
char _CharT>
3400 struct formatter<
chrono::zoned_time<_Duration, _TimeZonePtr>, _CharT>
3401 : formatter<chrono::__detail::__local_time_fmt_for<_Duration>, _CharT>
3403 template<
typename _Out>
3404 typename basic_format_context<_Out, _CharT>::iterator
3405 format(
const chrono::zoned_time<_Duration, _TimeZonePtr>& __tp,
3406 basic_format_context<_Out, _CharT>& __fc)
const
3408 using _Ltf = chrono::__detail::__local_time_fmt_for<_Duration>;
3409 using _Base = formatter<_Ltf, _CharT>;
3410 const chrono::sys_info __info = __tp.get_info();
3411 const auto __lf = chrono::local_time_format(__tp.get_local_time(),
3414 return _Base::format(__lf, __fc);
3418#if __glibcxx_print >= 202406L
3421 template<
typename _Duration>
3423 enable_nonlocking_formatter_optimization<
3424 chrono::zoned_time<_Duration, const chrono::time_zone*>>
3425 = enable_nonlocking_formatter_optimization<_Duration>;
3437 template<
typename _Duration = seconds>
3440 static_assert(is_same_v<common_type_t<_Duration, seconds>, _Duration>);
3443 _Parser(__format::_ChronoParts __need) : _M_need(__need) { }
3445 _Parser(_Parser&&) =
delete;
3446 void operator=(_Parser&&) =
delete;
3448 _Duration _M_time{};
3449 sys_days _M_sys_days{};
3450 year_month_day _M_ymd{};
3452 __format::_ChronoParts _M_need;
3453 unsigned _M_60th_second : 1 {};
3454 unsigned _M_reserved : 15 {};
3456 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3457 basic_istream<_CharT, _Traits>&
3458 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3459 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3460 minutes* __offset =
nullptr);
3465 template<
typename _CharT,
typename _Traits>
3466 static int_least32_t
3467 _S_read_unsigned(basic_istream<_CharT, _Traits>& __is,
3468 ios_base::iostate& __err,
int __n)
3470 int_least32_t __val = _S_try_read_digit(__is, __err);
3471 if (__val == -1) [[unlikely]]
3472 __err |= ios_base::failbit;
3477 for (
int __i = 1; __i < __n1; ++__i)
3478 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
3484 while (__n1++ < __n) [[unlikely]]
3485 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
3487 if (__builtin_mul_overflow(__val, 10, &__val)
3488 || __builtin_add_overflow(__val, __dig, &__val))
3490 __err |= ios_base::failbit;
3500 template<
typename _CharT,
typename _Traits>
3501 static int_least32_t
3502 _S_read_signed(basic_istream<_CharT, _Traits>& __is,
3503 ios_base::iostate& __err,
int __n)
3505 auto __sign = __is.peek();
3506 if (__sign ==
'-' || __sign ==
'+')
3508 int_least32_t __val = _S_read_unsigned(__is, __err, __n);
3509 if (__err & ios_base::failbit)
3511 if (__sign ==
'-') [[unlikely]]
3519 template<
typename _CharT,
typename _Traits>
3520 static int_least32_t
3521 _S_try_read_digit(basic_istream<_CharT, _Traits>& __is,
3522 ios_base::iostate& __err)
3524 int_least32_t __val = -1;
3525 auto __i = __is.peek();
3526 if (!_Traits::eq_int_type(__i, _Traits::eof())) [[likely]]
3528 _CharT __c = _Traits::to_char_type(__i);
3529 if (_CharT(
'0') <= __c && __c <= _CharT(
'9')) [[likely]]
3532 __val = __c - _CharT(
'0');
3536 __err |= ios_base::eofbit;
3542 template<
typename _CharT,
typename _Traits>
3544 _S_read_chr(basic_istream<_CharT, _Traits>& __is,
3545 ios_base::iostate& __err, _CharT __c)
3547 auto __i = __is.peek();
3548 if (_Traits::eq_int_type(__i, _Traits::eof()))
3549 __err |= ios_base::eofbit;
3550 else if (_Traits::to_char_type(__i) == __c) [[likely]]
3555 __err |= ios_base::failbit;
3560 template<
typename _Duration>
3561 using _Parser_t = _Parser<common_type_t<_Duration, seconds>>;
3563 template<
typename _Duration>
3567 if constexpr (_Duration::period::den == 1)
3569 switch (_Duration::period::num)
3571 case minutes::period::num:
3572 case hours::period::num:
3573 case days::period::num:
3574 case weeks::period::num:
3575 case years::period::num:
3592 template<
typename _ToDur,
typename _Tp>
3594 __round(
const _Tp& __t)
3596 if constexpr (__is_duration_v<_Tp>)
3598 if constexpr (treat_as_floating_point_v<typename _Tp::rep>)
3600 else if constexpr (__detail::__use_floor<_ToDur>())
3607 static_assert(__is_time_point_v<_Tp>);
3608 using _Tpt = time_point<typename _Tp::clock, _ToDur>;
3609 return _Tpt(__detail::__round<_ToDur>(__t.time_since_epoch()));
3618 template<
size_t _BufSize,
typename _CharT,
typename _Traits,
3619 typename _Arg,
typename... _OptLocale>
3620 inline basic_ostream<_CharT, _Traits>&
3621 __chrono_write(basic_ostream<_CharT, _Traits>& __os,
3622 const _Arg& __arg,
const _OptLocale&... __loc)
3624 static_assert(
sizeof...(_OptLocale) <= 1);
3626 = __format::__formatter_chrono<_CharT>::_S_empty_fs;
3627 constexpr size_t __bufsize = _BufSize;
3628 _CharT __buf[__bufsize];
3629 auto __res = std::format_to_n(__buf, __bufsize, __loc...,
3632 if (
static_cast<size_t>(__res.size) <= __bufsize) [[likely]]
3633 return std::__ostream_insert(__os, __buf, __res.size);
3635 auto __s = std::format(__loc..., __fs(), __arg);
3636 return std::__ostream_insert(__os, __s.data(), __s.size());
3641 template<
size_t _BufSize,
typename _TimePoint,
typename _CharT,
3643 [[__gnu__::__always_inline__]]
3644 inline basic_ostream<_CharT, _Traits>&
3645 __chrono_write_time(basic_ostream<_CharT, _Traits>& __os,
3646 const _TimePoint& __tp)
3648 using _Duration =
typename _TimePoint::duration;
3649 if constexpr (!treat_as_floating_point_v<typename _Duration::rep>
3650 && _Duration::period::den == 1)
3651 return __chrono_write<_BufSize>(__os, __tp);
3653 return __chrono_write<_BufSize>(__os, __tp, __os.getloc());
3659 template<
typename _CharT,
typename _Traits,
typename _Rep,
typename _Period,
3660 typename _Alloc = allocator<_CharT>>
3661 inline basic_istream<_CharT, _Traits>&
3662 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3664 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3667 auto __need = __format::_ChronoParts::_TimeOfDay;
3668 __detail::_Parser_t<duration<_Rep, _Period>> __p(__need);
3669 if (__p(__is, __fmt, __abbrev, __offset))
3670 __d = __detail::__round<duration<_Rep, _Period>>(__p._M_time);
3674 template<
typename _CharT,
typename _Traits>
3675 inline basic_ostream<_CharT, _Traits>&
3676 operator<<(basic_ostream<_CharT, _Traits>& __os,
const day& __d)
3677 {
return __detail::__chrono_write<32>(__os, __d); }
3679 template<
typename _CharT,
typename _Traits,
3680 typename _Alloc = allocator<_CharT>>
3681 inline basic_istream<_CharT, _Traits>&
3682 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3684 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3687 __detail::_Parser<> __p(__format::_ChronoParts::_Day);
3688 if (__p(__is, __fmt, __abbrev, __offset))
3689 __d = __p._M_ymd.day();
3693 template<
typename _CharT,
typename _Traits>
3694 inline basic_ostream<_CharT, _Traits>&
3695 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month& __m)
3696 {
return __detail::__chrono_write<64>(__os, __m, __os.getloc()); }
3698 template<
typename _CharT,
typename _Traits,
3699 typename _Alloc = allocator<_CharT>>
3700 inline basic_istream<_CharT, _Traits>&
3701 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3703 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3706 __detail::_Parser<> __p(__format::_ChronoParts::_Month);
3707 if (__p(__is, __fmt, __abbrev, __offset))
3708 __m = __p._M_ymd.month();
3712 template<
typename _CharT,
typename _Traits>
3713 inline basic_ostream<_CharT, _Traits>&
3714 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year& __y)
3715 {
return __detail::__chrono_write<32>(__os, __y); }
3717 template<
typename _CharT,
typename _Traits,
3718 typename _Alloc = allocator<_CharT>>
3719 inline basic_istream<_CharT, _Traits>&
3720 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3722 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3725 __detail::_Parser<> __p(__format::_ChronoParts::_Year);
3726 if (__p(__is, __fmt, __abbrev, __offset))
3727 __y = __p._M_ymd.year();
3731 template<
typename _CharT,
typename _Traits>
3732 inline basic_ostream<_CharT, _Traits>&
3733 operator<<(basic_ostream<_CharT, _Traits>& __os,
const weekday& __wd)
3734 {
return __detail::__chrono_write<64>(__os, __wd, __os.getloc()); }
3736 template<
typename _CharT,
typename _Traits,
3737 typename _Alloc = allocator<_CharT>>
3738 inline basic_istream<_CharT, _Traits>&
3739 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3741 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3744 __detail::_Parser<> __p(__format::_ChronoParts::_Weekday);
3745 if (__p(__is, __fmt, __abbrev, __offset))
3750 template<
typename _CharT,
typename _Traits>
3751 inline basic_ostream<_CharT, _Traits>&
3752 operator<<(basic_ostream<_CharT, _Traits>& __os,
3753 const weekday_indexed& __wdi)
3754 {
return __detail::__chrono_write<128>(__os, __wdi, __os.getloc()); }
3756 template<
typename _CharT,
typename _Traits>
3757 inline basic_ostream<_CharT, _Traits>&
3758 operator<<(basic_ostream<_CharT, _Traits>& __os,
3759 const weekday_last& __wdl)
3760 {
return __detail::__chrono_write<128>(__os, __wdl, __os.getloc()); }
3762 template<
typename _CharT,
typename _Traits>
3763 inline basic_ostream<_CharT, _Traits>&
3764 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month_day& __md)
3765 {
return __detail::__chrono_write<128>(__os, __md, __os.getloc()); }
3767 template<
typename _CharT,
typename _Traits,
3768 typename _Alloc = allocator<_CharT>>
3769 inline basic_istream<_CharT, _Traits>&
3770 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3772 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3775 using __format::_ChronoParts;
3776 auto __need = _ChronoParts::_Month | _ChronoParts::_Day;
3777 __detail::_Parser<> __p(__need);
3778 if (__p(__is, __fmt, __abbrev, __offset))
3779 __md = month_day(__p._M_ymd.month(), __p._M_ymd.day());
3783 template<
typename _CharT,
typename _Traits>
3784 inline basic_ostream<_CharT, _Traits>&
3785 operator<<(basic_ostream<_CharT, _Traits>& __os,
3786 const month_day_last& __mdl)
3787 {
return __detail::__chrono_write<128>(__os, __mdl, __os.getloc()); }
3789 template<
typename _CharT,
typename _Traits>
3790 inline basic_ostream<_CharT, _Traits>&
3791 operator<<(basic_ostream<_CharT, _Traits>& __os,
3792 const month_weekday& __mwd)
3793 {
return __detail::__chrono_write<128>(__os, __mwd, __os.getloc()); }
3795 template<
typename _CharT,
typename _Traits>
3796 inline basic_ostream<_CharT, _Traits>&
3797 operator<<(basic_ostream<_CharT, _Traits>& __os,
3798 const month_weekday_last& __mwdl)
3799 {
return __detail::__chrono_write<128>(__os, __mwdl, __os.getloc()); }
3801 template<
typename _CharT,
typename _Traits>
3802 inline basic_ostream<_CharT, _Traits>&
3803 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year_month& __ym)
3804 {
return __detail::__chrono_write<128>(__os, __ym, __os.getloc()); }
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::_Year | _ChronoParts::_Month;
3816 __detail::_Parser<> __p(__need);
3817 if (__p(__is, __fmt, __abbrev, __offset))
3818 __ym = year_month(__p._M_ymd.year(), __p._M_ymd.month());
3822 template<
typename _CharT,
typename _Traits>
3823 inline basic_ostream<_CharT, _Traits>&
3824 operator<<(basic_ostream<_CharT, _Traits>& __os,
3825 const year_month_day& __ymd)
3826 {
return __detail::__chrono_write<64>(__os, __ymd); }
3828 template<
typename _CharT,
typename _Traits,
3829 typename _Alloc = allocator<_CharT>>
3830 inline basic_istream<_CharT, _Traits>&
3831 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3832 year_month_day& __ymd,
3833 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3836 using __format::_ChronoParts;
3837 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3838 | _ChronoParts::_Day;
3839 __detail::_Parser<> __p(__need);
3840 if (__p(__is, __fmt, __abbrev, __offset))
3845 template<
typename _CharT,
typename _Traits>
3846 inline basic_ostream<_CharT, _Traits>&
3847 operator<<(basic_ostream<_CharT, _Traits>& __os,
3848 const year_month_day_last& __ymdl)
3849 {
return __detail::__chrono_write<128>(__os, __ymdl, __os.getloc()); }
3851 template<
typename _CharT,
typename _Traits>
3852 inline basic_ostream<_CharT, _Traits>&
3853 operator<<(basic_ostream<_CharT, _Traits>& __os,
3854 const year_month_weekday& __ymwd)
3855 {
return __detail::__chrono_write<128>(__os, __ymwd, __os.getloc()); }
3857 template<
typename _CharT,
typename _Traits>
3858 inline basic_ostream<_CharT, _Traits>&
3859 operator<<(basic_ostream<_CharT, _Traits>& __os,
3860 const year_month_weekday_last& __ymwdl)
3861 {
return __detail::__chrono_write<128>(__os, __ymwdl, __os.getloc()); }
3863 template<
typename _CharT,
typename _Traits,
typename _Duration>
3864 inline basic_ostream<_CharT, _Traits>&
3865 operator<<(basic_ostream<_CharT, _Traits>& __os,
3868 if constexpr (!treat_as_floating_point_v<typename _Duration::rep>
3869 && _Duration::period::den == 1)
3870 return __detail::__chrono_write<64>(__os, __hms);
3872 return __detail::__chrono_write<64>(__os, __hms, __os.getloc());
3875#if __glibcxx_chrono >= 201803L
3877 template<typename _CharT, typename _Traits>
3878 basic_ostream<_CharT, _Traits>&
3879 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_info& __i)
3880 {
return __detail::__chrono_write<128>(__os, __i); }
3883 template<
typename _CharT,
typename _Traits>
3884 basic_ostream<_CharT, _Traits>&
3885 operator<<(basic_ostream<_CharT, _Traits>& __os,
const local_info& __li)
3886 {
return __detail::__chrono_write<256>(__os, __li); }
3888 template<
typename _CharT,
typename _Traits,
typename _Duration,
3889 typename _TimeZonePtr>
3890 inline basic_ostream<_CharT, _Traits>&
3891 operator<<(basic_ostream<_CharT, _Traits>& __os,
3892 const zoned_time<_Duration, _TimeZonePtr>& __t)
3893 {
return __detail::__chrono_write_time<128>(__os, __t); }
3896 template<
typename _CharT,
typename _Traits,
typename _Duration>
3897 requires (!treat_as_floating_point_v<typename _Duration::rep>)
3898 && ratio_less_v<typename _Duration::period, days::period>
3899 inline basic_ostream<_CharT, _Traits>&
3900 operator<<(basic_ostream<_CharT, _Traits>& __os,
3901 const sys_time<_Duration>& __tp)
3902 {
return __detail::__chrono_write_time<64>(__os, __tp); }
3904 template<
typename _CharT,
typename _Traits>
3905 inline basic_ostream<_CharT, _Traits>&
3906 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_days& __dp)
3907 {
return __detail::__chrono_write<32>(__os, __dp); }
3909 template<
typename _CharT,
typename _Traits,
typename _Duration,
3910 typename _Alloc = allocator<_CharT>>
3911 basic_istream<_CharT, _Traits>&
3912 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3913 sys_time<_Duration>& __tp,
3914 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3920 using __format::_ChronoParts;
3921 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3922 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
3923 __detail::_Parser_t<_Duration> __p(__need);
3924 if (__p(__is, __fmt, __abbrev, __offset))
3926 if (__p._M_60th_second)
3930 auto __st = __p._M_sys_days + __p._M_time - *__offset;
3931 __tp = __detail::__round<_Duration>(__st);
3937 template<
typename _CharT,
typename _Traits,
typename _Duration>
3938 inline basic_ostream<_CharT, _Traits>&
3939 operator<<(basic_ostream<_CharT, _Traits>& __os,
3940 const utc_time<_Duration>& __t)
3941 {
return __detail::__chrono_write_time<64>(__os, __t); }
3943 template<
typename _CharT,
typename _Traits,
typename _Duration,
3944 typename _Alloc = allocator<_CharT>>
3945 inline basic_istream<_CharT, _Traits>&
3946 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3947 utc_time<_Duration>& __tp,
3948 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3954 using __format::_ChronoParts;
3955 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3956 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
3957 __detail::_Parser_t<_Duration> __p(__need);
3958 if (__p(__is, __fmt, __abbrev, __offset))
3962 auto __ut = utc_clock::from_sys(__p._M_sys_days) + __p._M_time
3965 if (__p._M_60th_second
3967 || !chrono::get_leap_second_info(__ut).is_leap_second))
3970 __tp = __detail::__round<_Duration>(__ut);
3975 template<
typename _CharT,
typename _Traits,
typename _Duration>
3976 inline basic_ostream<_CharT, _Traits>&
3977 operator<<(basic_ostream<_CharT, _Traits>& __os,
3978 const tai_time<_Duration>& __t)
3979 {
return __detail::__chrono_write_time<64>(__os, __t); }
3981 template<
typename _CharT,
typename _Traits,
typename _Duration,
3982 typename _Alloc = allocator<_CharT>>
3983 inline basic_istream<_CharT, _Traits>&
3984 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3985 tai_time<_Duration>& __tp,
3986 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3992 using __format::_ChronoParts;
3993 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3994 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
3995 __detail::_Parser_t<_Duration> __p(__need);
3996 if (__p(__is, __fmt, __abbrev, __offset))
3998 if (__p._M_60th_second)
4002 constexpr sys_days __epoch(-
days(4383));
4003 auto __d = __p._M_sys_days - __epoch + __p._M_time - *__offset;
4004 tai_time<common_type_t<_Duration, seconds>> __tt(__d);
4005 __tp = __detail::__round<_Duration>(__tt);
4011 template<
typename _CharT,
typename _Traits,
typename _Duration>
4012 inline basic_ostream<_CharT, _Traits>&
4013 operator<<(basic_ostream<_CharT, _Traits>& __os,
4014 const gps_time<_Duration>& __t)
4015 {
return __detail::__chrono_write_time<64>(__os, __t); }
4017 template<
typename _CharT,
typename _Traits,
typename _Duration,
4018 typename _Alloc = allocator<_CharT>>
4019 inline basic_istream<_CharT, _Traits>&
4020 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4021 gps_time<_Duration>& __tp,
4022 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4028 using __format::_ChronoParts;
4029 auto __need = _ChronoParts::_YearMonthDay | _ChronoParts::_TimeOfDay;
4030 __detail::_Parser_t<_Duration> __p(__need);
4031 if (__p(__is, __fmt, __abbrev, __offset))
4033 if (__p._M_60th_second)
4037 constexpr sys_days __epoch(
days(3657));
4038 auto __d = __p._M_sys_days - __epoch + __p._M_time - *__offset;
4039 gps_time<common_type_t<_Duration, seconds>> __gt(__d);
4040 __tp = __detail::__round<_Duration>(__gt);
4046 template<
typename _CharT,
typename _Traits,
typename _Duration>
4047 inline basic_ostream<_CharT, _Traits>&
4048 operator<<(basic_ostream<_CharT, _Traits>& __os,
4049 const file_time<_Duration>& __t)
4050 {
return __detail::__chrono_write_time<64>(__os, __t); }
4052 template<
typename _CharT,
typename _Traits,
typename _Duration,
4053 typename _Alloc = allocator<_CharT>>
4054 inline basic_istream<_CharT, _Traits>&
4055 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4056 file_time<_Duration>& __tp,
4057 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4060 sys_time<_Duration> __st;
4061 if (chrono::from_stream(__is, __fmt, __st, __abbrev, __offset))
4062 __tp = __detail::__round<_Duration>(file_clock::from_sys(__st));
4066 template<
typename _CharT,
typename _Traits,
typename _Duration>
4067 inline basic_ostream<_CharT, _Traits>&
4068 operator<<(basic_ostream<_CharT, _Traits>& __os,
4069 const local_time<_Duration>& __lt)
4072 requires requires(
const sys_time<_Duration>& __st) { __os << __st; }
4073 {
return __detail::__chrono_write_time<64>(__os, __lt); }
4075 template<
typename _CharT,
typename _Traits,
typename _Duration,
4076 typename _Alloc = allocator<_CharT>>
4077 basic_istream<_CharT, _Traits>&
4078 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4079 local_time<_Duration>& __tp,
4080 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4083 using __format::_ChronoParts;
4084 auto __need = _ChronoParts::_YearMonthDay | _ChronoParts::_TimeOfDay;
4085 __detail::_Parser_t<_Duration> __p(__need);
4086 if (__p(__is, __fmt, __abbrev, __offset))
4088 days __d = __p._M_sys_days.time_since_epoch();
4089 auto __t = local_days(__d) + __p._M_time;
4090 __tp = __detail::__round<_Duration>(__t);
4101 void from_stream() =
delete;
4103 template<
typename _Parsable,
typename _CharT,
4104 typename _Traits = std::char_traits<_CharT>,
4105 typename... _OptArgs>
4106 concept __parsable =
requires (basic_istream<_CharT, _Traits>& __is,
4107 const _CharT* __fmt, _Parsable& __tp,
4108 _OptArgs*... __args)
4109 { from_stream(__is, __fmt, __tp, __args...); };
4111 template<
typename _Parsable,
typename _CharT,
4112 typename _Traits = char_traits<_CharT>,
4113 typename _Alloc = allocator<_CharT>>
4117 using __string_type = basic_string<_CharT, _Traits, _Alloc>;
4120 _Parse(
const _CharT* __fmt, _Parsable& __tp,
4121 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4124 _M_abbrev(__abbrev), _M_offset(__offset)
4127 _Parse(_Parse&&) =
delete;
4128 _Parse& operator=(_Parse&&) =
delete;
4131 using __stream_type = basic_istream<_CharT, _Traits>;
4133 const _CharT*
const _M_fmt;
4134 _Parsable*
const _M_tp;
4135 __string_type*
const _M_abbrev;
4138 friend __stream_type&
4139 operator>>(__stream_type& __is, _Parse&& __p)
4142 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev,
4144 else if (__p._M_abbrev)
4145 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev);
4147 from_stream(__is, __p._M_fmt, *__p._M_tp);
4151 friend void operator>>(__stream_type&, _Parse&) =
delete;
4152 friend void operator>>(__stream_type&,
const _Parse&) =
delete;
4156 template<
typename _CharT, __detail::__parsable<_CharT> _Parsable>
4157 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4159 parse(
const _CharT* __fmt, _Parsable& __tp)
4160 {
return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp); }
4162 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4163 __detail::__parsable<_CharT, _Traits> _Parsable>
4166 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp)
4168 return __detail::_Parse<_Parsable, _CharT, _Traits>(__fmt.c_str(), __tp);
4171 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4172 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4173 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
4174 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4176 parse(
const _CharT* __fmt, _Parsable& __tp,
4177 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
4180 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
4184 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4185 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4186 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
4189 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
4190 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
4193 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
4197 template<
typename _CharT,
typename _Traits =
char_traits<_CharT>,
4198 typename _StrT = basic_
string<_CharT, _Traits>,
4199 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4200 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4202 parse(
const _CharT* __fmt, _Parsable& __tp,
minutes& __offset)
4204 return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp,
nullptr,
4208 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4209 typename _StrT = basic_string<_CharT, _Traits>,
4210 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4213 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
4216 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
4221 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4222 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4223 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4224 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4226 parse(
const _CharT* __fmt, _Parsable& __tp,
4227 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
4230 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
4235 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4236 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4237 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4240 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
4241 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
4244 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
4250 template<
typename _Duration>
4251 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4252 basic_istream<_CharT, _Traits>&
4253 __detail::_Parser<_Duration>::
4254 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4255 basic_string<_CharT, _Traits, _Alloc>* __abbrev,
4258 using sentry =
typename basic_istream<_CharT, _Traits>::sentry;
4260 if (sentry __cerb(__is,
true); __cerb)
4262 locale __loc = __is.getloc();
4267 struct _Stream_state
4270 _Stream_state(basic_istream<_CharT, _Traits>& __i)
4272 _M_flags(__i.flags(ios_base::
skipws | ios_base::
dec)),
4278 _M_is.flags(_M_flags);
4282 _Stream_state(_Stream_state&&) =
delete;
4284 basic_istream<_CharT, _Traits>& _M_is;
4285 ios_base::fmtflags _M_flags;
4295 auto __read_unsigned = [&] (
int __n) {
4296 return _S_read_unsigned(__is, __err, __n);
4301 auto __read_signed = [&] (
int __n) {
4302 return _S_read_signed(__is, __err, __n);
4306 auto __read_chr = [&__is, &__err] (_CharT __c) {
4307 return _S_read_chr(__is, __err, __c);
4310 using __format::_ChronoParts;
4311 _ChronoParts __parts{};
4313 const year __bad_y = --year::min();
4314 const month __bad_mon(255);
4315 const day __bad_day(255);
4316 const weekday __bad_wday(255);
4317 const hours __bad_h(-1);
4318 const minutes __bad_min(-9999);
4321 year __y = __bad_y, __yy = __bad_y;
4322 year __iso_y = __bad_y, __iso_yy = __bad_y;
4323 month __m = __bad_mon;
4324 day __d = __bad_day;
4325 weekday __wday = __bad_wday;
4326 hours __h = __bad_h, __h12 = __bad_h;
4328 _Duration __s = __bad_sec;
4330 int __iso_wk = -1, __sunday_wk = -1, __monday_wk = -1;
4332 int __dayofyear = -1;
4334 minutes __tz_offset = __bad_min;
4335 basic_string<_CharT, _Traits> __tz_abbr;
4337 if ((_M_need & _ChronoParts::_TimeOfDay) != 0
4338 && (_M_need & _ChronoParts::_Year) != 0)
4344 __parts = _ChronoParts::_TimeOfDay;
4351 bool __is_flag =
false;
4353 constexpr bool __is_floating
4354 = treat_as_floating_point_v<typename _Duration::rep>;
4373 _CharT __c = *__fmt++;
4380 else if (!__read_chr(__c)) [[unlikely]]
4391 if (__mod || __num) [[unlikely]]
4396 __tmget.get(__is, {}, __is, __err, &__tm,
4398 if (!__is_failed(__err))
4399 __wday = weekday(__tm.tm_wday);
4401 __parts |= _ChronoParts::_Weekday;
4407 if (__mod || __num) [[unlikely]]
4415 __tmget.get(__is, {}, __is, __err, &__tm,
4417 if (!__is_failed(__err))
4418 __m = month(__tm.tm_mon + 1);
4420 __parts |= _ChronoParts::_Month;
4424 if (__mod ==
'O' || __num) [[unlikely]]
4429 __tmget.get(__is, {}, __is, __err, &__tm,
4430 __fmt - 2 - (__mod ==
'E'), __fmt);
4431 if (!__is_failed(__err))
4433 __y = year(__tm.tm_year + 1900);
4434 __m = month(__tm.tm_mon + 1);
4435 __d = day(__tm.tm_mday);
4436 __h =
hours(__tm.tm_hour);
4441 __parts |= _ChronoParts::_DateTime;
4445 if (!__mod) [[likely]]
4447 auto __v = __read_signed(__num ? __num : 2);
4448 if (!__is_failed(__err))
4450 int __cmin = (int)year::min() / 100;
4451 int __cmax = (int)year::max() / 100;
4452 if (__cmin <= __v && __v <= __cmax)
4453 __century = __v * 100;
4458 else if (__mod ==
'E')
4461 __tmget.get(__is, {}, __is, __err, &__tm,
4463 if (!__is_failed(__err))
4464 __century = __tm.tm_year;
4473 if (!__mod) [[likely]]
4475 auto __v = __read_unsigned(__num ? __num : 2);
4476 if (!__is_failed(__err))
4479 else if (__mod ==
'O')
4482 __tmget.get(__is, {}, __is, __err, &__tm,
4484 if (!__is_failed(__err))
4485 __d = day(__tm.tm_mday);
4489 __parts |= _ChronoParts::_Day;
4493 if (__mod || __num) [[unlikely]]
4497 auto __month = __read_unsigned(2);
4499 auto __day = __read_unsigned(2);
4501 auto __year = __read_unsigned(2);
4502 if (__is_failed(__err))
4504 __y = year(__year + 1900 + 100 *
int(__year < 69));
4505 __m = month(__month);
4507 if (!year_month_day(__y, __m, __d).ok())
4509 __y = __yy = __iso_y = __iso_yy = __bad_y;
4515 __parts |= _ChronoParts::_Date;
4519 if (__mod) [[unlikely]]
4523 auto __year = __read_signed(__num ? __num : 4);
4525 auto __month = __read_unsigned(2);
4527 auto __day = __read_unsigned(2);
4528 if (__is_failed(__err))
4531 __m = month(__month);
4533 if (!year_month_day(__y, __m, __d).ok())
4535 __y = __yy = __iso_y = __iso_yy = __bad_y;
4541 __parts |= _ChronoParts::_Date;
4545 if (__mod) [[unlikely]]
4549 auto __val = __read_unsigned(__num ? __num : 2);
4550 if (__val >= 0 && __val <= 99)
4552 __iso_yy = year(__val);
4553 if (__century == -1)
4557 __iso_yy = __iso_y = __y = __yy = __bad_y;
4559 __parts |= _ChronoParts::_Year;
4563 if (__mod) [[unlikely]]
4566 __iso_y = year(__read_unsigned(__num ? __num : 4));
4567 __parts |= _ChronoParts::_Year;
4572 if (__mod ==
'E') [[unlikely]]
4574 else if (__mod ==
'O')
4579 __tmget.get(__is, {}, __is, __err, &__tm,
4581 if (!__is_failed(__err))
4585 __h12 =
hours(__tm.tm_hour);
4589 __h =
hours(__tm.tm_hour);
4598 auto __val = __read_unsigned(__num ? __num : 2);
4599 if (__c ==
'I' && __val >= 1 && __val <= 12)
4601 __h12 =
hours(__val);
4604 else if (__c ==
'H' && __val >= 0 && __val <= 23)
4611 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4616 __parts |= _ChronoParts::_TimeOfDay;
4620 if (__mod) [[unlikely]]
4622 else if (_M_need == _ChronoParts::_TimeOfDay)
4624 auto __val = __read_signed(__num ? __num : 3);
4625 if (!__is_failed(__err))
4628 __parts |= _ChronoParts::_TimeOfDay;
4633 __dayofyear = __read_unsigned(__num ? __num : 3);
4640 if (__mod ==
'E') [[unlikely]]
4642 else if (__mod ==
'O')
4645 __tmget.get(__is, {}, __is, __err, &__tm,
4647 if (!__is_failed(__err))
4648 __m = month(__tm.tm_mon + 1);
4652 auto __val = __read_unsigned(__num ? __num : 2);
4653 if (__val >= 1 && __val <= 12)
4658 __parts |= _ChronoParts::_Month;
4662 if (__mod ==
'E') [[unlikely]]
4664 else if (__mod ==
'O')
4667 __tmget.get(__is, {}, __is, __err, &__tm,
4669 if (!__is_failed(__err))
4674 auto __val = __read_unsigned(__num ? __num : 2);
4675 if (0 <= __val && __val < 60)
4679 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4684 __parts |= _ChronoParts::_TimeOfDay;
4694 const _CharT* __ampms[2];
4695 __tmpunct._M_am_pm(__ampms);
4696 int __n = 0, __which = 3;
4697 while (__which != 0)
4699 auto __i = __is.peek();
4700 if (_Traits::eq_int_type(__i, _Traits::eof()))
4710 else if (__ampms[0][__n + 1] == _CharT())
4721 else if (__ampms[1][__n + 1] == _CharT())
4732 if (__which == 0 || __which == 3)
4745 __tmget.get(__is, {}, __is, __err, &__tm,
4747 if (!__is_failed(__err))
4749 __h =
hours(__tm.tm_hour);
4754 __parts |= _ChronoParts::_TimeOfDay;
4759 if (__mod || __num) [[unlikely]]
4766 auto __val = __read_unsigned(2);
4767 if (__val == -1 || __val > 23) [[unlikely]]
4768 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4773 if (!__read_chr(
':')) [[unlikely]]
4777 __val = __read_unsigned(2);
4778 if (__val == -1 || __val > 59) [[unlikely]]
4779 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4788 __parts |= _ChronoParts::_TimeOfDay;
4791 else if (!__read_chr(
':')) [[unlikely]]
4797 if (__mod ==
'E') [[unlikely]]
4799 else if (__mod ==
'O')
4802 __tmget.get(__is, {}, __is, __err, &__tm,
4804 if (!__is_failed(__err))
4807 else if constexpr (_Duration::period::den == 1
4810 auto __val = __read_unsigned(__num ? __num : 2);
4811 if (0 <= __val && __val <= 60) [[likely]]
4817 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4825 auto __digit = _S_try_read_digit(__is, __err);
4828 __buf.put(
'0' + __digit);
4829 __digit = _S_try_read_digit(__is, __err);
4831 __buf.put(
'0' + __digit);
4834 auto __i = __is.peek();
4835 if (_Traits::eq_int_type(__i, _Traits::eof()))
4843 __dp = __np.decimal_point();
4845 _CharT __c = _Traits::to_char_type(__i);
4851 = hh_mm_ss<_Duration>::fractional_width;
4854 __digit = _S_try_read_digit(__is, __err);
4856 __buf.put(
'0' + __digit);
4864 if (!__is_failed(__err)) [[likely]]
4866 long double __val{};
4867#if __cpp_lib_to_chars
4869 auto __first = __str.data();
4870 auto __last = __first + __str.size();
4874 if ((
bool)ec || ptr != __last) [[unlikely]]
4882 if constexpr (__is_floating)
4889 __parts |= _ChronoParts::_TimeOfDay;
4894 if (__mod ==
'E') [[unlikely]]
4896 else if (__mod ==
'O')
4901 __tmget.get(__is, {}, __is, __err, &__tm,
4903 if (!__is_failed(__err))
4904 __wday = weekday(__tm.tm_wday);
4911 const int __lo = __c ==
'u' ? 1 : 0;
4912 const int __hi = __lo + 6;
4913 auto __val = __read_unsigned(__num ? __num : 1);
4914 if (__lo <= __val && __val <= __hi)
4915 __wday = weekday(__val);
4918 __wday = __bad_wday;
4922 __parts |= _ChronoParts::_Weekday;
4928 if (__mod ==
'E') [[unlikely]]
4930 else if (__mod ==
'O')
4932 if (__c ==
'V') [[unlikely]]
4942 const int __lo = __c ==
'V' ? 1 : 0;
4943 const int __hi = 53;
4944 auto __val = __read_unsigned(__num ? __num : 2);
4945 if (__lo <= __val && __val <= __hi)
4950 __sunday_wk = __val;
4956 __monday_wk = __val;
4961 __iso_wk = __sunday_wk = __monday_wk = -1;
4967 if (__mod ==
'O' || __num) [[unlikely]]
4972 __tmget.get(__is, {}, __is, __err, &__tm,
4973 __fmt - 2 - (__mod ==
'E'), __fmt);
4974 if (!__is_failed(__err))
4976 __y = year(__tm.tm_year + 1900);
4977 __m = month(__tm.tm_mon + 1);
4978 __d = day(__tm.tm_mday);
4981 __parts |= _ChronoParts::_Date;
4985 if (__mod ==
'O' || __num) [[unlikely]]
4990 __tmget.get(__is, {}, __is, __err, &__tm,
4991 __fmt - 2 - (__mod ==
'E'), __fmt);
4992 if (!__is_failed(__err))
4994 __h =
hours(__tm.tm_hour);
4999 __parts |= _ChronoParts::_TimeOfDay;
5003 if (__mod) [[unlikely]]
5006 __tmget.get(__is, {}, __is, __err, &__tm,
5008 if (!__is_failed(__err))
5010 int __cent = __tm.tm_year < 2000 ? 1900 : 2000;
5011 __yy = year(__tm.tm_year - __cent);
5012 if (__century == -1)
5018 auto __val = __read_unsigned(__num ? __num : 2);
5019 if (__val >= 0 && __val <= 99)
5022 if (__century == -1)
5023 __century = __val < 69 ? 2000 : 1900;
5026 __y = __yy = __iso_yy = __iso_y = __bad_y;
5028 __parts |= _ChronoParts::_Year;
5032 if (__mod ==
'O') [[unlikely]]
5034 else if (__mod ==
'E')
5037 __tmget.get(__is, {}, __is, __err, &__tm,
5039 if (!__is_failed(__err))
5040 __y = year(__tm.tm_year);
5044 auto __val = __read_unsigned(__num ? __num : 4);
5045 if (!__is_failed(__err))
5048 __parts |= _ChronoParts::_Year;
5052 if (__num) [[unlikely]]
5059 auto __i = __is.peek();
5060 if (_Traits::eq_int_type(__i, _Traits::eof()))
5065 _CharT __ic = _Traits::to_char_type(__i);
5066 const bool __neg = __ic == _CharT(
'-');
5067 if (__ic == _CharT(
'-') || __ic == _CharT(
'+'))
5074 __hh = __read_unsigned(2);
5079 auto __d1 = _S_try_read_digit(__is, __err);
5080 auto __d2 = _S_try_read_digit(__is, __err);
5081 if (__d1 >= 0 && __d2 >= 0) [[likely]]
5082 __hh = 10 * __d1 + __d2;
5087 if (__is_failed(__err))
5091 if (_Traits::eq_int_type(__i, _Traits::eof()))
5094 __tz_offset =
minutes(__hh * (__neg ? -60 : 60));
5097 __ic = _Traits::to_char_type(__i);
5099 bool __read_mm =
false;
5102 if (__ic == _GLIBCXX_WIDEN(
":")[0])
5109 else if (_CharT(
'0') <= __ic && __ic <= _CharT(
'9'))
5115 int_least32_t __mm = 0;
5118 auto __d1 = _S_try_read_digit(__is, __err);
5119 auto __d2 = _S_try_read_digit(__is, __err);
5120 if (__d1 >= 0 && __d2 >= 0) [[likely]]
5121 __mm = 10 * __d1 + __d2;
5126 if (!__is_failed(__err))
5128 auto __z = __hh * 60 + __mm;
5129 __tz_offset =
minutes(__neg ? -__z : __z);
5135 if (__mod || __num) [[unlikely]]
5139 basic_string_view<_CharT> __x = _GLIBCXX_WIDEN(
"_/-+");
5143 auto __i = __is.peek();
5144 if (!_Traits::eq_int_type(__i, _Traits::eof()))
5146 _CharT __a = _Traits::to_char_type(__i);
5148 || __x.find(__a) != __x.npos)
5150 __tz_abbr.push_back(__a);
5159 if (__tz_abbr.empty())
5165 if (__mod || __num) [[unlikely]]
5169 _CharT __i = __is.peek();
5170 if (_Traits::eq_int_type(__i, _Traits::eof()))
5172 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
5180 if (__mod || __num) [[unlikely]]
5184 _CharT __i = __is.peek();
5185 if (_Traits::eq_int_type(__i, _Traits::eof()))
5187 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
5193 if (__mod || __num) [[unlikely]]
5201 if (__mod || __num) [[unlikely]]
5210 if (_CharT(
'1') <= __c && __c <= _CharT(
'9'))
5212 if (!__mod) [[likely]]
5215 auto __end = __fmt + _Traits::length(__fmt);
5217 = __format::__parse_integer(__fmt - 1, __end);
5218 if (__ptr) [[likely]]
5229 if (__is_failed(__err)) [[unlikely]]
5239 if (__yy != __bad_y && __y == __bad_y)
5240 __y =
years(__century) + __yy;
5241 if (__iso_yy != __bad_y && __iso_y == __bad_y)
5242 __iso_y =
years(__century) + __iso_yy;
5245 bool __can_use_doy =
false;
5246 bool __can_use_iso_wk =
false;
5247 bool __can_use_sun_wk =
false;
5248 bool __can_use_mon_wk =
false;
5251 if (__y != __bad_y && __dayofyear >= 0)
5253 __can_use_doy =
true;
5254 __parts |= _ChronoParts::_Date;
5256 else if (__y != __bad_y && __wday != __bad_wday && __sunday_wk >= 0)
5258 __can_use_sun_wk =
true;
5259 __parts |= _ChronoParts::_Date;
5261 else if (__y != __bad_y && __wday != __bad_wday && __monday_wk >= 0)
5263 __can_use_mon_wk =
true;
5264 __parts |= _ChronoParts::_Date;
5266 else if (__iso_y != __bad_y && __wday != __bad_wday && __iso_wk > 0)
5269 __can_use_iso_wk =
true;
5270 __parts |= _ChronoParts::_Date;
5273 if (__is_failed(__err)) [[unlikely]]
5275 else if (__is_flag) [[unlikely]]
5277 else if ((_M_need & __parts) == _M_need) [[likely]]
5299 const bool __need_wday = (_M_need & _ChronoParts::_Weekday) != 0;
5303 const bool __need_time = (_M_need & _ChronoParts::_TimeOfDay) != 0;
5305 if (__need_wday && __wday != __bad_wday)
5307 else if ((_M_need & _ChronoParts::_Date) != 0)
5311 const bool __need_ymd = !__need_wday && !__need_time;
5313 if (((_M_need & _ChronoParts::_Year) != 0 && __y == __bad_y)
5314 || ((_M_need & _ChronoParts::_Month) != 0 && __m == __bad_mon)
5315 || ((_M_need & _ChronoParts::_Day) != 0 && __d == __bad_day))
5322 if ((0 < __dayofyear && __dayofyear <= 365)
5323 || (__dayofyear == 366 && __y.is_leap()))
5326 _M_sys_days = sys_days(__y/January/1)
5327 +
days(__dayofyear - 1);
5329 _M_ymd = year_month_day(_M_sys_days);
5334 else if (__can_use_iso_wk)
5342 const sys_days __jan4(__iso_y/January/4);
5343 weekday __wd1(__jan4 -
days(3));
5344 if (__wd1 != Thursday)
5345 if (__wd1 != Wednesday || !__iso_y.is_leap())
5349 if (!__is_failed(__err)) [[likely]]
5352 sys_days __w(Thursday[1]/January/__iso_y);
5354 __w -= Thursday - Monday;
5356 __w += __wday - Monday;
5360 _M_ymd = year_month_day(_M_sys_days);
5363 else if (__can_use_sun_wk)
5366 sys_days __wk1(__y/January/Sunday[1]);
5367 _M_sys_days = __wk1 +
weeks(__sunday_wk - 1)
5368 +
days(__wday.c_encoding());
5369 _M_ymd = year_month_day(_M_sys_days);
5370 if (_M_ymd.year() != __y) [[unlikely]]
5373 else if (__can_use_mon_wk)
5376 sys_days __wk1(__y/January/Monday[1]);
5377 _M_sys_days = __wk1 +
weeks(__monday_wk - 1)
5378 +
days(__wday.c_encoding() - 1);
5379 _M_ymd = year_month_day(_M_sys_days);
5380 if (_M_ymd.year() != __y) [[unlikely]]
5392 if ((_M_need & _ChronoParts::_Year) != 0)
5394 if (!__y.ok()) [[unlikely]]
5397 else if (__y == __bad_y)
5400 if ((_M_need & _ChronoParts::_Month) != 0)
5402 if (!__m.ok()) [[unlikely]]
5405 else if (__m == __bad_mon)
5408 if ((_M_need & _ChronoParts::_Day) != 0)
5410 if (__d < day(1) || __d > (__y/__m/last).day())
5413 else if (__d == __bad_day)
5416 if (year_month_day __ymd(__y, __m, __d); __ymd.ok())
5419 if (__need_wday || __need_time)
5420 _M_sys_days = sys_days(_M_ymd);
5427 _M_wd = weekday(_M_sys_days);
5433 if (__h == __bad_h && __h12 != __bad_h)
5437 else if (__ampm == 2)
5438 __h = __h12 ==
hours(12) ? __h12 : __h12 +
hours(12);
5443 auto __t = _M_time.zero();
5452 if (__min != __bad_min)
5458 if (__s != __bad_sec)
5464 _M_60th_second = __s >=
seconds(60);
5473 if (!__is_failed(__err)) [[likely]]
5475 if (__offset && __tz_offset != __bad_min)
5476 *__offset = __tz_offset;
5477 if (__abbrev && !__tz_abbr.empty())
5485 __is.setstate(__err);
5489#undef _GLIBCXX_WIDEN
5494_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.
Provides compile-time rational arithmetic.
Controlling output for std::string.
A non-owning reference to a string.
locale imbue(const locale &__loc)
Moves to a new locale.
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...
Template class basic_ostream.
Provides output iterator semantics for streambufs.
static const locale & classic()
Return reference to the C locale.