|
33 | 33 | #include <__chrono/year_month.h>
|
34 | 34 | #include <__chrono/year_month_day.h>
|
35 | 35 | #include <__chrono/year_month_weekday.h>
|
| 36 | +#include <__chrono/zoned_time.h> |
36 | 37 | #include <__concepts/arithmetic.h>
|
37 | 38 | #include <__concepts/same_as.h>
|
38 | 39 | #include <__config>
|
|
44 | 45 | #include <__format/parser_std_format_spec.h>
|
45 | 46 | #include <__format/write_escaped.h>
|
46 | 47 | #include <__memory/addressof.h>
|
| 48 | +#include <__type_traits/is_specialization.h> |
47 | 49 | #include <cmath>
|
48 | 50 | #include <ctime>
|
49 | 51 | #include <limits>
|
@@ -137,10 +139,24 @@ __format_sub_seconds(basic_stringstream<_CharT>& __sstr, const chrono::hh_mm_ss<
|
137 | 139 | __value.fractional_width);
|
138 | 140 | }
|
139 | 141 |
|
| 142 | +# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && \ |
| 143 | + !defined(_LIBCPP_HAS_NO_FILESYSTEM) && !defined(_LIBCPP_HAS_NO_LOCALIZATION) |
| 144 | +template <class _CharT, class _Duration, class _TimeZonePtr> |
| 145 | +_LIBCPP_HIDE_FROM_ABI void |
| 146 | +__format_sub_seconds(basic_stringstream<_CharT>& __sstr, const chrono::zoned_time<_Duration, _TimeZonePtr>& __value) { |
| 147 | + __formatter::__format_sub_seconds(__sstr, __value.get_local_time().time_since_epoch()); |
| 148 | +} |
| 149 | +# endif |
| 150 | + |
140 | 151 | template <class _Tp>
|
141 | 152 | consteval bool __use_fraction() {
|
142 | 153 | if constexpr (__is_time_point<_Tp>)
|
143 | 154 | return chrono::hh_mm_ss<typename _Tp::duration>::fractional_width;
|
| 155 | +# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && \ |
| 156 | + !defined(_LIBCPP_HAS_NO_FILESYSTEM) && !defined(_LIBCPP_HAS_NO_LOCALIZATION) |
| 157 | + else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>) |
| 158 | + return chrono::hh_mm_ss<typename _Tp::duration>::fractional_width; |
| 159 | +# endif |
144 | 160 | else if constexpr (chrono::__is_duration<_Tp>::value)
|
145 | 161 | return chrono::hh_mm_ss<_Tp>::fractional_width;
|
146 | 162 | else if constexpr (__is_hh_mm_ss<_Tp>)
|
@@ -212,8 +228,13 @@ _LIBCPP_HIDE_FROM_ABI __time_zone __convert_to_time_zone([[maybe_unused]] const
|
212 | 228 | # if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
|
213 | 229 | if constexpr (same_as<_Tp, chrono::sys_info>)
|
214 | 230 | return {__value.abbrev, __value.offset};
|
| 231 | +# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \ |
| 232 | + !defined(_LIBCPP_HAS_NO_LOCALIZATION) |
| 233 | + else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>) |
| 234 | + return __formatter::__convert_to_time_zone(__value.get_info()); |
| 235 | +# endif |
215 | 236 | else
|
216 |
| -# endif |
| 237 | +# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) |
217 | 238 | return {"UTC", chrono::seconds{0}};
|
218 | 239 | }
|
219 | 240 |
|
@@ -426,7 +447,12 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __weekday_ok(const _Tp& __value) {
|
426 | 447 | return true;
|
427 | 448 | else if constexpr (same_as<_Tp, chrono::local_info>)
|
428 | 449 | return true;
|
429 |
| -# endif |
| 450 | +# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \ |
| 451 | + !defined(_LIBCPP_HAS_NO_LOCALIZATION) |
| 452 | + else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>) |
| 453 | + return true; |
| 454 | +# endif |
| 455 | +# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) |
430 | 456 | else
|
431 | 457 | static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
|
432 | 458 | }
|
@@ -472,7 +498,12 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __weekday_name_ok(const _Tp& __value) {
|
472 | 498 | return true;
|
473 | 499 | else if constexpr (same_as<_Tp, chrono::local_info>)
|
474 | 500 | return true;
|
475 |
| -# endif |
| 501 | +# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \ |
| 502 | + !defined(_LIBCPP_HAS_NO_LOCALIZATION) |
| 503 | + else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>) |
| 504 | + return true; |
| 505 | +# endif |
| 506 | +# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) |
476 | 507 | else
|
477 | 508 | static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
|
478 | 509 | }
|
@@ -518,7 +549,12 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __date_ok(const _Tp& __value) {
|
518 | 549 | return true;
|
519 | 550 | else if constexpr (same_as<_Tp, chrono::local_info>)
|
520 | 551 | return true;
|
521 |
| -# endif |
| 552 | +# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \ |
| 553 | + !defined(_LIBCPP_HAS_NO_LOCALIZATION) |
| 554 | + else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>) |
| 555 | + return true; |
| 556 | +# endif |
| 557 | +# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) |
522 | 558 | else
|
523 | 559 | static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
|
524 | 560 | }
|
@@ -564,7 +600,12 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __month_name_ok(const _Tp& __value) {
|
564 | 600 | return true;
|
565 | 601 | else if constexpr (same_as<_Tp, chrono::local_info>)
|
566 | 602 | return true;
|
567 |
| -# endif |
| 603 | +# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \ |
| 604 | + !defined(_LIBCPP_HAS_NO_LOCALIZATION) |
| 605 | + else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>) |
| 606 | + return true; |
| 607 | +# endif |
| 608 | +# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) |
568 | 609 | else
|
569 | 610 | static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
|
570 | 611 | }
|
@@ -924,7 +965,23 @@ struct formatter<chrono::local_info, _CharT> : public __formatter_chrono<_CharT>
|
924 | 965 | return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags{});
|
925 | 966 | }
|
926 | 967 | };
|
927 |
| -# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) |
| 968 | +# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \ |
| 969 | + !defined(_LIBCPP_HAS_NO_LOCALIZATION) |
| 970 | +// Note due to how libc++'s formatters are implemented there is no need to add |
| 971 | +// the exposition only local-time-format-t abstraction. |
| 972 | +template <class _Duration, class _TimeZonePtr, __fmt_char_type _CharT> |
| 973 | +struct formatter<chrono::zoned_time<_Duration, _TimeZonePtr>, _CharT> : public __formatter_chrono<_CharT> { |
| 974 | +public: |
| 975 | + using _Base = __formatter_chrono<_CharT>; |
| 976 | + |
| 977 | + template <class _ParseContext> |
| 978 | + _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { |
| 979 | + return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__clock); |
| 980 | + } |
| 981 | +}; |
| 982 | +# endif // !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && |
| 983 | + // !defined(_LIBCPP_HAS_NO_LOCALIZATION) |
| 984 | +# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) |
928 | 985 |
|
929 | 986 | #endif // if _LIBCPP_STD_VER >= 20
|
930 | 987 |
|
|
0 commit comments