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