30#ifndef _GLIBCXX_CHRONO_IO_H
31#define _GLIBCXX_CHRONO_IO_H 1
34#pragma GCC system_header
37#if __cplusplus >= 202002L
47namespace std _GLIBCXX_VISIBILITY(default)
49_GLIBCXX_BEGIN_NAMESPACE_VERSION
59#define _GLIBCXX_WIDEN_(C, S) ::std::__format::_Widen<C>(S, L##S)
60#define _GLIBCXX_WIDEN(S) _GLIBCXX_WIDEN_(_CharT, S)
62 template<
typename _Period,
typename _CharT>
64 __units_suffix()
noexcept
69#define _GLIBCXX_UNITS_SUFFIX(period, suffix) \
70 if constexpr (is_same_v<_Period, period>) \
71 return _GLIBCXX_WIDEN(suffix); \
74 _GLIBCXX_UNITS_SUFFIX(atto,
"as")
75 _GLIBCXX_UNITS_SUFFIX(femto,
"fs")
76 _GLIBCXX_UNITS_SUFFIX(pico,
"ps")
77 _GLIBCXX_UNITS_SUFFIX(nano,
"ns")
78 _GLIBCXX_UNITS_SUFFIX(milli,
"ms")
79#if _GLIBCXX_USE_ALT_MICROSECONDS_SUFFIX
82 _GLIBCXX_UNITS_SUFFIX(micro,
"\u00b5s")
84 _GLIBCXX_UNITS_SUFFIX(micro,
"us")
86 _GLIBCXX_UNITS_SUFFIX(centi,
"cs")
87 _GLIBCXX_UNITS_SUFFIX(deci,
"ds")
89 _GLIBCXX_UNITS_SUFFIX(deca,
"das")
90 _GLIBCXX_UNITS_SUFFIX(hecto,
"hs")
91 _GLIBCXX_UNITS_SUFFIX(kilo,
"ks")
92 _GLIBCXX_UNITS_SUFFIX(mega,
"Ms")
93 _GLIBCXX_UNITS_SUFFIX(giga,
"Gs")
94 _GLIBCXX_UNITS_SUFFIX(tera,
"Ts")
95 _GLIBCXX_UNITS_SUFFIX(tera,
"Ts")
96 _GLIBCXX_UNITS_SUFFIX(peta,
"Ps")
97 _GLIBCXX_UNITS_SUFFIX(exa,
"Es")
101#undef _GLIBCXX_UNITS_SUFFIX
105 template<
typename _Period,
typename _CharT,
typename _Out>
107 __fmt_units_suffix(_Out __out)
noexcept
109 if (
auto __s = __detail::__units_suffix<_Period, _CharT>(); __s.size())
110 return __format::__write(
std::move(__out), __s);
111 else if constexpr (_Period::den == 1)
112 return std::format_to(
std::move(__out), _GLIBCXX_WIDEN(
"[{}]s"),
113 (uintmax_t)_Period::num);
115 return std::format_to(
std::move(__out), _GLIBCXX_WIDEN(
"[{}/{}]s"),
116 (uintmax_t)_Period::num,
117 (uintmax_t)_Period::den);
126 template<
typename _CharT,
typename _Traits,
127 typename _Rep,
typename _Period>
133 using period =
typename _Period::type;
141 __detail::__fmt_units_suffix<period, _CharT>(_Out(__s));
151 template<
typename _Duration>
152 struct __local_time_fmt
154 local_time<_Duration> _M_time;
155 const string* _M_abbrev;
161 template<
typename _Duration>
162 using __local_time_fmt_for
163 = __local_time_fmt<common_type_t<_Duration, seconds>>;
176 template<
typename _Duration>
177 inline __detail::__local_time_fmt<_Duration>
179 const string* __abbrev =
nullptr,
180 const seconds* __offset_sec =
nullptr)
181 {
return {__time, __abbrev, __offset_sec}; }
189 [[noreturn,__gnu__::__always_inline__]]
191 __not_valid_for_duration()
192 { __throw_format_error(
"format error: chrono-format-spec not valid for "
193 "chrono::duration"); }
195 [[noreturn,__gnu__::__always_inline__]]
197 __invalid_chrono_spec()
198 { __throw_format_error(
"format error: chrono-format-spec not valid for "
204 enum class _ChronoParts :
unsigned short {
205 _None = 0, _TotalSeconds = 1u, _Subseconds = 1u << 2,
208 _EpochUnits = 1u << 3, _UnitSuffix = 1u << 4,
209 _EpochSeconds = _EpochUnits | _TotalSeconds,
212 _LocalDays = 1u << 5,
213 _LocalSeconds = _LocalDays | _TotalSeconds,
215 _Year = 1u << 6, _Month = 1u << 7, _Day = 1u << 8,
216 _Weekday = 1u << 9, _WeekdayIndex = 1u << 10, _DayOfYear = 1u << 11,
217 _IndexedWeekday = _Weekday | _WeekdayIndex,
218 _YearMonthDay = _Year | _Month | _Day,
219 _Date = _LocalDays | _YearMonthDay | _IndexedWeekday | _DayOfYear,
221 _HoursMinutesSeconds = 1u << 12,
222 _TimeOfDay = _HoursMinutesSeconds | _Subseconds,
223 _Time = _TimeOfDay | _TotalSeconds,
224 _EpochTime = _Time | _EpochUnits | _UnitSuffix,
225 _DateTime = _Date | _Time,
227 _ZoneAbbrev = 1u << 13, _ZoneOffset = 1u << 14,
228 _TimeZone = _ZoneAbbrev | _ZoneOffset,
229 _ZonedDateTime = _DateTime | _TimeZone,
232 [[__gnu__::__always_inline__]]
233 constexpr _ChronoParts
234 operator&(_ChronoParts __x, _ChronoParts __y)
noexcept
235 {
return static_cast<_ChronoParts
>((unsigned)__x & (unsigned)__y); }
237 [[__gnu__::__always_inline__]]
238 constexpr _ChronoParts&
239 operator&=(_ChronoParts& __x, _ChronoParts __y)
noexcept
240 {
return __x = __x & __y; }
242 [[__gnu__::__always_inline__]]
243 constexpr _ChronoParts
244 operator|(_ChronoParts __x, _ChronoParts __y)
noexcept
245 {
return static_cast<_ChronoParts
>((
unsigned short)__x | (
unsigned short)__y); }
247 [[__gnu__::__always_inline__]]
248 constexpr _ChronoParts&
249 operator|=(_ChronoParts& __x, _ChronoParts __y)
noexcept
250 {
return __x = __x | __y; }
253 [[__gnu__::__always_inline__]]
254 constexpr _ChronoParts
255 operator-(_ChronoParts __x, _ChronoParts __y)
noexcept
256 {
return static_cast<_ChronoParts
>((
unsigned short)__x & ~(
unsigned short)__y); }
259 [[__gnu__::__always_inline__]]
260 constexpr _ChronoParts&
261 operator-=(_ChronoParts& __x, _ChronoParts __y)
noexcept
262 {
return __x = __x - __y; }
264 [[__gnu__::__always_inline__]]
266 operator==(_ChronoParts __x,
decltype(
nullptr)) noexcept
267 {
return (
unsigned short)__x == 0; }
269 template<
typename _CharT>
270 struct _ChronoSpec : _Spec<_CharT>
281 unsigned _M_locale_specific : 1;
284 unsigned _M_needs_ok_check : 1;
286 unsigned _M_floating_point_rep : 1;
288 unsigned _M_custom_rep : 1;
289 unsigned _M_unused : 4;
292 _ChronoParts _M_needed;
293 basic_string_view<_CharT> _M_chrono_specs;
295 [[__gnu__::__always_inline__]]
297 _M_needs(_ChronoParts __parts)
const
298 {
return (_M_needed & __parts) != 0; }
301 template<
typename _CharT>
302 struct _ChronoFormats
304 using _String_view = basic_string_view<_CharT>;
309 {
return _GLIBCXX_WIDEN(
"%F %T %Z"); }
314 {
return _S_ftz().substr(0, 5); }
319 {
return _S_ftz().substr(0, 2); }
324 {
return _S_ftz().substr(3, 2); }
329 {
return _GLIBCXX_WIDEN(
"%Y/%b/%d"); }
334 {
return _S_ymd().substr(0, 5); }
339 {
return _S_ymd().substr(3); }
344 {
return _S_ymd().substr(0, 2); }
349 {
return _S_ymd().substr(3, 2); }
354 {
return _S_ymd().substr(6, 2); }
360 {
return _String_view(_GLIBCXX_WIDEN(
"%Y/%b/%a[%\0]"), 12); }
365 {
return _S_ymwi().substr(3); }
370 {
return _S_ymwi().substr(6); }
375 {
return _S_ymwi().substr(6, 2); }
380 {
return _GLIBCXX_WIDEN(
"%Y/%b/%a[last]"); }
385 {
return _S_ymwl().substr(3); }
390 {
return _S_ymwl().substr(6); }
395 {
return _GLIBCXX_WIDEN(
"%Y/%b/last"); }
400 {
return _S_yml().substr(3); }
403 template<
typename _CharT>
406 static constexpr unsigned _S_max_prec = 18;
407 using _Attoseconds = chrono::duration<__UINT_LEAST64_TYPE__, atto>;
410 = basic_format_context<_Sink_iter<_CharT>, _CharT>;
411 using _FormatArgs = basic_format_args<_FormatContext>;
412 static inline auto _S_args = std::make_format_args<_FormatContext>();
414 _ChronoData() =
default;
415 _ChronoData(_ChronoData&&) =
delete;
418 chrono::seconds _M_eseconds;
421 _Attoseconds _M_subseconds;
425 _FormatArgs _M_ereps = _S_args;
426 basic_string_view<_CharT> _M_unit_suffix;
429 chrono::local_seconds _M_lseconds;
430 chrono::local_days _M_ldays;
432 chrono::year _M_year;
433 chrono::month _M_month;
435 chrono::weekday _M_weekday;
436 unsigned char _M_weekday_index;
437 chrono::days _M_day_of_year;
440 chrono::hours _M_hours;
441 chrono::minutes _M_minutes;
442 chrono::seconds _M_seconds;
444 chrono::seconds _M_zone_offset;
445 basic_string_view<_CharT> _M_zone_abbrev;
446 const char* _M_zone_cstr =
"";
448 template<
typename _YearMonth>
449 [[__gnu__::__always_inline__]]
451 _M_fill_year_month(
const _YearMonth& __ym, _ChronoParts __parts)
453 _M_year = __ym.year();
454 __parts -= _ChronoParts::_Year;
455 _M_month = __ym.month();
456 __parts -= _ChronoParts::_Month;
460 [[__gnu__::__always_inline__]]
462 _M_fill_day(chrono::day __d, _ChronoParts __parts)
465 __parts -= _ChronoParts::_Day;
466 _M_weekday_index = ((unsigned)__d + 6u) % 7u;
467 __parts -= _ChronoParts::_WeekdayIndex;
471 [[__gnu__::__always_inline__]]
473 _M_fill_weekday(chrono::weekday_indexed __wi, _ChronoParts __parts)
475 _M_weekday = __wi.weekday();
476 __parts -= _ChronoParts::_Weekday;
477 _M_weekday_index = __wi.index();
478 __parts -= _ChronoParts::_WeekdayIndex;
482 [[__gnu__::__always_inline__]]
484 _M_fill_aux(chrono::local_days __ld, _ChronoParts __parts)
486 using namespace chrono;
487 if ((__parts & _ChronoParts::_Weekday) != 0)
488 _M_weekday = weekday(__ld);
489 __parts -= _ChronoParts::_Weekday;
490 if ((__parts & _ChronoParts::_DayOfYear) != 0)
493 _M_day_of_year = __ld - local_days(_M_year/January/0);
494 __parts -= _ChronoParts::_DayOfYear;
498 [[__gnu__::__always_inline__]]
500 _M_fill_ldays(chrono::local_days __ld, _ChronoParts __parts)
503 __parts -= _ChronoParts::_LocalDays;
504 return _M_fill_aux(__ld, __parts);
508 _M_fill_time(chrono::seconds __d)
510 chrono::hh_mm_ss<chrono::seconds> __hms(__d);
511 _M_hours = __hms.hours();
512 _M_minutes = __hms.minutes();
513 _M_seconds = __hms.seconds();
517 _M_fill_date_time(chrono::local_seconds __ls, _ChronoParts __parts)
519 _M_ldays = chrono::floor<chrono::days>(__ls);
520 __parts -= _ChronoParts::_LocalDays;
521 if ((__parts & _ChronoParts::_HoursMinutesSeconds) != 0)
522 _M_fill_time(_M_lseconds - _M_ldays);
524 if ((__parts & _ChronoParts::_Date) != 0)
526 const chrono::year_month_day __ymd(_M_ldays);
527 _M_fill_year_month(__ymd, __parts);
528 _M_fill_day(__ymd.day(), __parts);
529 _M_fill_aux(_M_ldays, __parts);
534 _M_fill_zone(
const char* __abbrev,
const wchar_t* __wabbrev)
536 if constexpr (is_same_v<_CharT, char>)
537 _M_zone_abbrev = __abbrev;
539 _M_zone_abbrev = __wabbrev;
540 _M_zone_cstr = __abbrev;
543 [[__gnu__::__always_inline__]]
546 { _M_fill_zone(
"UTC", L
"UTC"); }
550 template<
typename _CharT>
551 struct __formatter_chrono
553 using __string_view = basic_string_view<_CharT>;
554 using __string = basic_string<_CharT>;
556 __formatter_chrono() =
default;
559 __formatter_chrono(_ChronoSpec<_CharT> __spec) noexcept
563 constexpr typename basic_format_parse_context<_CharT>::iterator
564 _M_parse(basic_format_parse_context<_CharT>& __pc, _ChronoParts __parts,
565 const _ChronoSpec<_CharT>& __def)
567 auto __first = __pc.
begin();
568 auto __last = __pc.end();
570 _ChronoSpec<_CharT> __spec = __def;
572 auto __finalize = [
this, &__spec, &__def] {
573 using enum _ChronoParts;
574 _ChronoParts __checked
575 = __spec._M_debug ? _YearMonthDay|_IndexedWeekday
579 __spec._M_needs_ok_check
580 = __spec._M_needs(__def._M_needed & __checked);
584 auto __finished = [&] {
585 if (__first == __last || *__first ==
'}')
596 __first = __spec._M_parse_fill_and_align(__first, __last);
600 __first = __spec._M_parse_width(__first, __last, __pc);
606 if ((__parts & _ChronoParts::_EpochUnits) == 0
607 || !__spec._M_floating_point_rep)
608 __throw_format_error(
"format error: invalid precision for duration");
611 __first = _Spec<_CharT>()._M_parse_precision(__first, __last, __pc);
613 __spec._M_prec_kind = _WP_value;
618 __spec._M_localized =
false;
619 __first = __spec._M_parse_locale(__first, __last);
626 __string_view __str(__first, __last - __first);
627 auto __end = __str.find(
'}');
628 if (__end != __str.npos)
630 __str.remove_suffix(__str.length() - __end);
631 __last = __first + __end;
633 if (__str.find(
'{') != __str.npos)
634 __throw_format_error(
"chrono format error: '{' in chrono-specs");
640 __spec._M_debug =
false;
641 __spec._M_locale_specific =
false;
642 __spec._M_needed = _ChronoParts::_None;
643 __spec._M_chrono_specs = __string_view();
645 const auto __chrono_specs = __first++;
646 if (*__chrono_specs !=
'%')
647 __throw_format_error(
"chrono format error: no '%' at start of "
652 while (__first != __last)
654 enum _Mods { _Mod_none, _Mod_E, _Mod_O, _Mod_E_O };
655 _Mods __allowed_mods = _Mod_none;
657 _ChronoParts __needed = _ChronoParts::_None;
658 bool __locale_specific =
false;
660 _CharT __c = *__first++;
663 using enum _ChronoParts;
667 __locale_specific =
true;
673 __locale_specific =
true;
676 __needed = _Date|_HoursMinutesSeconds;
677 __allowed_mods = _Mod_E;
678 __locale_specific =
true;
682 __allowed_mods = _Mod_E;
687 __allowed_mods = _Mod_O;
691 __needed = _YearMonthDay;
696 __needed = _LocalDays|_Year|_DayOfYear|_Weekday;
700 __needed = _HoursMinutesSeconds;
701 __allowed_mods = _Mod_O;
704 __needed = __parts & _DayOfYear;
707 if (__needed == _None)
708 __needed = _HoursMinutesSeconds;
712 __allowed_mods = _Mod_O;
715 __needed = _HoursMinutesSeconds;
716 __allowed_mods = _Mod_O;
720 __locale_specific =
true;
723 __needed = _HoursMinutesSeconds;
726 __needed = _TimeOfDay;
729 __needed = _UnitSuffix;
732 __needed = _EpochUnits;
735 __needed = _TimeOfDay;
736 __allowed_mods = _Mod_O;
741 __allowed_mods = _Mod_O;
745 __needed = _DayOfYear|_Weekday;
746 __allowed_mods = _Mod_O;
750 __locale_specific =
true;
751 __allowed_mods = _Mod_E;
754 __needed = _HoursMinutesSeconds;
755 __locale_specific =
true;
756 __allowed_mods = _Mod_E;
760 __allowed_mods = _Mod_E_O;
764 __allowed_mods = _Mod_E;
767 __needed = _ZoneOffset;
768 __allowed_mods = _Mod_E_O;
771 __needed = _ZoneAbbrev;
779 if (__mod) [[unlikely]]
781 __allowed_mods = _Mod_none;
787 __throw_format_error(
"chrono format error: invalid specifier "
791 if ((__mod ==
'E' && !(__allowed_mods & _Mod_E))
792 || (__mod ==
'O' && !(__allowed_mods & _Mod_O)))
793 __throw_format_error(
"chrono format error: invalid modifier "
795 if (__mod && __c !=
'z')
796 __locale_specific =
true;
800 if (__locale_specific)
801 __needed -= _ChronoParts::_Subseconds;
803 if ((__parts & __needed) != __needed)
804 __throw_format_error(
"chrono format error: format argument does "
805 "not contain the information required by the "
807 __spec._M_needed |= __needed;
808 __spec._M_locale_specific |= __locale_specific;
811 size_t __pos = __string_view(__first, __last - __first).find(
'%');
816 if (__pos == __string_view::npos)
822 __first += __pos + 1;
827 if (__conv || __mod != _CharT())
828 __throw_format_error(
"chrono format error: unescaped '%' in "
831 __spec._M_chrono_specs
832 = __string_view(__chrono_specs, __first - __chrono_specs);
839 template<
typename _FormatContext>
840 typename _FormatContext::iterator
841 _M_format(
const _ChronoData<_CharT>& __t, _FormatContext& __fc)
const
843#if defined _GLIBCXX_USE_NL_LANGINFO_L && __CHAR_BIT__ == 8
847 if constexpr (is_same_v<_CharT, char>)
848 if constexpr (__unicode::__literal_encoding_is_utf8())
849 if (_M_spec._M_localized && _M_spec._M_locale_specific)
851 extern locale __with_encoding_conversion(
const locale&);
855 locale __loc = __fc.locale();
856 if (__loc != locale::classic())
857 __fc._M_loc = __with_encoding_conversion(__loc);
861 const size_t __padwidth = _M_spec._M_get_width(__fc);
863 return _M_format_to(__t, __fc.out(), __fc);
865 using _Out =
typename _FormatContext::iterator;
866 _Padding_sink<_Out, _CharT> __sink(__fc.out(), __padwidth);
867 _M_format_to(__t, __sink.out(), __fc);
868 return __sink._M_finish(_M_spec._M_align, _M_spec._M_fill);
871 _ChronoSpec<_CharT> _M_spec;
874 static constexpr const _CharT* _S_chars
875 = _GLIBCXX_WIDEN(
"0123456789.Lf:/ +-{}");
876 static constexpr _CharT _S_dot = _S_chars[10];
877 static constexpr _CharT _S_colon = _S_chars[13];
878 static constexpr _CharT _S_slash = _S_chars[14];
879 static constexpr _CharT _S_space = _S_chars[15];
880 static constexpr const _CharT* _S_fp_fmt = _S_chars + 11;
881 static constexpr const _CharT* _S_plus_minus = _S_chars + 16;
882 static constexpr const _CharT* _S_minus_empty_spec = _S_chars + 17;
883 static constexpr const _CharT* _S_empty_spec = _S_chars + 18;
885 [[__gnu__::__always_inline__]]
886 static _Runtime_format_string<_CharT>
888 {
return _Runtime_format_string<_CharT>(_S_empty_spec); }
890 static constexpr const _CharT* _S_weekdays[]
892 _GLIBCXX_WIDEN(
"Sunday"),
893 _GLIBCXX_WIDEN(
"Monday"),
894 _GLIBCXX_WIDEN(
"Tuesday"),
895 _GLIBCXX_WIDEN(
"Wednesday"),
896 _GLIBCXX_WIDEN(
"Thursday"),
897 _GLIBCXX_WIDEN(
"Friday"),
898 _GLIBCXX_WIDEN(
"Saturday"),
901 static constexpr const _CharT* _S_months[]
903 _GLIBCXX_WIDEN(
"January"),
904 _GLIBCXX_WIDEN(
"February"),
905 _GLIBCXX_WIDEN(
"March"),
906 _GLIBCXX_WIDEN(
"April"),
907 _GLIBCXX_WIDEN(
"May"),
908 _GLIBCXX_WIDEN(
"June"),
909 _GLIBCXX_WIDEN(
"July"),
910 _GLIBCXX_WIDEN(
"August"),
911 _GLIBCXX_WIDEN(
"September"),
912 _GLIBCXX_WIDEN(
"October"),
913 _GLIBCXX_WIDEN(
"November"),
914 _GLIBCXX_WIDEN(
"December"),
918 template<
typename _OutIter>
920 _M_write(_OutIter __out,
const locale& __loc, __string_view __s)
const
922#if defined _GLIBCXX_USE_NL_LANGINFO_L && __CHAR_BIT__ == 8
927 if constexpr (is_same_v<_CharT, char>)
928 if constexpr (__unicode::__literal_encoding_is_utf8())
929 if (_M_spec._M_localized && _M_spec._M_locale_specific
930 && __loc != locale::classic())
933 __locale_encoding_to_utf8(
const locale&, string_view,
void*);
935 __s = __locale_encoding_to_utf8(__loc, __s, &__buf);
938 return __format::__write(
std::move(__out), __s);
941 [[__gnu__::__always_inline__]]
943 _S_localized_spec(_CharT __conv, _CharT __mod)
967 template<
typename _Iter>
969 _M_locale_fmt(_Iter __out,
const locale& __loc,
const struct tm& __tm,
970 char __fmt,
char __mod)
const
972 basic_ostringstream<_CharT> __os;
974 const auto& __tp = use_facet<time_put<_CharT>>(__loc);
975 __tp.put(__os, __os, _S_space, &__tm, __fmt, __mod);
977 __out = _M_write(
std::move(__out), __loc, __os.view());
982 _M_check_ok(
const _ChronoData<_CharT>& __t, _CharT& __conv)
const
984 if (!_M_spec._M_debug)
990 if (!__t._M_weekday.ok()) [[unlikely]]
991 __throw_format_error(
"format error: invalid weekday");
996 if (!__t._M_month.ok()) [[unlikely]]
997 __throw_format_error(
"format error: invalid month");
1002 return __string_view();
1009 if (__t._M_weekday_index < 1 || __t._M_weekday_index > 5) [[unlikely]]
1010 return _GLIBCXX_WIDEN(
"index");
1014 if (!__t._M_weekday.ok()) [[unlikely]]
1017 return _GLIBCXX_WIDEN(
"weekday");
1023 if (!__t._M_month.ok()) [[unlikely]]
1026 return _GLIBCXX_WIDEN(
"month");
1031 if (!__t._M_day.ok()) [[unlikely]]
1032 return _GLIBCXX_WIDEN(
"day");
1035 if (!(__t._M_year/__t._M_month/__t._M_day).ok()) [[unlikely]]
1036 return _GLIBCXX_WIDEN(
"date");
1039 if (!__t._M_year.ok()) [[unlikely]]
1040 return _GLIBCXX_WIDEN(
"year");
1045 return __string_view();
1048 template<
typename _OutIter,
typename _FormatContext>
1050 _M_format_to(
const _ChronoData<_CharT>& __t, _OutIter __out,
1051 _FormatContext& __fc)
const
1053 auto __first = _M_spec._M_chrono_specs.begin();
1054 const auto __last = _M_spec._M_chrono_specs.end();
1056 auto __print_sign = [__is_neg = __t._M_is_neg, &__out] ()
mutable {
1059 *__out++ = _S_plus_minus[1];
1066 bool __use_locale_fmt =
false;
1067 if (_M_spec._M_localized && _M_spec._M_locale_specific)
1068 if (__fc.locale() != locale::classic())
1070 __use_locale_fmt =
true;
1072 __tm.tm_year = (int)__t._M_year - 1900;
1073 __tm.tm_yday = __t._M_day_of_year.count();
1074 __tm.tm_mon = (unsigned)__t._M_month - 1;
1075 __tm.tm_mday = (unsigned)__t._M_day;
1076 __tm.tm_wday = __t._M_weekday.c_encoding();
1077 __tm.tm_hour = __t._M_hours.count();
1078 __tm.tm_min = __t._M_minutes.count();
1079 __tm.tm_sec = __t._M_seconds.count();
1087#ifdef _GLIBCXX_USE_STRUCT_TM_TM_ZONE
1090 if (__t._M_zone_cstr)
1091 __tm.tm_zone =
const_cast<char*
>(__t._M_zone_cstr);
1096 constexpr const _CharT* __literals = _GLIBCXX_WIDEN(
"\n\t%");
1103 _CharT __c = *__first++;
1104 __string_view __invalid;
1105 if (_M_spec._M_needs_ok_check)
1106 __invalid = _M_check_ok(__t, __c);
1108 if (__invalid.empty() &&__use_locale_fmt
1109 && _S_localized_spec(__c, __mod)) [[unlikely]]
1110 __out = _M_locale_fmt(
std::move(__out), __fc.locale(),
1116 __out = _M_wi(__t._M_weekday_index,
std::move(__out));
1120 __out = _M_a_A(__t._M_weekday,
std::move(__out), __c ==
'A');
1125 __out = _M_b_B(__t._M_month,
std::move(__out), __c ==
'B');
1133 __out = _M_C_y_Y(__t._M_year,
std::move(__out), __c);
1137 __out = _M_d_e(__t._M_day,
std::move(__out), __c);
1149 __out = _M_g_G_V(__t,
std::move(__out), __c);
1153 __out = _M_H_I(__t._M_hours, __print_sign(), __c);
1156 __out = _M_j(__t, __print_sign());
1159 __out = _M_m(__t._M_month,
std::move(__out));
1162 __out = _M_M(__t._M_minutes, __print_sign());
1165 __out = _M_p(__t._M_hours,
std::move(__out));
1168 __out = _M_q(__t._M_unit_suffix,
std::move(__out));
1171 __out = _M_Q(__t, __print_sign(), __fc);
1174 __out = _M_r(__t, __print_sign());
1178 __out = _M_R_X(__t, __print_sign(), __c !=
'R');
1181 __out = _M_T(__t, __print_sign(), __fc);
1184 __out = _M_S(__t, __print_sign(), __fc, __mod !=
'O');
1188 __out = _M_u_w(__t._M_weekday,
std::move(__out), __c);
1192 __out = _M_U_W(__t,
std::move(__out), __c);
1195 __out = _M_z(__t._M_zone_offset,
std::move(__out), (
bool)__mod);
1198 __out = _M_Z(__t._M_zone_abbrev,
std::move(__out));
1201 *__out++ = __literals[0];
1204 *__out++ = __literals[1];
1207 *__out++ = __literals[2];
1218 if (!__invalid.empty())
1220 constexpr __string_view __pref = _GLIBCXX_WIDEN(
" is not a valid ");
1221 __out = __format::__write(
std::move(__out), __pref);
1222 __out = __format::__write(
std::move(__out), __invalid);
1227 __string_view __str(__first, __last - __first);
1228 size_t __pos = __str.find(
'%');
1233 if (__pos == __str.npos)
1237 __str.remove_suffix(__str.length() - __pos);
1238 __first += __pos + 1;
1240 __out = __format::__write(
std::move(__out), __str);
1243 while (__first != __last);
1247 template<
typename _OutIter>
1249 _M_wi(
unsigned __wi, _OutIter __out)
const
1253 __out = __format::__write(
std::move(__out), _S_str_d1(__buf, __wi));
1257 template<
typename _OutIter>
1259 _M_a_A(chrono::weekday __wd, _OutIter __out,
bool __full)
const
1263 __string_view __str = _S_weekdays[__wd.c_encoding()];
1265 __str = __str.substr(0, 3);
1266 return __format::__write(
std::move(__out), __str);
1269 template<
typename _OutIter>
1271 _M_b_B(chrono::month __m, _OutIter __out,
bool __full)
const
1275 __string_view __str = _S_months[(unsigned)__m - 1];
1277 __str = __str.substr(0, 3);
1278 return __format::__write(
std::move(__out), __str);
1281 template<
typename _OutIter>
1283 _M_c(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1288 __out = _M_a_A(__t._M_weekday,
std::move(__out),
false);
1290 __out = _M_b_B(__t._M_month,
std::move(++__out),
false);
1292 __out = _M_d_e(__t._M_day,
std::move(++__out),
'e');
1294 __out = _M_R_X(__t,
std::move(++__out),
true);
1296 return _M_C_y_Y(__t._M_year,
std::move(++__out),
'Y');
1299 template<
typename _OutIter>
1301 _M_C_y_Y(chrono::year __y, _OutIter __out, _CharT __conv)
const
1311 int __yi = (int)__y;
1312 const bool __is_neg = __yi < 0;
1313 __yi = __builtin_abs(__yi);
1314 int __ci = __yi / 100;
1316 if (__conv ==
'C' && __is_neg && (__ci * 100) != __yi) [[unlikely]]
1319 if (__conv !=
'y' && __ci >= 100) [[unlikely]]
1321 using _FmtStr = _Runtime_format_string<_CharT>;
1322 __string_view __fs = _S_minus_empty_spec + !__is_neg;
1323 __out = std::format_to(
std::move(__out), _FmtStr(__fs),
1324 __conv ==
'C' ? __ci : __yi);
1329 __buf[0] = _S_plus_minus[1];
1330 __string_view __sv(__buf + 3, __buf + 3);
1333 _S_fill_two_digits(__buf + 1, __ci);
1334 __sv = __string_view(__buf + !__is_neg, __buf + 3);
1338 _S_fill_two_digits(__buf + 3, __yi % 100);
1339 __sv = __string_view(__sv.data(), __buf + 5);
1341 __out = __format::__write(
std::move(__out), __sv);
1346 template<
typename _OutIter>
1348 _M_D_x(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1354 auto __di = (unsigned)__t._M_day;
1355 auto __mi = (unsigned)__t._M_month;
1356 auto __yi = __builtin_abs((
int)__t._M_year) % 100;
1358 if (__mi >= 100 || __di >= 100) [[unlikely]]
1360 using _FmtStr = _Runtime_format_string<_CharT>;
1361 __string_view __fs = _GLIBCXX_WIDEN(
"{:02d}/{:02d}/{:02d}");
1362 __out = std::format_to(
std::move(__out), _FmtStr(__fs),
1368 __buf[2] = _S_slash;
1369 __buf[5] = _S_slash;
1370 __string_view __sv(__buf, __buf + 8);
1372 _S_fill_two_digits(__buf, __mi);
1373 _S_fill_two_digits(__buf + 3, __di);
1374 _S_fill_two_digits(__buf + 6, __yi);
1375 __out = __format::__write(
std::move(__out), __sv);
1380 template<
typename _OutIter>
1382 _M_d_e(chrono::day __d, _OutIter __out, _CharT __conv)
const
1389 unsigned __i = (unsigned)__d;
1392 auto __sv = _S_str_d2(__buf, __i);
1393 if (__conv == _CharT(
'e') && __i < 10)
1396 __buf[0] = _S_space;
1400 __out = __format::__write(
std::move(__out), __sv);
1404 template<
typename _OutIter>
1406 _M_F(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1408 auto __di = (unsigned)__t._M_day;
1409 auto __mi = (unsigned)__t._M_month;
1410 auto __yi = (int)__t._M_year;
1411 const bool __is_neg = __yi < 0;
1412 __yi = __builtin_abs(__yi);
1414 if (__yi >= 10000 || __mi >= 100 || __di >= 100) [[unlikely]]
1416 using _FmtStr = _Runtime_format_string<_CharT>;
1418 = _GLIBCXX_WIDEN(
"-{:04d}-{:02d}-{:02d}") + !__is_neg;
1419 __out = std::format_to(
std::move(__out), _FmtStr(__fs),
1425 __buf[0] = _S_plus_minus[1];
1426 __buf[5] = _S_plus_minus[1];
1427 __buf[8] = _S_plus_minus[1];
1428 __string_view __sv(__buf + !__is_neg, __buf + 11);
1430 _S_fill_two_digits(__buf + 1, __yi / 100);
1431 _S_fill_two_digits(__buf + 3, __yi % 100);
1432 _S_fill_two_digits(__buf + 6, __mi);
1433 _S_fill_two_digits(__buf + 9, __di);
1434 __out = __format::__write(
std::move(__out), __sv);
1440 template<
typename _OutIter>
1442 _M_g_G_V(
const _ChronoData<_CharT>& __t, _OutIter __out,
1443 _CharT __conv)
const
1454 using namespace chrono;
1456 const days __offset = (__t._M_weekday - Monday) -
days(3);
1458 const local_days __ild = __t._M_ldays - __offset;
1460 days __idoy = __t._M_day_of_year - __offset;
1464 if (__idoy <=
days(0))
1465 __iyear = __t._M_year -
years(1);
1466 else if (__idoy <=
days(365))
1467 __iyear = __t._M_year;
1468 else if (__idoy ==
days(366) && __t._M_year.is_leap())
1469 __iyear = __t._M_year;
1470 else if (__idoy <=
days(730))
1471 __iyear = __t._M_year +
years(1);
1473 __iyear = year_month_day(__ild).year();
1476 return _M_C_y_Y(__iyear,
std::move(__out),
"yY"[__conv ==
'G']);
1478 if (__iyear != __t._M_year)
1479 __idoy = __ild - local_days(__iyear/January/0);
1481 const auto __wi = chrono::floor<weeks>(__idoy -
days(1)).count() + 1;
1482 return __format::__write(
std::move(__out), _S_two_digits(__wi));
1485 template<
typename _OutIter>
1487 _M_H_I(chrono::hours __h, _OutIter __out, _CharT __conv)
const
1494 int __i = __h.count();
1496 if (__conv == _CharT(
'I'))
1502 else if (__i >= 100) [[unlikely]]
1503 return std::format_to(
std::move(__out), _S_empty_fs(), __i);
1505 return __format::__write(
std::move(__out), _S_two_digits(__i));
1508 template<
typename _OutIter>
1510 _M_j(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1512 if (!_M_spec._M_needs(_ChronoParts::_DayOfYear))
1515 auto __d = chrono::floor<chrono::days>(__t._M_hours).count();
1516 return std::format_to(
std::move(__out), _S_empty_fs(), __d);
1519 auto __d = __t._M_day_of_year.count();
1520 if (__d >= 1000) [[unlikely]]
1521 return std::format_to(
std::move(__out), _S_empty_fs(), __d);
1524 return __format::__write(
std::move(__out), _S_str_d3(__buf, __d));
1527 template<
typename _OutIter>
1529 _M_m(chrono::month __m, _OutIter __out)
const
1533 auto __i = (unsigned)__m;
1534 if (__i == 0 && _M_spec._M_debug) [[unlikely]]
1536 return __format::__write(
std::move(__out), _S_digit(0));
1539 return __format::__write(
std::move(__out), _S_str_d2(__buf, __i));
1542 template<
typename _OutIter>
1544 _M_M(chrono::minutes __m, _OutIter __out)
const
1549 auto __i = __m.count();
1550 return __format::__write(
std::move(__out), _S_two_digits(__i));
1553 template<
typename _OutIter>
1555 _M_p(chrono::hours __h, _OutIter __out)
const
1560 _S_fill_ampm(__buf, __h);
1561 return __format::__write(
std::move(__out), __string_view(__buf, 2));
1564 template<
typename _OutIter>
1566 _M_q(__string_view __us, _OutIter __out)
const
1569 return __format::__write(
std::move(__out), __us);
1572 template<
typename _OutIter,
typename _FormatContext>
1574 _M_Q(
const _ChronoData<_CharT>& __t, _OutIter __out,
1575 _FormatContext&)
const
1578 return std::vformat_to(
std::move(__out), _S_empty_spec, __t._M_ereps);
1581 template<
typename _OutIter>
1583 _M_r(
const _ChronoData<_CharT>& __t, _OutIter __out)
const
1586 auto __hi = __t._M_hours.count() % 12;
1591 __buf[2] = _S_colon;
1592 __buf[5] = _S_colon;
1593 __buf[8] = _S_space;
1594 _S_fill_two_digits(__buf, __hi);
1595 _S_fill_two_digits(__buf + 3, __t._M_minutes.count());
1596 _S_fill_two_digits(__buf + 6, __t._M_seconds.count());
1597 _S_fill_ampm(__buf + 9, __t._M_hours);
1599 return __format::__write(
std::move(__out), __string_view(__buf, 11));
1602 template<
typename _OutIter>
1604 _M_R_X(
const _ChronoData<_CharT>& __t, _OutIter __out,
1611 auto __hi = __t._M_hours.count();
1614 __buf[2] = _S_colon;
1615 __buf[5] = _S_colon;
1616 __string_view __sv(__buf, 8);
1618 if (__hi >= 100) [[unlikely]]
1620 __out = std::format_to(
std::move(__out), _S_empty_fs(), __hi);
1621 __sv.remove_prefix(2);
1624 _S_fill_two_digits(__buf, __hi);
1626 _S_fill_two_digits(__buf + 3, __t._M_minutes.count());
1628 _S_fill_two_digits(__buf + 6, __t._M_seconds.count());
1630 __sv.remove_suffix(3);
1632 return __format::__write(
std::move(__out), __sv);
1635 template<
typename _OutIter,
typename _FormatContext>
1637 _M_S(
const _ChronoData<_CharT>& __t, _OutIter __out,
1638 _FormatContext& __ctx,
bool __subs =
true)
const
1642 auto __s = __t._M_seconds;
1644 __out = __format::__write(
std::move(__out),
1645 _S_two_digits(__s.count()));
1647 __out = _M_subsecs(__t,
std::move(__out), __ctx);
1651 template<
typename _OutIter,
typename _FormatContext>
1653 _M_subsecs(
const _ChronoData<_CharT>& __t, _OutIter __out,
1654 _FormatContext& __ctx)
const
1656 unsigned __prec = _M_spec._M_prec_kind != _WP_none
1657 ? _M_spec._M_get_precision(__ctx)
1662 _CharT __dot = _S_dot;
1663 if (_M_spec._M_localized) [[unlikely]]
1665 auto __loc = __ctx.locale();
1666 const auto& __np = use_facet<numpunct<_CharT>>(__loc);
1667 __dot = __np.decimal_point();
1672 if (_M_spec._M_floating_point_rep)
1674 _Str_sink<_CharT> __sink;
1675 if (_M_spec._M_localized && _M_spec._M_custom_rep) [[unlikely]]
1676 std::vformat_to(__sink.out(), __ctx.locale(),
1677 _GLIBCXX_WIDEN(
"{1:0.{2}Lf}"), __t._M_ereps);
1679 std::vformat_to(__sink.out(),
1680 _GLIBCXX_WIDEN(
"{1:0.{2}f}"), __t._M_ereps);
1682 auto __sv = __sink.view();
1684 __sv.remove_prefix(2);
1685 return __format::__write(
std::move(__out), __sv);
1688 constexpr unsigned __max_prec = _ChronoData<_CharT>::_S_max_prec;
1689 constexpr typename _ChronoData<_CharT>::_Attoseconds::rep __pow10t[]
1693 10'000u, 100'000u, 1000'000u,
1694 10'000'000u, 100'000'000u, 1000'000'000u,
1695 10'000'000'000u, 100'000'000'000u, 1000'000'000'000u,
1696 10'000'000'000'000u, 100'000'000'000'000u, 1000'000'000'000'000u,
1697 10'000'000'000'000'000u, 100'000'000'000'000'000u, 1000'000'000'000'000'000u,
1700 auto __subs = __t._M_subseconds.count();
1701 if (__prec < __max_prec)
1702 __subs /= __pow10t[__max_prec - __prec];
1703 else if (__prec > __max_prec)
1704 __prec = __max_prec;
1706 using _FmtStr = _Runtime_format_string<_CharT>;
1707 return std::format_to(__out, _FmtStr(_GLIBCXX_WIDEN(
"{0:0{1}}")),
1713 template<
typename _OutIter,
typename _FormatContext>
1715 _M_T(
const _ChronoData<_CharT>& __t, _OutIter __out,
1716 _FormatContext& __ctx)
const
1719 __out = _M_R_X(__t,
std::move(__out),
true);
1720 return _M_subsecs(__t,
std::move(__out), __ctx);
1723 template<
typename _OutIter>
1725 _M_u_w(chrono::weekday __wd, _OutIter __out, _CharT __conv)
const
1731 unsigned __wdi = __conv ==
'u' ? __wd.iso_encoding()
1732 : __wd.c_encoding();
1734 return __format::__write(
std::move(__out), _S_str_d1(__buf, __wdi));
1737 template<
typename _OutIter>
1739 _M_U_W(
const _ChronoData<_CharT>& __t, _OutIter __out,
1740 _CharT __conv)
const
1747 using namespace chrono;
1748 const weekday __weekstart = __conv ==
'U' ? Sunday : Monday;
1749 const days __offset = __t._M_weekday - __weekstart;
1750 auto __weeks = chrono::floor<weeks>(__t._M_day_of_year - __offset -
days(1));
1751 return __format::__write(
std::move(__out), _S_two_digits(__weeks.count() + 1));
1754 template<
typename _OutIter>
1756 _M_z(chrono::seconds __ts, _OutIter __out,
bool __mod =
false)
const
1760 __string_view __zero
1761 = __mod ? _GLIBCXX_WIDEN(
"+00:00") : _GLIBCXX_WIDEN(
"+0000");
1762 return __format::__write(
std::move(__out), __zero);
1765 chrono::hh_mm_ss<chrono::seconds> __hms(__ts);
1766 unsigned __mo = 3 + __mod;
1769 __buf[0] = _S_plus_minus[__hms.is_negative()];
1770 __buf[3] = _S_colon;
1771 _S_fill_two_digits(__buf + 1, __hms.hours().count());
1772 _S_fill_two_digits(__buf + __mo, __hms.minutes().count());
1774 __string_view __sv(__buf, __mo + 2);
1775 return __format::__write(
std::move(__out), __sv);
1778 template<
typename _OutIter>
1780 _M_Z(__string_view __abbrev, _OutIter __out)
const
1781 {
return __format::__write(
std::move(__out), __abbrev); }
1786 static basic_string_view<_CharT>
1787 _S_digit(
int __n)
noexcept
1790 return { _GLIBCXX_WIDEN(
"0123456789999999") + (__n & 0xf), 1 };
1794 static basic_string_view<_CharT>
1795 _S_two_digits(
int __n)
noexcept
1798 _GLIBCXX_WIDEN(
"0001020304050607080910111213141516171819"
1799 "2021222324252627282930313233343536373839"
1800 "4041424344454647484950515253545556575859"
1801 "6061626364656667686970717273747576777879"
1802 "8081828384858687888990919293949596979899"
1803 "9999999999999999999999999999999999999999"
1804 "9999999999999999") + 2 * (__n & 0x7f),
1810 [[__gnu__::__always_inline__]]
1812 _S_fill_two_digits(_CharT* __buf,
unsigned __n)
1814 auto __sv = _S_two_digits(__n);
1820 [[__gnu__::__always_inline__]]
1822 _S_fill_ampm(_CharT* __buf, chrono::hours __h)
1824 auto __hi = __h.count();
1825 if (__hi >= 24) [[unlikely]]
1828 constexpr const _CharT* __apm = _GLIBCXX_WIDEN(
"APM");
1829 __buf[0] = __apm[__hi >= 12];
1830 __buf[1] = __apm[2];
1835 [[__gnu__::__always_inline__]]
1836 static basic_string_view<_CharT>
1837 _S_str_d1(span<_CharT, 3> __buf,
unsigned __n)
1839 if (__n < 10) [[likely]]
1840 return _S_digit(__n);
1841 return _S_str_d2(__buf, __n);
1846 [[__gnu__::__always_inline__]]
1847 static basic_string_view<_CharT>
1848 _S_str_d2(span<_CharT, 3> __buf,
unsigned __n)
1850 if (__n < 100) [[likely]]
1851 return _S_two_digits(__n);
1852 return _S_str_d3(__buf, __n);
1857 [[__gnu__::__always_inline__]]
1858 static basic_string_view<_CharT>
1859 _S_str_d3(span<_CharT, 3> __buf,
unsigned __n)
1861 _S_fill_two_digits(__buf.data(), __n / 10);
1862 __buf[2] = _S_chars[__n % 10];
1863 return __string_view(__buf.data(), 3);
1867 template<
typename _CharT>
1868 struct __formatter_duration :
private __formatter_chrono<_CharT>
1870 template<
typename _Rep,
typename _Period>
1871 constexpr static auto
1872 _S_subseconds(
const chrono::duration<_Rep, _Period>& __d)
1874 if constexpr (chrono::treat_as_floating_point_v<_Rep>)
1875 return chrono::duration<_Rep>(__d);
1876 else if constexpr (_Period::den == 1)
1877 return chrono::seconds(0);
1880 using _Attoseconds = _ChronoData<_CharT>::_Attoseconds;
1881 using _CRep = common_type_t<_Rep, typename _Attoseconds::rep>;
1882 chrono::duration<_CRep, _Period> subs(__d.count());
1883 return chrono::duration_cast<_Attoseconds>(subs);
1888 template<
typename _Duration>
1891 _S_spec_for(_ChronoParts __parts)
1893 using _Rep =
typename _Duration::rep;
1894 using enum _ChronoParts;
1896 _ChronoSpec<_CharT> __res{};
1897 __res._M_floating_point_rep = chrono::treat_as_floating_point_v<_Rep>;
1898 __res._M_custom_rep = !is_arithmetic_v<_Rep>;
1899 __res._M_prec = chrono::hh_mm_ss<_Duration>::fractional_width;
1900 if ((__parts & _TimeOfDay) != 0)
1901 __res._M_localized = __res._M_prec > 0 || __res._M_floating_point_rep;
1903 if ((__parts & _TimeOfDay) != 0)
1904 __res._M_needed |= _TimeOfDay;
1905 if ((__parts & _Date) != 0)
1906 __res._M_needed |= _YearMonthDay;
1907 if ((__parts & _ZoneAbbrev) != 0)
1908 __res._M_needed |= _ZoneAbbrev;
1912 case _ZonedDateTime:
1913 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ftz();
1916 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ft();
1919 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_f();
1922 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_t();
1927 __builtin_unreachable();
1932 template<
typename _Duration>
1937 using enum _ChronoParts;
1939 constexpr bool __stream_insertable =
1940 requires (basic_ostream<_CharT>& __os, chrono::sys_time<_Duration> __t)
1942 if constexpr (!__stream_insertable)
1943 return _S_spec_for<_Duration>(_None);
1944 else if constexpr (is_convertible_v<_Duration, chrono::days>)
1945 return _S_spec_for<_Duration>(_Date);
1947 return _S_spec_for<_Duration>(_DateTime);
1950 using __formatter_chrono<_CharT>::__formatter_chrono;
1951 using __formatter_chrono<_CharT>::_M_spec;
1953 template<
typename _Duration>
1954 constexpr typename basic_format_parse_context<_CharT>::iterator
1955 _M_parse(basic_format_parse_context<_CharT>& __pc, _ChronoParts __parts,
1956 const _ChronoSpec<_CharT>& __def)
1958 using _Rep =
typename _Duration::rep;
1959 using enum _ChronoParts;
1962 = __formatter_chrono<_CharT>::_M_parse(__pc, __parts, __def);
1965 _M_spec._M_needs_ok_check =
false;
1970 if constexpr (!is_floating_point_v<_Rep>)
1971 if constexpr (chrono::treat_as_floating_point_v<_Rep>)
1972 if (_M_spec._M_needs(_Subseconds|_EpochUnits)
1973 || _M_spec._M_prec_kind != _WP_none
1974 || _M_spec._M_prec_value > 0)
1976 constexpr const _CharT* __fs = _GLIBCXX_WIDEN(
"#02.5Lf");
1977 basic_format_parse_context<_CharT> __npc(__fs);
1978 formatter<_Rep, _CharT> __fmtter;
1979 __fmtter.parse(__npc);
1985 template<
typename _FormatContext>
1987 _M_locale(_FormatContext& __fc)
const
1989 if (!_M_spec._M_localized)
1992 return __fc.locale();
1996 template<
typename _Rep,
typename _Period,
typename _FormatContext>
1997 typename _FormatContext::iterator
1998 _M_format_to_ostream(
const chrono::duration<_Rep, _Period>& __d,
2000 _FormatContext& __fc)
const
2002 basic_ostringstream<_CharT> __os;
2003 __os.imbue(this->_M_locale(__fc));
2005 if (__is_neg) [[unlikely]]
2006 __os << this->_S_plus_minus[1];
2010 return __format::__write_padded_as_spec(__str, __str.size(),
2014 template<
typename _Rep1,
typename _Period1,
2015 typename _Rep2,
typename _Period2,
2016 typename _FormatContext>
2017 typename _FormatContext::iterator
2018 _M_format_units(_ChronoData<_CharT>& __cd,
2019 const chrono::duration<_Rep1, _Period1>& __ed,
2020 const chrono::duration<_Rep2, _Period2>& __ss,
2021 _FormatContext& __fc)
const
2023 __format::_Str_sink<_CharT> __suffix_store;
2024 constexpr auto _S_unit_suffix
2025 = chrono::__detail::__units_suffix<_Period1, _CharT>();
2026 if constexpr (!_S_unit_suffix.empty())
2027 __cd._M_unit_suffix = _S_unit_suffix;
2028 else if (_M_spec._M_needs(_ChronoParts::_UnitSuffix))
2031 __fmt_units_suffix<_Period1, _CharT>(__suffix_store.out());
2032 __cd._M_unit_suffix = __suffix_store.view();
2035 const auto __prec = _M_spec._M_prec_kind != _WP_none
2036 ? _M_spec._M_get_precision(__fc)
2039 using _ErasedContext =
typename _ChronoData<_CharT>::_FormatContext;
2042 auto __ereps = +__ed.count();
2043 if (!_M_spec._M_needs(_ChronoParts::_Subseconds))
2047 = std::make_format_args<_ErasedContext>(__ereps, __ssreps, __prec);
2048 __cd._M_ereps = __args_store;
2049 return this->_M_format(__cd, __fc);
2052 using _Attoseconds = _ChronoData<_CharT>::_Attoseconds;
2053 auto __nss = _S_subseconds(__ss);
2054 __cd._M_subseconds = chrono::duration_cast<_Attoseconds>(__nss);
2056 auto __ssreps = __nss.count();
2058 = std::make_format_args<_ErasedContext>(__ereps, __ssreps, __prec);
2059 __cd._M_ereps = __args_store;
2061 return this->_M_format(__cd, __fc);
2065 template<
typename _Rep1,
typename _Period1,
typename _FormatContext>
2066 typename _FormatContext::iterator
2067 _M_format_time_point(_ChronoData<_CharT>& __cd,
2068 const chrono::duration<_Rep1, _Period1>& __ed,
2069 _FormatContext& __fc)
const
2071 auto __parts = _M_spec._M_needed - _ChronoParts::_TotalSeconds;
2072 if ((__parts & _ChronoParts::_DateTime) != 0)
2073 __cd._M_fill_date_time(__cd._M_lseconds, __parts);
2074 return _M_format_units(__cd, __ed, __ed - __cd._M_eseconds, __fc);
2078#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2079 template<
typename _CharT>
2080 struct __formatter_chrono_info
2082 constexpr typename basic_format_parse_context<_CharT>::iterator
2083 parse(basic_format_parse_context<_CharT>& __pc)
2084 {
return _M_f._M_parse(__pc, _ChronoParts(), {}); }
2086 template<
typename _Info,
typename _Out>
2087 typename basic_format_context<_Out, _CharT>::iterator
2088 format(
const _Info& __i,
2089 basic_format_context<_Out, _CharT>& __fc)
const
2093 if (!_M_f._M_spec._M_chrono_specs.empty()) [[unlikely]]
2094 return _M_f._M_format(_ChronoData<_CharT>{}, __fc);
2096 const size_t __padwidth = _M_f._M_spec._M_get_width(__fc);
2097 if (__padwidth == 0)
2098 return _M_format_to(__fc.out(), __i);
2100 _Padding_sink<_Out, _CharT> __sink(__fc.out(), __padwidth);
2101 _M_format_to(__sink.out(), __i);
2102 return __sink._M_finish(_M_f._M_spec._M_align, _M_f._M_spec._M_fill);
2106 template<
typename _Out>
2108 _M_format_to(_Out __out,
const chrono::sys_info& __si)
const
2110 using _FmtStr = _Runtime_format_string<_CharT>;
2114 constexpr auto* __fs
2115 = _GLIBCXX_WIDEN(
"[{0:%F %T},{1:%F %T},{2:%T},{3:%Q%q},{0:%Z}]");
2116 const chrono::local_seconds __lb(__si.begin.time_since_epoch());
2117 return std::format_to(
std::move(__out), _FmtStr(__fs),
2118 chrono::local_time_format(__lb, &__si.abbrev),
2119 __si.end, __si.offset, __si.save);
2122 template<
typename _Out>
2124 _M_format_to(_Out __out,
const chrono::local_info& __li)
const
2126 *__out = _Separators<_CharT>::_S_squares()[0];
2128 if (__li.result == chrono::local_info::unique)
2129 __out = _M_format_to(
std::move(__out), __li.first);
2132 basic_string_view<_CharT> __sv;
2133 if (__li.result == chrono::local_info::nonexistent)
2134 __sv =_GLIBCXX_WIDEN(
"nonexistent");
2136 __sv = _GLIBCXX_WIDEN(
"ambiguous");
2137 __out = __format::__write(
std::move(__out), __sv);
2139 __sv = _GLIBCXX_WIDEN(
" local time between ");
2140 __out = __format::__write(
std::move(__out), __sv);
2141 __out = _M_format_to(
std::move(__out), __li.first);
2143 __sv = _GLIBCXX_WIDEN(
" and ");
2144 __out = __format::__write(
std::move(__out), __sv);
2145 __out = _M_format_to(
std::move(__out), __li.second);
2147 *__out = _Separators<_CharT>::_S_squares()[1];
2152 __formatter_chrono<_CharT> _M_f;
2159 template<
typename _Rep,
typename _Period,
typename _CharT>
2160 requires __format::__formattable_impl<_Rep, _CharT>
2161 struct formatter<
chrono::duration<_Rep, _Period>, _CharT>
2163 constexpr typename basic_format_parse_context<_CharT>::iterator
2164 parse(basic_format_parse_context<_CharT>& __pc)
2166 using enum __format::_ChronoParts;
2167 return _M_f.template _M_parse<_Duration>(__pc, _EpochTime, __defSpec);
2170 template<
typename _Out>
2171 typename basic_format_context<_Out, _CharT>::iterator
2172 format(
const chrono::duration<_Rep, _Period>& __d,
2173 basic_format_context<_Out, _CharT>& __fc)
const
2175 if constexpr (numeric_limits<_Rep>::is_signed)
2176 if (__d < __d.zero()) [[unlikely]]
2178 if constexpr (is_integral_v<_Rep>)
2182 using _URep = make_unsigned_t<_Rep>;
2183 auto __ucnt = -
static_cast<_URep
>(__d.count());
2184 auto __ud = chrono::duration<_URep, _Period>(__ucnt);
2185 return _M_format(__ud,
true, __fc);
2188 return _M_format(-__d,
true, __fc);
2190 return _M_format(__d,
false, __fc);
2194 using _Duration = chrono::duration<_Rep, _Period>;
2196 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2198 using enum __format::_ChronoParts;
2199 auto __res = __format::__formatter_duration<_CharT>::
2200 template _S_spec_for<_Duration>(_None);
2201 __res._M_localized = !is_integral_v<_Rep>;
2203 if constexpr (is_integral_v<_Rep>)
2205 __res._M_needed = _EpochUnits|_UnitSuffix;
2206 __res._M_chrono_specs = _GLIBCXX_WIDEN(
"%Q%q");
2211 template<
typename _Rep2,
typename _Out>
2212 typename basic_format_context<_Out, _CharT>::iterator
2213 _M_format(
const chrono::duration<_Rep2, _Period>& __d,
2215 basic_format_context<_Out, _CharT>& __fc)
const
2217 using namespace chrono;
2218 using enum __format::_ChronoParts;
2219 if constexpr (!is_integral_v<_Rep>)
2220 if (_M_f._M_spec._M_chrono_specs.empty())
2221 return _M_f._M_format_to_ostream(__d, __is_neg, __fc);
2223 __format::_ChronoData<_CharT> __cd;
2224 __cd._M_is_neg = __is_neg;
2225 auto __ts = chrono::floor<chrono::seconds>(__d);
2226 __cd._M_eseconds = __ts;
2227 if (_M_f._M_spec._M_needs(_HoursMinutesSeconds))
2228 __cd._M_fill_time(__ts);
2229 return _M_f._M_format_units(__cd, __d, __d - __ts, __fc);
2232 __format::__formatter_duration<_CharT> _M_f{__defSpec};
2235 template<__format::__
char _CharT>
2236 struct formatter<
chrono::day, _CharT>
2238 constexpr typename basic_format_parse_context<_CharT>::iterator
2239 parse(basic_format_parse_context<_CharT>& __pc)
2241 using enum __format::_ChronoParts;
2242 return _M_f._M_parse(__pc, _Day|_WeekdayIndex, __defSpec);
2245 template<
typename _Out>
2246 typename basic_format_context<_Out, _CharT>::iterator
2247 format(
const chrono::day& __t,
2248 basic_format_context<_Out, _CharT>& __fc)
const
2250 __format::_ChronoData<_CharT> __cd{};
2251 __cd._M_fill_day(__t, __defSpec._M_needed);
2252 return _M_f._M_format(__cd, __fc);
2256 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2258 using __format::_ChronoFormats;
2259 using enum __format::_ChronoParts;
2261 __format::_ChronoSpec<_CharT> __res{};
2262 __res._M_debug =
true;
2263 __res._M_needed = _Day;
2264 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_d();
2268 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2271 template<__format::__
char _CharT>
2272 struct formatter<
chrono::month, _CharT>
2274 constexpr typename basic_format_parse_context<_CharT>::iterator
2275 parse(basic_format_parse_context<_CharT>& __pc)
2277 using enum __format::_ChronoParts;
2278 return _M_f._M_parse(__pc, _Month, __defSpec);
2281 template<
typename _Out>
2282 typename basic_format_context<_Out, _CharT>::iterator
2283 format(
const chrono::month& __t,
2284 basic_format_context<_Out, _CharT>& __fc)
const
2286 __format::_ChronoData<_CharT> __cd{};
2287 __cd._M_month = __t;
2288 return _M_f._M_format(__cd, __fc);
2292 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2294 using __format::_ChronoFormats;
2295 using enum __format::_ChronoParts;
2297 __format::_ChronoSpec<_CharT> __res{};
2298 __res._M_debug =
true;
2299 __res._M_localized =
true;
2300 __res._M_locale_specific =
true;
2301 __res._M_needed = _Month;
2302 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_m();
2306 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2309 template<__format::__
char _CharT>
2310 struct formatter<
chrono::year, _CharT>
2312 constexpr typename basic_format_parse_context<_CharT>::iterator
2313 parse(basic_format_parse_context<_CharT>& __pc)
2315 using enum __format::_ChronoParts;
2316 return _M_f._M_parse(__pc, _Year, __defSpec);
2319 template<
typename _Out>
2320 typename basic_format_context<_Out, _CharT>::iterator
2321 format(
const chrono::year& __t,
2322 basic_format_context<_Out, _CharT>& __fc)
const
2324 __format::_ChronoData<_CharT> __cd{};
2326 return _M_f._M_format(__cd, __fc);
2330 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2332 using __format::_ChronoFormats;
2333 using enum __format::_ChronoParts;
2335 __format::_ChronoSpec<_CharT> __res{};
2336 __res._M_debug =
true;
2337 __res._M_needed = _Year;
2338 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_y();
2342 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2345 template<__format::__
char _CharT>
2346 struct formatter<
chrono::weekday, _CharT>
2348 constexpr typename basic_format_parse_context<_CharT>::iterator
2349 parse(basic_format_parse_context<_CharT>& __pc)
2351 using enum __format::_ChronoParts;
2352 return _M_f._M_parse(__pc, _Weekday, __defSpec);
2355 template<
typename _Out>
2356 typename basic_format_context<_Out, _CharT>::iterator
2357 format(
const chrono::weekday& __t,
2358 basic_format_context<_Out, _CharT>& __fc)
const
2360 __format::_ChronoData<_CharT> __cd{};
2361 __cd._M_weekday = __t;
2362 return _M_f._M_format(__cd, __fc);
2366 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2368 using __format::_ChronoFormats;
2369 using enum __format::_ChronoParts;
2371 __format::_ChronoSpec<_CharT> __res{};
2372 __res._M_debug =
true;
2373 __res._M_localized =
true;
2374 __res._M_locale_specific =
true;
2375 __res._M_needed = _Weekday;
2376 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_w();
2380 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2383 template<__format::__
char _CharT>
2384 struct formatter<
chrono::weekday_indexed, _CharT>
2386 constexpr typename basic_format_parse_context<_CharT>::iterator
2387 parse(basic_format_parse_context<_CharT>& __pc)
2389 using enum __format::_ChronoParts;
2390 return _M_f._M_parse(__pc, _IndexedWeekday, __defSpec);
2393 template<
typename _Out>
2394 typename basic_format_context<_Out, _CharT>::iterator
2395 format(
const chrono::weekday_indexed& __t,
2396 basic_format_context<_Out, _CharT>& __fc)
const
2398 __format::_ChronoData<_CharT> __cd{};
2399 __cd._M_fill_weekday(__t, __defSpec._M_needed);
2400 return _M_f._M_format(__cd, __fc);
2404 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2406 using __format::_ChronoFormats;
2407 using enum __format::_ChronoParts;
2409 __format::_ChronoSpec<_CharT> __res{};
2410 __res._M_debug =
true;
2411 __res._M_localized =
true;
2412 __res._M_locale_specific =
true;
2413 __res._M_needed = _IndexedWeekday;
2414 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_wi();
2418 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2421 template<__format::__
char _CharT>
2422 struct formatter<
chrono::weekday_last, _CharT>
2424 constexpr typename basic_format_parse_context<_CharT>::iterator
2425 parse(basic_format_parse_context<_CharT>& __pc)
2427 using enum __format::_ChronoParts;
2428 return _M_f._M_parse(__pc, _Weekday, __defSpec);
2431 template<
typename _Out>
2432 typename basic_format_context<_Out, _CharT>::iterator
2433 format(
const chrono::weekday_last& __t,
2434 basic_format_context<_Out, _CharT>& __fc)
const
2436 __format::_ChronoData<_CharT> __cd{};
2437 __cd._M_weekday = __t.weekday();
2438 return _M_f._M_format(__cd, __fc);
2442 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2444 using __format::_ChronoFormats;
2445 using enum __format::_ChronoParts;
2447 __format::_ChronoSpec<_CharT> __res{};
2448 __res._M_debug =
true;
2449 __res._M_localized =
true;
2450 __res._M_locale_specific =
true;
2451 __res._M_needed = _Weekday;
2452 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_wl();
2456 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2459 template<__format::__
char _CharT>
2460 struct formatter<
chrono::month_day, _CharT>
2462 constexpr typename basic_format_parse_context<_CharT>::iterator
2463 parse(basic_format_parse_context<_CharT>& __pc)
2465 using enum __format::_ChronoParts;
2466 return _M_f._M_parse(__pc, _Month|_Day|_WeekdayIndex, __defSpec);
2469 template<
typename _Out>
2470 typename basic_format_context<_Out, _CharT>::iterator
2471 format(
const chrono::month_day& __t,
2472 basic_format_context<_Out, _CharT>& __fc)
const
2474 __format::_ChronoData<_CharT> __cd{};
2475 __cd._M_month = __t.month();
2476 __cd._M_fill_day(__t.day(), __defSpec._M_needed);
2477 return _M_f._M_format(__cd, __fc);
2481 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2483 using __format::_ChronoFormats;
2484 using enum __format::_ChronoParts;
2486 __format::_ChronoSpec<_CharT> __res{};
2487 __res._M_debug =
true;
2488 __res._M_localized =
true;
2489 __res._M_locale_specific =
true;
2490 __res._M_needed = _Month|_Day;
2491 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_md();
2495 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2498 template<__format::__
char _CharT>
2499 struct formatter<
chrono::month_day_last, _CharT>
2501 constexpr typename basic_format_parse_context<_CharT>::iterator
2502 parse(basic_format_parse_context<_CharT>& __pc)
2504 using enum __format::_ChronoParts;
2505 return _M_f._M_parse(__pc, _Month, __defSpec);
2508 template<
typename _Out>
2509 typename basic_format_context<_Out, _CharT>::iterator
2510 format(
const chrono::month_day_last& __t,
2511 basic_format_context<_Out, _CharT>& __fc)
const
2513 __format::_ChronoData<_CharT> __cd{};
2514 __cd._M_month = __t.month();
2515 return _M_f._M_format(__cd, __fc);
2519 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2521 using __format::_ChronoFormats;
2522 using enum __format::_ChronoParts;
2524 __format::_ChronoSpec<_CharT> __res{};
2525 __res._M_debug =
true;
2526 __res._M_localized =
true;
2527 __res._M_locale_specific =
true;
2528 __res._M_needed = _Month;
2529 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ml();
2533 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2536 template<__format::__
char _CharT>
2537 struct formatter<
chrono::month_weekday, _CharT>
2539 constexpr typename basic_format_parse_context<_CharT>::iterator
2540 parse(basic_format_parse_context<_CharT>& __pc)
2542 using enum __format::_ChronoParts;
2543 return _M_f._M_parse(__pc, _Month|_IndexedWeekday, __defSpec);
2546 template<
typename _Out>
2547 typename basic_format_context<_Out, _CharT>::iterator
2548 format(
const chrono::month_weekday& __t,
2549 basic_format_context<_Out, _CharT>& __fc)
const
2551 __format::_ChronoData<_CharT> __cd{};
2552 __cd._M_month = __t.month();
2553 __cd._M_fill_weekday(__t.weekday_indexed(), __defSpec._M_needed);
2554 return _M_f._M_format(__cd, __fc);
2558 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2560 using __format::_ChronoFormats;
2561 using enum __format::_ChronoParts;
2563 __format::_ChronoSpec<_CharT> __res{};
2564 __res._M_debug =
true;
2565 __res._M_localized =
true;
2566 __res._M_locale_specific =
true;
2567 __res._M_needed = _Month|_IndexedWeekday;
2568 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_mwi();
2572 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2575 template<__format::__
char _CharT>
2576 struct formatter<
chrono::month_weekday_last, _CharT>
2578 constexpr typename basic_format_parse_context<_CharT>::iterator
2579 parse(basic_format_parse_context<_CharT>& __pc)
2581 using enum __format::_ChronoParts;
2582 return _M_f._M_parse(__pc, _Month|_Weekday, __defSpec);
2585 template<
typename _Out>
2586 typename basic_format_context<_Out, _CharT>::iterator
2587 format(
const chrono::month_weekday_last& __t,
2588 basic_format_context<_Out, _CharT>& __fc)
const
2590 __format::_ChronoData<_CharT> __cd{};
2591 __cd._M_month = __t.month();
2592 __cd._M_weekday = __t.weekday_last().weekday();
2593 return _M_f._M_format(__cd, __fc);
2597 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2599 using __format::_ChronoFormats;
2600 using enum __format::_ChronoParts;
2602 __format::_ChronoSpec<_CharT> __res{};
2603 __res._M_debug =
true;
2604 __res._M_localized =
true;
2605 __res._M_locale_specific =
true;
2606 __res._M_needed = _Month|_Weekday;
2607 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_mwl();
2611 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2614 template<__format::__
char _CharT>
2615 struct formatter<
chrono::year_month, _CharT>
2617 constexpr typename basic_format_parse_context<_CharT>::iterator
2618 parse(basic_format_parse_context<_CharT>& __pc)
2620 using enum __format::_ChronoParts;
2621 return _M_f._M_parse(__pc, _Year|_Month, __defSpec);
2624 template<
typename _Out>
2625 typename basic_format_context<_Out, _CharT>::iterator
2626 format(
const chrono::year_month& __t,
2627 basic_format_context<_Out, _CharT>& __fc)
const
2629 __format::_ChronoData<_CharT> __cd{};
2630 __cd._M_fill_year_month(__t, __defSpec._M_needed);
2631 return _M_f._M_format(__cd, __fc);
2635 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2637 using __format::_ChronoFormats;
2638 using enum __format::_ChronoParts;
2640 __format::_ChronoSpec<_CharT> __res{};
2641 __res._M_debug =
true;
2642 __res._M_localized =
true;
2643 __res._M_locale_specific =
true;
2644 __res._M_needed = _Year|_Month;
2645 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ym();
2649 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2652 template<__format::__
char _CharT>
2653 struct formatter<
chrono::year_month_day, _CharT>
2655 constexpr typename basic_format_parse_context<_CharT>::iterator
2656 parse(basic_format_parse_context<_CharT>& __pc)
2658 using enum __format::_ChronoParts;
2659 return _M_f._M_parse(__pc, _Date, __defSpec);
2662 template<
typename _Out>
2663 typename basic_format_context<_Out, _CharT>::iterator
2664 format(
const chrono::year_month_day& __t,
2665 basic_format_context<_Out, _CharT>& __fc)
const
2667 __format::_ChronoData<_CharT> __cd{};
2668 auto __parts = _M_f._M_spec._M_needed;
2669 __parts = __cd._M_fill_year_month(__t, __parts);
2670 __parts = __cd._M_fill_day(__t.day(), __parts);
2672 return _M_f._M_format(__cd, __fc);
2674 chrono::local_days __ld(__t);
2675 __cd._M_fill_ldays(__ld, __parts);
2676 return _M_f._M_format(__cd, __fc);
2680 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2682 using __format::_ChronoFormats;
2683 using enum __format::_ChronoParts;
2685 __format::_ChronoSpec<_CharT> __res{};
2686 __res._M_debug =
true;
2687 __res._M_needed = _YearMonthDay;
2688 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_f();
2692 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2695 template<__format::__
char _CharT>
2696 struct formatter<
chrono::year_month_day_last, _CharT>
2698 constexpr typename basic_format_parse_context<_CharT>::iterator
2699 parse(basic_format_parse_context<_CharT>& __pc)
2701 using enum __format::_ChronoParts;
2702 return _M_f._M_parse(__pc, _Date, __defSpec);
2705 template<
typename _Out>
2706 typename basic_format_context<_Out, _CharT>::iterator
2707 format(
const chrono::year_month_day_last& __t,
2708 basic_format_context<_Out, _CharT>& __fc)
const
2710 __format::_ChronoData<_CharT> __cd{};
2711 auto __parts = _M_f._M_spec._M_needed;
2712 __parts = __cd._M_fill_year_month(__t, __parts);
2714 return _M_f._M_format(__cd, __fc);
2716 chrono::local_days __ld(__t);
2717 __parts = __cd._M_fill_ldays(__ld, __parts);
2719 return _M_f._M_format(__cd, __fc);
2721 chrono::year_month_day __ymd(__ld);
2722 __cd._M_fill_day(__ymd.day(), __parts);
2723 return _M_f._M_format(__cd, __fc);
2727 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2729 using __format::_ChronoFormats;
2730 using enum __format::_ChronoParts;
2732 __format::_ChronoSpec<_CharT> __res{};
2733 __res._M_debug =
true;
2734 __res._M_localized =
true;
2735 __res._M_locale_specific =
true;
2736 __res._M_needed = _Year|_Month;
2737 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_yml();
2741 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2744 template<__format::__
char _CharT>
2745 struct formatter<
chrono::year_month_weekday, _CharT>
2747 constexpr typename basic_format_parse_context<_CharT>::iterator
2748 parse(basic_format_parse_context<_CharT>& __pc)
2750 using enum __format::_ChronoParts;
2751 return _M_f._M_parse(__pc, _Date, __defSpec);
2754 template<
typename _Out>
2755 typename basic_format_context<_Out, _CharT>::iterator
2756 format(
const chrono::year_month_weekday& __t,
2757 basic_format_context<_Out, _CharT>& __fc)
const
2759 __format::_ChronoData<_CharT> __cd{};
2760 auto __parts = _M_f._M_spec._M_needed;
2761 __parts = __cd._M_fill_year_month(__t, __parts);
2762 __parts = __cd._M_fill_weekday(__t.weekday_indexed(), __parts);
2764 return _M_f._M_format(__cd, __fc);
2766 chrono::local_days __ld(__t);
2767 __parts = __cd._M_fill_ldays(__ld, __parts);
2769 return _M_f._M_format(__cd, __fc);
2771 chrono::year_month_day __ymd(__ld);
2773 __cd._M_day = __ymd.day();
2774 return _M_f._M_format(__cd, __fc);
2778 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2780 using __format::_ChronoFormats;
2781 using enum __format::_ChronoParts;
2783 __format::_ChronoSpec<_CharT> __res{};
2784 __res._M_debug =
true;
2785 __res._M_localized =
true;
2786 __res._M_locale_specific =
true;
2787 __res._M_needed = _Year|_Month|_IndexedWeekday;
2788 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ymwi();
2792 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2795 template<__format::__
char _CharT>
2796 struct formatter<
chrono::year_month_weekday_last, _CharT>
2798 constexpr typename basic_format_parse_context<_CharT>::iterator
2799 parse(basic_format_parse_context<_CharT>& __pc)
2801 using enum __format::_ChronoParts;
2802 return _M_f._M_parse(__pc, _Date, __defSpec);
2805 template<
typename _Out>
2806 typename basic_format_context<_Out, _CharT>::iterator
2807 format(
const chrono::year_month_weekday_last& __t,
2808 basic_format_context<_Out, _CharT>& __fc)
const
2810 __format::_ChronoData<_CharT> __cd{};
2811 auto __parts = _M_f._M_spec._M_needed;
2812 __parts = __cd._M_fill_year_month(__t, __parts);
2813 __cd._M_weekday = __t.weekday_last().weekday();
2814 __parts -= __format::_ChronoParts::_Weekday;
2816 return _M_f._M_format(__cd, __fc);
2818 chrono::local_days __ld(__t);
2819 __parts = __cd._M_fill_ldays(__ld, __parts);
2821 return _M_f._M_format(__cd, __fc);
2823 chrono::year_month_day __ymd(__ld);
2824 __cd._M_fill_day(__ymd.day(), __parts);
2825 return _M_f._M_format(__cd, __fc);
2829 static constexpr __format::_ChronoSpec<_CharT> __defSpec = []
2831 using __format::_ChronoFormats;
2832 using enum __format::_ChronoParts;
2834 __format::_ChronoSpec<_CharT> __res{};
2835 __res._M_debug =
true;
2836 __res._M_localized =
true;
2837 __res._M_locale_specific =
true;
2838 __res._M_needed = _Year|_Month|_Weekday;
2839 __res._M_chrono_specs = _ChronoFormats<_CharT>::_S_ymwl();
2843 __format::__formatter_chrono<_CharT> _M_f{__defSpec};
2846 template<
typename _Rep,
typename _Period, __format::__
char _CharT>
2847 struct formatter<
chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>, _CharT>
2849 constexpr typename basic_format_parse_context<_CharT>::iterator
2850 parse(basic_format_parse_context<_CharT>& __pc)
2852 using enum __format::_ChronoParts;
2853 return _M_f.template _M_parse<_Precision>(__pc, _Time, __defSpec);
2856 template<
typename _Out>
2857 typename basic_format_context<_Out, _CharT>::iterator
2858 format(
const chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>& __t,
2859 basic_format_context<_Out, _CharT>& __fc)
const
2861 using enum __format::_ChronoParts;
2863 __format::_ChronoData<_CharT> __cd;
2864 __cd._M_is_neg = __t.is_negative();
2865 __cd._M_hours = __t.hours();
2866 __cd._M_minutes = __t.minutes();
2867 __cd._M_seconds = __t.seconds();
2872 if (_M_f._M_spec._M_needs(_EpochUnits))
2873 __d = __t.to_duration();
2874 if (_M_f._M_spec._M_needs(_TotalSeconds))
2876 = __cd._M_hours + __cd._M_minutes + __cd._M_seconds;
2877 return _M_f._M_format_units(__cd, __d, __t.subseconds(), __fc);
2882 =
typename chrono::hh_mm_ss<chrono::duration<_Rep, _Period>>::precision;
2883 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
2884 __format::__formatter_duration<_CharT>::
2885 template _S_spec_for<_Precision>(__format::_ChronoParts::_Time);
2887 __format::__formatter_duration<_CharT> _M_f{__defSpec};
2890#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
2891 template<__format::__
char _CharT>
2892 struct formatter<
chrono::sys_info, _CharT>
2894 constexpr typename basic_format_parse_context<_CharT>::iterator
2895 parse(basic_format_parse_context<_CharT>& __pc)
2896 {
return _M_f.parse(__pc); }
2898 template<
typename _Out>
2899 typename basic_format_context<_Out, _CharT>::iterator
2900 format(
const chrono::sys_info& __i,
2901 basic_format_context<_Out, _CharT>& __fc)
const
2902 {
return _M_f.format(__i, __fc); }
2905 __format::__formatter_chrono_info<_CharT> _M_f;
2908 template<__format::__
char _CharT>
2909 struct formatter<
chrono::local_info, _CharT>
2911 constexpr typename basic_format_parse_context<_CharT>::iterator
2912 parse(basic_format_parse_context<_CharT>& __pc)
2913 {
return _M_f.parse(__pc); }
2915 template<
typename _Out>
2916 typename basic_format_context<_Out, _CharT>::iterator
2917 format(
const chrono::local_info& __i,
2918 basic_format_context<_Out, _CharT>& __fc)
const
2919 {
return _M_f.format(__i, __fc); }
2922 __format::__formatter_chrono_info<_CharT> _M_f;
2926 template<
typename _Duration, __format::__
char _CharT>
2927 struct formatter<
chrono::sys_time<_Duration>, _CharT>
2929 constexpr typename basic_format_parse_context<_CharT>::iterator
2930 parse(basic_format_parse_context<_CharT>& __pc)
2932 using enum __format::_ChronoParts;
2934 = _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
2935 if constexpr (__defSpec._M_chrono_specs.empty())
2936 if (_M_f._M_spec._M_chrono_specs.empty())
2937 __format::__invalid_chrono_spec();
2941 template<
typename _Out>
2942 typename basic_format_context<_Out, _CharT>::iterator
2943 format(
const chrono::sys_time<_Duration>& __t,
2944 basic_format_context<_Out, _CharT>& __fc)
const
2946 __format::_ChronoData<_CharT> __cd{};
2947 __cd._M_fill_utc_zone();
2949 _Duration __ed = __t.time_since_epoch();
2950 __cd._M_eseconds = chrono::floor<chrono::seconds>(__ed);
2951 __cd._M_lseconds = chrono::local_seconds(__cd._M_eseconds);
2952 return _M_f._M_format_time_point(__cd, __ed, __fc);
2956 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
2957 __format::__formatter_duration<_CharT>::template _S_spec_for_tp<_Duration>();
2959 __format::__formatter_duration<_CharT> _M_f{__defSpec};
2962 template<
typename _Duration, __format::__
char _CharT>
2963 struct formatter<
chrono::utc_time<_Duration>, _CharT>
2965 constexpr typename basic_format_parse_context<_CharT>::iterator
2966 parse(basic_format_parse_context<_CharT>& __pc)
2968 using enum __format::_ChronoParts;
2969 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
2972 template<
typename _Out>
2973 typename basic_format_context<_Out, _CharT>::iterator
2974 format(
const chrono::utc_time<_Duration>& __t,
2975 basic_format_context<_Out, _CharT>& __fc)
const
2977 using __format::_ChronoParts;
2978 using namespace chrono;
2979 __format::_ChronoData<_CharT> __cd{};
2980 __cd._M_fill_utc_zone();
2982 _Duration __ed = __t.time_since_epoch();
2983 __cd._M_eseconds = chrono::floor<seconds>(__ed);
2987 const auto __li = chrono::get_leap_second_info(__t);
2988 __cd._M_lseconds = local_seconds(__cd._M_eseconds - __li.elapsed);
2989 auto __parts = _M_f._M_spec._M_needed - _ChronoParts::_TotalSeconds;
2990 if ((__parts & _ChronoParts::_DateTime) != 0)
2992 __cd._M_fill_date_time(__cd._M_lseconds, __parts);
2993 __cd._M_seconds +=
seconds(__li.is_leap_second);
2995 return _M_f._M_format_units(__cd, __ed, __ed - __cd._M_eseconds, __fc);
2999 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3000 __format::__formatter_duration<_CharT>::
3001 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3003 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3006 template<
typename _Duration, __format::__
char _CharT>
3007 struct formatter<
chrono::tai_time<_Duration>, _CharT>
3009 constexpr typename basic_format_parse_context<_CharT>::iterator
3010 parse(basic_format_parse_context<_CharT>& __pc)
3012 using enum __format::_ChronoParts;
3013 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3016 template<
typename _Out>
3017 typename basic_format_context<_Out, _CharT>::iterator
3018 format(
const chrono::tai_time<_Duration>& __t,
3019 basic_format_context<_Out, _CharT>& __fc)
const
3021 using namespace chrono;
3022 __format::_ChronoData<_CharT> __cd{};
3023 __cd._M_fill_zone(
"TAI", L
"TAI");
3025 _Duration __ed = __t.time_since_epoch();
3026 __cd._M_eseconds = chrono::floor<seconds>(__ed);
3028 constexpr chrono::days __tai_offset = chrono::days(4383);
3029 __cd._M_lseconds = local_seconds(__cd._M_eseconds - __tai_offset);
3030 return _M_f._M_format_time_point(__cd, __ed, __fc);
3034 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3035 __format::__formatter_duration<_CharT>::
3036 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3038 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3041 template<
typename _Duration, __format::__
char _CharT>
3042 struct formatter<
chrono::gps_time<_Duration>, _CharT>
3044 constexpr typename basic_format_parse_context<_CharT>::iterator
3045 parse(basic_format_parse_context<_CharT>& __pc)
3047 using enum __format::_ChronoParts;
3048 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3051 template<
typename _Out>
3052 typename basic_format_context<_Out, _CharT>::iterator
3053 format(
const chrono::gps_time<_Duration>& __t,
3054 basic_format_context<_Out, _CharT>& __fc)
const
3056 using namespace chrono;
3057 __format::_ChronoData<_CharT> __cd{};
3058 __cd._M_fill_zone(
"GPS", L
"GPS");
3060 _Duration __ed = __t.time_since_epoch();
3061 __cd._M_eseconds = chrono::floor<seconds>(__ed);
3063 constexpr chrono::days __gps_offset = chrono::days(3657);
3064 __cd._M_lseconds = local_seconds(__cd._M_eseconds + __gps_offset);
3065 return _M_f._M_format_time_point(__cd, __ed, __fc);
3069 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3070 __format::__formatter_duration<_CharT>::
3071 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3073 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3076 template<
typename _Duration, __format::__
char _CharT>
3077 struct formatter<
chrono::file_time<_Duration>, _CharT>
3079 constexpr typename basic_format_parse_context<_CharT>::iterator
3080 parse(basic_format_parse_context<_CharT>& __pc)
3082 using enum __format::_ChronoParts;
3083 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3086 template<
typename _Out>
3087 typename basic_format_context<_Out, _CharT>::iterator
3088 format(
const chrono::file_time<_Duration>& __t,
3089 basic_format_context<_Out, _CharT>& __fc)
const
3091 using namespace chrono;
3092 __format::_ChronoData<_CharT> __cd{};
3093 __cd._M_fill_utc_zone();
3095 _Duration __ed = __t.time_since_epoch();
3096 __cd._M_eseconds = chrono::floor<seconds>(__ed);
3097 auto __st = chrono::clock_cast<system_clock>(__t);
3099 = local_seconds(chrono::floor<seconds>(__st.time_since_epoch()));
3100 return _M_f._M_format_time_point(__cd, __ed, __fc);
3104 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3105 __format::__formatter_duration<_CharT>::
3106 template _S_spec_for<_Duration>(__format::_ChronoParts::_DateTime);
3108 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3111 template<
typename _Duration, __format::__
char _CharT>
3112 struct formatter<
chrono::local_time<_Duration>, _CharT>
3114 constexpr typename basic_format_parse_context<_CharT>::iterator
3115 parse(basic_format_parse_context<_CharT>& __pc)
3117 using enum __format::_ChronoParts;
3119 = _M_f.template _M_parse<_Duration>(__pc, _DateTime, __defSpec);
3120 if constexpr (__defSpec._M_chrono_specs.empty())
3121 if (_M_f._M_spec._M_chrono_specs.empty())
3122 __format::__invalid_chrono_spec();
3126 template<
typename _Out>
3127 typename basic_format_context<_Out, _CharT>::iterator
3128 format(
const chrono::local_time<_Duration>& __lt,
3129 basic_format_context<_Out, _CharT>& __fc)
const
3131 __format::_ChronoData<_CharT> __cd{};
3132 _Duration __ed = __lt.time_since_epoch();
3133 __cd._M_lseconds = chrono::floor<chrono::seconds>(__lt);
3134 __cd._M_eseconds = __cd._M_lseconds.time_since_epoch();
3135 return _M_f._M_format_time_point(__cd, __ed, __fc);
3139 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3140 __format::__formatter_duration<_CharT>::template _S_spec_for_tp<_Duration>();
3142 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3145 template<
typename _Duration, __format::__
char _CharT>
3146 struct formatter<
chrono::__detail::__local_time_fmt<_Duration>, _CharT>
3148 constexpr typename basic_format_parse_context<_CharT>::iterator
3149 parse(basic_format_parse_context<_CharT>& __pc)
3151 using enum __format::_ChronoParts;
3152 return _M_f.template _M_parse<_Duration>(__pc, _ZonedDateTime, __defSpec);
3155 template<
typename _Out>
3156 typename basic_format_context<_Out, _CharT>::iterator
3157 format(
const chrono::__detail::__local_time_fmt<_Duration>& __zt,
3158 basic_format_context<_Out, _CharT>& __fc)
const
3160 using enum __format::_ChronoParts;
3161 __format::_ChronoData<_CharT> __cd{};
3163 if (_M_f._M_spec._M_needs(_ZoneOffset))
3165 if (!__zt._M_offset_sec)
3166 std::__throw_format_error(
"format error: no timezone available for %z");
3167 __cd._M_zone_offset = *__zt._M_offset_sec;
3170 basic_string<_CharT> __zone_store;
3171 if (_M_f._M_spec._M_needs(_ZoneAbbrev))
3173 if (!__zt._M_abbrev)
3174 std::__throw_format_error(
"format error: no timezone available for %Z");
3176 __cd._M_zone_cstr = __zt._M_abbrev->data();
3177 if constexpr (is_same_v<_CharT, char>)
3178 __cd._M_zone_abbrev = *__zt._M_abbrev;
3182 __zone_store.resize(__zt._M_abbrev->size());
3183 auto& __ct = use_facet<ctype<_CharT>>(_M_f._M_locale(__fc));
3184 __ct.widen(__zt._M_abbrev->data(),
3185 __zt._M_abbrev->data() + __zt._M_abbrev->size(),
3186 __zone_store.data());
3187 __cd._M_zone_abbrev = __zone_store;
3191 _Duration __ed = __zt._M_time.time_since_epoch();
3192 __cd._M_lseconds = chrono::floor<chrono::seconds>(__zt._M_time);
3193 __cd._M_eseconds = __cd._M_lseconds.time_since_epoch();
3194 return _M_f._M_format_time_point(__cd, __ed, __fc);
3198 static constexpr __format::_ChronoSpec<_CharT> __defSpec =
3199 __format::__formatter_duration<_CharT>::
3200 template _S_spec_for<_Duration>(__format::_ChronoParts::_ZonedDateTime);
3202 __format::__formatter_duration<_CharT> _M_f{__defSpec};
3205#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
3206 template<
typename _Duration,
typename _TimeZonePtr, __format::__
char _CharT>
3207 struct formatter<
chrono::zoned_time<_Duration, _TimeZonePtr>, _CharT>
3208 : formatter<chrono::__detail::__local_time_fmt_for<_Duration>, _CharT>
3210 template<
typename _Out>
3211 typename basic_format_context<_Out, _CharT>::iterator
3212 format(
const chrono::zoned_time<_Duration, _TimeZonePtr>& __tp,
3213 basic_format_context<_Out, _CharT>& __fc)
const
3215 using _Ltf = chrono::__detail::__local_time_fmt_for<_Duration>;
3216 using _Base = formatter<_Ltf, _CharT>;
3217 const chrono::sys_info __info = __tp.get_info();
3218 const auto __lf = chrono::local_time_format(__tp.get_local_time(),
3221 return _Base::format(__lf, __fc);
3234 template<
typename _Duration = seconds>
3237 static_assert(is_same_v<common_type_t<_Duration, seconds>, _Duration>);
3240 _Parser(__format::_ChronoParts __need) : _M_need(__need) { }
3242 _Parser(_Parser&&) =
delete;
3243 void operator=(_Parser&&) =
delete;
3245 _Duration _M_time{};
3246 sys_days _M_sys_days{};
3247 year_month_day _M_ymd{};
3249 __format::_ChronoParts _M_need;
3250 unsigned _M_is_leap_second : 1 {};
3251 unsigned _M_reserved : 15 {};
3253 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3254 basic_istream<_CharT, _Traits>&
3255 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3256 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3257 minutes* __offset =
nullptr);
3262 template<
typename _CharT,
typename _Traits>
3263 static int_least32_t
3264 _S_read_unsigned(basic_istream<_CharT, _Traits>& __is,
3265 ios_base::iostate& __err,
int __n)
3267 int_least32_t __val = _S_try_read_digit(__is, __err);
3268 if (__val == -1) [[unlikely]]
3269 __err |= ios_base::failbit;
3274 for (
int __i = 1; __i < __n1; ++__i)
3275 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
3281 while (__n1++ < __n) [[unlikely]]
3282 if (
auto __dig = _S_try_read_digit(__is, __err); __dig != -1)
3284 if (__builtin_mul_overflow(__val, 10, &__val)
3285 || __builtin_add_overflow(__val, __dig, &__val))
3287 __err |= ios_base::failbit;
3297 template<
typename _CharT,
typename _Traits>
3298 static int_least32_t
3299 _S_read_signed(basic_istream<_CharT, _Traits>& __is,
3300 ios_base::iostate& __err,
int __n)
3302 auto __sign = __is.peek();
3303 if (__sign ==
'-' || __sign ==
'+')
3305 int_least32_t __val = _S_read_unsigned(__is, __err, __n);
3306 if (__err & ios_base::failbit)
3308 if (__sign ==
'-') [[unlikely]]
3316 template<
typename _CharT,
typename _Traits>
3317 static int_least32_t
3318 _S_try_read_digit(basic_istream<_CharT, _Traits>& __is,
3319 ios_base::iostate& __err)
3321 int_least32_t __val = -1;
3322 auto __i = __is.peek();
3323 if (!_Traits::eq_int_type(__i, _Traits::eof())) [[likely]]
3325 _CharT __c = _Traits::to_char_type(__i);
3326 if (_CharT(
'0') <= __c && __c <= _CharT(
'9')) [[likely]]
3329 __val = __c - _CharT(
'0');
3333 __err |= ios_base::eofbit;
3339 template<
typename _CharT,
typename _Traits>
3341 _S_read_chr(basic_istream<_CharT, _Traits>& __is,
3342 ios_base::iostate& __err, _CharT __c)
3344 auto __i = __is.peek();
3345 if (_Traits::eq_int_type(__i, _Traits::eof()))
3346 __err |= ios_base::eofbit;
3347 else if (_Traits::to_char_type(__i) == __c) [[likely]]
3352 __err |= ios_base::failbit;
3357 template<
typename _Duration>
3358 using _Parser_t = _Parser<common_type_t<_Duration, seconds>>;
3360 template<
typename _Duration>
3364 if constexpr (_Duration::period::den == 1)
3366 switch (_Duration::period::num)
3368 case minutes::period::num:
3369 case hours::period::num:
3370 case days::period::num:
3371 case weeks::period::num:
3372 case years::period::num:
3389 template<
typename _ToDur,
typename _Tp>
3391 __round(
const _Tp& __t)
3393 if constexpr (__is_duration_v<_Tp>)
3395 if constexpr (treat_as_floating_point_v<typename _Tp::rep>)
3397 else if constexpr (__detail::__use_floor<_ToDur>())
3404 static_assert(__is_time_point_v<_Tp>);
3405 using _Tpt = time_point<typename _Tp::clock, _ToDur>;
3406 return _Tpt(__detail::__round<_ToDur>(__t.time_since_epoch()));
3413 template<
typename _CharT,
typename _Traits,
typename _Rep,
typename _Period,
3414 typename _Alloc = allocator<_CharT>>
3415 inline basic_istream<_CharT, _Traits>&
3416 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3418 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3421 auto __need = __format::_ChronoParts::_TimeOfDay;
3422 __detail::_Parser_t<duration<_Rep, _Period>> __p(__need);
3423 if (__p(__is, __fmt, __abbrev, __offset))
3424 __d = __detail::__round<duration<_Rep, _Period>>(__p._M_time);
3428 template<
typename _CharT,
typename _Traits>
3429 inline basic_ostream<_CharT, _Traits>&
3430 operator<<(basic_ostream<_CharT, _Traits>& __os,
const day& __d)
3432 using _Ctx = __format::__format_context<_CharT>;
3433 using _Str = basic_string_view<_CharT>;
3434 _Str __s = _GLIBCXX_WIDEN(
"{:02d} is not a valid day");
3436 __s = __s.substr(0, 6);
3437 auto __u = (unsigned)__d;
3438 __os << std::vformat(__s, make_format_args<_Ctx>(__u));
3442 template<
typename _CharT,
typename _Traits,
3443 typename _Alloc = allocator<_CharT>>
3444 inline basic_istream<_CharT, _Traits>&
3445 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3447 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3450 __detail::_Parser<> __p(__format::_ChronoParts::_Day);
3451 if (__p(__is, __fmt, __abbrev, __offset))
3452 __d = __p._M_ymd.day();
3456 template<
typename _CharT,
typename _Traits>
3457 inline basic_ostream<_CharT, _Traits>&
3458 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month& __m)
3460 using _Ctx = __format::__format_context<_CharT>;
3461 using _Str = basic_string_view<_CharT>;
3462 _Str __s = _GLIBCXX_WIDEN(
"{:L%b}{} is not a valid month");
3464 __os << std::vformat(__os.getloc(), __s.substr(0, 6),
3465 make_format_args<_Ctx>(__m));
3468 auto __u = (unsigned)__m;
3469 __os << std::vformat(__s.substr(6), make_format_args<_Ctx>(__u));
3474 template<
typename _CharT,
typename _Traits,
3475 typename _Alloc = allocator<_CharT>>
3476 inline basic_istream<_CharT, _Traits>&
3477 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3479 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3482 __detail::_Parser<> __p(__format::_ChronoParts::_Month);
3483 if (__p(__is, __fmt, __abbrev, __offset))
3484 __m = __p._M_ymd.month();
3488 template<
typename _CharT,
typename _Traits>
3489 inline basic_ostream<_CharT, _Traits>&
3490 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year& __y)
3492 using _Ctx = __format::__format_context<_CharT>;
3493 using _Str = basic_string_view<_CharT>;
3494 _Str __s = _GLIBCXX_WIDEN(
"-{:04d} is not a valid year");
3496 __s = __s.substr(0, 7);
3498 if (__i >= 0) [[likely]]
3499 __s.remove_prefix(1);
3502 __os << std::vformat(__s, make_format_args<_Ctx>(__i));
3506 template<
typename _CharT,
typename _Traits,
3507 typename _Alloc = allocator<_CharT>>
3508 inline basic_istream<_CharT, _Traits>&
3509 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3511 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3514 __detail::_Parser<> __p(__format::_ChronoParts::_Year);
3515 if (__p(__is, __fmt, __abbrev, __offset))
3516 __y = __p._M_ymd.year();
3520 template<
typename _CharT,
typename _Traits>
3521 inline basic_ostream<_CharT, _Traits>&
3522 operator<<(basic_ostream<_CharT, _Traits>& __os,
const weekday& __wd)
3524 using _Ctx = __format::__format_context<_CharT>;
3525 using _Str = basic_string_view<_CharT>;
3526 _Str __s = _GLIBCXX_WIDEN(
"{:L%a}{} is not a valid weekday");
3528 __os << std::vformat(__os.getloc(), __s.substr(0, 6),
3529 make_format_args<_Ctx>(__wd));
3532 auto __c = __wd.c_encoding();
3533 __os << std::vformat(__s.substr(6), make_format_args<_Ctx>(__c));
3538 template<
typename _CharT,
typename _Traits,
3539 typename _Alloc = allocator<_CharT>>
3540 inline basic_istream<_CharT, _Traits>&
3541 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3543 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3546 __detail::_Parser<> __p(__format::_ChronoParts::_Weekday);
3547 if (__p(__is, __fmt, __abbrev, __offset))
3552 template<
typename _CharT,
typename _Traits>
3553 inline basic_ostream<_CharT, _Traits>&
3554 operator<<(basic_ostream<_CharT, _Traits>& __os,
3555 const weekday_indexed& __wdi)
3560 basic_stringstream<_CharT> __os2;
3561 __os2.imbue(__os.getloc());
3562 __os2 << __wdi.weekday();
3563 const auto __i = __wdi.index();
3564 basic_string_view<_CharT> __s
3565 = _GLIBCXX_WIDEN(
"[ is not a valid index]");
3567 __os2 << std::format(_GLIBCXX_WIDEN(
"{}"), __i);
3568 if (__i >= 1 && __i <= 5)
3569 __os2 << __s.back();
3571 __os2 << __s.substr(1);
3572 __os << __os2.view();
3576 template<
typename _CharT,
typename _Traits>
3577 inline basic_ostream<_CharT, _Traits>&
3578 operator<<(basic_ostream<_CharT, _Traits>& __os,
3579 const weekday_last& __wdl)
3582 basic_stringstream<_CharT> __os2;
3583 __os2.imbue(__os.getloc());
3584 __os2 << __wdl.weekday() << _GLIBCXX_WIDEN(
"[last]");
3585 __os << __os2.view();
3589 template<
typename _CharT,
typename _Traits>
3590 inline basic_ostream<_CharT, _Traits>&
3591 operator<<(basic_ostream<_CharT, _Traits>& __os,
const month_day& __md)
3594 basic_stringstream<_CharT> __os2;
3595 __os2.imbue(__os.getloc());
3596 __os2 << __md.month();
3597 if constexpr (is_same_v<_CharT, char>)
3601 __os2 << __md.day();
3602 __os << __os2.view();
3606 template<
typename _CharT,
typename _Traits,
3607 typename _Alloc = allocator<_CharT>>
3608 inline basic_istream<_CharT, _Traits>&
3609 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3611 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3614 using __format::_ChronoParts;
3615 auto __need = _ChronoParts::_Month | _ChronoParts::_Day;
3616 __detail::_Parser<> __p(__need);
3617 if (__p(__is, __fmt, __abbrev, __offset))
3618 __md = month_day(__p._M_ymd.month(), __p._M_ymd.day());
3622 template<
typename _CharT,
typename _Traits>
3623 inline basic_ostream<_CharT, _Traits>&
3624 operator<<(basic_ostream<_CharT, _Traits>& __os,
3625 const month_day_last& __mdl)
3628 basic_stringstream<_CharT> __os2;
3629 __os2.imbue(__os.getloc());
3630 __os2 << __mdl.month() << _GLIBCXX_WIDEN(
"/last");
3631 __os << __os2.view();
3635 template<
typename _CharT,
typename _Traits>
3636 inline basic_ostream<_CharT, _Traits>&
3637 operator<<(basic_ostream<_CharT, _Traits>& __os,
3638 const month_weekday& __mwd)
3641 basic_stringstream<_CharT> __os2;
3642 __os2.imbue(__os.getloc());
3643 __os2 << __mwd.month();
3644 if constexpr (is_same_v<_CharT, char>)
3648 __os2 << __mwd.weekday_indexed();
3649 __os << __os2.view();
3653 template<
typename _CharT,
typename _Traits>
3654 inline basic_ostream<_CharT, _Traits>&
3655 operator<<(basic_ostream<_CharT, _Traits>& __os,
3656 const month_weekday_last& __mwdl)
3659 basic_stringstream<_CharT> __os2;
3660 __os2.imbue(__os.getloc());
3661 __os2 << __mwdl.month();
3662 if constexpr (is_same_v<_CharT, char>)
3666 __os2 << __mwdl.weekday_last();
3667 __os << __os2.view();
3671 template<
typename _CharT,
typename _Traits>
3672 inline basic_ostream<_CharT, _Traits>&
3673 operator<<(basic_ostream<_CharT, _Traits>& __os,
const year_month& __ym)
3676 basic_stringstream<_CharT> __os2;
3677 __os2.imbue(__os.getloc());
3678 __os2 << __ym.year();
3679 if constexpr (is_same_v<_CharT, char>)
3683 __os2 << __ym.month();
3684 __os << __os2.view();
3688 template<
typename _CharT,
typename _Traits,
3689 typename _Alloc = allocator<_CharT>>
3690 inline basic_istream<_CharT, _Traits>&
3691 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3693 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3696 using __format::_ChronoParts;
3697 auto __need = _ChronoParts::_Year | _ChronoParts::_Month;
3698 __detail::_Parser<> __p(__need);
3699 if (__p(__is, __fmt, __abbrev, __offset))
3700 __ym = year_month(__p._M_ymd.year(), __p._M_ymd.month());
3704 template<
typename _CharT,
typename _Traits>
3705 inline basic_ostream<_CharT, _Traits>&
3706 operator<<(basic_ostream<_CharT, _Traits>& __os,
3707 const year_month_day& __ymd)
3709 using _Ctx = __format::__format_context<_CharT>;
3710 using _Str = basic_string_view<_CharT>;
3711 _Str __s = _GLIBCXX_WIDEN(
"{:%F} is not a valid date");
3712 __os << std::vformat(__ymd.ok() ? __s.substr(0, 5) : __s,
3713 make_format_args<_Ctx>(__ymd));
3717 template<
typename _CharT,
typename _Traits,
3718 typename _Alloc = allocator<_CharT>>
3719 inline basic_istream<_CharT, _Traits>&
3721 year_month_day& __ymd,
3725 using __format::_ChronoParts;
3726 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3727 | _ChronoParts::_Day;
3728 __detail::_Parser<> __p(__need);
3729 if (__p(__is, __fmt, __abbrev, __offset))
3734 template<
typename _CharT,
typename _Traits>
3737 const year_month_day_last& __ymdl)
3742 __os2 << __ymdl.year();
3743 if constexpr (is_same_v<_CharT, char>)
3747 __os2 << __ymdl.month_day_last();
3748 __os << __os2.view();
3752 template<
typename _CharT,
typename _Traits>
3753 inline basic_ostream<_CharT, _Traits>&
3754 operator<<(basic_ostream<_CharT, _Traits>& __os,
3755 const year_month_weekday& __ymwd)
3759 basic_stringstream<_CharT> __os2;
3760 __os2.
imbue(__os.getloc());
3762 if constexpr (is_same_v<_CharT, char>)
3766 __os2 << __ymwd.year() << __slash << __ymwd.month() << __slash
3767 << __ymwd.weekday_indexed();
3768 __os << __os2.view();
3772 template<
typename _CharT,
typename _Traits>
3773 inline basic_ostream<_CharT, _Traits>&
3774 operator<<(basic_ostream<_CharT, _Traits>& __os,
3775 const year_month_weekday_last& __ymwdl)
3779 basic_stringstream<_CharT> __os2;
3780 __os2.imbue(__os.getloc());
3782 if constexpr (is_same_v<_CharT, char>)
3786 __os2 << __ymwdl.year() << __slash << __ymwdl.month() << __slash
3787 << __ymwdl.weekday_last();
3788 __os << __os2.view();
3792 template<
typename _CharT,
typename _Traits,
typename _Duration>
3793 inline basic_ostream<_CharT, _Traits>&
3794 operator<<(basic_ostream<_CharT, _Traits>& __os,
3797 return __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%T}"), __hms);
3800#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
3802 template<
typename _CharT,
typename _Traits>
3803 basic_ostream<_CharT, _Traits>&
3804 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_info& __i)
3806 return __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{}"), __i);
3810 template<
typename _CharT,
typename _Traits>
3811 basic_ostream<_CharT, _Traits>&
3812 operator<<(basic_ostream<_CharT, _Traits>& __os,
const local_info& __li)
3814 __os << __format::_Separators<_CharT>::_S_squares()[0];
3815 if (__li.result == local_info::unique)
3819 if (__li.result == local_info::nonexistent)
3820 __os << _GLIBCXX_WIDEN(
"nonexistent");
3822 __os << _GLIBCXX_WIDEN(
"ambiguous");
3823 __os << _GLIBCXX_WIDEN(
" local time between ") << __li.first;
3824 __os << _GLIBCXX_WIDEN(
" and ") << __li.second;
3826 __os << __format::_Separators<_CharT>::_S_squares()[1];
3830 template<
typename _CharT,
typename _Traits,
typename _Duration,
3831 typename _TimeZonePtr>
3832 inline basic_ostream<_CharT, _Traits>&
3833 operator<<(basic_ostream<_CharT, _Traits>& __os,
3834 const zoned_time<_Duration, _TimeZonePtr>& __t)
3836 __os << format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T %Z}"), __t);
3841 template<
typename _CharT,
typename _Traits,
typename _Duration>
3842 requires (!treat_as_floating_point_v<typename _Duration::rep>)
3843 && ratio_less_v<typename _Duration::period, days::period>
3844 inline basic_ostream<_CharT, _Traits>&
3845 operator<<(basic_ostream<_CharT, _Traits>& __os,
3846 const sys_time<_Duration>& __tp)
3848 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __tp);
3852 template<
typename _CharT,
typename _Traits>
3853 inline basic_ostream<_CharT, _Traits>&
3854 operator<<(basic_ostream<_CharT, _Traits>& __os,
const sys_days& __dp)
3856 __os << year_month_day{__dp};
3860 template<
typename _CharT,
typename _Traits,
typename _Duration,
3861 typename _Alloc = allocator<_CharT>>
3862 basic_istream<_CharT, _Traits>&
3863 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3864 sys_time<_Duration>& __tp,
3865 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3871 using __format::_ChronoParts;
3872 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3873 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
3874 __detail::_Parser_t<_Duration> __p(__need);
3875 if (__p(__is, __fmt, __abbrev, __offset))
3877 if (__p._M_is_leap_second)
3881 auto __st = __p._M_sys_days + __p._M_time - *__offset;
3882 __tp = __detail::__round<_Duration>(__st);
3888 template<
typename _CharT,
typename _Traits,
typename _Duration>
3889 inline basic_ostream<_CharT, _Traits>&
3890 operator<<(basic_ostream<_CharT, _Traits>& __os,
3891 const utc_time<_Duration>& __t)
3893 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
3897 template<
typename _CharT,
typename _Traits,
typename _Duration,
3898 typename _Alloc = allocator<_CharT>>
3899 inline basic_istream<_CharT, _Traits>&
3900 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3901 utc_time<_Duration>& __tp,
3902 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3908 using __format::_ChronoParts;
3909 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3910 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
3911 __detail::_Parser_t<_Duration> __p(__need);
3912 if (__p(__is, __fmt, __abbrev, __offset))
3916 auto __ut = utc_clock::from_sys(__p._M_sys_days) + __p._M_time
3918 __tp = __detail::__round<_Duration>(__ut);
3923 template<
typename _CharT,
typename _Traits,
typename _Duration>
3924 inline basic_ostream<_CharT, _Traits>&
3925 operator<<(basic_ostream<_CharT, _Traits>& __os,
3926 const tai_time<_Duration>& __t)
3928 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
3932 template<
typename _CharT,
typename _Traits,
typename _Duration,
3933 typename _Alloc = allocator<_CharT>>
3934 inline basic_istream<_CharT, _Traits>&
3935 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3936 tai_time<_Duration>& __tp,
3937 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3943 using __format::_ChronoParts;
3944 auto __need = _ChronoParts::_Year | _ChronoParts::_Month
3945 | _ChronoParts::_Day | _ChronoParts::_TimeOfDay;
3946 __detail::_Parser_t<_Duration> __p(__need);
3947 if (__p(__is, __fmt, __abbrev, __offset))
3949 if (__p._M_is_leap_second)
3953 constexpr sys_days __epoch(-
days(4383));
3954 auto __d = __p._M_sys_days - __epoch + __p._M_time - *__offset;
3955 tai_time<common_type_t<_Duration, seconds>> __tt(__d);
3956 __tp = __detail::__round<_Duration>(__tt);
3962 template<
typename _CharT,
typename _Traits,
typename _Duration>
3963 inline basic_ostream<_CharT, _Traits>&
3964 operator<<(basic_ostream<_CharT, _Traits>& __os,
3965 const gps_time<_Duration>& __t)
3967 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
3971 template<
typename _CharT,
typename _Traits,
typename _Duration,
3972 typename _Alloc = allocator<_CharT>>
3973 inline basic_istream<_CharT, _Traits>&
3974 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
3975 gps_time<_Duration>& __tp,
3976 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
3982 using __format::_ChronoParts;
3983 auto __need = _ChronoParts::_YearMonthDay | _ChronoParts::_TimeOfDay;
3984 __detail::_Parser_t<_Duration> __p(__need);
3985 if (__p(__is, __fmt, __abbrev, __offset))
3987 if (__p._M_is_leap_second)
3991 constexpr sys_days __epoch(
days(3657));
3992 auto __d = __p._M_sys_days - __epoch + __p._M_time - *__offset;
3993 gps_time<common_type_t<_Duration, seconds>> __gt(__d);
3994 __tp = __detail::__round<_Duration>(__gt);
4000 template<
typename _CharT,
typename _Traits,
typename _Duration>
4001 inline basic_ostream<_CharT, _Traits>&
4002 operator<<(basic_ostream<_CharT, _Traits>& __os,
4003 const file_time<_Duration>& __t)
4005 __os << std::format(__os.getloc(), _GLIBCXX_WIDEN(
"{:L%F %T}"), __t);
4009 template<
typename _CharT,
typename _Traits,
typename _Duration,
4010 typename _Alloc = allocator<_CharT>>
4011 inline basic_istream<_CharT, _Traits>&
4012 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4013 file_time<_Duration>& __tp,
4014 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4017 sys_time<_Duration> __st;
4018 if (chrono::from_stream(__is, __fmt, __st, __abbrev, __offset))
4019 __tp = __detail::__round<_Duration>(file_clock::from_sys(__st));
4023 template<
typename _CharT,
typename _Traits,
typename _Duration>
4024 inline basic_ostream<_CharT, _Traits>&
4025 operator<<(basic_ostream<_CharT, _Traits>& __os,
4026 const local_time<_Duration>& __lt)
4029 requires requires(
const sys_time<_Duration>& __st) { __os << __st; }
4031 __os << sys_time<_Duration>{__lt.time_since_epoch()};
4035 template<
typename _CharT,
typename _Traits,
typename _Duration,
4036 typename _Alloc = allocator<_CharT>>
4037 basic_istream<_CharT, _Traits>&
4038 from_stream(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4039 local_time<_Duration>& __tp,
4040 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4043 using __format::_ChronoParts;
4044 auto __need = _ChronoParts::_YearMonthDay | _ChronoParts::_TimeOfDay;
4045 __detail::_Parser_t<_Duration> __p(__need);
4046 if (__p(__is, __fmt, __abbrev, __offset))
4048 days __d = __p._M_sys_days.time_since_epoch();
4049 auto __t = local_days(__d) + __p._M_time;
4050 __tp = __detail::__round<_Duration>(__t);
4061 void from_stream() =
delete;
4063 template<
typename _Parsable,
typename _CharT,
4064 typename _Traits = std::char_traits<_CharT>,
4065 typename... _OptArgs>
4066 concept __parsable =
requires (basic_istream<_CharT, _Traits>& __is,
4067 const _CharT* __fmt, _Parsable& __tp,
4068 _OptArgs*... __args)
4069 { from_stream(__is, __fmt, __tp, __args...); };
4071 template<
typename _Parsable,
typename _CharT,
4072 typename _Traits = char_traits<_CharT>,
4073 typename _Alloc = allocator<_CharT>>
4077 using __string_type = basic_string<_CharT, _Traits, _Alloc>;
4080 _Parse(
const _CharT* __fmt, _Parsable& __tp,
4081 basic_string<_CharT, _Traits, _Alloc>* __abbrev =
nullptr,
4084 _M_abbrev(__abbrev), _M_offset(__offset)
4087 _Parse(_Parse&&) =
delete;
4088 _Parse& operator=(_Parse&&) =
delete;
4091 using __stream_type = basic_istream<_CharT, _Traits>;
4093 const _CharT*
const _M_fmt;
4094 _Parsable*
const _M_tp;
4095 __string_type*
const _M_abbrev;
4098 friend __stream_type&
4099 operator>>(__stream_type& __is, _Parse&& __p)
4102 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev,
4104 else if (__p._M_abbrev)
4105 from_stream(__is, __p._M_fmt, *__p._M_tp, __p._M_abbrev);
4107 from_stream(__is, __p._M_fmt, *__p._M_tp);
4111 friend void operator>>(__stream_type&, _Parse&) =
delete;
4112 friend void operator>>(__stream_type&,
const _Parse&) =
delete;
4116 template<
typename _CharT, __detail::__parsable<_CharT> _Parsable>
4117 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4119 parse(
const _CharT* __fmt, _Parsable& __tp)
4120 {
return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp); }
4122 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4123 __detail::__parsable<_CharT, _Traits> _Parsable>
4126 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp)
4128 return __detail::_Parse<_Parsable, _CharT, _Traits>(__fmt.c_str(), __tp);
4131 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4132 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4133 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
4134 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4136 parse(
const _CharT* __fmt, _Parsable& __tp,
4137 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
4140 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
4144 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4145 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4146 __detail::__parsable<_CharT, _Traits, _StrT> _Parsable>
4149 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
4150 basic_string<_CharT, _Traits, _Alloc>& __abbrev)
4153 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
4157 template<
typename _CharT,
typename _Traits =
char_traits<_CharT>,
4158 typename _StrT = basic_
string<_CharT, _Traits>,
4159 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4160 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4162 parse(
const _CharT* __fmt, _Parsable& __tp,
minutes& __offset)
4164 return __detail::_Parse<_Parsable, _CharT>(__fmt, __tp,
nullptr,
4168 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4169 typename _StrT = basic_string<_CharT, _Traits>,
4170 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4173 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
4176 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
4181 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4182 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4183 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4184 [[nodiscard, __gnu__::__access__(__read_only__, 1)]]
4186 parse(
const _CharT* __fmt, _Parsable& __tp,
4187 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
4190 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt, __tp,
4195 template<
typename _CharT,
typename _Traits,
typename _Alloc,
4196 typename _StrT = basic_string<_CharT, _Traits, _Alloc>,
4197 __detail::__parsable<_CharT, _Traits, _StrT, minutes> _Parsable>
4200 parse(
const basic_string<_CharT, _Traits, _Alloc>& __fmt, _Parsable& __tp,
4201 basic_string<_CharT, _Traits, _Alloc>& __abbrev,
minutes& __offset)
4204 return __detail::_Parse<_Parsable, _CharT, _Traits, _Alloc>(__fmt.c_str(),
4210 template<
typename _Duration>
4211 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4212 basic_istream<_CharT, _Traits>&
4213 __detail::_Parser<_Duration>::
4214 operator()(basic_istream<_CharT, _Traits>& __is,
const _CharT* __fmt,
4215 basic_string<_CharT, _Traits, _Alloc>* __abbrev,
4218 using sentry =
typename basic_istream<_CharT, _Traits>::sentry;
4220 if (sentry __cerb(__is,
true); __cerb)
4222 locale __loc = __is.getloc();
4227 struct _Stream_state
4230 _Stream_state(basic_istream<_CharT, _Traits>& __i)
4232 _M_flags(__i.flags(ios_base::
skipws | ios_base::
dec)),
4238 _M_is.flags(_M_flags);
4242 _Stream_state(_Stream_state&&) =
delete;
4244 basic_istream<_CharT, _Traits>& _M_is;
4245 ios_base::fmtflags _M_flags;
4255 auto __read_unsigned = [&] (
int __n) {
4256 return _S_read_unsigned(__is, __err, __n);
4261 auto __read_signed = [&] (
int __n) {
4262 return _S_read_signed(__is, __err, __n);
4266 auto __read_chr = [&__is, &__err] (_CharT __c) {
4267 return _S_read_chr(__is, __err, __c);
4270 using __format::_ChronoParts;
4271 _ChronoParts __parts{};
4273 const year __bad_y = --year::min();
4274 const month __bad_mon(255);
4275 const day __bad_day(255);
4276 const weekday __bad_wday(255);
4277 const hours __bad_h(-1);
4278 const minutes __bad_min(-9999);
4281 year __y = __bad_y, __yy = __bad_y;
4282 year __iso_y = __bad_y, __iso_yy = __bad_y;
4283 month __m = __bad_mon;
4284 day __d = __bad_day;
4285 weekday __wday = __bad_wday;
4286 hours __h = __bad_h, __h12 = __bad_h;
4288 _Duration __s = __bad_sec;
4290 int __iso_wk = -1, __sunday_wk = -1, __monday_wk = -1;
4292 int __dayofyear = -1;
4294 minutes __tz_offset = __bad_min;
4295 basic_string<_CharT, _Traits> __tz_abbr;
4297 if ((_M_need & _ChronoParts::_TimeOfDay) != 0
4298 && (_M_need & _ChronoParts::_Year) != 0)
4304 __parts = _ChronoParts::_TimeOfDay;
4311 bool __is_flag =
false;
4313 constexpr bool __is_floating
4314 = treat_as_floating_point_v<typename _Duration::rep>;
4333 _CharT __c = *__fmt++;
4340 else if (!__read_chr(__c)) [[unlikely]]
4351 if (__mod || __num) [[unlikely]]
4356 __tmget.get(__is, {}, __is, __err, &__tm,
4358 if (!__is_failed(__err))
4359 __wday = weekday(__tm.tm_wday);
4361 __parts |= _ChronoParts::_Weekday;
4367 if (__mod || __num) [[unlikely]]
4375 __tmget.get(__is, {}, __is, __err, &__tm,
4377 if (!__is_failed(__err))
4378 __m = month(__tm.tm_mon + 1);
4380 __parts |= _ChronoParts::_Month;
4384 if (__mod ==
'O' || __num) [[unlikely]]
4389 __tmget.get(__is, {}, __is, __err, &__tm,
4390 __fmt - 2 - (__mod ==
'E'), __fmt);
4391 if (!__is_failed(__err))
4393 __y = year(__tm.tm_year + 1900);
4394 __m = month(__tm.tm_mon + 1);
4395 __d = day(__tm.tm_mday);
4396 __h =
hours(__tm.tm_hour);
4401 __parts |= _ChronoParts::_DateTime;
4405 if (!__mod) [[likely]]
4407 auto __v = __read_signed(__num ? __num : 2);
4408 if (!__is_failed(__err))
4410 int __cmin = (int)year::min() / 100;
4411 int __cmax = (int)year::max() / 100;
4412 if (__cmin <= __v && __v <= __cmax)
4413 __century = __v * 100;
4418 else if (__mod ==
'E')
4421 __tmget.get(__is, {}, __is, __err, &__tm,
4423 if (!__is_failed(__err))
4424 __century = __tm.tm_year;
4433 if (!__mod) [[likely]]
4435 auto __v = __read_unsigned(__num ? __num : 2);
4436 if (!__is_failed(__err))
4439 else if (__mod ==
'O')
4442 __tmget.get(__is, {}, __is, __err, &__tm,
4444 if (!__is_failed(__err))
4445 __d = day(__tm.tm_mday);
4449 __parts |= _ChronoParts::_Day;
4453 if (__mod || __num) [[unlikely]]
4457 auto __month = __read_unsigned(2);
4459 auto __day = __read_unsigned(2);
4461 auto __year = __read_unsigned(2);
4462 if (__is_failed(__err))
4464 __y = year(__year + 1900 + 100 *
int(__year < 69));
4465 __m = month(__month);
4467 if (!year_month_day(__y, __m, __d).ok())
4469 __y = __yy = __iso_y = __iso_yy = __bad_y;
4475 __parts |= _ChronoParts::_Date;
4479 if (__mod) [[unlikely]]
4483 auto __year = __read_signed(__num ? __num : 4);
4485 auto __month = __read_unsigned(2);
4487 auto __day = __read_unsigned(2);
4488 if (__is_failed(__err))
4491 __m = month(__month);
4493 if (!year_month_day(__y, __m, __d).ok())
4495 __y = __yy = __iso_y = __iso_yy = __bad_y;
4501 __parts |= _ChronoParts::_Date;
4505 if (__mod) [[unlikely]]
4509 auto __val = __read_unsigned(__num ? __num : 2);
4510 if (__val >= 0 && __val <= 99)
4512 __iso_yy = year(__val);
4513 if (__century == -1)
4517 __iso_yy = __iso_y = __y = __yy = __bad_y;
4519 __parts |= _ChronoParts::_Year;
4523 if (__mod) [[unlikely]]
4526 __iso_y = year(__read_unsigned(__num ? __num : 4));
4527 __parts |= _ChronoParts::_Year;
4532 if (__mod ==
'E') [[unlikely]]
4534 else if (__mod ==
'O')
4539 __tmget.get(__is, {}, __is, __err, &__tm,
4541 if (!__is_failed(__err))
4545 __h12 =
hours(__tm.tm_hour);
4549 __h =
hours(__tm.tm_hour);
4558 auto __val = __read_unsigned(__num ? __num : 2);
4559 if (__c ==
'I' && __val >= 1 && __val <= 12)
4561 __h12 =
hours(__val);
4564 else if (__c ==
'H' && __val >= 0 && __val <= 23)
4571 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4576 __parts |= _ChronoParts::_TimeOfDay;
4580 if (__mod) [[unlikely]]
4582 else if (_M_need == _ChronoParts::_TimeOfDay)
4584 auto __val = __read_signed(__num ? __num : 3);
4585 if (!__is_failed(__err))
4588 __parts |= _ChronoParts::_TimeOfDay;
4593 __dayofyear = __read_unsigned(__num ? __num : 3);
4600 if (__mod ==
'E') [[unlikely]]
4602 else if (__mod ==
'O')
4605 __tmget.get(__is, {}, __is, __err, &__tm,
4607 if (!__is_failed(__err))
4608 __m = month(__tm.tm_mon + 1);
4612 auto __val = __read_unsigned(__num ? __num : 2);
4613 if (__val >= 1 && __val <= 12)
4618 __parts |= _ChronoParts::_Month;
4622 if (__mod ==
'E') [[unlikely]]
4624 else if (__mod ==
'O')
4627 __tmget.get(__is, {}, __is, __err, &__tm,
4629 if (!__is_failed(__err))
4634 auto __val = __read_unsigned(__num ? __num : 2);
4635 if (0 <= __val && __val < 60)
4639 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4644 __parts |= _ChronoParts::_TimeOfDay;
4654 const _CharT* __ampms[2];
4655 __tmpunct._M_am_pm(__ampms);
4656 int __n = 0, __which = 3;
4657 while (__which != 0)
4659 auto __i = __is.peek();
4660 if (_Traits::eq_int_type(__i, _Traits::eof()))
4670 else if (__ampms[0][__n + 1] == _CharT())
4681 else if (__ampms[1][__n + 1] == _CharT())
4692 if (__which == 0 || __which == 3)
4705 __tmget.get(__is, {}, __is, __err, &__tm,
4707 if (!__is_failed(__err))
4709 __h =
hours(__tm.tm_hour);
4714 __parts |= _ChronoParts::_TimeOfDay;
4719 if (__mod || __num) [[unlikely]]
4726 auto __val = __read_unsigned(2);
4727 if (__val == -1 || __val > 23) [[unlikely]]
4729 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4733 if (!__read_chr(
':')) [[unlikely]]
4737 __val = __read_unsigned(2);
4738 if (__val == -1 || __val > 60) [[unlikely]]
4740 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4748 __parts |= _ChronoParts::_TimeOfDay;
4751 else if (!__read_chr(
':')) [[unlikely]]
4757 if (__mod ==
'E') [[unlikely]]
4759 else if (__mod ==
'O')
4762 __tmget.get(__is, {}, __is, __err, &__tm,
4764 if (!__is_failed(__err))
4767 else if constexpr (_Duration::period::den == 1
4770 auto __val = __read_unsigned(__num ? __num : 2);
4771 if (0 <= __val && __val <= 59) [[likely]]
4775 if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
4782 basic_stringstream<_CharT> __buf;
4783 auto __digit = _S_try_read_digit(__is, __err);
4786 __buf.put(_CharT(
'0') + __digit);
4787 __digit = _S_try_read_digit(__is, __err);
4789 __buf.put(_CharT(
'0') + __digit);
4792 auto __i = __is.peek();
4793 if (_Traits::eq_int_type(__i, _Traits::eof()))
4801 __dp = __np.decimal_point();
4803 _CharT __c = _Traits::to_char_type(__i);
4809 = hh_mm_ss<_Duration>::fractional_width;
4812 __digit = _S_try_read_digit(__is, __err);
4814 __buf.put(_CharT(
'0') + __digit);
4822 if (!__is_failed(__err)) [[likely]]
4824 long double __val{};
4825#if __cpp_lib_to_chars
4827 auto __first = __str.data();
4828 auto __last = __first + __str.size();
4832 if ((
bool)ec || ptr != __last) [[unlikely]]
4840 if constexpr (__is_floating)
4847 __parts |= _ChronoParts::_TimeOfDay;
4852 if (__mod ==
'E') [[unlikely]]
4854 else if (__mod ==
'O')
4859 __tmget.get(__is, {}, __is, __err, &__tm,
4861 if (!__is_failed(__err))
4862 __wday = weekday(__tm.tm_wday);
4869 const int __lo = __c ==
'u' ? 1 : 0;
4870 const int __hi = __lo + 6;
4871 auto __val = __read_unsigned(__num ? __num : 1);
4872 if (__lo <= __val && __val <= __hi)
4873 __wday = weekday(__val);
4876 __wday = __bad_wday;
4880 __parts |= _ChronoParts::_Weekday;
4886 if (__mod ==
'E') [[unlikely]]
4888 else if (__mod ==
'O')
4890 if (__c ==
'V') [[unlikely]]
4900 const int __lo = __c ==
'V' ? 1 : 0;
4901 const int __hi = 53;
4902 auto __val = __read_unsigned(__num ? __num : 2);
4903 if (__lo <= __val && __val <= __hi)
4908 __sunday_wk = __val;
4914 __monday_wk = __val;
4919 __iso_wk = __sunday_wk = __monday_wk = -1;
4925 if (__mod ==
'O' || __num) [[unlikely]]
4930 __tmget.get(__is, {}, __is, __err, &__tm,
4931 __fmt - 2 - (__mod ==
'E'), __fmt);
4932 if (!__is_failed(__err))
4934 __y = year(__tm.tm_year + 1900);
4935 __m = month(__tm.tm_mon + 1);
4936 __d = day(__tm.tm_mday);
4939 __parts |= _ChronoParts::_Date;
4943 if (__mod ==
'O' || __num) [[unlikely]]
4948 __tmget.get(__is, {}, __is, __err, &__tm,
4949 __fmt - 2 - (__mod ==
'E'), __fmt);
4950 if (!__is_failed(__err))
4952 __h =
hours(__tm.tm_hour);
4957 __parts |= _ChronoParts::_TimeOfDay;
4961 if (__mod) [[unlikely]]
4964 __tmget.get(__is, {}, __is, __err, &__tm,
4966 if (!__is_failed(__err))
4968 int __cent = __tm.tm_year < 2000 ? 1900 : 2000;
4969 __yy = year(__tm.tm_year - __cent);
4970 if (__century == -1)
4976 auto __val = __read_unsigned(__num ? __num : 2);
4977 if (__val >= 0 && __val <= 99)
4980 if (__century == -1)
4981 __century = __val < 69 ? 2000 : 1900;
4984 __y = __yy = __iso_yy = __iso_y = __bad_y;
4986 __parts |= _ChronoParts::_Year;
4990 if (__mod ==
'O') [[unlikely]]
4992 else if (__mod ==
'E')
4995 __tmget.get(__is, {}, __is, __err, &__tm,
4997 if (!__is_failed(__err))
4998 __y = year(__tm.tm_year);
5002 auto __val = __read_unsigned(__num ? __num : 4);
5003 if (!__is_failed(__err))
5006 __parts |= _ChronoParts::_Year;
5010 if (__num) [[unlikely]]
5017 auto __i = __is.peek();
5018 if (_Traits::eq_int_type(__i, _Traits::eof()))
5023 _CharT __ic = _Traits::to_char_type(__i);
5024 const bool __neg = __ic == _CharT(
'-');
5025 if (__ic == _CharT(
'-') || __ic == _CharT(
'+'))
5032 __hh = __read_unsigned(2);
5037 __hh = 10 * _S_try_read_digit(__is, __err);
5038 __hh += _S_try_read_digit(__is, __err);
5041 if (__is_failed(__err))
5045 if (_Traits::eq_int_type(__i, _Traits::eof()))
5048 __tz_offset =
minutes(__hh * (__neg ? -60 : 60));
5051 __ic = _Traits::to_char_type(__i);
5053 bool __read_mm =
false;
5056 if (__ic == _GLIBCXX_WIDEN(
":")[0])
5063 else if (_CharT(
'0') <= __ic && __ic <= _CharT(
'9'))
5069 int_least32_t __mm = 0;
5072 __mm = 10 * _S_try_read_digit(__is, __err);
5073 __mm += _S_try_read_digit(__is, __err);
5076 if (!__is_failed(__err))
5078 auto __z = __hh * 60 + __mm;
5079 __tz_offset =
minutes(__neg ? -__z : __z);
5085 if (__mod || __num) [[unlikely]]
5089 basic_string_view<_CharT> __x = _GLIBCXX_WIDEN(
"_/-+");
5093 auto __i = __is.peek();
5094 if (!_Traits::eq_int_type(__i, _Traits::eof()))
5096 _CharT __a = _Traits::to_char_type(__i);
5098 || __x.find(__a) != __x.npos)
5100 __tz_abbr.push_back(__a);
5109 if (__tz_abbr.empty())
5115 if (__mod || __num) [[unlikely]]
5119 _CharT __i = __is.peek();
5120 if (_Traits::eq_int_type(__i, _Traits::eof()))
5122 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
5130 if (__mod || __num) [[unlikely]]
5134 _CharT __i = __is.peek();
5135 if (_Traits::eq_int_type(__i, _Traits::eof()))
5137 else if (
std::isspace(_Traits::to_char_type(__i), __loc))
5143 if (__mod || __num) [[unlikely]]
5151 if (__mod || __num) [[unlikely]]
5160 if (_CharT(
'1') <= __c && __c <= _CharT(
'9'))
5162 if (!__mod) [[likely]]
5165 auto __end = __fmt + _Traits::length(__fmt);
5167 = __format::__parse_integer(__fmt - 1, __end);
5168 if (__ptr) [[likely]]
5179 if (__is_failed(__err)) [[unlikely]]
5189 if (__yy != __bad_y && __y == __bad_y)
5190 __y =
years(__century) + __yy;
5191 if (__iso_yy != __bad_y && __iso_y == __bad_y)
5192 __iso_y =
years(__century) + __iso_yy;
5195 bool __can_use_doy =
false;
5196 bool __can_use_iso_wk =
false;
5197 bool __can_use_sun_wk =
false;
5198 bool __can_use_mon_wk =
false;
5201 if (__y != __bad_y && __dayofyear >= 0)
5203 __can_use_doy =
true;
5204 __parts |= _ChronoParts::_Date;
5206 else if (__y != __bad_y && __wday != __bad_wday && __sunday_wk >= 0)
5208 __can_use_sun_wk =
true;
5209 __parts |= _ChronoParts::_Date;
5211 else if (__y != __bad_y && __wday != __bad_wday && __monday_wk >= 0)
5213 __can_use_mon_wk =
true;
5214 __parts |= _ChronoParts::_Date;
5216 else if (__iso_y != __bad_y && __wday != __bad_wday && __iso_wk > 0)
5219 __can_use_iso_wk =
true;
5220 __parts |= _ChronoParts::_Date;
5223 if (__is_failed(__err)) [[unlikely]]
5225 else if (__is_flag) [[unlikely]]
5227 else if ((_M_need & __parts) == _M_need) [[likely]]
5249 const bool __need_wday = (_M_need & _ChronoParts::_Weekday) != 0;
5253 const bool __need_time = (_M_need & _ChronoParts::_TimeOfDay) != 0;
5255 if (__need_wday && __wday != __bad_wday)
5257 else if ((_M_need & _ChronoParts::_Date) != 0)
5261 const bool __need_ymd = !__need_wday && !__need_time;
5263 if (((_M_need & _ChronoParts::_Year) != 0 && __y == __bad_y)
5264 || ((_M_need & _ChronoParts::_Month) != 0 && __m == __bad_mon)
5265 || ((_M_need & _ChronoParts::_Day) != 0 && __d == __bad_day))
5272 if ((0 < __dayofyear && __dayofyear <= 365)
5273 || (__dayofyear == 366 && __y.is_leap()))
5276 _M_sys_days = sys_days(__y/January/1)
5277 +
days(__dayofyear - 1);
5279 _M_ymd = year_month_day(_M_sys_days);
5284 else if (__can_use_iso_wk)
5292 const sys_days __jan4(__iso_y/January/4);
5293 weekday __wd1(__jan4 -
days(3));
5294 if (__wd1 != Thursday)
5295 if (__wd1 != Wednesday || !__iso_y.is_leap())
5299 if (!__is_failed(__err)) [[likely]]
5302 sys_days __w(Thursday[1]/January/__iso_y);
5304 __w -= Thursday - Monday;
5306 __w += __wday - Monday;
5310 _M_ymd = year_month_day(_M_sys_days);
5313 else if (__can_use_sun_wk)
5316 sys_days __wk1(__y/January/Sunday[1]);
5317 _M_sys_days = __wk1 +
weeks(__sunday_wk - 1)
5318 +
days(__wday.c_encoding());
5319 _M_ymd = year_month_day(_M_sys_days);
5320 if (_M_ymd.year() != __y) [[unlikely]]
5323 else if (__can_use_mon_wk)
5326 sys_days __wk1(__y/January/Monday[1]);
5327 _M_sys_days = __wk1 +
weeks(__monday_wk - 1)
5328 +
days(__wday.c_encoding() - 1);
5329 _M_ymd = year_month_day(_M_sys_days);
5330 if (_M_ymd.year() != __y) [[unlikely]]
5342 if ((_M_need & _ChronoParts::_Year) != 0)
5344 if (!__y.ok()) [[unlikely]]
5347 else if (__y == __bad_y)
5350 if ((_M_need & _ChronoParts::_Month) != 0)
5352 if (!__m.ok()) [[unlikely]]
5355 else if (__m == __bad_mon)
5358 if ((_M_need & _ChronoParts::_Day) != 0)
5360 if (__d < day(1) || __d > (__y/__m/last).day())
5363 else if (__d == __bad_day)
5366 if (year_month_day __ymd(__y, __m, __d); __ymd.ok())
5369 if (__need_wday || __need_time)
5370 _M_sys_days = sys_days(_M_ymd);
5377 _M_wd = weekday(_M_sys_days);
5383 if (__h == __bad_h && __h12 != __bad_h)
5387 else if (__ampm == 2)
5388 __h = __h12 ==
hours(12) ? __h12 : __h12 +
hours(12);
5393 auto __t = _M_time.zero();
5402 if (__min != __bad_min)
5408 if (__s != __bad_sec)
5412 _M_is_leap_second = __s >=
seconds(60);
5421 if (!__is_failed(__err)) [[likely]]
5423 if (__offset && __tz_offset != __bad_min)
5424 *__offset = __tz_offset;
5425 if (__abbrev && !__tz_abbr.empty())
5433 __is.setstate(__err);
5437#undef _GLIBCXX_WIDEN
5442_GLIBCXX_END_NAMESPACE_VERSION
__detail::__local_time_fmt< _Duration > local_time_format(local_time< _Duration > __time, const string *__abbrev=nullptr, const seconds *__offset_sec=nullptr)
duration< int64_t, ratio< 604800 > > weeks
weeks
constexpr __enable_if_is_duration< _ToDur > floor(const duration< _Rep, _Period > &__d)
constexpr enable_if_t< __and_< __is_duration< _ToDur >, __not_< treat_as_floating_point< typename _ToDur::rep > > >::value, _ToDur > round(const duration< _Rep, _Period > &__d)
duration< int64_t, ratio< 86400 > > days
days
duration< int64_t, ratio< 31556952 > > years
years
duration< int64_t, ratio< 3600 > > hours
hours
duration< int64_t, ratio< 60 > > minutes
minutes
basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const duration< _Rep, _Period > &__d)
duration< int64_t > seconds
seconds
constexpr __enable_if_is_duration< _ToDur > duration_cast(const duration< _Rep, _Period > &__d)
constexpr complex< _Tp > operator-(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x minus y.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
const _Facet & use_facet(const locale &__loc)
Return a facet.
ISO C++ entities toplevel namespace is std.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
chars_format
floating-point format for primitive numerical conversion
bool isspace(_CharT __c, const locale &__loc)
Convenience interface to ctype.is(ctype_base::space, __c).
_CharT toupper(_CharT __c, const locale &__loc)
Convenience interface to ctype.toupper(__c).
bool isalnum(_CharT __c, const locale &__loc)
Convenience interface to ctype.is(ctype_base::alnum, __c).
ios_base & dec(ios_base &__base)
Calls base.setf(ios_base::dec, ios_base::basefield).
ios_base & skipws(ios_base &__base)
Calls base.setf(ios_base::skipws).
constexpr bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
basic_istream< _CharT, _Traits > & ws(basic_istream< _CharT, _Traits > &__is)
Quick and easy way to eat whitespace.
constexpr bitset< _Nb > operator&(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
constexpr from_chars_result from_chars(const char *__first, const char *__last, _Tp &__value, int __base=10)
std::from_chars for integral types.
ISO C++ 2011 namespace for date and time utilities.
locale imbue(const locale &__loc)
Moves to a new locale.
Template class basic_istream.
Template class basic_ostream.
Controlling output for std::string.
Controlling input and output for std::string.
Provides output iterator semantics for streambufs.
Provides compile-time rational arithmetic.
A non-owning reference to a string.
Managing sequences of characters and character-like objects.
constexpr iterator begin() noexcept
chrono::duration represents a distance between two points in time
_Ios_Iostate iostate
This is a bitmask type.
streamsize precision() const
Flags access.
fmtflags flags() const
Access to format flags.
static const iostate eofbit
Indicates that an input operation reached the end of an input sequence.
static const iostate goodbit
Indicates all is well.
locale getloc() const
Locale access.
static const iostate failbit
Indicates that an input operation failed to read the expected characters, or that an output operation...
static const locale & classic()
Return reference to the C locale.