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>
1660 _M_subsecs(
const _ChronoData<_CharT>& __t, _OutIter __out,
1661 _FormatContext& __ctx)
const
1663 unsigned __prec = _M_spec._M_prec_kind != _WP_none
1664 ? _M_spec._M_get_precision(__ctx)
1669 _CharT __dot = _S_dot;
1670 if (_M_spec._M_localized) [[unlikely]]
1672 auto __loc = __ctx.locale();
1673 const auto& __np = use_facet<numpunct<_CharT>>(__loc);
1674 __dot = __np.decimal_point();
1679 if (_M_spec._M_floating_point_rep)
1681 _Str_sink<_CharT> __sink;
1682 if (_M_spec._M_localized && _M_spec._M_custom_rep) [[unlikely]]
1683 std::vformat_to(__sink.out(), __ctx.locale(),
1684 _GLIBCXX_WIDEN(
"{1:0.{2}Lf}"), __t._M_ereps);
1686 std::vformat_to(__sink.out(),
1687 _GLIBCXX_WIDEN(
"{1:0.{2}f}"), __t._M_ereps);
1689 auto __sv = __sink.view();
1691 __sv.remove_prefix(2);
1692 return __format::__write(
std::move(__out), __sv);
1695 constexpr unsigned __max_prec = _ChronoData<_CharT>::_S_max_prec;
1696 constexpr typename _ChronoData<_CharT>::_Attoseconds::rep __pow10t[]
1700 10'000u, 100'000u, 1000'000u,
1701 10'000'000u, 100'000'000u, 1000'000'000u,
1702 10'000'000'000u, 100'000'000'000u, 1000'000'000'000u,
1703 10'000'000'000'000u, 100'000'000'000'000u, 1000'000'000'000'000u,
1704 10'000'000'000'000'000u, 100'000'000'000'000'000u, 1000'000'000'000'000'000u,
1707 auto __subs = __t._M_subseconds.count();
1708 if (__prec < __max_prec)
1709 __subs /= __pow10t[__max_prec - __prec];
1710 else if (__prec > __max_prec)
1711 __prec = __max_prec;
1713 using _FmtStr = _Dynamic_format_string<_CharT>;
1714 return std::format_to(__out, _FmtStr(_GLIBCXX_WIDEN(
"{0:0{1}}")),
1720 template<
typename _OutIter,
typename _FormatContext>
1722 _M_T(
const _ChronoData<_CharT>& __t, _OutIter __out,
1723 _FormatContext& __ctx)
const
1726 __out = _M_R_X(__t,
std::move(__out),
true);
1727 return _M_subsecs(__t,
std::move(__out), __ctx);
1730 template<
typename _OutIter>
1732 _M_u_w(chrono::weekday __wd, _OutIter __out, _CharT __conv)
const
1738 unsigned __wdi = __conv ==
'u' ? __wd.iso_encoding()
1739 : __wd.c_encoding();
1741 return __format::__write(
std::move(__out), _S_str_d1(__buf, __wdi));
1744 template<
typename _OutIter>
1746 _M_U_W(
const _ChronoData<_CharT>& __t, _OutIter __out,
1747 _CharT __conv)
const
1754 using namespace chrono;
1755 const weekday __weekstart = __conv ==
'U' ? Sunday : Monday;
1756 const days __offset = __t._M_weekday - __weekstart;
1757 auto __weeks = chrono::floor<weeks>(__t._M_day_of_year - __offset -
days(1));
1758 return __format::__write(
std::move(__out), _S_two_digits(__weeks.count() + 1));
1761 template<
typename _OutIter>
1763 _M_z(chrono::seconds __ts, _OutIter __out,
bool __mod =
false)
const
1767 __string_view __zero
1768 = __mod ? _GLIBCXX_WIDEN(
"+00:00") : _GLIBCXX_WIDEN(
"+0000");
1769 return __format::__write(
std::move(__out), __zero);
1772 chrono::hh_mm_ss<chrono::seconds> __hms(__ts);
1773 unsigned __mo = 3 + __mod;
1776 __buf[0] = _S_plus_minus[__hms.is_negative()];
1777 __buf[3] = _S_colon;
1778 _S_fill_two_digits(__buf + 1, __hms.hours().count());
1779 _S_fill_two_digits(__buf + __mo, __hms.minutes().count());
1781 __string_view __sv(__buf, __mo + 2);
1782 return __format::__write(
std::move(__out), __sv);
1785 template<
typename _OutIter>
1787 _M_Z(__string_view __abbrev, _OutIter __out)
const
1788 {
return __format::__write(
std::move(__out), __abbrev); }
1793 static basic_string_view<_CharT>
1794 _S_digit(
int __n)
noexcept
1797 return { _GLIBCXX_WIDEN(
"0123456789999999") + (__n & 0xf), 1 };
1801 static basic_string_view<_CharT>
1802 _S_two_digits(
int __n)
noexcept
1805 _GLIBCXX_WIDEN(
"0001020304050607080910111213141516171819"
1806 "2021222324252627282930313233343536373839"
1807 "4041424344454647484950515253545556575859"
1808 "6061626364656667686970717273747576777879"
1809 "8081828384858687888990919293949596979899"
1810 "9999999999999999999999999999999999999999"
1811 "9999999999999999") + 2 * (__n & 0x7f),
1817 [[__gnu__::__always_inline__]]
1819 _S_fill_two_digits(_CharT* __buf,
unsigned __n)
1821 auto __sv = _S_two_digits(__n);
1827 [[__gnu__::__always_inline__]]
1829 _S_fill_ampm(_CharT* __buf, chrono::hours __h)
1831 auto __hi = __h.count();
1832 if (__hi >= 24) [[unlikely]]
1835 constexpr const _CharT* __apm = _GLIBCXX_WIDEN(
"APM");
1836 __buf[0] = __apm[__hi >= 12];
1837 __buf[1] = __apm[2];
1842 [[__gnu__::__always_inline__]]
1843 static basic_string_view<_CharT>
1844 _S_str_d1(span<_CharT, 3> __buf,
unsigned __n)
1846 if (__n < 10) [[likely]]
1847 return _S_digit(__n);
1848 return _S_str_d2(__buf, __n);
1853 [[__gnu__::__always_inline__]]
1854 static basic_string_view<_CharT>
1855 _S_str_d2(span<_CharT, 3> __buf,
unsigned __n)
1857 if (__n < 100) [[likely]]
1858 return _S_two_digits(__n);
1859 return _S_str_d3(__buf, __n);
1864 [[__gnu__::__always_inline__]]
1865 static basic_string_view<_CharT>
1866 _S_str_d3(span<_CharT, 3> __buf,
unsigned __n)
1868 _S_fill_two_digits(__buf.data(), __n / 10);
1869 __buf[2] = _S_chars[__n % 10];
1870 return __string_view(__buf.data(), 3);
1874 template<
typename _CharT>
1875 struct __formatter_duration :
private __formatter_chrono<_CharT>
1877 template<
typename _Rep,
typename _Period>
1878 constexpr static auto
1879 _S_subseconds(
const chrono::duration<_Rep, _Period>& __d)
1881 if constexpr (chrono::treat_as_floating_point_v<_Rep>)
1882 return chrono::duration<_Rep>(__d);
1883 else if constexpr (_Period::den == 1)
1884 return chrono::seconds(0);
1887 using _Attoseconds = _ChronoData<_CharT>::_Attoseconds;
1888 using _CRep = common_type_t<_Rep, typename _Attoseconds::rep>;
1889 chrono::duration<_CRep, _Period> __subs(__d.count());
1890 return chrono::duration_cast<_Attoseconds>(__subs);
1895 template<
typename _Duration>
1898 _S_spec_for(_ChronoParts __parts)
1900 using _Rep =
typename _Duration::rep;
1901 using enum _ChronoParts;
1903 _ChronoSpec<_CharT> __res{};
1904 __res._M_floating_point_rep = chrono::treat_as_floating_point_v<_Rep>;
1905 __res._M_custom_rep = !is_arithmetic_v<_Rep>;
1906 __res._M_prec = chrono::hh_mm_ss<_Duration>::fractional_width;
1907 if ((__parts & _TimeOfDay) != 0)
1908 __res._M_localized = __res._M_prec > 0 || __res._M_floating_point_rep;
1910 if ((__parts & _TimeOfDay) != 0)
1911 __res._M_needed |= _TimeOfDay;
1912 if ((__parts & _Date) != 0)
1913 __res._M_needed |= _YearMonthDay;
1914 if ((__parts & _ZoneAbbrev) != 0)
1915 __res._M_needed |= _ZoneAbbrev;
1919 case _ZonedDateTime:
1920 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ftz();
1923 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ft();
1926 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_f();
1929 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_t();
1934 __builtin_unreachable();
1939 template<
typename _Duration>
1944 using enum _ChronoParts;
1946 constexpr bool __stream_insertable =
1947 requires (basic_ostream<_CharT>& __os, chrono::sys_time<_Duration> __t)
1949 if constexpr (!__stream_insertable)
1950 return _S_spec_for<_Duration>(_None);
1951 else if constexpr (is_convertible_v<_Duration, chrono::days>)
1952 return _S_spec_for<_Duration>(_Date);
1954 return _S_spec_for<_Duration>(_DateTime);
1957 using __formatter_chrono<_CharT>::__formatter_chrono;
1958 using __formatter_chrono<_CharT>::_M_spec;
1960 template<
typename _Duration>
1961 constexpr typename basic_format_parse_context<_CharT>::iterator
1962 _M_parse(basic_format_parse_context<_CharT>& __pc, _ChronoParts __parts,
1963 const _ChronoSpec<_CharT>& __def)
1965 using _Rep =
typename _Duration::rep;
1966 using enum _ChronoParts;
1969 = __formatter_chrono<_CharT>::_M_parse(__pc, __parts, __def);
1972 _M_spec._M_needs_ok_check =
false;
1977 if constexpr (!is_floating_point_v<_Rep>)
1978 if constexpr (chrono::treat_as_floating_point_v<_Rep>)
1979 if (_M_spec._M_needs(_Subseconds|_EpochUnits)
1980 || _M_spec._M_prec_kind != _WP_none
1981 || _M_spec._M_prec_value > 0)
1983 constexpr const _CharT* __fs = _GLIBCXX_WIDEN(
"#02.5Lf");
1984 basic_format_parse_context<_CharT> __npc(__fs);
1985 formatter<_Rep, _CharT> __fmtter;
1986 __fmtter.parse(__npc);
1992 template<
typename _FormatContext>
1994 _M_locale(_FormatContext& __fc)
const
1996 if (!_M_spec._M_localized)
1999 return __fc.locale();
2003 template<
typename _Rep,
typename _Period,
typename _FormatContext>
2004 typename _FormatContext::iterator
2005 _M_format_to_ostream(
const chrono::duration<_Rep, _Period>& __d,
2007 _FormatContext& __fc)
const
2009 basic_ostringstream<_CharT> __os;
2010 __os.imbue(this->_M_locale(__fc));
2012 if (__is_neg) [[unlikely]]
2013 __os << this->_S_plus_minus[1];
2017 return __format::__write_padded_as_spec(__str, __str.size(),
2021 template<
typename _Rep1,
typename _Period1,
2022 typename _Rep2,
typename _Period2,
2023 typename _FormatContext>
2024 typename _FormatContext::iterator
2025 _M_format_units(_ChronoData<_CharT>& __cd,
2026 const chrono::duration<_Rep1, _Period1>& __ed,
2027 const chrono::duration<_Rep2, _Period2>& __ss,
2028 _FormatContext& __fc)
const
2030 __format::_Str_sink<_CharT> __suffix_store;
2031 constexpr auto _S_unit_suffix
2032 = chrono::__detail::__units_suffix<_Period1, _CharT>();
2033 if constexpr (!_S_unit_suffix.empty())
2034 __cd._M_unit_suffix = _S_unit_suffix;
2035 else if (_M_spec._M_needs(_ChronoParts::_UnitSuffix))
2038 __fmt_units_suffix<_Period1, _CharT>(__suffix_store.out());
2039 __cd._M_unit_suffix = __suffix_store.view();
2042 const auto __prec = _M_spec._M_prec_kind != _WP_none
2043 ? _M_spec._M_get_precision(__fc)
2046 using _ErasedContext =
typename _ChronoData<_CharT>::_FormatContext;
2049 auto __ereps = +__ed.count();
2050 if (!_M_spec._M_needs(_ChronoParts::_Subseconds))
2054 = std::make_format_args<_ErasedContext>(__ereps, __ssreps, __prec);
2055 __cd._M_ereps = __args_store;
2056 return this->_M_format(__cd, __fc);
2059 using _Attoseconds = _ChronoData<_CharT>::_Attoseconds;
2060 auto __nss = _S_subseconds(__ss);
2061 __cd._M_subseconds = chrono::duration_cast<_Attoseconds>(__nss);
2063 auto __ssreps = __nss.count();
2065 = std::make_format_args<_ErasedContext>(__ereps, __ssreps, __prec);
2066 __cd._M_ereps = __args_store;
2068 return this->_M_format(__cd, __fc);
2072 template<
typename _Rep1,
typename _Period1,
typename _FormatContext>
2073 typename _FormatContext::iterator
2074 _M_format_time_point(_ChronoData<_CharT>& __cd,
2075 const chrono::duration<_Rep1, _Period1>& __ed,
2076 _FormatContext& __fc)
const
2078 auto __parts = _M_spec._M_needed - _ChronoParts::_TotalSeconds;
2079 if ((__parts & _ChronoParts::_DateTime) != 0)
2080 __cd._M_fill_date_time(__cd._M_lseconds, __parts);
2081 return _M_format_units(__cd, __ed, __ed - __cd._M_eseconds, __fc);
2085#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2086 template<
typename _CharT>
2087 struct __formatter_chrono_info
2089 constexpr typename basic_format_parse_context<_CharT>::iterator
2090 parse(basic_format_parse_context<_CharT>& __pc)
2091 {
return _M_f._M_parse(__pc, _ChronoParts(), {}); }
2093 template<
typename _Info,
typename _Out>
2094 typename basic_format_context<_Out, _CharT>::iterator
2095 format(
const _Info& __i,
2096 basic_format_context<_Out, _CharT>& __fc)
const
2100 if (!_M_f._M_spec._M_chrono_specs.empty()) [[unlikely]]
2101 return _M_f._M_format(_ChronoData<_CharT>{}, __fc);
2103 const size_t __padwidth = _M_f._M_spec._M_get_width(__fc);
2104 if (__padwidth == 0)
2105 return _M_format_to(__fc.out(), __i);
2107 _Padding_sink<_Out, _CharT> __sink(__fc.out(), __padwidth);
2108 _M_format_to(__sink.out(), __i);
2109 return __sink._M_finish(_M_f._M_spec._M_align, _M_f._M_spec._M_fill);
2113 template<
typename _Out>
2115 _M_format_to(_Out __out,
const chrono::sys_info& __si)
const
2117 using _FmtStr = _Dynamic_format_string<_CharT>;
2121 constexpr auto* __fs
2122 = _GLIBCXX_WIDEN(
"[{0:%F %T},{1:%F %T},{2:%T},{3:%Q%q},{0:%Z}]");
2123 const chrono::local_seconds __lb(__si.begin.time_since_epoch());
2124 return std::format_to(
std::move(__out), _FmtStr(__fs),
2125 chrono::local_time_format(__lb, &__si.abbrev),
2126 __si.end, __si.offset, __si.save);
2129 template<
typename _Out>
2131 _M_format_to(_Out __out,
const chrono::local_info& __li)
const
2133 *__out = _Separators<_CharT>::_S_squares()[0];
2135 if (__li.result == chrono::local_info::unique)
2136 __out = _M_format_to(
std::move(__out), __li.first);
2139 basic_string_view<_CharT> __sv;
2140 if (__li.result == chrono::local_info::nonexistent)
2141 __sv =_GLIBCXX_WIDEN(
"nonexistent");
2143 __sv = _GLIBCXX_WIDEN(
"ambiguous");
2144 __out = __format::__write(
std::move(__out), __sv);
2146 __sv = _GLIBCXX_WIDEN(
" local time between ");
2147 __out = __format::__write(
std::move(__out), __sv);
2148 __out = _M_format_to(
std::move(__out), __li.first);
2150 __sv = _GLIBCXX_WIDEN(
" and ");
2151 __out = __format::__write(
std::move(__out), __sv);
2152 __out = _M_format_to(
std::move(__out), __li.second);
2154 *__out = _Separators<_CharT>::_S_squares()[1];
2159 __formatter_chrono<_CharT> _M_f;
2166 template<
typename _Rep,
typename _Period,
typename _CharT>
2167 requires __format::__formattable_impl<_Rep, _CharT>
2168 struct formatter<
chrono::duration<_Rep, _Period>, _CharT>
2170 constexpr typename basic_format_parse_context<_CharT>::iterator
2171 parse(basic_format_parse_context<_CharT>& __pc)
2173 using enum __format::_ChronoParts;
2174 return _M_f.template _M_parse<_Duration>(__pc, _EpochTime, __defSpec);
2177 template<
typename _Out>
2178 typename basic_format_context<_Out, _CharT>::iterator
2179 format(
const chrono::duration<_Rep, _Period>& __d,
2180 basic_format_context<_Out, _CharT>& __fc)
const
2182 if constexpr (numeric_limits<_Rep>::is_signed)
2183 if (__d < __d.zero()) [[unlikely]]
2185 if constexpr (is_integral_v<_Rep>)
2189 using _URep = make_unsigned_t<_Rep>;
2190 auto __ucnt = -
static_cast<_URep
>(__d.count());
2191 auto __ud = chrono::duration<_URep, _Period>(__ucnt);
2192 return _M_format(__ud,
true, __fc);
2195 return _M_format(-__d,
true, __fc);
2197 return _M_format(__d,
false, __fc);
2201 using _Duration = chrono::duration<_Rep, _Period>;
2203 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2205 using enum __format::_ChronoParts;
2206 auto __res = __format::__formatter_duration<_CharT>::
2207 template _S_spec_for<_Duration>(_None);
2208 __res._M_localized = !is_integral_v<_Rep>;
2210 if constexpr (is_integral_v<_Rep>)
2212 __res._M_needed = _EpochUnits|_UnitSuffix;
2213 __res._M_chrono_specs = _GLIBCXX_WIDEN(
"%Q%q");
2218 template<
typename _Rep2,
typename _Out>
2219 typename basic_format_context<_Out, _CharT>::iterator
2220 _M_format(
const chrono::duration<_Rep2, _Period>& __d,
2222 basic_format_context<_Out, _CharT>& __fc)
const
2224 using namespace chrono;
2225 using enum __format::_ChronoParts;
2226 if constexpr (!is_integral_v<_Rep>)
2227 if (_M_f._M_spec._M_chrono_specs.empty())
2228 return _M_f._M_format_to_ostream(__d, __is_neg, __fc);
2230 __format::_ChronoData<_CharT> __cd;
2231 __cd._M_is_neg = __is_neg;
2232 auto __ts = chrono::floor<chrono::seconds>(__d);
2233 __cd._M_eseconds = __ts;
2234 if (_M_f._M_spec._M_needs(_HoursMinutesSeconds))
2235 __cd._M_fill_time(__ts);
2236 return _M_f._M_format_units(__cd, __d, __d - __ts, __fc);
2239 __format::__formatter_duration<_CharT> _M_f{__defSpec};
2242#if __glibcxx_print >= 202406L
2245 template<
typename _Rep,
typename _Period>
2247 enable_nonlocking_formatter_optimization<chrono::duration<_Rep, _Period>>
2248 = is_arithmetic_v<_Rep>;
2251 template<__format::__
char _CharT>
2252 struct formatter<
chrono::day, _CharT>
2254 constexpr typename basic_format_parse_context<_CharT>::iterator
2255 parse(basic_format_parse_context<_CharT>& __pc)
2257 using enum __format::_ChronoParts;
2258 return _M_f._M_parse(__pc, _Day|_WeekdayIndex, __defSpec);
2261 template<
typename _Out>
2262 typename basic_format_context<_Out, _CharT>::iterator
2263 format(
const chrono::day& __t,
2264 basic_format_context<_Out, _CharT>& __fc)
const
2266 __format::_ChronoData<_CharT> __cd{};
2267 __cd._M_fill_day(__t, __defSpec._M_needed);
2268 return _M_f._M_format(__cd, __fc);
2272 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2274 using __format::_ChronoFormats;
2275 using enum __format::_ChronoParts;
2277 __format::_ChronoSpec<_CharT> __res{};
2278 __res._M_debug =
true;
2279 __res._M_needed = _Day;
2280 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_d();
2284 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2287#if __glibcxx_print >= 202406L
2289 inline constexpr bool
2290 enable_nonlocking_formatter_optimization<chrono::day> =
true;
2293 template<__format::__
char _CharT>
2294 struct formatter<
chrono::month, _CharT>
2296 constexpr typename basic_format_parse_context<_CharT>::iterator
2297 parse(basic_format_parse_context<_CharT>& __pc)
2299 using enum __format::_ChronoParts;
2300 return _M_f._M_parse(__pc, _Month, __defSpec);
2303 template<
typename _Out>
2304 typename basic_format_context<_Out, _CharT>::iterator
2305 format(
const chrono::month& __t,
2306 basic_format_context<_Out, _CharT>& __fc)
const
2308 __format::_ChronoData<_CharT> __cd{};
2309 __cd._M_month = __t;
2310 return _M_f._M_format(__cd, __fc);
2314 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2316 using __format::_ChronoFormats;
2317 using enum __format::_ChronoParts;
2319 __format::_ChronoSpec<_CharT> __res{};
2320 __res._M_debug =
true;
2321 __res._M_localized =
true;
2322 __res._M_locale_specific =
true;
2323 __res._M_needed = _Month;
2324 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_m();
2328 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2331#if __glibcxx_print >= 202406L
2333 inline constexpr bool
2334 enable_nonlocking_formatter_optimization<chrono::month> =
true;
2337 template<__format::__
char _CharT>
2338 struct formatter<
chrono::year, _CharT>
2340 constexpr typename basic_format_parse_context<_CharT>::iterator
2341 parse(basic_format_parse_context<_CharT>& __pc)
2343 using enum __format::_ChronoParts;
2344 return _M_f._M_parse(__pc, _Year, __defSpec);
2347 template<
typename _Out>
2348 typename basic_format_context<_Out, _CharT>::iterator
2349 format(
const chrono::year& __t,
2350 basic_format_context<_Out, _CharT>& __fc)
const
2352 __format::_ChronoData<_CharT> __cd{};
2354 return _M_f._M_format(__cd, __fc);
2358 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2360 using __format::_ChronoFormats;
2361 using enum __format::_ChronoParts;
2363 __format::_ChronoSpec<_CharT> __res{};
2364 __res._M_debug =
true;
2365 __res._M_needed = _Year;
2366 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_y();
2370 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2373#if __glibcxx_print >= 202406L
2375 inline constexpr bool
2376 enable_nonlocking_formatter_optimization<chrono::year> =
true;
2379 template<__format::__
char _CharT>
2380 struct formatter<
chrono::weekday, _CharT>
2382 constexpr typename basic_format_parse_context<_CharT>::iterator
2383 parse(basic_format_parse_context<_CharT>& __pc)
2385 using enum __format::_ChronoParts;
2386 return _M_f._M_parse(__pc, _Weekday, __defSpec);
2389 template<
typename _Out>
2390 typename basic_format_context<_Out, _CharT>::iterator
2391 format(
const chrono::weekday& __t,
2392 basic_format_context<_Out, _CharT>& __fc)
const
2394 __format::_ChronoData<_CharT> __cd{};
2395 __cd._M_weekday = __t;
2396 return _M_f._M_format(__cd, __fc);
2400 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2402 using __format::_ChronoFormats;
2403 using enum __format::_ChronoParts;
2405 __format::_ChronoSpec<_CharT> __res{};
2406 __res._M_debug =
true;
2407 __res._M_localized =
true;
2408 __res._M_locale_specific =
true;
2409 __res._M_needed = _Weekday;
2410 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_w();
2414 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2417#if __glibcxx_print >= 202406L
2419 inline constexpr bool
2420 enable_nonlocking_formatter_optimization<chrono::weekday> =
true;
2423 template<__format::__
char _CharT>
2424 struct formatter<
chrono::weekday_indexed, _CharT>
2426 constexpr typename basic_format_parse_context<_CharT>::iterator
2427 parse(basic_format_parse_context<_CharT>& __pc)
2429 using enum __format::_ChronoParts;
2430 return _M_f._M_parse(__pc, _IndexedWeekday, __defSpec);
2433 template<
typename _Out>
2434 typename basic_format_context<_Out, _CharT>::iterator
2435 format(
const chrono::weekday_indexed& __t,
2436 basic_format_context<_Out, _CharT>& __fc)
const
2438 __format::_ChronoData<_CharT> __cd{};
2439 __cd._M_fill_weekday(__t, __defSpec._M_needed);
2440 return _M_f._M_format(__cd, __fc);
2444 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2446 using __format::_ChronoFormats;
2447 using enum __format::_ChronoParts;
2449 __format::_ChronoSpec<_CharT> __res{};
2450 __res._M_debug =
true;
2451 __res._M_localized =
true;
2452 __res._M_locale_specific =
true;
2453 __res._M_needed = _IndexedWeekday;
2454 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_wi();
2458 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2461#if __glibcxx_print >= 202406L
2463 inline constexpr bool
2464 enable_nonlocking_formatter_optimization<chrono::weekday_indexed> =
true;
2467 template<__format::__
char _CharT>
2468 struct formatter<
chrono::weekday_last, _CharT>
2470 constexpr typename basic_format_parse_context<_CharT>::iterator
2471 parse(basic_format_parse_context<_CharT>& __pc)
2473 using enum __format::_ChronoParts;
2474 return _M_f._M_parse(__pc, _Weekday, __defSpec);
2477 template<
typename _Out>
2478 typename basic_format_context<_Out, _CharT>::iterator
2479 format(
const chrono::weekday_last& __t,
2480 basic_format_context<_Out, _CharT>& __fc)
const
2482 __format::_ChronoData<_CharT> __cd{};
2483 __cd._M_weekday = __t.weekday();
2484 return _M_f._M_format(__cd, __fc);
2488 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2490 using __format::_ChronoFormats;
2491 using enum __format::_ChronoParts;
2493 __format::_ChronoSpec<_CharT> __res{};
2494 __res._M_debug =
true;
2495 __res._M_localized =
true;
2496 __res._M_locale_specific =
true;
2497 __res._M_needed = _Weekday;
2498 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_wl();
2502 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2505#if __glibcxx_print >= 202406L
2507 inline constexpr bool
2508 enable_nonlocking_formatter_optimization<chrono::weekday_last> =
true;
2511 template<__format::__
char _CharT>
2512 struct formatter<
chrono::month_day, _CharT>
2514 constexpr typename basic_format_parse_context<_CharT>::iterator
2515 parse(basic_format_parse_context<_CharT>& __pc)
2517 using enum __format::_ChronoParts;
2518 return _M_f._M_parse(__pc, _Month|_Day|_WeekdayIndex, __defSpec);
2521 template<
typename _Out>
2522 typename basic_format_context<_Out, _CharT>::iterator
2523 format(
const chrono::month_day& __t,
2524 basic_format_context<_Out, _CharT>& __fc)
const
2526 __format::_ChronoData<_CharT> __cd{};
2527 __cd._M_month = __t.month();
2528 __cd._M_fill_day(__t.day(), __defSpec._M_needed);
2529 return _M_f._M_format(__cd, __fc);
2533 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2535 using __format::_ChronoFormats;
2536 using enum __format::_ChronoParts;
2538 __format::_ChronoSpec<_CharT> __res{};
2539 __res._M_debug =
true;
2540 __res._M_localized =
true;
2541 __res._M_locale_specific =
true;
2542 __res._M_needed = _Month|_Day;
2543 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_md();
2547 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2550#if __glibcxx_print >= 202406L
2552 inline constexpr bool
2553 enable_nonlocking_formatter_optimization<chrono::month_day> =
true;
2556 template<__format::__
char _CharT>
2557 struct formatter<
chrono::month_day_last, _CharT>
2559 constexpr typename basic_format_parse_context<_CharT>::iterator
2560 parse(basic_format_parse_context<_CharT>& __pc)
2562 using enum __format::_ChronoParts;
2563 return _M_f._M_parse(__pc, _Month, __defSpec);
2566 template<
typename _Out>
2567 typename basic_format_context<_Out, _CharT>::iterator
2568 format(
const chrono::month_day_last& __t,
2569 basic_format_context<_Out, _CharT>& __fc)
const
2571 __format::_ChronoData<_CharT> __cd{};
2572 __cd._M_month = __t.month();
2573 return _M_f._M_format(__cd, __fc);
2577 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2579 using __format::_ChronoFormats;
2580 using enum __format::_ChronoParts;
2582 __format::_ChronoSpec<_CharT> __res{};
2583 __res._M_debug =
true;
2584 __res._M_localized =
true;
2585 __res._M_locale_specific =
true;
2586 __res._M_needed = _Month;
2587 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ml();
2591 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2594#if __glibcxx_print >= 202406L
2596 inline constexpr bool
2597 enable_nonlocking_formatter_optimization<chrono::month_day_last> =
true;
2600 template<__format::__
char _CharT>
2601 struct formatter<
chrono::month_weekday, _CharT>
2603 constexpr typename basic_format_parse_context<_CharT>::iterator
2604 parse(basic_format_parse_context<_CharT>& __pc)
2606 using enum __format::_ChronoParts;
2607 return _M_f._M_parse(__pc, _Month|_IndexedWeekday, __defSpec);
2610 template<
typename _Out>
2611 typename basic_format_context<_Out, _CharT>::iterator
2612 format(
const chrono::month_weekday& __t,
2613 basic_format_context<_Out, _CharT>& __fc)
const
2615 __format::_ChronoData<_CharT> __cd{};
2616 __cd._M_month = __t.month();
2617 __cd._M_fill_weekday(__t.weekday_indexed(), __defSpec._M_needed);
2618 return _M_f._M_format(__cd, __fc);
2622 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2624 using __format::_ChronoFormats;
2625 using enum __format::_ChronoParts;
2627 __format::_ChronoSpec<_CharT> __res{};
2628 __res._M_debug =
true;
2629 __res._M_localized =
true;
2630 __res._M_locale_specific =
true;
2631 __res._M_needed = _Month|_IndexedWeekday;
2632 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_mwi();
2636 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2639#if __glibcxx_print >= 202406L
2641 inline constexpr bool
2642 enable_nonlocking_formatter_optimization<chrono::month_weekday> =
true;
2645 template<__format::__
char _CharT>
2646 struct formatter<
chrono::month_weekday_last, _CharT>
2648 constexpr typename basic_format_parse_context<_CharT>::iterator
2649 parse(basic_format_parse_context<_CharT>& __pc)
2651 using enum __format::_ChronoParts;
2652 return _M_f._M_parse(__pc, _Month|_Weekday, __defSpec);
2655 template<
typename _Out>
2656 typename basic_format_context<_Out, _CharT>::iterator
2657 format(
const chrono::month_weekday_last& __t,
2658 basic_format_context<_Out, _CharT>& __fc)
const
2660 __format::_ChronoData<_CharT> __cd{};
2661 __cd._M_month = __t.month();
2662 __cd._M_weekday = __t.weekday_last().weekday();
2663 return _M_f._M_format(__cd, __fc);
2667 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2669 using __format::_ChronoFormats;
2670 using enum __format::_ChronoParts;
2672 __format::_ChronoSpec<_CharT> __res{};
2673 __res._M_debug =
true;
2674 __res._M_localized =
true;
2675 __res._M_locale_specific =
true;
2676 __res._M_needed = _Month|_Weekday;
2677 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_mwl();
2681 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2684#if __glibcxx_print >= 202406L
2686 inline constexpr bool
2687 enable_nonlocking_formatter_optimization<chrono::month_weekday_last> =
true;
2690 template<__format::__
char _CharT>
2691 struct formatter<
chrono::year_month, _CharT>
2693 constexpr typename basic_format_parse_context<_CharT>::iterator
2694 parse(basic_format_parse_context<_CharT>& __pc)
2696 using enum __format::_ChronoParts;
2697 return _M_f._M_parse(__pc, _Year|_Month, __defSpec);
2700 template<
typename _Out>
2701 typename basic_format_context<_Out, _CharT>::iterator
2702 format(
const chrono::year_month& __t,
2703 basic_format_context<_Out, _CharT>& __fc)
const
2705 __format::_ChronoData<_CharT> __cd{};
2706 __cd._M_fill_year_month(__t, __defSpec._M_needed);
2707 return _M_f._M_format(__cd, __fc);
2711 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2713 using __format::_ChronoFormats;
2714 using enum __format::_ChronoParts;
2716 __format::_ChronoSpec<_CharT> __res{};
2717 __res._M_debug =
true;
2718 __res._M_localized =
true;
2719 __res._M_locale_specific =
true;
2720 __res._M_needed = _Year|_Month;
2721 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ym();
2725 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2728#if __glibcxx_print >= 202406L
2730 inline constexpr bool
2731 enable_nonlocking_formatter_optimization<chrono::year_month> =
true;
2734 template<__format::__
char _CharT>
2735 struct formatter<
chrono::year_month_day, _CharT>
2737 constexpr typename basic_format_parse_context<_CharT>::iterator
2738 parse(basic_format_parse_context<_CharT>& __pc)
2740 using enum __format::_ChronoParts;
2741 return _M_f._M_parse(__pc, _Date, __defSpec);
2744 template<
typename _Out>
2745 typename basic_format_context<_Out, _CharT>::iterator
2746 format(
const chrono::year_month_day& __t,
2747 basic_format_context<_Out, _CharT>& __fc)
const
2749 __format::_ChronoData<_CharT> __cd{};
2750 auto __parts = _M_f._M_spec._M_needed;
2751 __parts = __cd._M_fill_year_month(__t, __parts);
2752 __parts = __cd._M_fill_day(__t.day(), __parts);
2754 return _M_f._M_format(__cd, __fc);
2756 __cd._M_fill_ldays(chrono::local_days(__t), __parts);
2757 return _M_f._M_format(__cd, __fc);
2761 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2763 using __format::_ChronoFormats;
2764 using enum __format::_ChronoParts;
2766 __format::_ChronoSpec<_CharT> __res{};
2767 __res._M_debug =
true;
2768 __res._M_needed = _YearMonthDay;
2769 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_f();
2773 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2776#if __glibcxx_print >= 202406L
2778 inline constexpr bool
2779 enable_nonlocking_formatter_optimization<chrono::year_month_day> =
true;
2782 template<__format::__
char _CharT>
2783 struct formatter<
chrono::year_month_day_last, _CharT>
2785 constexpr typename basic_format_parse_context<_CharT>::iterator
2786 parse(basic_format_parse_context<_CharT>& __pc)
2788 using enum __format::_ChronoParts;
2789 return _M_f._M_parse(__pc, _Date, __defSpec);
2792 template<
typename _Out>
2793 typename basic_format_context<_Out, _CharT>::iterator
2794 format(
const chrono::year_month_day_last& __t,
2795 basic_format_context<_Out, _CharT>& __fc)
const
2797 using enum __format::_ChronoParts;
2799 __format::_ChronoData<_CharT> __cd{};
2800 auto __parts = _M_f._M_spec._M_needed;
2801 __parts = __cd._M_fill_year_month(__t, __parts);
2802 if (_M_f._M_spec._M_needs(_Day|_WeekdayIndex))
2803 __parts = __cd._M_fill_day(__t.day(), __parts);
2805 return _M_f._M_format(__cd, __fc);
2807 __cd._M_fill_ldays(chrono::local_days(__t), __parts);
2808 return _M_f._M_format(__cd, __fc);
2812 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2814 using __format::_ChronoFormats;
2815 using enum __format::_ChronoParts;
2817 __format::_ChronoSpec<_CharT> __res{};
2818 __res._M_debug =
true;
2819 __res._M_localized =
true;
2820 __res._M_locale_specific =
true;
2821 __res._M_needed = _Year|_Month;
2822 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_yml();
2826 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2829#if __glibcxx_print >= 202406L
2831 inline constexpr bool
2832 enable_nonlocking_formatter_optimization<chrono::year_month_day_last> =
true;
2835 template<__format::__
char _CharT>
2836 struct formatter<
chrono::year_month_weekday, _CharT>
2838 constexpr typename basic_format_parse_context<_CharT>::iterator
2839 parse(basic_format_parse_context<_CharT>& __pc)
2841 using enum __format::_ChronoParts;
2842 return _M_f._M_parse(__pc, _Date, __defSpec);
2845 template<
typename _Out>
2846 typename basic_format_context<_Out, _CharT>::iterator
2847 format(
const chrono::year_month_weekday& __t,
2848 basic_format_context<_Out, _CharT>& __fc)
const
2850 __format::_ChronoData<_CharT> __cd{};
2851 auto __parts = _M_f._M_spec._M_needed;
2852 __parts = __cd._M_fill_year_month(__t, __parts);
2853 __parts = __cd._M_fill_weekday(__t.weekday_indexed(), __parts);
2854 if (__t.index() == 0) [[unlikely]]
2857 __parts -= __format::_ChronoParts::_Day;
2859 return _M_f._M_format(__cd, __fc);
2861 chrono::local_days __ld(__t);
2862 __parts = __cd._M_fill_ldays(__ld, __parts);
2864 return _M_f._M_format(__cd, __fc);
2866 auto __dom = __ld - chrono::local_days(__t.year()/__t.month()/0);
2868 __cd._M_day = chrono::day(__dom.count());
2869 return _M_f._M_format(__cd, __fc);
2873 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2875 using __format::_ChronoFormats;
2876 using enum __format::_ChronoParts;
2878 __format::_ChronoSpec<_CharT> __res{};
2879 __res._M_debug =
true;
2880 __res._M_localized =
true;
2881 __res._M_locale_specific =
true;
2882 __res._M_needed = _Year|_Month|_IndexedWeekday;
2883 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ymwi();
2887 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2890#if __glibcxx_print >= 202406L
2892 inline constexpr bool
2893 enable_nonlocking_formatter_optimization<chrono::year_month_weekday> =
true;
2896 template<__format::__
char _CharT>
2897 struct formatter<
chrono::year_month_weekday_last, _CharT>
2899 constexpr typename basic_format_parse_context<_CharT>::iterator
2900 parse(basic_format_parse_context<_CharT>& __pc)
2902 using enum __format::_ChronoParts;
2903 return _M_f._M_parse(__pc, _Date, __defSpec);
2906 template<
typename _Out>
2907 typename basic_format_context<_Out, _CharT>::iterator
2908 format(
const chrono::year_month_weekday_last& __t,
2909 basic_format_context<_Out, _CharT>& __fc)
const
2911 __format::_ChronoData<_CharT> __cd{};
2912 auto __parts = _M_f._M_spec._M_needed;
2913 __parts = __cd._M_fill_year_month(__t, __parts);
2914 __cd._M_weekday = __t.weekday_last().weekday();
2915 __parts -= __format::_ChronoParts::_Weekday;
2917 return _M_f._M_format(__cd, __fc);
2919 chrono::local_days __ld(__t);
2920 __parts = __cd._M_fill_ldays(__ld, __parts);
2922 return _M_f._M_format(__cd, __fc);
2924 auto __dom = __ld - chrono::local_days(__t.year()/__t.month()/0);
2925 __cd._M_fill_day(chrono::day(__dom.count()), __parts);
2926 return _M_f._M_format(__cd, __fc);
2930 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2932 using __format::_ChronoFormats;
2933 using enum __format::_ChronoParts;
2935 __format::_ChronoSpec<_CharT> __res{};
2936 __res._M_debug =
true;
2937 __res._M_localized =
true;
2938 __res._M_locale_specific =
true;
2939 __res._M_needed = _Year|_Month|_Weekday;
2940 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ymwl();
2944 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2947#if __glibcxx_print >= 202406L
2949 inline constexpr bool
2950 enable_nonlocking_formatter_optimization<chrono::year_month_weekday_last> =
true;
2953 template<
typename _Rep,
typename _Period, __format::__
char _CharT>
2954 struct formatter<
chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>, _CharT>
2956 constexpr typename basic_format_parse_context<_CharT>::iterator
2957 parse(basic_format_parse_context<_CharT>& __pc)
2959 using enum __format::_ChronoParts;
2960 return _M_f.template _M_parse<_Precision>(__pc, _Time, __defSpec);
2963 template<
typename _Out>
2964 typename basic_format_context<_Out, _CharT>::iterator
2965 format(
const chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>& __t,
2966 basic_format_context<_Out, _CharT>& __fc)
const
2968 using enum __format::_ChronoParts;
2970 __format::_ChronoData<_CharT> __cd;
2971 __cd._M_is_neg = __t.is_negative();
2972 __cd._M_hours = __t.hours();
2973 __cd._M_minutes = __t.minutes();
2974 __cd._M_seconds = __t.seconds();
2979 if (_M_f._M_spec._M_needs(_EpochUnits))
2980 __d = __t.to_duration();
2981 if (_M_f._M_spec._M_needs(_TotalSeconds))
2983 = __cd._M_hours + __cd._M_minutes + __cd._M_seconds;
2984 return _M_f._M_format_units(__cd, __d, __t.subseconds(), __fc);
2989 =
typename chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>::precision;
2990 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
2991 __format::__formatter_duration<_CharT>::
2992 template _S_spec_for<_Precision>(__format::_ChronoParts::_Time);
2994 __format::__formatter_duration<_CharT> _M_f{__defSpec};
2997#if __glibcxx_print >= 202406L
3000 template<
typename _Duration>
3002 enable_nonlocking_formatter_optimization<chrono::hh_mm_ss<_Duration>>
3003 = enable_nonlocking_formatter_optimization<_Duration>;
3006#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
3007 template<__format::__
char _CharT>
3008 struct formatter<
chrono::sys_info, _CharT>
3010 constexpr typename basic_format_parse_context<_CharT>::iterator
3011 parse(basic_format_parse_context<_CharT>& __pc)
3012 {
return _M_f.parse(__pc); }
3014 template<
typename _Out>
3015 typename basic_format_context<_Out, _CharT>::iterator
3016 format(
const chrono::sys_info& __i,
3017 basic_format_context<_Out, _CharT>& __fc)
const
3018 {
return _M_f.format(__i, __fc); }
3021 __format::__formatter_chrono_info<_CharT> _M_f;
3024#if __glibcxx_print >= 202406L
3026 inline constexpr bool
3027 enable_nonlocking_formatter_optimization<chrono::sys_info> =
true;
3030 template<__format::__
char _CharT>
3031 struct formatter<
chrono::local_info, _CharT>
3033 constexpr typename basic_format_parse_context<_CharT>::iterator
3034 parse(basic_format_parse_context<_CharT>& __pc)
3035 {
return _M_f.parse(__pc); }
3037 template<
typename _Out>
3038 typename basic_format_context<_Out, _CharT>::iterator
3039 format(
const chrono::local_info& __i,
3040 basic_format_context<_Out, _CharT>& __fc)
const
3041 {
return _M_f.format(__i, __fc); }
3044 __format::__formatter_chrono_info<_CharT> _M_f;
3047#if __glibcxx_print >= 202406L
3049 inline constexpr bool
3050 enable_nonlocking_formatter_optimization<chrono::local_info> =
true;
3054 template<
typename _Duration, __format::__
char _CharT>
3055 struct formatter<
chrono::sys_time<_Duration>, _CharT>
3057 constexpr typename basic_format_parse_context<_CharT>::iterator
3058 parse(basic_format_parse_context<_CharT>& __pc)
3060 using enum __format::_ChronoParts;
3062 = _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3063 if constexpr (__defSpec._M_chrono_specs.empty())
3064 if (_M_f._M_spec._M_chrono_specs.empty())
3065 __format::__invalid_chrono_spec();
3069 template<
typename _Out>
3070 typename basic_format_context<_Out, _CharT>::iterator
3071 format(
const chrono::sys_time<_Duration>& __t,
3072 basic_format_context<_Out, _CharT>& __fc)
const
3074 __format::_ChronoData<_CharT> __cd{};
3075 __cd._M_fill_utc_zone();
3077 _Duration __ed = __t.time_since_epoch();
3078 __cd._M_eseconds = chrono::floor<chrono::seconds>(__ed);
3079 __cd._M_lseconds = chrono::local_seconds(__cd._M_eseconds);
3080 return _M_f._M_format_time_point(__cd, __ed, __fc);
3084 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3085 __format::__formatter_duration<_CharT>::template _S_spec_for_tp<_Duration>();
3087 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3090#if __glibcxx_print >= 202406L
3093 template<
typename _Duration>
3095 enable_nonlocking_formatter_optimization<chrono::sys_time<_Duration>>
3096 = enable_nonlocking_formatter_optimization<_Duration>;
3099 template<
typename _Duration, __format::__
char _CharT>
3100 struct formatter<
chrono::utc_time<_Duration>, _CharT>
3102 constexpr typename basic_format_parse_context<_CharT>::iterator
3103 parse(basic_format_parse_context<_CharT>& __pc)
3105 using enum __format::_ChronoParts;
3106 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3109 template<
typename _Out>
3110 typename basic_format_context<_Out, _CharT>::iterator
3111 format(
const chrono::utc_time<_Duration>& __t,
3112 basic_format_context<_Out, _CharT>& __fc)
const
3114 using __format::_ChronoParts;
3115 using namespace chrono;
3116 __format::_ChronoData<_CharT> __cd{};
3117 __cd._M_fill_utc_zone();
3119 _Duration __ed = __t.time_since_epoch();
3120 __cd._M_eseconds = chrono::floor<seconds>(__ed);
3124 const auto __li = chrono::get_leap_second_info(__t);
3125 __cd._M_lseconds = local_seconds(__cd._M_eseconds - __li.elapsed);
3126 auto __parts = _M_f._M_spec._M_needed - _ChronoParts::_TotalSeconds;
3127 if ((__parts & _ChronoParts::_DateTime) != 0)
3129 __cd._M_fill_date_time(__cd._M_lseconds, __parts);
3130 __cd._M_seconds +=
seconds(__li.is_leap_second);
3132 return _M_f._M_format_units(__cd, __ed, __ed - __cd._M_eseconds, __fc);
3136 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3137 __format::__formatter_duration<_CharT>::
3138 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3140 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3143#if __glibcxx_print >= 202406L
3146 template<
typename _Duration>
3148 enable_nonlocking_formatter_optimization<chrono::utc_time<_Duration>>
3149 = enable_nonlocking_formatter_optimization<_Duration>;
3152 template<
typename _Duration, __format::__
char _CharT>
3153 struct formatter<
chrono::tai_time<_Duration>, _CharT>
3155 constexpr typename basic_format_parse_context<_CharT>::iterator
3156 parse(basic_format_parse_context<_CharT>& __pc)
3158 using enum __format::_ChronoParts;
3159 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3162 template<
typename _Out>
3163 typename basic_format_context<_Out, _CharT>::iterator
3164 format(
const chrono::tai_time<_Duration>& __t,
3165 basic_format_context<_Out, _CharT>& __fc)
const
3167 using namespace chrono;
3168 __format::_ChronoData<_CharT> __cd{};
3169 __cd._M_fill_zone(
"TAI", L
"TAI");
3171 _Duration __ed = __t.time_since_epoch();
3172 __cd._M_eseconds = chrono::floor<seconds>(__ed);
3174 constexpr chrono::days __tai_offset = chrono::days(4383);
3175 __cd._M_lseconds = local_seconds(__cd._M_eseconds - __tai_offset);
3176 return _M_f._M_format_time_point(__cd, __ed, __fc);
3180 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3181 __format::__formatter_duration<_CharT>::
3182 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3184 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3187#if __glibcxx_print >= 202406L
3190 template<
typename _Duration>
3192 enable_nonlocking_formatter_optimization<chrono::tai_time<_Duration>>
3193 = enable_nonlocking_formatter_optimization<_Duration>;
3196 template<
typename _Duration, __format::__
char _CharT>
3197 struct formatter<
chrono::gps_time<_Duration>, _CharT>
3199 constexpr typename basic_format_parse_context<_CharT>::iterator
3200 parse(basic_format_parse_context<_CharT>& __pc)
3202 using enum __format::_ChronoParts;
3203 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3206 template<
typename _Out>
3207 typename basic_format_context<_Out, _CharT>::iterator
3208 format(
const chrono::gps_time<_Duration>& __t,
3209 basic_format_context<_Out, _CharT>& __fc)
const
3211 using namespace chrono;
3212 __format::_ChronoData<_CharT> __cd{};
3213 __cd._M_fill_zone(
"GPS", L
"GPS");
3215 _Duration __ed = __t.time_since_epoch();
3216 __cd._M_eseconds = chrono::floor<seconds>(__ed);
3218 constexpr chrono::days __gps_offset = chrono::days(3657);
3219 __cd._M_lseconds = local_seconds(__cd._M_eseconds + __gps_offset);
3220 return _M_f._M_format_time_point(__cd, __ed, __fc);
3224 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3225 __format::__formatter_duration<_CharT>::
3226 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3228 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3231#if __glibcxx_print >= 202406L
3234 template<
typename _Duration>
3236 enable_nonlocking_formatter_optimization<chrono::gps_time<_Duration>>
3237 = enable_nonlocking_formatter_optimization<_Duration>;
3240 template<
typename _Duration, __format::__
char _CharT>
3241 struct formatter<
chrono::file_time<_Duration>, _CharT>
3243 constexpr typename basic_format_parse_context<_CharT>::iterator
3244 parse(basic_format_parse_context<_CharT>& __pc)
3246 using enum __format::_ChronoParts;
3247 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3250 template<
typename _Out>
3251 typename basic_format_context<_Out, _CharT>::iterator
3252 format(
const chrono::file_time<_Duration>& __t,
3253 basic_format_context<_Out, _CharT>& __fc)
const
3255 using namespace chrono;
3256 __format::_ChronoData<_CharT> __cd{};
3257 __cd._M_fill_utc_zone();
3259 _Duration __ed = __t.time_since_epoch();
3260 __cd._M_eseconds = chrono::floor<seconds>(__ed);
3261 auto __st = chrono::clock_cast<system_clock>(__t);
3263 = local_seconds(chrono::floor<seconds>(__st.time_since_epoch()));
3264 return _M_f._M_format_time_point(__cd, __ed, __fc);
3268 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3269 __format::__formatter_duration<_CharT>::
3270 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3272 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3275#if __glibcxx_print >= 202406L
3278 template<
typename _Duration>
3280 enable_nonlocking_formatter_optimization<chrono::file_time<_Duration>>
3281 = enable_nonlocking_formatter_optimization<_Duration>;
3284 template<
typename _Duration, __format::__
char _CharT>
3285 struct formatter<
chrono::local_time<_Duration>, _CharT>
3287 constexpr typename basic_format_parse_context<_CharT>::iterator
3288 parse(basic_format_parse_context<_CharT>& __pc)
3290 using enum __format::_ChronoParts;
3292 = _M_f.template _M_parse<_Duration>(__pc, _DateTime, __defSpec);
3293 if constexpr (__defSpec._M_chrono_specs.empty())
3294 if (_M_f._M_spec._M_chrono_specs.empty())
3295 __format::__invalid_chrono_spec();
3299 template<
typename _Out>
3300 typename basic_format_context<_Out, _CharT>::iterator
3301 format(
const chrono::local_time<_Duration>& __lt,
3302 basic_format_context<_Out, _CharT>& __fc)
const
3304 __format::_ChronoData<_CharT> __cd{};
3305 _Duration __ed = __lt.time_since_epoch();
3306 __cd._M_lseconds = chrono::floor<chrono::seconds>(__lt);
3307 __cd._M_eseconds = __cd._M_lseconds.time_since_epoch();
3308 return _M_f._M_format_time_point(__cd, __ed, __fc);
3312 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3313 __format::__formatter_duration<_CharT>::template _S_spec_for_tp<_Duration>();
3315 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3318#if __glibcxx_print >= 202406L
3321 template<
typename _Duration>
3323 enable_nonlocking_formatter_optimization<chrono::local_time<_Duration>>
3324 = enable_nonlocking_formatter_optimization<_Duration>;
3327 template<
typename _Duration, __format::__
char _CharT>
3328 struct formatter<
chrono::__detail::__local_time_fmt<_Duration>, _CharT>
3330 constexpr typename basic_format_parse_context<_CharT>::iterator
3331 parse(basic_format_parse_context<_CharT>& __pc)
3333 using enum __format::_ChronoParts;
3334 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3337 template<
typename _Out>
3338 typename basic_format_context<_Out, _CharT>::iterator
3339 format(
const chrono::__detail::__local_time_fmt<_Duration>& __zt,
3340 basic_format_context<_Out, _CharT>& __fc)
const
3342 using enum __format::_ChronoParts;
3343 __format::_ChronoData<_CharT> __cd{};
3345 if (_M_f._M_spec._M_needs(_ZoneOffset))
3347 if (!__zt._M_offset_sec)
3348 std::__throw_format_error(
"format error: no timezone available for %z");
3349 __cd._M_zone_offset = *__zt._M_offset_sec;
3352 basic_string<_CharT> __zone_store;
3353 if (_M_f._M_spec._M_needs(_ZoneAbbrev))
3355 if (!__zt._M_abbrev)
3356 std::__throw_format_error(
"format error: no timezone available for %Z");
3358 __cd._M_zone_cstr = __zt._M_abbrev->data();
3359 if constexpr (is_same_v<_CharT, char>)
3360 __cd._M_zone_abbrev = *__zt._M_abbrev;
3364 __zone_store.resize(__zt._M_abbrev->size());
3365 auto& __ct = use_facet<ctype<_CharT>>(_M_f._M_locale(__fc));
3366 __ct.widen(__zt._M_abbrev->data(),
3367 __zt._M_abbrev->data() + __zt._M_abbrev->size(),
3368 __zone_store.data());
3369 __cd._M_zone_abbrev = __zone_store;
3373 _Duration __ed = __zt._M_time.time_since_epoch();
3374 __cd._M_lseconds = chrono::floor<chrono::seconds>(__zt._M_time);
3375 __cd._M_eseconds = __cd._M_lseconds.time_since_epoch();
3376 return _M_f._M_format_time_point(__cd, __ed, __fc);
3380 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3381 __format::__formatter_duration<_CharT>::
3382 template _S_spec_for<_Duration>(__format::_ChronoParts::_ZonedDateTime);
3384 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3387#if __glibcxx_print >= 202406L
3390 template<
typename _Duration>
3392 enable_nonlocking_formatter_optimization<
3393 chrono::__detail::__local_time_fmt<_Duration>>
3394 = enable_nonlocking_formatter_optimization<_Duration>;
3397#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
3398 template<
typename _Duration,
typename _TimeZonePtr, __format::__
char _CharT>
3399 struct formatter<
chrono::zoned_time<_Duration, _TimeZonePtr>, _CharT>
3400 : formatter<chrono::__detail::__local_time_fmt_for<_Duration>, _CharT>
3402 template<
typename _Out>
3403 typename basic_format_context<_Out, _CharT>::iterator
3404 format(
const chrono::zoned_time<_Duration, _TimeZonePtr>& __tp,
3405 basic_format_context<_Out, _CharT>& __fc)
const
3407 using _Ltf = chrono::__detail::__local_time_fmt_for<_Duration>;
3408 using _Base = formatter<_Ltf, _CharT>;
3409 const chrono::sys_info __info = __tp.get_info();
3410 const auto __lf = chrono::local_time_format(__tp.get_local_time(),
3413 return _Base::format(__lf, __fc);
3417#if __glibcxx_print >= 202406L
3420 template<
typename _Duration>
3422 enable_nonlocking_formatter_optimization<
3423 chrono::zoned_time<_Duration, const chrono::time_zone*>>
3424 = enable_nonlocking_formatter_optimization<_Duration>;
3436 template<
typename _Duration = seconds>
3439 static_assert(is_same_v<common_type_t<_Duration, seconds>, _Duration>);
3442 _Parser(__format::_ChronoParts __need) : _M_need(__need) { }
3444 _Parser(_Parser&&) =
delete;
3445 void operator=(_Parser&&) =
delete;
3447 _Duration _M_time{};
3448 sys_days _M_sys_days{};
3449 year_month_day _M_ymd{};
3451 __format::_ChronoParts _M_need;
3452 unsigned _M_is_leap_second : 1 {};
3453 unsigned _M_reserved : 15 {};
3455 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3456 basic_istream<_CharT, _Traits>&
3457 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3458 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3459 minutes* __offset =
nullptr);
3464 template<
typename _CharT,
typename _Traits>
3465 static int_least32_t
3466 _S_read_unsigned(basic_istream<_CharT, _Traits>& __is,
3467 ios_base::iostate& __err,
int __n)
3469 int_least32_t __val = _S_try_read_digit(__is, __err);
3470 if (__val == -1) [[unlikely]]
3471 __err |= ios_base::failbit;
3476 for (
int __i = 1; __i < __n1; ++__i)
3477 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
3483 while (__n1++ < __n) [[unlikely]]
3484 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
3486 if (__builtin_mul_overflow(__val, 10, &__val)
3487 || __builtin_add_overflow(__val, __dig, &__val))
3489 __err |= ios_base::failbit;
3499 template<
typename _CharT,
typename _Traits>
3500 static int_least32_t
3501 _S_read_signed(basic_istream<_CharT, _Traits>& __is,
3502 ios_base::iostate& __err,
int __n)
3504 auto __sign = __is.peek();
3505 if (__sign ==
'-' || __sign ==
'+')
3507 int_least32_t __val = _S_read_unsigned(__is, __err, __n);
3508 if (__err & ios_base::failbit)
3510 if (__sign ==
'-') [[unlikely]]
3518 template<
typename _CharT,
typename _Traits>
3519 static int_least32_t
3520 _S_try_read_digit(basic_istream<_CharT, _Traits>& __is,
3521 ios_base::iostate& __err)
3523 int_least32_t __val = -1;
3524 auto __i = __is.peek();
3525 if (!_Traits::eq_int_type(__i, _Traits::eof())) [[likely]]
3527 _CharT __c = _Traits::to_char_type(__i);
3528 if (_CharT(
'0') <= __c && __c <= _CharT(
'9')) [[likely]]
3531 __val = __c - _CharT(
'0');
3535 __err |= ios_base::eofbit;
3541 template<
typename _CharT,
typename _Traits>
3543 _S_read_chr(basic_istream<_CharT, _Traits>& __is,
3544 ios_base::iostate& __err, _CharT __c)
3546 auto __i = __is.peek();
3547 if (_Traits::eq_int_type(__i, _Traits::eof()))
3548 __err |= ios_base::eofbit;
3549 else if (_Traits::to_char_type(__i) == __c) [[likely]]
3554 __err |= ios_base::failbit;
3559 template<
typename _Duration>
3560 using _Parser_t = _Parser<common_type_t<_Duration, seconds>>;
3562 template<
typename _Duration>
3566 if constexpr (_Duration::period::den == 1)
3568 switch (_Duration::period::num)
3570 case minutes::period::num:
3571 case hours::period::num:
3572 case days::period::num:
3573 case weeks::period::num:
3574 case years::period::num:
3591 template<
typename _ToDur,
typename _Tp>
3593 __round(
const _Tp& __t)
3595 if constexpr (__is_duration_v<_Tp>)
3597 if constexpr (treat_as_floating_point_v<typename _Tp::rep>)
3599 else if constexpr (__detail::__use_floor<_ToDur>())
3606 static_assert(__is_time_point_v<_Tp>);
3607 using _Tpt = time_point<typename _Tp::clock, _ToDur>;
3608 return _Tpt(__detail::__round<_ToDur>(__t.time_since_epoch()));
3617 template<
size_t _BufSize,
typename _CharT,
typename _Traits,
3618 typename _Arg,
typename... _OptLocale>
3619 inline basic_ostream<_CharT, _Traits>&
3620 __chrono_write(basic_ostream<_CharT, _Traits>& __os,
3621 const _Arg& __arg,
const _OptLocale&... __loc)
3623 static_assert(
sizeof...(_OptLocale) <= 1);
3625 = __format::__formatter_chrono<_CharT>::_S_empty_fs;
3626 constexpr size_t __bufsize = _BufSize;
3627 _CharT __buf[__bufsize];
3628 auto __res = std::format_to_n(__buf, __bufsize, __loc...,
3631 if (
static_cast<size_t>(__res.size) <= __bufsize) [[likely]]
3632 return std::__ostream_insert(__os, __buf, __res.size);
3634 auto __s = std::format(__loc..., __fs(), __arg);
3635 return std::__ostream_insert(__os, __s.data(), __s.size());
3641 template<
typename _CharT,
typename _Traits,
typename _Rep,
typename _Period,
3642 typename _Alloc = allocator<_CharT>>
3643 inline basic_istream<_CharT, _Traits>&
3644 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3646 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3649 auto __need = __format::_ChronoParts::_TimeOfDay;
3650 __detail::_Parser_t<duration<_Rep, _Period>> __p(__need);
3651 if (__p(__is, __fmt, __abbrev, __offset))
3652 __d = __detail::__round<duration<_Rep, _Period>>(__p._M_time);
3656 template<
typename _CharT,
typename _Traits>
3657 inline basic_ostream<_CharT, _Traits>&
3658 operator<<(basic_ostream<_CharT, _Traits>& __os,
const day& __d)
3659 {
return __detail::__chrono_write<32>(__os, __d); }
3661 template<
typename _CharT,
typename _Traits,
3662 typename _Alloc = allocator<_CharT>>
3663 inline basic_istream<_CharT, _Traits>&
3664 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3666 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3669 __detail::_Parser<> __p(__format::_ChronoParts::_Day);
3670 if (__p(__is, __fmt, __abbrev, __offset))
3671 __d = __p._M_ymd.day();
3675 template<
typename _CharT,
typename _Traits>
3676 inline basic_ostream<_CharT, _Traits>&
3677 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month& __m)
3678 {
return __detail::__chrono_write<64>(__os, __m, __os.getloc()); }
3680 template<
typename _CharT,
typename _Traits,
3681 typename _Alloc = allocator<_CharT>>
3682 inline basic_istream<_CharT, _Traits>&
3683 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3685 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3688 __detail::_Parser<> __p(__format::_ChronoParts::_Month);
3689 if (__p(__is, __fmt, __abbrev, __offset))
3690 __m = __p._M_ymd.month();
3694 template<
typename _CharT,
typename _Traits>
3695 inline basic_ostream<_CharT, _Traits>&
3696 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year& __y)
3697 {
return __detail::__chrono_write<32>(__os, __y); }
3699 template<
typename _CharT,
typename _Traits,
3700 typename _Alloc = allocator<_CharT>>
3701 inline basic_istream<_CharT, _Traits>&
3702 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3704 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3707 __detail::_Parser<> __p(__format::_ChronoParts::_Year);
3708 if (__p(__is, __fmt, __abbrev, __offset))
3709 __y = __p._M_ymd.year();
3713 template<
typename _CharT,
typename _Traits>
3714 inline basic_ostream<_CharT, _Traits>&
3715 operator<<(basic_ostream<_CharT, _Traits>& __os,
const weekday& __wd)
3716 {
return __detail::__chrono_write<64>(__os, __wd, __os.getloc()); }
3718 template<
typename _CharT,
typename _Traits,
3719 typename _Alloc = allocator<_CharT>>
3720 inline basic_istream<_CharT, _Traits>&
3721 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3723 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3726 __detail::_Parser<> __p(__format::_ChronoParts::_Weekday);
3727 if (__p(__is, __fmt, __abbrev, __offset))
3732 template<
typename _CharT,
typename _Traits>
3733 inline basic_ostream<_CharT, _Traits>&
3734 operator<<(basic_ostream<_CharT, _Traits>& __os,
3735 const weekday_indexed& __wdi)
3736 {
return __detail::__chrono_write<128>(__os, __wdi, __os.getloc()); }
3738 template<
typename _CharT,
typename _Traits>
3739 inline basic_ostream<_CharT, _Traits>&
3740 operator<<(basic_ostream<_CharT, _Traits>& __os,
3741 const weekday_last& __wdl)
3742 {
return __detail::__chrono_write<128>(__os, __wdl, __os.getloc()); }
3744 template<
typename _CharT,
typename _Traits>
3745 inline basic_ostream<_CharT, _Traits>&
3746 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month_day& __md)
3747 {
return __detail::__chrono_write<128>(__os, __md, __os.getloc()); }
3749 template<
typename _CharT,
typename _Traits,
3750 typename _Alloc = allocator<_CharT>>
3751 inline basic_istream<_CharT, _Traits>&
3752 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3754 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3757 using __format::_ChronoParts;
3758 auto __need = _ChronoParts::_Month | _ChronoParts::_Day;
3759 __detail::_Parser<> __p(__need);
3760 if (__p(__is, __fmt, __abbrev, __offset))
3761 __md = month_day(__p._M_ymd.month(), __p._M_ymd.day());
3765 template<
typename _CharT,
typename _Traits>
3766 inline basic_ostream<_CharT, _Traits>&
3767 operator<<(basic_ostream<_CharT, _Traits>& __os,
3768 const month_day_last& __mdl)
3769 {
return __detail::__chrono_write<128>(__os, __mdl, __os.getloc()); }
3771 template<
typename _CharT,
typename _Traits>
3772 inline basic_ostream<_CharT, _Traits>&
3773 operator<<(basic_ostream<_CharT, _Traits>& __os,
3774 const month_weekday& __mwd)
3775 {
return __detail::__chrono_write<128>(__os, __mwd, __os.getloc()); }
3777 template<
typename _CharT,
typename _Traits>
3778 inline basic_ostream<_CharT, _Traits>&
3779 operator<<(basic_ostream<_CharT, _Traits>& __os,
3780 const month_weekday_last& __mwdl)
3781 {
return __detail::__chrono_write<128>(__os, __mwdl, __os.getloc()); }
3783 template<
typename _CharT,
typename _Traits>
3784 inline basic_ostream<_CharT, _Traits>&
3785 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year_month& __ym)
3786 {
return __detail::__chrono_write<128>(__os, __ym, __os.getloc()); }
3788 template<
typename _CharT,
typename _Traits,
3789 typename _Alloc = allocator<_CharT>>
3790 inline basic_istream<_CharT, _Traits>&
3791 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3793 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3796 using __format::_ChronoParts;
3797 auto __need = _ChronoParts::_Year | _ChronoParts::_Month;
3798 __detail::_Parser<> __p(__need);
3799 if (__p(__is, __fmt, __abbrev, __offset))
3800 __ym = year_month(__p._M_ymd.year(), __p._M_ymd.month());
3804 template<
typename _CharT,
typename _Traits>
3805 inline basic_ostream<_CharT, _Traits>&
3806 operator<<(basic_ostream<_CharT, _Traits>& __os,
3807 const year_month_day& __ymd)
3808 {
return __detail::__chrono_write<64>(__os, __ymd); }
3810 template<
typename _CharT,
typename _Traits,
3811 typename _Alloc = allocator<_CharT>>
3812 inline basic_istream<_CharT, _Traits>&
3814 year_month_day& __ymd,
3818 using __format::_ChronoParts;
3819 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3820 | _ChronoParts::_Day;
3821 __detail::_Parser<> __p(__need);
3822 if (__p(__is, __fmt, __abbrev, __offset))
3827 template<
typename _CharT,
typename _Traits>
3830 const year_month_day_last& __ymdl)
3831 {
return __detail::__chrono_write<128>(__os, __ymdl, __os.
getloc()); }
3833 template<
typename _CharT,
typename _Traits>
3834 inline basic_ostream<_CharT, _Traits>&
3835 operator<<(basic_ostream<_CharT, _Traits>& __os,
3836 const year_month_weekday& __ymwd)
3837 {
return __detail::__chrono_write<128>(__os, __ymwd, __os.getloc()); }
3839 template<
typename _CharT,
typename _Traits>
3840 inline basic_ostream<_CharT, _Traits>&
3841 operator<<(basic_ostream<_CharT, _Traits>& __os,
3842 const year_month_weekday_last& __ymwdl)
3843 {
return __detail::__chrono_write<128>(__os, __ymwdl, __os.getloc()); }
3845 template<
typename _CharT,
typename _Traits,
typename _Duration>
3846 inline basic_ostream<_CharT, _Traits>&
3847 operator<<(basic_ostream<_CharT, _Traits>& __os,
3849 {
return __detail::__chrono_write<64>(__os, __hms, __os.getloc()); }
3851#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
3853 template<
typename _CharT,
typename _Traits>
3854 basic_ostream<_CharT, _Traits>&
3855 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_info& __i)
3856 {
return __detail::__chrono_write<128>(__os, __i); }
3859 template<
typename _CharT,
typename _Traits>
3860 basic_ostream<_CharT, _Traits>&
3861 operator<<(basic_ostream<_CharT, _Traits>& __os,
const local_info& __li)
3862 {
return __detail::__chrono_write<256>(__os, __li); }
3864 template<
typename _CharT,
typename _Traits,
typename _Duration,
3865 typename _TimeZonePtr>
3866 inline basic_ostream<_CharT, _Traits>&
3867 operator<<(basic_ostream<_CharT, _Traits>& __os,
3868 const zoned_time<_Duration, _TimeZonePtr>& __t)
3869 {
return __detail::__chrono_write<128>(__os, __t, __os.getloc()); }
3872 template<
typename _CharT,
typename _Traits,
typename _Duration>
3873 requires (!treat_as_floating_point_v<typename _Duration::rep>)
3874 && ratio_less_v<typename _Duration::period, days::period>
3875 inline basic_ostream<_CharT, _Traits>&
3876 operator<<(basic_ostream<_CharT, _Traits>& __os,
3877 const sys_time<_Duration>& __tp)
3878 {
return __detail::__chrono_write<64>(__os, __tp, __os.getloc()); }
3880 template<
typename _CharT,
typename _Traits>
3881 inline basic_ostream<_CharT, _Traits>&
3882 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_days& __dp)
3883 {
return __detail::__chrono_write<32>(__os, __dp); };
3885 template<
typename _CharT,
typename _Traits,
typename _Duration,
3886 typename _Alloc = allocator<_CharT>>
3887 basic_istream<_CharT, _Traits>&
3888 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3889 sys_time<_Duration>& __tp,
3890 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3896 using __format::_ChronoParts;
3897 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3898 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
3899 __detail::_Parser_t<_Duration> __p(__need);
3900 if (__p(__is, __fmt, __abbrev, __offset))
3902 if (__p._M_is_leap_second)
3906 auto __st = __p._M_sys_days + __p._M_time - *__offset;
3907 __tp = __detail::__round<_Duration>(__st);
3913 template<
typename _CharT,
typename _Traits,
typename _Duration>
3914 inline basic_ostream<_CharT, _Traits>&
3915 operator<<(basic_ostream<_CharT, _Traits>& __os,
3916 const utc_time<_Duration>& __t)
3917 {
return __detail::__chrono_write<64>(__os, __t, __os.getloc()); }
3919 template<
typename _CharT,
typename _Traits,
typename _Duration,
3920 typename _Alloc = allocator<_CharT>>
3921 inline basic_istream<_CharT, _Traits>&
3922 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3923 utc_time<_Duration>& __tp,
3924 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3930 using __format::_ChronoParts;
3931 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3932 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
3933 __detail::_Parser_t<_Duration> __p(__need);
3934 if (__p(__is, __fmt, __abbrev, __offset))
3938 auto __ut = utc_clock::from_sys(__p._M_sys_days) + __p._M_time
3940 __tp = __detail::__round<_Duration>(__ut);
3945 template<
typename _CharT,
typename _Traits,
typename _Duration>
3946 inline basic_ostream<_CharT, _Traits>&
3947 operator<<(basic_ostream<_CharT, _Traits>& __os,
3948 const tai_time<_Duration>& __t)
3949 {
return __detail::__chrono_write<64>(__os, __t, __os.getloc()); }
3951 template<
typename _CharT,
typename _Traits,
typename _Duration,
3952 typename _Alloc = allocator<_CharT>>
3953 inline basic_istream<_CharT, _Traits>&
3954 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3955 tai_time<_Duration>& __tp,
3956 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3962 using __format::_ChronoParts;
3963 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3964 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
3965 __detail::_Parser_t<_Duration> __p(__need);
3966 if (__p(__is, __fmt, __abbrev, __offset))
3968 if (__p._M_is_leap_second)
3972 constexpr sys_days __epoch(-
days(4383));
3973 auto __d = __p._M_sys_days - __epoch + __p._M_time - *__offset;
3974 tai_time<common_type_t<_Duration, seconds>> __tt(__d);
3975 __tp = __detail::__round<_Duration>(__tt);
3981 template<
typename _CharT,
typename _Traits,
typename _Duration>
3982 inline basic_ostream<_CharT, _Traits>&
3983 operator<<(basic_ostream<_CharT, _Traits>& __os,
3984 const gps_time<_Duration>& __t)
3985 {
return __detail::__chrono_write<64>(__os, __t, __os.getloc()); }
3987 template<
typename _CharT,
typename _Traits,
typename _Duration,
3988 typename _Alloc = allocator<_CharT>>
3989 inline basic_istream<_CharT, _Traits>&
3990 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3991 gps_time<_Duration>& __tp,
3992 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3998 using __format::_ChronoParts;
3999 auto __need = _ChronoParts::_YearMonthDay | _ChronoParts::_TimeOfDay;
4000 __detail::_Parser_t<_Duration> __p(__need);
4001 if (__p(__is, __fmt, __abbrev, __offset))
4003 if (__p._M_is_leap_second)
4007 constexpr sys_days __epoch(
days(3657));
4008 auto __d = __p._M_sys_days - __epoch + __p._M_time - *__offset;
4009 gps_time<common_type_t<_Duration, seconds>> __gt(__d);
4010 __tp = __detail::__round<_Duration>(__gt);
4016 template<
typename _CharT,
typename _Traits,
typename _Duration>
4017 inline basic_ostream<_CharT, _Traits>&
4018 operator<<(basic_ostream<_CharT, _Traits>& __os,
4019 const file_time<_Duration>& __t)
4020 {
return __detail::__chrono_write<64>(__os, __t, __os.getloc()); }
4022 template<
typename _CharT,
typename _Traits,
typename _Duration,
4023 typename _Alloc = allocator<_CharT>>
4024 inline basic_istream<_CharT, _Traits>&
4025 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4026 file_time<_Duration>& __tp,
4027 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4030 sys_time<_Duration> __st;
4031 if (chrono::from_stream(__is, __fmt, __st, __abbrev, __offset))
4032 __tp = __detail::__round<_Duration>(file_clock::from_sys(__st));
4036 template<
typename _CharT,
typename _Traits,
typename _Duration>
4037 inline basic_ostream<_CharT, _Traits>&
4038 operator<<(basic_ostream<_CharT, _Traits>& __os,
4039 const local_time<_Duration>& __lt)
4042 requires requires(
const sys_time<_Duration>& __st) { __os << __st; }
4043 {
return __detail::__chrono_write<64>(__os, __lt, __os.getloc()); }
4045 template<
typename _CharT,
typename _Traits,
typename _Duration,
4046 typename _Alloc = allocator<_CharT>>
4047 basic_istream<_CharT, _Traits>&
4048 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4049 local_time<_Duration>& __tp,
4050 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4053 using __format::_ChronoParts;
4054 auto __need = _ChronoParts::_YearMonthDay | _ChronoParts::_TimeOfDay;
4055 __detail::_Parser_t<_Duration> __p(__need);
4056 if (__p(__is, __fmt, __abbrev, __offset))
4058 days __d = __p._M_sys_days.time_since_epoch();
4059 auto __t = local_days(__d) + __p._M_time;
4060 __tp = __detail::__round<_Duration>(__t);
4071 void from_stream() =
delete;
4073 template<
typename _Parsable,
typename _CharT,
4074 typename _Traits = std::char_traits<_CharT>,
4075 typename... _OptArgs>
4076 concept __parsable =
requires (basic_istream<_CharT, _Traits>& __is,
4077 const _CharT* __fmt, _Parsable& __tp,
4078 _OptArgs*... __args)
4079 { from_stream(__is, __fmt, __tp, __args...); };
4081 template<
typename _Parsable,
typename _CharT,
4082 typename _Traits = char_traits<_CharT>,
4083 typename _Alloc = allocator<_CharT>>
4087 using __string_type = basic_string<_CharT, _Traits, _Alloc>;
4090 _Parse(
const _CharT* __fmt, _Parsable& __tp,
4091 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4094 _M_abbrev(__abbrev), _M_offset(__offset)
4097 _Parse(_Parse&&) =
delete;
4098 _Parse& operator=(_Parse&&) =
delete;
4101 using __stream_type = basic_istream<_CharT, _Traits>;
4103 const _CharT*
const _M_fmt;
4104 _Parsable*
const _M_tp;
4105 __string_type*
const _M_abbrev;
4108 friend __stream_type&
4109 operator>>(__stream_type& __is, _Parse&& __p)
4112 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev,
4114 else if (__p._M_abbrev)
4115 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev);
4117 from_stream(__is, __p._M_fmt, *__p._M_tp);
4121 friend void operator>>(__stream_type&, _Parse&) =
delete;
4122 friend void operator>>(__stream_type&,
const _Parse&) =
delete;
4126 template<
typename _CharT, __detail::__parsable<_CharT> _Parsable>
4127 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4129 parse(
const _CharT* __fmt, _Parsable& __tp)
4130 {
return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp); }
4132 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4133 __detail::__parsable<_CharT, _Traits> _Parsable>
4136 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp)
4138 return __detail::_Parse<_Parsable, _CharT, _Traits>(__fmt.c_str(), __tp);
4141 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4142 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4143 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
4144 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4146 parse(
const _CharT* __fmt, _Parsable& __tp,
4147 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
4150 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
4154 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4155 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4156 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
4159 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
4160 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
4163 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
4167 template<
typename _CharT,
typename _Traits =
char_traits<_CharT>,
4168 typename _StrT = basic_
string<_CharT, _Traits>,
4169 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4170 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4172 parse(
const _CharT* __fmt, _Parsable& __tp,
minutes& __offset)
4174 return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp,
nullptr,
4178 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4179 typename _StrT = basic_string<_CharT, _Traits>,
4180 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4183 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
4186 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
4191 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4192 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4193 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4194 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4196 parse(
const _CharT* __fmt, _Parsable& __tp,
4197 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
4200 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
4205 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4206 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4207 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4210 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
4211 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
4214 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
4220 template<
typename _Duration>
4221 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4222 basic_istream<_CharT, _Traits>&
4223 __detail::_Parser<_Duration>::
4224 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4225 basic_string<_CharT, _Traits, _Alloc>* __abbrev,
4228 using sentry =
typename basic_istream<_CharT, _Traits>::sentry;
4230 if (sentry __cerb(__is,
true); __cerb)
4232 locale __loc = __is.getloc();
4237 struct _Stream_state
4240 _Stream_state(basic_istream<_CharT, _Traits>& __i)
4242 _M_flags(__i.flags(ios_base::
skipws | ios_base::
dec)),
4248 _M_is.flags(_M_flags);
4252 _Stream_state(_Stream_state&&) =
delete;
4254 basic_istream<_CharT, _Traits>& _M_is;
4255 ios_base::fmtflags _M_flags;
4265 auto __read_unsigned = [&] (
int __n) {
4266 return _S_read_unsigned(__is, __err, __n);
4271 auto __read_signed = [&] (
int __n) {
4272 return _S_read_signed(__is, __err, __n);
4276 auto __read_chr = [&__is, &__err] (_CharT __c) {
4277 return _S_read_chr(__is, __err, __c);
4280 using __format::_ChronoParts;
4281 _ChronoParts __parts{};
4283 const year __bad_y = --year::min();
4284 const month __bad_mon(255);
4285 const day __bad_day(255);
4286 const weekday __bad_wday(255);
4287 const hours __bad_h(-1);
4288 const minutes __bad_min(-9999);
4291 year __y = __bad_y, __yy = __bad_y;
4292 year __iso_y = __bad_y, __iso_yy = __bad_y;
4293 month __m = __bad_mon;
4294 day __d = __bad_day;
4295 weekday __wday = __bad_wday;
4296 hours __h = __bad_h, __h12 = __bad_h;
4298 _Duration __s = __bad_sec;
4300 int __iso_wk = -1, __sunday_wk = -1, __monday_wk = -1;
4302 int __dayofyear = -1;
4304 minutes __tz_offset = __bad_min;
4305 basic_string<_CharT, _Traits> __tz_abbr;
4307 if ((_M_need & _ChronoParts::_TimeOfDay) != 0
4308 && (_M_need & _ChronoParts::_Year) != 0)
4314 __parts = _ChronoParts::_TimeOfDay;
4321 bool __is_flag =
false;
4323 constexpr bool __is_floating
4324 = treat_as_floating_point_v<typename _Duration::rep>;
4343 _CharT __c = *__fmt++;
4350 else if (!__read_chr(__c)) [[unlikely]]
4361 if (__mod || __num) [[unlikely]]
4366 __tmget.get(__is, {}, __is, __err, &__tm,
4368 if (!__is_failed(__err))
4369 __wday = weekday(__tm.tm_wday);
4371 __parts |= _ChronoParts::_Weekday;
4377 if (__mod || __num) [[unlikely]]
4385 __tmget.get(__is, {}, __is, __err, &__tm,
4387 if (!__is_failed(__err))
4388 __m = month(__tm.tm_mon + 1);
4390 __parts |= _ChronoParts::_Month;
4394 if (__mod ==
'O' || __num) [[unlikely]]
4399 __tmget.get(__is, {}, __is, __err, &__tm,
4400 __fmt - 2 - (__mod ==
'E'), __fmt);
4401 if (!__is_failed(__err))
4403 __y = year(__tm.tm_year + 1900);
4404 __m = month(__tm.tm_mon + 1);
4405 __d = day(__tm.tm_mday);
4406 __h =
hours(__tm.tm_hour);
4411 __parts |= _ChronoParts::_DateTime;
4415 if (!__mod) [[likely]]
4417 auto __v = __read_signed(__num ? __num : 2);
4418 if (!__is_failed(__err))
4420 int __cmin = (int)year::min() / 100;
4421 int __cmax = (int)year::max() / 100;
4422 if (__cmin <= __v && __v <= __cmax)
4423 __century = __v * 100;
4428 else if (__mod ==
'E')
4431 __tmget.get(__is, {}, __is, __err, &__tm,
4433 if (!__is_failed(__err))
4434 __century = __tm.tm_year;
4443 if (!__mod) [[likely]]
4445 auto __v = __read_unsigned(__num ? __num : 2);
4446 if (!__is_failed(__err))
4449 else if (__mod ==
'O')
4452 __tmget.get(__is, {}, __is, __err, &__tm,
4454 if (!__is_failed(__err))
4455 __d = day(__tm.tm_mday);
4459 __parts |= _ChronoParts::_Day;
4463 if (__mod || __num) [[unlikely]]
4467 auto __month = __read_unsigned(2);
4469 auto __day = __read_unsigned(2);
4471 auto __year = __read_unsigned(2);
4472 if (__is_failed(__err))
4474 __y = year(__year + 1900 + 100 *
int(__year < 69));
4475 __m = month(__month);
4477 if (!year_month_day(__y, __m, __d).ok())
4479 __y = __yy = __iso_y = __iso_yy = __bad_y;
4485 __parts |= _ChronoParts::_Date;
4489 if (__mod) [[unlikely]]
4493 auto __year = __read_signed(__num ? __num : 4);
4495 auto __month = __read_unsigned(2);
4497 auto __day = __read_unsigned(2);
4498 if (__is_failed(__err))
4501 __m = month(__month);
4503 if (!year_month_day(__y, __m, __d).ok())
4505 __y = __yy = __iso_y = __iso_yy = __bad_y;
4511 __parts |= _ChronoParts::_Date;
4515 if (__mod) [[unlikely]]
4519 auto __val = __read_unsigned(__num ? __num : 2);
4520 if (__val >= 0 && __val <= 99)
4522 __iso_yy = year(__val);
4523 if (__century == -1)
4527 __iso_yy = __iso_y = __y = __yy = __bad_y;
4529 __parts |= _ChronoParts::_Year;
4533 if (__mod) [[unlikely]]
4536 __iso_y = year(__read_unsigned(__num ? __num : 4));
4537 __parts |= _ChronoParts::_Year;
4542 if (__mod ==
'E') [[unlikely]]
4544 else if (__mod ==
'O')
4549 __tmget.get(__is, {}, __is, __err, &__tm,
4551 if (!__is_failed(__err))
4555 __h12 =
hours(__tm.tm_hour);
4559 __h =
hours(__tm.tm_hour);
4568 auto __val = __read_unsigned(__num ? __num : 2);
4569 if (__c ==
'I' && __val >= 1 && __val <= 12)
4571 __h12 =
hours(__val);
4574 else if (__c ==
'H' && __val >= 0 && __val <= 23)
4581 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4586 __parts |= _ChronoParts::_TimeOfDay;
4590 if (__mod) [[unlikely]]
4592 else if (_M_need == _ChronoParts::_TimeOfDay)
4594 auto __val = __read_signed(__num ? __num : 3);
4595 if (!__is_failed(__err))
4598 __parts |= _ChronoParts::_TimeOfDay;
4603 __dayofyear = __read_unsigned(__num ? __num : 3);
4610 if (__mod ==
'E') [[unlikely]]
4612 else if (__mod ==
'O')
4615 __tmget.get(__is, {}, __is, __err, &__tm,
4617 if (!__is_failed(__err))
4618 __m = month(__tm.tm_mon + 1);
4622 auto __val = __read_unsigned(__num ? __num : 2);
4623 if (__val >= 1 && __val <= 12)
4628 __parts |= _ChronoParts::_Month;
4632 if (__mod ==
'E') [[unlikely]]
4634 else if (__mod ==
'O')
4637 __tmget.get(__is, {}, __is, __err, &__tm,
4639 if (!__is_failed(__err))
4644 auto __val = __read_unsigned(__num ? __num : 2);
4645 if (0 <= __val && __val < 60)
4649 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4654 __parts |= _ChronoParts::_TimeOfDay;
4664 const _CharT* __ampms[2];
4665 __tmpunct._M_am_pm(__ampms);
4666 int __n = 0, __which = 3;
4667 while (__which != 0)
4669 auto __i = __is.peek();
4670 if (_Traits::eq_int_type(__i, _Traits::eof()))
4680 else if (__ampms[0][__n + 1] == _CharT())
4691 else if (__ampms[1][__n + 1] == _CharT())
4702 if (__which == 0 || __which == 3)
4715 __tmget.get(__is, {}, __is, __err, &__tm,
4717 if (!__is_failed(__err))
4719 __h =
hours(__tm.tm_hour);
4724 __parts |= _ChronoParts::_TimeOfDay;
4729 if (__mod || __num) [[unlikely]]
4736 auto __val = __read_unsigned(2);
4737 if (__val == -1 || __val > 23) [[unlikely]]
4738 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4743 if (!__read_chr(
':')) [[unlikely]]
4747 __val = __read_unsigned(2);
4748 if (__val == -1 || __val > 60) [[unlikely]]
4749 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4758 __parts |= _ChronoParts::_TimeOfDay;
4761 else if (!__read_chr(
':')) [[unlikely]]
4767 if (__mod ==
'E') [[unlikely]]
4769 else if (__mod ==
'O')
4772 __tmget.get(__is, {}, __is, __err, &__tm,
4774 if (!__is_failed(__err))
4777 else if constexpr (_Duration::period::den == 1
4780 auto __val = __read_unsigned(__num ? __num : 2);
4781 if (0 <= __val && __val <= 59) [[likely]]
4785 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4793 auto __digit = _S_try_read_digit(__is, __err);
4796 __buf.put(
'0' + __digit);
4797 __digit = _S_try_read_digit(__is, __err);
4799 __buf.put(
'0' + __digit);
4802 auto __i = __is.peek();
4803 if (_Traits::eq_int_type(__i, _Traits::eof()))
4811 __dp = __np.decimal_point();
4813 _CharT __c = _Traits::to_char_type(__i);
4819 = hh_mm_ss<_Duration>::fractional_width;
4822 __digit = _S_try_read_digit(__is, __err);
4824 __buf.put(
'0' + __digit);
4832 if (!__is_failed(__err)) [[likely]]
4834 long double __val{};
4835#if __cpp_lib_to_chars
4837 auto __first = __str.data();
4838 auto __last = __first + __str.size();
4842 if ((
bool)ec || ptr != __last) [[unlikely]]
4850 if constexpr (__is_floating)
4857 __parts |= _ChronoParts::_TimeOfDay;
4862 if (__mod ==
'E') [[unlikely]]
4864 else if (__mod ==
'O')
4869 __tmget.get(__is, {}, __is, __err, &__tm,
4871 if (!__is_failed(__err))
4872 __wday = weekday(__tm.tm_wday);
4879 const int __lo = __c ==
'u' ? 1 : 0;
4880 const int __hi = __lo + 6;
4881 auto __val = __read_unsigned(__num ? __num : 1);
4882 if (__lo <= __val && __val <= __hi)
4883 __wday = weekday(__val);
4886 __wday = __bad_wday;
4890 __parts |= _ChronoParts::_Weekday;
4896 if (__mod ==
'E') [[unlikely]]
4898 else if (__mod ==
'O')
4900 if (__c ==
'V') [[unlikely]]
4910 const int __lo = __c ==
'V' ? 1 : 0;
4911 const int __hi = 53;
4912 auto __val = __read_unsigned(__num ? __num : 2);
4913 if (__lo <= __val && __val <= __hi)
4918 __sunday_wk = __val;
4924 __monday_wk = __val;
4929 __iso_wk = __sunday_wk = __monday_wk = -1;
4935 if (__mod ==
'O' || __num) [[unlikely]]
4940 __tmget.get(__is, {}, __is, __err, &__tm,
4941 __fmt - 2 - (__mod ==
'E'), __fmt);
4942 if (!__is_failed(__err))
4944 __y = year(__tm.tm_year + 1900);
4945 __m = month(__tm.tm_mon + 1);
4946 __d = day(__tm.tm_mday);
4949 __parts |= _ChronoParts::_Date;
4953 if (__mod ==
'O' || __num) [[unlikely]]
4958 __tmget.get(__is, {}, __is, __err, &__tm,
4959 __fmt - 2 - (__mod ==
'E'), __fmt);
4960 if (!__is_failed(__err))
4962 __h =
hours(__tm.tm_hour);
4967 __parts |= _ChronoParts::_TimeOfDay;
4971 if (__mod) [[unlikely]]
4974 __tmget.get(__is, {}, __is, __err, &__tm,
4976 if (!__is_failed(__err))
4978 int __cent = __tm.tm_year < 2000 ? 1900 : 2000;
4979 __yy = year(__tm.tm_year - __cent);
4980 if (__century == -1)
4986 auto __val = __read_unsigned(__num ? __num : 2);
4987 if (__val >= 0 && __val <= 99)
4990 if (__century == -1)
4991 __century = __val < 69 ? 2000 : 1900;
4994 __y = __yy = __iso_yy = __iso_y = __bad_y;
4996 __parts |= _ChronoParts::_Year;
5000 if (__mod ==
'O') [[unlikely]]
5002 else if (__mod ==
'E')
5005 __tmget.get(__is, {}, __is, __err, &__tm,
5007 if (!__is_failed(__err))
5008 __y = year(__tm.tm_year);
5012 auto __val = __read_unsigned(__num ? __num : 4);
5013 if (!__is_failed(__err))
5016 __parts |= _ChronoParts::_Year;
5020 if (__num) [[unlikely]]
5027 auto __i = __is.peek();
5028 if (_Traits::eq_int_type(__i, _Traits::eof()))
5033 _CharT __ic = _Traits::to_char_type(__i);
5034 const bool __neg = __ic == _CharT(
'-');
5035 if (__ic == _CharT(
'-') || __ic == _CharT(
'+'))
5042 __hh = __read_unsigned(2);
5047 auto __d1 = _S_try_read_digit(__is, __err);
5048 auto __d2 = _S_try_read_digit(__is, __err);
5049 if (__d1 >= 0 && __d2 >= 0) [[likely]]
5050 __hh = 10 * __d1 + __d2;
5055 if (__is_failed(__err))
5059 if (_Traits::eq_int_type(__i, _Traits::eof()))
5062 __tz_offset =
minutes(__hh * (__neg ? -60 : 60));
5065 __ic = _Traits::to_char_type(__i);
5067 bool __read_mm =
false;
5070 if (__ic == _GLIBCXX_WIDEN(
":")[0])
5077 else if (_CharT(
'0') <= __ic && __ic <= _CharT(
'9'))
5083 int_least32_t __mm = 0;
5086 auto __d1 = _S_try_read_digit(__is, __err);
5087 auto __d2 = _S_try_read_digit(__is, __err);
5088 if (__d1 >= 0 && __d2 >= 0) [[likely]]
5089 __mm = 10 * __d1 + __d2;
5094 if (!__is_failed(__err))
5096 auto __z = __hh * 60 + __mm;
5097 __tz_offset =
minutes(__neg ? -__z : __z);
5103 if (__mod || __num) [[unlikely]]
5107 basic_string_view<_CharT> __x = _GLIBCXX_WIDEN(
"_/-+");
5111 auto __i = __is.peek();
5112 if (!_Traits::eq_int_type(__i, _Traits::eof()))
5114 _CharT __a = _Traits::to_char_type(__i);
5116 || __x.find(__a) != __x.npos)
5118 __tz_abbr.push_back(__a);
5127 if (__tz_abbr.empty())
5133 if (__mod || __num) [[unlikely]]
5137 _CharT __i = __is.peek();
5138 if (_Traits::eq_int_type(__i, _Traits::eof()))
5140 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
5148 if (__mod || __num) [[unlikely]]
5152 _CharT __i = __is.peek();
5153 if (_Traits::eq_int_type(__i, _Traits::eof()))
5155 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
5161 if (__mod || __num) [[unlikely]]
5169 if (__mod || __num) [[unlikely]]
5178 if (_CharT(
'1') <= __c && __c <= _CharT(
'9'))
5180 if (!__mod) [[likely]]
5183 auto __end = __fmt + _Traits::length(__fmt);
5185 = __format::__parse_integer(__fmt - 1, __end);
5186 if (__ptr) [[likely]]
5197 if (__is_failed(__err)) [[unlikely]]
5207 if (__yy != __bad_y && __y == __bad_y)
5208 __y =
years(__century) + __yy;
5209 if (__iso_yy != __bad_y && __iso_y == __bad_y)
5210 __iso_y =
years(__century) + __iso_yy;
5213 bool __can_use_doy =
false;
5214 bool __can_use_iso_wk =
false;
5215 bool __can_use_sun_wk =
false;
5216 bool __can_use_mon_wk =
false;
5219 if (__y != __bad_y && __dayofyear >= 0)
5221 __can_use_doy =
true;
5222 __parts |= _ChronoParts::_Date;
5224 else if (__y != __bad_y && __wday != __bad_wday && __sunday_wk >= 0)
5226 __can_use_sun_wk =
true;
5227 __parts |= _ChronoParts::_Date;
5229 else if (__y != __bad_y && __wday != __bad_wday && __monday_wk >= 0)
5231 __can_use_mon_wk =
true;
5232 __parts |= _ChronoParts::_Date;
5234 else if (__iso_y != __bad_y && __wday != __bad_wday && __iso_wk > 0)
5237 __can_use_iso_wk =
true;
5238 __parts |= _ChronoParts::_Date;
5241 if (__is_failed(__err)) [[unlikely]]
5243 else if (__is_flag) [[unlikely]]
5245 else if ((_M_need & __parts) == _M_need) [[likely]]
5267 const bool __need_wday = (_M_need & _ChronoParts::_Weekday) != 0;
5271 const bool __need_time = (_M_need & _ChronoParts::_TimeOfDay) != 0;
5273 if (__need_wday && __wday != __bad_wday)
5275 else if ((_M_need & _ChronoParts::_Date) != 0)
5279 const bool __need_ymd = !__need_wday && !__need_time;
5281 if (((_M_need & _ChronoParts::_Year) != 0 && __y == __bad_y)
5282 || ((_M_need & _ChronoParts::_Month) != 0 && __m == __bad_mon)
5283 || ((_M_need & _ChronoParts::_Day) != 0 && __d == __bad_day))
5290 if ((0 < __dayofyear && __dayofyear <= 365)
5291 || (__dayofyear == 366 && __y.is_leap()))
5294 _M_sys_days = sys_days(__y/January/1)
5295 +
days(__dayofyear - 1);
5297 _M_ymd = year_month_day(_M_sys_days);
5302 else if (__can_use_iso_wk)
5310 const sys_days __jan4(__iso_y/January/4);
5311 weekday __wd1(__jan4 -
days(3));
5312 if (__wd1 != Thursday)
5313 if (__wd1 != Wednesday || !__iso_y.is_leap())
5317 if (!__is_failed(__err)) [[likely]]
5320 sys_days __w(Thursday[1]/January/__iso_y);
5322 __w -= Thursday - Monday;
5324 __w += __wday - Monday;
5328 _M_ymd = year_month_day(_M_sys_days);
5331 else if (__can_use_sun_wk)
5334 sys_days __wk1(__y/January/Sunday[1]);
5335 _M_sys_days = __wk1 +
weeks(__sunday_wk - 1)
5336 +
days(__wday.c_encoding());
5337 _M_ymd = year_month_day(_M_sys_days);
5338 if (_M_ymd.year() != __y) [[unlikely]]
5341 else if (__can_use_mon_wk)
5344 sys_days __wk1(__y/January/Monday[1]);
5345 _M_sys_days = __wk1 +
weeks(__monday_wk - 1)
5346 +
days(__wday.c_encoding() - 1);
5347 _M_ymd = year_month_day(_M_sys_days);
5348 if (_M_ymd.year() != __y) [[unlikely]]
5360 if ((_M_need & _ChronoParts::_Year) != 0)
5362 if (!__y.ok()) [[unlikely]]
5365 else if (__y == __bad_y)
5368 if ((_M_need & _ChronoParts::_Month) != 0)
5370 if (!__m.ok()) [[unlikely]]
5373 else if (__m == __bad_mon)
5376 if ((_M_need & _ChronoParts::_Day) != 0)
5378 if (__d < day(1) || __d > (__y/__m/last).day())
5381 else if (__d == __bad_day)
5384 if (year_month_day __ymd(__y, __m, __d); __ymd.ok())
5387 if (__need_wday || __need_time)
5388 _M_sys_days = sys_days(_M_ymd);
5395 _M_wd = weekday(_M_sys_days);
5401 if (__h == __bad_h && __h12 != __bad_h)
5405 else if (__ampm == 2)
5406 __h = __h12 ==
hours(12) ? __h12 : __h12 +
hours(12);
5411 auto __t = _M_time.zero();
5420 if (__min != __bad_min)
5426 if (__s != __bad_sec)
5430 _M_is_leap_second = __s >=
seconds(60);
5439 if (!__is_failed(__err)) [[likely]]
5441 if (__offset && __tz_offset != __bad_min)
5442 *__offset = __tz_offset;
5443 if (__abbrev && !__tz_abbr.empty())
5451 __is.setstate(__err);
5455#undef _GLIBCXX_WIDEN
5460_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.
Template class basic_istream.
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.
Managing sequences of characters and character-like objects.
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.