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