Mark de Wever | e5d2d3e | 2022-03-20 12:40:02 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
| 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP___CHRONO_OSTREAM_H |
| 11 | #define _LIBCPP___CHRONO_OSTREAM_H |
| 12 | |
Mark de Wever | e5d2d3e | 2022-03-20 12:40:02 | [diff] [blame] | 13 | #include <__config> |
Mark de Wever | e5d2d3e | 2022-03-20 12:40:02 | [diff] [blame] | 14 | |
Nikolas Klauser | c6f3b7b | 2024-11-06 09:39:19 | [diff] [blame] | 15 | #if _LIBCPP_HAS_LOCALIZATION |
Louis Dionne | 87d56c5 | 2024-09-16 12:15:38 | [diff] [blame] | 16 | |
| 17 | # include <__chrono/calendar.h> |
| 18 | # include <__chrono/day.h> |
| 19 | # include <__chrono/duration.h> |
| 20 | # include <__chrono/file_clock.h> |
| 21 | # include <__chrono/hh_mm_ss.h> |
| 22 | # include <__chrono/local_info.h> |
| 23 | # include <__chrono/month.h> |
| 24 | # include <__chrono/month_weekday.h> |
| 25 | # include <__chrono/monthday.h> |
| 26 | # include <__chrono/statically_widen.h> |
| 27 | # include <__chrono/sys_info.h> |
| 28 | # include <__chrono/system_clock.h> |
Mark de Wever | aca829d | 2025-02-06 16:55:02 | [diff] [blame^] | 29 | # include <__chrono/tai_clock.h> |
Mark de Wever | 0cd794d | 2025-01-24 17:56:02 | [diff] [blame] | 30 | # include <__chrono/utc_clock.h> |
Louis Dionne | 87d56c5 | 2024-09-16 12:15:38 | [diff] [blame] | 31 | # include <__chrono/weekday.h> |
| 32 | # include <__chrono/year.h> |
| 33 | # include <__chrono/year_month.h> |
| 34 | # include <__chrono/year_month_day.h> |
| 35 | # include <__chrono/year_month_weekday.h> |
| 36 | # include <__chrono/zoned_time.h> |
| 37 | # include <__concepts/same_as.h> |
| 38 | # include <__format/format_functions.h> |
| 39 | # include <__fwd/ostream.h> |
| 40 | # include <ratio> |
Louis Dionne | 09e3a36 | 2024-09-16 19:06:20 | [diff] [blame] | 41 | # include <sstream> |
Louis Dionne | 87d56c5 | 2024-09-16 12:15:38 | [diff] [blame] | 42 | |
| 43 | # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 44 | # pragma GCC system_header |
| 45 | # endif |
Mark de Wever | e5d2d3e | 2022-03-20 12:40:02 | [diff] [blame] | 46 | |
| 47 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 48 | |
Louis Dionne | 87d56c5 | 2024-09-16 12:15:38 | [diff] [blame] | 49 | # if _LIBCPP_STD_VER >= 20 |
Mark de Wever | e5d2d3e | 2022-03-20 12:40:02 | [diff] [blame] | 50 | |
| 51 | namespace chrono { |
| 52 | |
Mark de Wever | 2c1d795 | 2022-03-20 12:40:02 | [diff] [blame] | 53 | template <class _CharT, class _Traits, class _Duration> |
Mark de Wever | 042a6a1 | 2024-01-22 18:06:15 | [diff] [blame] | 54 | requires(!treat_as_floating_point_v<typename _Duration::rep> && _Duration{1} < days{1}) |
Mark de Wever | 2c1d795 | 2022-03-20 12:40:02 | [diff] [blame] | 55 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
Mark de Wever | 042a6a1 | 2024-01-22 18:06:15 | [diff] [blame] | 56 | operator<<(basic_ostream<_CharT, _Traits>& __os, const sys_time<_Duration>& __tp) { |
Mark de Wever | 2c1d795 | 2022-03-20 12:40:02 | [diff] [blame] | 57 | return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%F %T}"), __tp); |
| 58 | } |
| 59 | |
Mark de Wever | 042a6a1 | 2024-01-22 18:06:15 | [diff] [blame] | 60 | template <class _CharT, class _Traits> |
| 61 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
| 62 | operator<<(basic_ostream<_CharT, _Traits>& __os, const sys_days& __dp) { |
| 63 | return __os << year_month_day{__dp}; |
| 64 | } |
| 65 | |
Mark de Wever | 0cd794d | 2025-01-24 17:56:02 | [diff] [blame] | 66 | # if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM |
Mark de Wever | 3b30f20 | 2025-01-24 19:23:18 | [diff] [blame] | 67 | # if _LIBCPP_HAS_EXPERIMENTAL_TZDB |
Mark de Wever | 0cd794d | 2025-01-24 17:56:02 | [diff] [blame] | 68 | |
| 69 | template <class _CharT, class _Traits, class _Duration> |
| 70 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
| 71 | operator<<(basic_ostream<_CharT, _Traits>& __os, const utc_time<_Duration>& __tp) { |
| 72 | return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%F %T}"), __tp); |
| 73 | } |
| 74 | |
Mark de Wever | aca829d | 2025-02-06 16:55:02 | [diff] [blame^] | 75 | template <class _CharT, class _Traits, class _Duration> |
| 76 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
| 77 | operator<<(basic_ostream<_CharT, _Traits>& __os, const tai_time<_Duration>& __tp) { |
| 78 | return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%F %T}"), __tp); |
| 79 | } |
| 80 | |
Mark de Wever | 3b30f20 | 2025-01-24 19:23:18 | [diff] [blame] | 81 | # endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB |
Mark de Wever | 0cd794d | 2025-01-24 17:56:02 | [diff] [blame] | 82 | # endif // _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM |
| 83 | |
Mark de Wever | 96f3033 | 2023-04-20 19:40:36 | [diff] [blame] | 84 | template <class _CharT, class _Traits, class _Duration> |
| 85 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
| 86 | operator<<(basic_ostream<_CharT, _Traits>& __os, const file_time<_Duration> __tp) { |
| 87 | return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%F %T}"), __tp); |
| 88 | } |
| 89 | |
Mark de Wever | bc2cf42 | 2023-04-28 06:13:01 | [diff] [blame] | 90 | template <class _CharT, class _Traits, class _Duration> |
| 91 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
| 92 | operator<<(basic_ostream<_CharT, _Traits>& __os, const local_time<_Duration> __tp) { |
| 93 | return __os << sys_time<_Duration>{__tp.time_since_epoch()}; |
| 94 | } |
| 95 | |
Mark de Wever | 719c3dc | 2022-03-20 12:40:02 | [diff] [blame] | 96 | // Depending on the type the return is a const _CharT* or a basic_string<_CharT> |
| 97 | template <class _CharT, class _Period> |
| 98 | _LIBCPP_HIDE_FROM_ABI auto __units_suffix() { |
| 99 | // TODO FMT LWG issue the suffixes are always char and not STATICALLY-WIDEN'ed. |
| 100 | if constexpr (same_as<typename _Period::type, atto>) |
| 101 | return _LIBCPP_STATICALLY_WIDEN(_CharT, "as"); |
| 102 | else if constexpr (same_as<typename _Period::type, femto>) |
| 103 | return _LIBCPP_STATICALLY_WIDEN(_CharT, "fs"); |
| 104 | else if constexpr (same_as<typename _Period::type, pico>) |
| 105 | return _LIBCPP_STATICALLY_WIDEN(_CharT, "ps"); |
| 106 | else if constexpr (same_as<typename _Period::type, nano>) |
| 107 | return _LIBCPP_STATICALLY_WIDEN(_CharT, "ns"); |
| 108 | else if constexpr (same_as<typename _Period::type, micro>) |
Nikolas Klauser | c6f3b7b | 2024-11-06 09:39:19 | [diff] [blame] | 109 | # if _LIBCPP_HAS_UNICODE |
Mark de Wever | 719c3dc | 2022-03-20 12:40:02 | [diff] [blame] | 110 | return _LIBCPP_STATICALLY_WIDEN(_CharT, "\u00b5s"); |
Louis Dionne | 87d56c5 | 2024-09-16 12:15:38 | [diff] [blame] | 111 | # else |
Mark de Wever | 719c3dc | 2022-03-20 12:40:02 | [diff] [blame] | 112 | return _LIBCPP_STATICALLY_WIDEN(_CharT, "us"); |
Louis Dionne | 87d56c5 | 2024-09-16 12:15:38 | [diff] [blame] | 113 | # endif |
Mark de Wever | 719c3dc | 2022-03-20 12:40:02 | [diff] [blame] | 114 | else if constexpr (same_as<typename _Period::type, milli>) |
| 115 | return _LIBCPP_STATICALLY_WIDEN(_CharT, "ms"); |
| 116 | else if constexpr (same_as<typename _Period::type, centi>) |
| 117 | return _LIBCPP_STATICALLY_WIDEN(_CharT, "cs"); |
| 118 | else if constexpr (same_as<typename _Period::type, deci>) |
| 119 | return _LIBCPP_STATICALLY_WIDEN(_CharT, "ds"); |
| 120 | else if constexpr (same_as<typename _Period::type, ratio<1>>) |
| 121 | return _LIBCPP_STATICALLY_WIDEN(_CharT, "s"); |
| 122 | else if constexpr (same_as<typename _Period::type, deca>) |
| 123 | return _LIBCPP_STATICALLY_WIDEN(_CharT, "das"); |
| 124 | else if constexpr (same_as<typename _Period::type, hecto>) |
| 125 | return _LIBCPP_STATICALLY_WIDEN(_CharT, "hs"); |
| 126 | else if constexpr (same_as<typename _Period::type, kilo>) |
| 127 | return _LIBCPP_STATICALLY_WIDEN(_CharT, "ks"); |
| 128 | else if constexpr (same_as<typename _Period::type, mega>) |
| 129 | return _LIBCPP_STATICALLY_WIDEN(_CharT, "Ms"); |
| 130 | else if constexpr (same_as<typename _Period::type, giga>) |
| 131 | return _LIBCPP_STATICALLY_WIDEN(_CharT, "Gs"); |
| 132 | else if constexpr (same_as<typename _Period::type, tera>) |
| 133 | return _LIBCPP_STATICALLY_WIDEN(_CharT, "Ts"); |
| 134 | else if constexpr (same_as<typename _Period::type, peta>) |
| 135 | return _LIBCPP_STATICALLY_WIDEN(_CharT, "Ps"); |
| 136 | else if constexpr (same_as<typename _Period::type, exa>) |
| 137 | return _LIBCPP_STATICALLY_WIDEN(_CharT, "Es"); |
| 138 | else if constexpr (same_as<typename _Period::type, ratio<60>>) |
| 139 | return _LIBCPP_STATICALLY_WIDEN(_CharT, "min"); |
| 140 | else if constexpr (same_as<typename _Period::type, ratio<3600>>) |
| 141 | return _LIBCPP_STATICALLY_WIDEN(_CharT, "h"); |
| 142 | else if constexpr (same_as<typename _Period::type, ratio<86400>>) |
| 143 | return _LIBCPP_STATICALLY_WIDEN(_CharT, "d"); |
| 144 | else if constexpr (_Period::den == 1) |
| 145 | return std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "[{}]s"), _Period::num); |
| 146 | else |
| 147 | return std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "[{}/{}]s"), _Period::num, _Period::den); |
| 148 | } |
| 149 | |
| 150 | template <class _CharT, class _Traits, class _Rep, class _Period> |
Louis Dionne | 3d334df | 2023-03-16 17:09:44 | [diff] [blame] | 151 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
Mark de Wever | 719c3dc | 2022-03-20 12:40:02 | [diff] [blame] | 152 | operator<<(basic_ostream<_CharT, _Traits>& __os, const duration<_Rep, _Period>& __d) { |
| 153 | basic_ostringstream<_CharT, _Traits> __s; |
| 154 | __s.flags(__os.flags()); |
| 155 | __s.imbue(__os.getloc()); |
| 156 | __s.precision(__os.precision()); |
| 157 | __s << __d.count() << chrono::__units_suffix<_CharT, _Period>(); |
| 158 | return __os << __s.str(); |
| 159 | } |
| 160 | |
Mark de Wever | e5d2d3e | 2022-03-20 12:40:02 | [diff] [blame] | 161 | template <class _CharT, class _Traits> |
Louis Dionne | 3d334df | 2023-03-16 17:09:44 | [diff] [blame] | 162 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const day& __d) { |
Mark de Wever | de6827b | 2023-02-24 20:35:41 | [diff] [blame] | 163 | return __os << (__d.ok() ? std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:%d}"), __d) |
| 164 | // Note this error differs from the wording of the Standard. The |
| 165 | // Standard wording doesn't work well on AIX or Windows. There |
| 166 | // the formatted day seems to be either modulo 100 or completely |
| 167 | // omitted. Judging by the wording this is valid. |
| 168 | // TODO FMT Write a paper of file an LWG issue. |
| 169 | : std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:02} is not a valid day"), |
| 170 | static_cast<unsigned>(__d))); |
Mark de Wever | e5d2d3e | 2022-03-20 12:40:02 | [diff] [blame] | 171 | } |
| 172 | |
Mark de Wever | 3eb4f16 | 2022-03-20 12:40:02 | [diff] [blame] | 173 | template <class _CharT, class _Traits> |
Louis Dionne | 3d334df | 2023-03-16 17:09:44 | [diff] [blame] | 174 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
Mark de Wever | 1522f19 | 2022-03-20 12:40:02 | [diff] [blame] | 175 | operator<<(basic_ostream<_CharT, _Traits>& __os, const month& __m) { |
| 176 | return __os << (__m.ok() ? std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%b}"), __m) |
| 177 | : std::format(__os.getloc(), |
| 178 | _LIBCPP_STATICALLY_WIDEN(_CharT, "{} is not a valid month"), |
| 179 | static_cast<unsigned>(__m))); // TODO FMT Standard mandated locale isn't used. |
| 180 | } |
| 181 | |
| 182 | template <class _CharT, class _Traits> |
Louis Dionne | 3d334df | 2023-03-16 17:09:44 | [diff] [blame] | 183 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
Mark de Wever | 3eb4f16 | 2022-03-20 12:40:02 | [diff] [blame] | 184 | operator<<(basic_ostream<_CharT, _Traits>& __os, const year& __y) { |
| 185 | return __os << (__y.ok() ? std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:%Y}"), __y) |
| 186 | : std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:%Y} is not a valid year"), __y)); |
| 187 | } |
| 188 | |
Mark de Wever | 566868c | 2022-03-20 12:40:02 | [diff] [blame] | 189 | template <class _CharT, class _Traits> |
Louis Dionne | 3d334df | 2023-03-16 17:09:44 | [diff] [blame] | 190 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
Mark de Wever | 566868c | 2022-03-20 12:40:02 | [diff] [blame] | 191 | operator<<(basic_ostream<_CharT, _Traits>& __os, const weekday& __wd) { |
| 192 | return __os << (__wd.ok() ? std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%a}"), __wd) |
| 193 | : std::format(__os.getloc(), // TODO FMT Standard mandated locale isn't used. |
| 194 | _LIBCPP_STATICALLY_WIDEN(_CharT, "{} is not a valid weekday"), |
| 195 | static_cast<unsigned>(__wd.c_encoding()))); |
| 196 | } |
| 197 | |
Mark de Wever | 105fef5 | 2022-03-20 12:40:02 | [diff] [blame] | 198 | template <class _CharT, class _Traits> |
Louis Dionne | 3d334df | 2023-03-16 17:09:44 | [diff] [blame] | 199 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
Mark de Wever | 105fef5 | 2022-03-20 12:40:02 | [diff] [blame] | 200 | operator<<(basic_ostream<_CharT, _Traits>& __os, const weekday_indexed& __wdi) { |
| 201 | auto __i = __wdi.index(); |
| 202 | return __os << (__i >= 1 && __i <= 5 |
| 203 | ? std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L}[{}]"), __wdi.weekday(), __i) |
| 204 | : std::format(__os.getloc(), |
| 205 | _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L}[{} is not a valid index]"), |
| 206 | __wdi.weekday(), |
| 207 | __i)); |
| 208 | } |
| 209 | |
| 210 | template <class _CharT, class _Traits> |
Louis Dionne | 3d334df | 2023-03-16 17:09:44 | [diff] [blame] | 211 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
Mark de Wever | 105fef5 | 2022-03-20 12:40:02 | [diff] [blame] | 212 | operator<<(basic_ostream<_CharT, _Traits>& __os, const weekday_last& __wdl) { |
| 213 | return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L}[last]"), __wdl.weekday()); |
| 214 | } |
| 215 | |
| 216 | template <class _CharT, class _Traits> |
Louis Dionne | 3d334df | 2023-03-16 17:09:44 | [diff] [blame] | 217 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
Mark de Wever | 105fef5 | 2022-03-20 12:40:02 | [diff] [blame] | 218 | operator<<(basic_ostream<_CharT, _Traits>& __os, const month_day& __md) { |
| 219 | // TODO FMT The Standard allows 30th of February to be printed. |
| 220 | // It would be nice to show an error message instead. |
| 221 | return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L}/{}"), __md.month(), __md.day()); |
| 222 | } |
| 223 | |
| 224 | template <class _CharT, class _Traits> |
Louis Dionne | 3d334df | 2023-03-16 17:09:44 | [diff] [blame] | 225 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
Mark de Wever | 105fef5 | 2022-03-20 12:40:02 | [diff] [blame] | 226 | operator<<(basic_ostream<_CharT, _Traits>& __os, const month_day_last& __mdl) { |
| 227 | return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L}/last"), __mdl.month()); |
| 228 | } |
| 229 | |
| 230 | template <class _CharT, class _Traits> |
Louis Dionne | 3d334df | 2023-03-16 17:09:44 | [diff] [blame] | 231 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
Mark de Wever | 105fef5 | 2022-03-20 12:40:02 | [diff] [blame] | 232 | operator<<(basic_ostream<_CharT, _Traits>& __os, const month_weekday& __mwd) { |
| 233 | return __os << std::format( |
| 234 | __os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L}/{:L}"), __mwd.month(), __mwd.weekday_indexed()); |
| 235 | } |
| 236 | |
| 237 | template <class _CharT, class _Traits> |
Louis Dionne | 3d334df | 2023-03-16 17:09:44 | [diff] [blame] | 238 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
Mark de Wever | 105fef5 | 2022-03-20 12:40:02 | [diff] [blame] | 239 | operator<<(basic_ostream<_CharT, _Traits>& __os, const month_weekday_last& __mwdl) { |
| 240 | return __os << std::format( |
| 241 | __os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L}/{:L}"), __mwdl.month(), __mwdl.weekday_last()); |
| 242 | } |
| 243 | |
| 244 | template <class _CharT, class _Traits> |
Louis Dionne | 3d334df | 2023-03-16 17:09:44 | [diff] [blame] | 245 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
Mark de Wever | 105fef5 | 2022-03-20 12:40:02 | [diff] [blame] | 246 | operator<<(basic_ostream<_CharT, _Traits>& __os, const year_month& __ym) { |
| 247 | return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{}/{:L}"), __ym.year(), __ym.month()); |
| 248 | } |
| 249 | |
| 250 | template <class _CharT, class _Traits> |
Louis Dionne | 3d334df | 2023-03-16 17:09:44 | [diff] [blame] | 251 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
Mark de Wever | 105fef5 | 2022-03-20 12:40:02 | [diff] [blame] | 252 | operator<<(basic_ostream<_CharT, _Traits>& __os, const year_month_day& __ymd) { |
| 253 | return __os << (__ymd.ok() ? std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:%F}"), __ymd) |
| 254 | : std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:%F} is not a valid date"), __ymd)); |
| 255 | } |
| 256 | |
| 257 | template <class _CharT, class _Traits> |
Louis Dionne | 3d334df | 2023-03-16 17:09:44 | [diff] [blame] | 258 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
Mark de Wever | 105fef5 | 2022-03-20 12:40:02 | [diff] [blame] | 259 | operator<<(basic_ostream<_CharT, _Traits>& __os, const year_month_day_last& __ymdl) { |
| 260 | return __os << std::format( |
| 261 | __os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{}/{:L}"), __ymdl.year(), __ymdl.month_day_last()); |
| 262 | } |
| 263 | |
| 264 | template <class _CharT, class _Traits> |
Louis Dionne | 3d334df | 2023-03-16 17:09:44 | [diff] [blame] | 265 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
Mark de Wever | 105fef5 | 2022-03-20 12:40:02 | [diff] [blame] | 266 | operator<<(basic_ostream<_CharT, _Traits>& __os, const year_month_weekday& __ymwd) { |
| 267 | return __os << std::format( |
| 268 | __os.getloc(), |
| 269 | _LIBCPP_STATICALLY_WIDEN(_CharT, "{}/{:L}/{:L}"), |
| 270 | __ymwd.year(), |
| 271 | __ymwd.month(), |
| 272 | __ymwd.weekday_indexed()); |
| 273 | } |
| 274 | |
| 275 | template <class _CharT, class _Traits> |
Louis Dionne | 3d334df | 2023-03-16 17:09:44 | [diff] [blame] | 276 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
Mark de Wever | 105fef5 | 2022-03-20 12:40:02 | [diff] [blame] | 277 | operator<<(basic_ostream<_CharT, _Traits>& __os, const year_month_weekday_last& __ymwdl) { |
| 278 | return __os << std::format( |
| 279 | __os.getloc(), |
| 280 | _LIBCPP_STATICALLY_WIDEN(_CharT, "{}/{:L}/{:L}"), |
| 281 | __ymwdl.year(), |
| 282 | __ymwdl.month(), |
| 283 | __ymwdl.weekday_last()); |
| 284 | } |
| 285 | |
Mark de Wever | 7f5d130 | 2022-03-20 12:40:02 | [diff] [blame] | 286 | template <class _CharT, class _Traits, class _Duration> |
Louis Dionne | 3d334df | 2023-03-16 17:09:44 | [diff] [blame] | 287 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
Mark de Wever | 7f5d130 | 2022-03-20 12:40:02 | [diff] [blame] | 288 | operator<<(basic_ostream<_CharT, _Traits>& __os, const hh_mm_ss<_Duration> __hms) { |
| 289 | return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%T}"), __hms); |
| 290 | } |
| 291 | |
Nikolas Klauser | 24e70e3 | 2025-01-24 08:34:42 | [diff] [blame] | 292 | # if _LIBCPP_HAS_EXPERIMENTAL_TZDB |
Mark de Wever | 6f7976c | 2024-04-17 18:55:51 | [diff] [blame] | 293 | |
| 294 | template <class _CharT, class _Traits> |
| 295 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
| 296 | operator<<(basic_ostream<_CharT, _Traits>& __os, const sys_info& __info) { |
| 297 | // __info.abbrev is always std::basic_string<char>. |
| 298 | // Since these strings typically are short the conversion should be cheap. |
| 299 | std::basic_string<_CharT> __abbrev{__info.abbrev.begin(), __info.abbrev.end()}; |
| 300 | return __os << std::format( |
| 301 | _LIBCPP_STATICALLY_WIDEN(_CharT, "[{:%F %T}, {:%F %T}) {:%T} {:%Q%q} \"{}\""), |
| 302 | __info.begin, |
| 303 | __info.end, |
| 304 | hh_mm_ss{__info.offset}, |
| 305 | __info.save, |
| 306 | __abbrev); |
| 307 | } |
| 308 | |
Mark de Wever | 8a21d59 | 2024-04-18 15:23:07 | [diff] [blame] | 309 | template <class _CharT, class _Traits> |
| 310 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
| 311 | operator<<(basic_ostream<_CharT, _Traits>& __os, const local_info& __info) { |
| 312 | auto __result = [&]() -> basic_string<_CharT> { |
| 313 | switch (__info.result) { |
| 314 | case local_info::unique: |
| 315 | return _LIBCPP_STATICALLY_WIDEN(_CharT, "unique"); |
| 316 | case local_info::nonexistent: |
| 317 | return _LIBCPP_STATICALLY_WIDEN(_CharT, "non-existent"); |
| 318 | case local_info::ambiguous: |
| 319 | return _LIBCPP_STATICALLY_WIDEN(_CharT, "ambiguous"); |
| 320 | |
| 321 | default: |
| 322 | return std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "unspecified result ({})"), __info.result); |
| 323 | }; |
| 324 | }; |
| 325 | |
| 326 | return __os << std::format( |
| 327 | _LIBCPP_STATICALLY_WIDEN(_CharT, "{}: {{{}, {}}}"), __result(), __info.first, __info.second); |
| 328 | } |
| 329 | |
Nikolas Klauser | c6f3b7b | 2024-11-06 09:39:19 | [diff] [blame] | 330 | # if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM |
Mark de Wever | afbfb16 | 2024-07-20 17:24:41 | [diff] [blame] | 331 | template <class _CharT, class _Traits, class _Duration, class _TimeZonePtr> |
| 332 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
| 333 | operator<<(basic_ostream<_CharT, _Traits>& __os, const zoned_time<_Duration, _TimeZonePtr>& __tp) { |
| 334 | return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%F %T %Z}"), __tp); |
| 335 | } |
Louis Dionne | 87d56c5 | 2024-09-16 12:15:38 | [diff] [blame] | 336 | # endif |
Nikolas Klauser | 24e70e3 | 2025-01-24 08:34:42 | [diff] [blame] | 337 | # endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB |
Mark de Wever | 6f7976c | 2024-04-17 18:55:51 | [diff] [blame] | 338 | |
Mark de Wever | e5d2d3e | 2022-03-20 12:40:02 | [diff] [blame] | 339 | } // namespace chrono |
| 340 | |
Louis Dionne | 87d56c5 | 2024-09-16 12:15:38 | [diff] [blame] | 341 | # endif // if _LIBCPP_STD_VER >= 20 |
Mark de Wever | e5d2d3e | 2022-03-20 12:40:02 | [diff] [blame] | 342 | |
| 343 | _LIBCPP_END_NAMESPACE_STD |
| 344 | |
Nikolas Klauser | c6f3b7b | 2024-11-06 09:39:19 | [diff] [blame] | 345 | #endif // _LIBCPP_HAS_LOCALIZATION |
Louis Dionne | 87d56c5 | 2024-09-16 12:15:38 | [diff] [blame] | 346 | |
Mark de Wever | e5d2d3e | 2022-03-20 12:40:02 | [diff] [blame] | 347 | #endif // _LIBCPP___CHRONO_OSTREAM_H |