Coverage Report

Created: 2026-07-26 06:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fmt/include/fmt/chrono.h
Line
Count
Source
1
// Formatting library for C++ - chrono support
2
//
3
// Copyright (c) 2012 - present, Victor Zverovich and {fmt} contributors
4
// All rights reserved.
5
//
6
// For the license information refer to format.h.
7
8
#ifndef FMT_CHRONO_H_
9
#define FMT_CHRONO_H_
10
11
#ifndef FMT_MODULE
12
#  include <algorithm>
13
#  include <chrono>
14
#  include <cmath>    // std::isfinite
15
#  include <cstring>  // std::memcpy
16
#  include <ctime>
17
#  include <iterator>
18
#  include <locale>
19
#  include <ostream>
20
#  include <type_traits>
21
#endif
22
23
#include "format.h"
24
25
FMT_BEGIN_NAMESPACE
26
27
// Enable safe chrono durations, unless explicitly disabled.
28
#ifndef FMT_SAFE_DURATION_CAST
29
#  define FMT_SAFE_DURATION_CAST 1
30
#endif
31
#if FMT_SAFE_DURATION_CAST
32
33
// For conversion between std::chrono::durations without undefined
34
// behaviour or erroneous results.
35
// This is a stripped down version of duration_cast, for inclusion in fmt.
36
// See https://github.com/pauldreik/safe_duration_cast
37
//
38
// Copyright Paul Dreik 2019
39
namespace safe_duration_cast {
40
41
// DEPRECATED!
42
template <typename To, typename From,
43
          FMT_ENABLE_IF(!std::is_same<From, To>::value &&
44
                        std::numeric_limits<From>::is_signed ==
45
                            std::numeric_limits<To>::is_signed)>
46
FMT_CONSTEXPR auto lossless_integral_conversion(const From from, int& ec)
47
9.12k
    -> To {
48
9.12k
  ec = 0;
49
9.12k
  using F = std::numeric_limits<From>;
50
9.12k
  using T = std::numeric_limits<To>;
51
9.12k
  static_assert(F::is_integer, "From must be integral");
52
9.12k
  static_assert(T::is_integer, "To must be integral");
53
54
  // A and B are both signed, or both unsigned.
55
9.12k
  if FMT_CONSTEXPR20 (F::digits <= T::digits) {
56
    // From fits in To without any problem.
57
9.12k
  } else {
58
    // From does not always fit in To, resort to a dynamic check.
59
0
    if (from < (T::min)() || from > (T::max)()) {
60
      // outside range.
61
0
      ec = 1;
62
0
      return {};
63
0
    }
64
0
  }
65
9.12k
  return static_cast<To>(from);
66
9.12k
}
67
68
/// Converts From to To, without loss. If the dynamic value of from
69
/// can't be converted to To without loss, ec is set.
70
template <typename To, typename From,
71
          FMT_ENABLE_IF(!std::is_same<From, To>::value &&
72
                        std::numeric_limits<From>::is_signed !=
73
                            std::numeric_limits<To>::is_signed)>
74
FMT_CONSTEXPR auto lossless_integral_conversion(const From from, int& ec)
75
    -> To {
76
  ec = 0;
77
  using F = std::numeric_limits<From>;
78
  using T = std::numeric_limits<To>;
79
  static_assert(F::is_integer, "From must be integral");
80
  static_assert(T::is_integer, "To must be integral");
81
82
  if FMT_CONSTEXPR20 (F::is_signed && !T::is_signed) {
83
    // From may be negative, not allowed!
84
    if (fmt::detail::is_negative(from)) {
85
      ec = 1;
86
      return {};
87
    }
88
    // From is positive. Can it always fit in To?
89
    if (F::digits > T::digits &&
90
        from > static_cast<From>(detail::max_value<To>())) {
91
      ec = 1;
92
      return {};
93
    }
94
  }
95
96
  if (!F::is_signed && T::is_signed && F::digits >= T::digits &&
97
      from > static_cast<From>(detail::max_value<To>())) {
98
    ec = 1;
99
    return {};
100
  }
101
  return static_cast<To>(from);  // Lossless conversion.
102
}
103
104
template <typename To, typename From,
105
          FMT_ENABLE_IF(std::is_same<From, To>::value)>
106
FMT_CONSTEXPR auto lossless_integral_conversion(const From from, int& ec)
107
121k
    -> To {
108
121k
  ec = 0;
109
121k
  return from;
110
121k
}  // function
111
112
// clang-format off
113
/**
114
 * converts From to To if possible, otherwise ec is set.
115
 *
116
 * input                            |    output
117
 * ---------------------------------|---------------
118
 * NaN                              | NaN
119
 * Inf                              | Inf
120
 * normal, fits in output           | converted (possibly lossy)
121
 * normal, does not fit in output   | ec is set
122
 * subnormal                        | best effort
123
 * -Inf                             | -Inf
124
 */
125
// clang-format on
126
template <typename To, typename From,
127
          FMT_ENABLE_IF(!std::is_same<From, To>::value)>
128
FMT_CONSTEXPR auto safe_float_conversion(const From from, int& ec) -> To {
129
  ec = 0;
130
  using T = std::numeric_limits<To>;
131
  static_assert(std::is_floating_point<From>::value, "From must be floating");
132
  static_assert(std::is_floating_point<To>::value, "To must be floating");
133
134
  // catch the only happy case
135
  if (std::isfinite(from)) {
136
    if (from >= T::lowest() && from <= (T::max)()) {
137
      return static_cast<To>(from);
138
    }
139
    // not within range.
140
    ec = 1;
141
    return {};
142
  }
143
144
  // nan and inf will be preserved
145
  return static_cast<To>(from);
146
}  // function
147
148
template <typename To, typename From,
149
          FMT_ENABLE_IF(std::is_same<From, To>::value)>
150
FMT_CONSTEXPR auto safe_float_conversion(const From from, int& ec) -> To {
151
  ec = 0;
152
  static_assert(std::is_floating_point<From>::value, "From must be floating");
153
  return from;
154
}
155
156
/// Safe duration_cast between floating point durations
157
template <typename To, typename FromRep, typename FromPeriod,
158
          FMT_ENABLE_IF(std::is_floating_point<FromRep>::value),
159
          FMT_ENABLE_IF(std::is_floating_point<typename To::rep>::value)>
160
auto safe_duration_cast(std::chrono::duration<FromRep, FromPeriod> from,
161
                        int& ec) -> To {
162
  using From = std::chrono::duration<FromRep, FromPeriod>;
163
  ec = 0;
164
165
  // the basic idea is that we need to convert from count() in the from type
166
  // to count() in the To type, by multiplying it with this:
167
  struct Factor
168
      : std::ratio_divide<typename From::period, typename To::period> {};
169
170
  static_assert(Factor::num > 0, "num must be positive");
171
  static_assert(Factor::den > 0, "den must be positive");
172
173
  // the conversion is like this: multiply from.count() with Factor::num
174
  // /Factor::den and convert it to To::rep, all this without
175
  // overflow/underflow. let's start by finding a suitable type that can hold
176
  // both To, From and Factor::num
177
  using IntermediateRep =
178
      typename std::common_type<typename From::rep, typename To::rep,
179
                                decltype(Factor::num)>::type;
180
181
  // force conversion of From::rep -> IntermediateRep to be safe,
182
  // even if it will never happen be narrowing in this context.
183
  IntermediateRep count =
184
      safe_float_conversion<IntermediateRep>(from.count(), ec);
185
  if (ec) {
186
    return {};
187
  }
188
189
  // multiply with Factor::num without overflow or underflow
190
  if FMT_CONSTEXPR20 (Factor::num != 1) {
191
    constexpr auto max1 = detail::max_value<IntermediateRep>() /
192
                          static_cast<IntermediateRep>(Factor::num);
193
    if (count > max1) {
194
      ec = 1;
195
      return {};
196
    }
197
    constexpr auto min1 = std::numeric_limits<IntermediateRep>::lowest() /
198
                          static_cast<IntermediateRep>(Factor::num);
199
    if (count < min1) {
200
      ec = 1;
201
      return {};
202
    }
203
    count *= static_cast<IntermediateRep>(Factor::num);
204
  }
205
206
  // this can't go wrong, right? den>0 is checked earlier.
207
  if FMT_CONSTEXPR20 (Factor::den != 1) {
208
    using common_t = typename std::common_type<IntermediateRep, intmax_t>::type;
209
    count /= static_cast<common_t>(Factor::den);
210
  }
211
212
  // convert to the to type, safely
213
  using ToRep = typename To::rep;
214
215
  const ToRep tocount = safe_float_conversion<ToRep>(count, ec);
216
  if (ec) {
217
    return {};
218
  }
219
  return To{tocount};
220
}
221
}  // namespace safe_duration_cast
222
#endif
223
224
namespace detail {
225
226
// Check if std::chrono::utc_time is available.
227
#ifdef FMT_USE_UTC_TIME
228
// Use the provided definition.
229
#elif defined(__cpp_lib_chrono)
230
#  define FMT_USE_UTC_TIME (__cpp_lib_chrono >= 201907L)
231
#else
232
#  define FMT_USE_UTC_TIME 0
233
#endif
234
#if FMT_USE_UTC_TIME
235
using utc_clock = std::chrono::utc_clock;
236
#else
237
struct utc_clock {
238
  template <typename T> void to_sys(T);
239
};
240
#endif
241
242
// Check if std::chrono::local_time is available.
243
#ifdef FMT_USE_LOCAL_TIME
244
// Use the provided definition.
245
#elif defined(__cpp_lib_chrono)
246
#  define FMT_USE_LOCAL_TIME (__cpp_lib_chrono >= 201907L)
247
#else
248
#  define FMT_USE_LOCAL_TIME 0
249
#endif
250
#if FMT_USE_LOCAL_TIME
251
using local_t = std::chrono::local_t;
252
#else
253
struct local_t {};
254
#endif
255
256
}  // namespace detail
257
258
template <typename Duration>
259
using sys_time = std::chrono::time_point<std::chrono::system_clock, Duration>;
260
261
template <typename Duration>
262
using utc_time = std::chrono::time_point<detail::utc_clock, Duration>;
263
264
template <class Duration>
265
using local_time = std::chrono::time_point<detail::local_t, Duration>;
266
267
namespace detail {
268
269
// Prevents expansion of a preceding token as a function-style macro.
270
// Usage: f FMT_NOMACRO()
271
#define FMT_NOMACRO
272
273
template <typename T = void> struct null {};
274
0
inline auto gmtime_r(...) -> null<> { return null<>(); }
275
0
inline auto gmtime_s(...) -> null<> { return null<>(); }
276
277
// It is defined here and not in ostream.h because the latter has expensive
278
// includes.
279
template <typename StreamBuf> class formatbuf : public StreamBuf {
280
 private:
281
  using char_type = typename StreamBuf::char_type;
282
  using streamsize = decltype(std::declval<StreamBuf>().sputn(nullptr, 0));
283
  using int_type = typename StreamBuf::int_type;
284
  using traits_type = typename StreamBuf::traits_type;
285
286
  buffer<char_type>& buffer_;
287
288
 public:
289
0
  explicit formatbuf(buffer<char_type>& buf) : buffer_(buf) {}
290
291
 protected:
292
  // The put area is always empty. This makes the implementation simpler and has
293
  // the advantage that the streambuf and the buffer are always in sync and
294
  // sputc never writes into uninitialized memory. A disadvantage is that each
295
  // call to sputc always results in a (virtual) call to overflow. There is no
296
  // disadvantage here for sputn since this always results in a call to xsputn.
297
298
0
  auto overflow(int_type ch) -> int_type override {
299
0
    if (!traits_type::eq_int_type(ch, traits_type::eof()))
300
0
      buffer_.push_back(static_cast<char_type>(ch));
301
0
    return ch;
302
0
  }
303
304
0
  auto xsputn(const char_type* s, streamsize count) -> streamsize override {
305
0
    buffer_.append(s, s + count);
306
0
    return count;
307
0
  }
308
};
309
310
18.0k
inline auto get_classic_locale() -> const std::locale& {
311
18.0k
  static const auto& locale = std::locale::classic();
312
18.0k
  return locale;
313
18.0k
}
314
315
template <typename CodeUnit> struct codecvt_result {
316
  static constexpr size_t max_size = 32;
317
  CodeUnit buf[max_size];
318
  CodeUnit* end;
319
};
320
321
template <typename CodeUnit>
322
void write_codecvt(codecvt_result<CodeUnit>& out, string_view in,
323
0
                   const std::locale& loc) {
324
0
  FMT_PRAGMA_CLANG(diagnostic push)
325
0
  FMT_PRAGMA_CLANG(diagnostic ignored "-Wdeprecated")
326
0
  auto& f = std::use_facet<std::codecvt<CodeUnit, char, std::mbstate_t>>(loc);
327
0
  FMT_PRAGMA_CLANG(diagnostic pop)
328
0
  auto mb = std::mbstate_t();
329
0
  const char* from_next = nullptr;
330
0
  auto result = f.in(mb, in.begin(), in.end(), from_next, std::begin(out.buf),
331
0
                     std::end(out.buf), out.end);
332
0
  if (result != std::codecvt_base::ok)
333
0
    FMT_THROW(format_error("failed to format time"));
334
0
}
335
336
template <typename OutputIt>
337
auto write_encoded_tm_str(OutputIt out, string_view in, const std::locale& loc)
338
755
    -> OutputIt {
339
755
  if (detail::use_utf8 && loc != get_classic_locale()) {
340
    // char16_t and char32_t codecvts are broken in MSVC (linkage errors) and
341
    // gcc-4.
342
#if FMT_MSC_VERSION != 0 ||  \
343
    (defined(__GLIBCXX__) && \
344
     (!defined(_GLIBCXX_USE_DUAL_ABI) || _GLIBCXX_USE_DUAL_ABI == 0))
345
    // The _GLIBCXX_USE_DUAL_ABI macro is always defined in libstdc++ from gcc-5
346
    // and newer.
347
    using code_unit = wchar_t;
348
#else
349
0
    using code_unit = char32_t;
350
0
#endif
351
352
0
    using unit_t = codecvt_result<code_unit>;
353
0
    unit_t unit;
354
0
    write_codecvt(unit, in, loc);
355
    // In UTF-8 is used one to four one-byte code units.
356
0
    auto u =
357
0
        to_utf8<code_unit, basic_memory_buffer<char, unit_t::max_size * 4>>();
358
0
    if (!u.convert({unit.buf, to_unsigned(unit.end - unit.buf)}))
359
0
      FMT_THROW(format_error("failed to format time"));
360
0
    return copy<char>(u.c_str(), u.c_str() + u.size(), out);
361
0
  }
362
755
  return copy<char>(in.data(), in.data() + in.size(), out);
363
755
}
364
365
template <typename Char, typename OutputIt,
366
          FMT_ENABLE_IF(!std::is_same<Char, char>::value)>
367
auto write_tm_str(OutputIt out, string_view sv, const std::locale& loc)
368
    -> OutputIt {
369
  codecvt_result<Char> unit;
370
  write_codecvt(unit, sv, loc);
371
  return copy<Char>(unit.buf, unit.end, out);
372
}
373
374
template <typename Char, typename OutputIt,
375
          FMT_ENABLE_IF(std::is_same<Char, char>::value)>
376
auto write_tm_str(OutputIt out, string_view sv, const std::locale& loc)
377
755
    -> OutputIt {
378
755
  return write_encoded_tm_str(out, sv, loc);
379
755
}
380
381
template <typename Char>
382
inline void do_write(buffer<Char>& buf, const std::tm& time,
383
0
                     const std::locale& loc, char format, char modifier) {
384
0
  auto&& format_buf = formatbuf<std::basic_streambuf<Char>>(buf);
385
0
  auto&& os = std::basic_ostream<Char>(&format_buf);
386
0
  os.imbue(loc);
387
0
  const auto& facet = std::use_facet<std::time_put<Char>>(loc);
388
0
  auto end = facet.put(os, os, Char(' '), &time, format, modifier);
389
0
  if (end.failed()) FMT_THROW(format_error("failed to format time"));
390
0
}
391
392
template <typename Char, typename OutputIt,
393
          FMT_ENABLE_IF(!std::is_same<Char, char>::value)>
394
auto write(OutputIt out, const std::tm& time, const std::locale& loc,
395
           char format, char modifier = 0) -> OutputIt {
396
  auto&& buf = get_buffer<Char>(out);
397
  do_write<Char>(buf, time, loc, format, modifier);
398
  return get_iterator(buf, out);
399
}
400
401
template <typename Char, typename OutputIt,
402
          FMT_ENABLE_IF(std::is_same<Char, char>::value)>
403
auto write(OutputIt out, const std::tm& time, const std::locale& loc,
404
0
           char format, char modifier = 0) -> OutputIt {
405
0
  auto&& buf = basic_memory_buffer<Char>();
406
0
  do_write<char>(buf, time, loc, format, modifier);
407
0
  return write_encoded_tm_str(out, string_view(buf.data(), buf.size()), loc);
408
0
}
409
410
template <typename T, typename U>
411
using is_similar_arithmetic_type =
412
    bool_constant<(std::is_integral<T>::value && std::is_integral<U>::value) ||
413
                  (std::is_floating_point<T>::value &&
414
                   std::is_floating_point<U>::value)>;
415
416
0
FMT_NORETURN inline void throw_duration_error() {
417
0
  FMT_THROW(format_error("cannot format duration"));
418
0
}
419
420
// Cast one integral duration to another with an overflow check.
421
template <typename To, typename FromRep, typename FromPeriod,
422
          FMT_ENABLE_IF(std::is_integral<FromRep>::value&&
423
                            std::is_integral<typename To::rep>::value)>
424
130k
auto duration_cast(std::chrono::duration<FromRep, FromPeriod> from) -> To {
425
#if !FMT_SAFE_DURATION_CAST
426
  return std::chrono::duration_cast<To>(from);
427
#else
428
  // The conversion factor: to.count() == factor * from.count().
429
130k
  using factor = std::ratio_divide<FromPeriod, typename To::period>;
430
431
130k
  using common_rep = typename std::common_type<FromRep, typename To::rep,
432
130k
                                               decltype(factor::num)>::type;
433
130k
  common_rep count = from.count();  // This conversion is lossless.
434
435
  // Multiply from.count() by factor and check for overflow.
436
130k
  if FMT_CONSTEXPR20 (factor::num != 1) {
437
3.97k
    if (count > max_value<common_rep>() / factor::num) throw_duration_error();
438
3.97k
    const auto min = (std::numeric_limits<common_rep>::min)() / factor::num;
439
3.97k
    if (!std::is_unsigned<common_rep>::value && count < min)
440
0
      throw_duration_error();
441
3.97k
    count *= factor::num;
442
3.97k
  }
443
130k
  if FMT_CONSTEXPR20 (factor::den != 1) count /= factor::den;
444
130k
  int ec = 0;
445
130k
  auto to =
446
130k
      To(safe_duration_cast::lossless_integral_conversion<typename To::rep>(
447
130k
          count, ec));
448
130k
  if (ec) throw_duration_error();
449
130k
  return to;
450
130k
#endif
451
130k
}
_ZN3fmt3v126detail13duration_castINSt3__16chrono8durationIlNS3_5ratioILl1ELl1EEEEExNS6_ILl1ELl1000000EEETnNS3_9enable_ifIXaasr3std11is_integralIT0_EE5valuesr3std11is_integralINT_3repEEE5valueEiE4typeELi0EEESC_NS5_ISB_T1_EE
Line
Count
Source
424
9.12k
auto duration_cast(std::chrono::duration<FromRep, FromPeriod> from) -> To {
425
#if !FMT_SAFE_DURATION_CAST
426
  return std::chrono::duration_cast<To>(from);
427
#else
428
  // The conversion factor: to.count() == factor * from.count().
429
9.12k
  using factor = std::ratio_divide<FromPeriod, typename To::period>;
430
431
9.12k
  using common_rep = typename std::common_type<FromRep, typename To::rep,
432
9.12k
                                               decltype(factor::num)>::type;
433
9.12k
  common_rep count = from.count();  // This conversion is lossless.
434
435
  // Multiply from.count() by factor and check for overflow.
436
9.12k
  if FMT_CONSTEXPR20 (factor::num != 1) {
437
0
    if (count > max_value<common_rep>() / factor::num) throw_duration_error();
438
0
    const auto min = (std::numeric_limits<common_rep>::min)() / factor::num;
439
0
    if (!std::is_unsigned<common_rep>::value && count < min)
440
0
      throw_duration_error();
441
0
    count *= factor::num;
442
0
  }
443
9.12k
  if FMT_CONSTEXPR20 (factor::den != 1) count /= factor::den;
444
9.12k
  int ec = 0;
445
9.12k
  auto to =
446
9.12k
      To(safe_duration_cast::lossless_integral_conversion<typename To::rep>(
447
9.12k
          count, ec));
448
9.12k
  if (ec) throw_duration_error();
449
9.12k
  return to;
450
9.12k
#endif
451
9.12k
}
_ZN3fmt3v126detail13duration_castINSt3__16chrono8durationIxNS3_5ratioILl1ELl1000000EEEEExS7_TnNS3_9enable_ifIXaasr3std11is_integralIT0_EE5valuesr3std11is_integralINT_3repEEE5valueEiE4typeELi0EEESB_NS5_ISA_T1_EE
Line
Count
Source
424
58.5k
auto duration_cast(std::chrono::duration<FromRep, FromPeriod> from) -> To {
425
#if !FMT_SAFE_DURATION_CAST
426
  return std::chrono::duration_cast<To>(from);
427
#else
428
  // The conversion factor: to.count() == factor * from.count().
429
58.5k
  using factor = std::ratio_divide<FromPeriod, typename To::period>;
430
431
58.5k
  using common_rep = typename std::common_type<FromRep, typename To::rep,
432
58.5k
                                               decltype(factor::num)>::type;
433
58.5k
  common_rep count = from.count();  // This conversion is lossless.
434
435
  // Multiply from.count() by factor and check for overflow.
436
58.5k
  if FMT_CONSTEXPR20 (factor::num != 1) {
437
0
    if (count > max_value<common_rep>() / factor::num) throw_duration_error();
438
0
    const auto min = (std::numeric_limits<common_rep>::min)() / factor::num;
439
0
    if (!std::is_unsigned<common_rep>::value && count < min)
440
0
      throw_duration_error();
441
0
    count *= factor::num;
442
0
  }
443
58.5k
  if FMT_CONSTEXPR20 (factor::den != 1) count /= factor::den;
444
58.5k
  int ec = 0;
445
58.5k
  auto to =
446
58.5k
      To(safe_duration_cast::lossless_integral_conversion<typename To::rep>(
447
58.5k
          count, ec));
448
58.5k
  if (ec) throw_duration_error();
449
58.5k
  return to;
450
58.5k
#endif
451
58.5k
}
_ZN3fmt3v126detail13duration_castINSt3__16chrono8durationIxNS3_5ratioILl1ELl1EEEEExNS6_ILl1ELl1000000EEETnNS3_9enable_ifIXaasr3std11is_integralIT0_EE5valuesr3std11is_integralINT_3repEEE5valueEiE4typeELi0EEESC_NS5_ISB_T1_EE
Line
Count
Source
424
58.5k
auto duration_cast(std::chrono::duration<FromRep, FromPeriod> from) -> To {
425
#if !FMT_SAFE_DURATION_CAST
426
  return std::chrono::duration_cast<To>(from);
427
#else
428
  // The conversion factor: to.count() == factor * from.count().
429
58.5k
  using factor = std::ratio_divide<FromPeriod, typename To::period>;
430
431
58.5k
  using common_rep = typename std::common_type<FromRep, typename To::rep,
432
58.5k
                                               decltype(factor::num)>::type;
433
58.5k
  common_rep count = from.count();  // This conversion is lossless.
434
435
  // Multiply from.count() by factor and check for overflow.
436
58.5k
  if FMT_CONSTEXPR20 (factor::num != 1) {
437
0
    if (count > max_value<common_rep>() / factor::num) throw_duration_error();
438
0
    const auto min = (std::numeric_limits<common_rep>::min)() / factor::num;
439
0
    if (!std::is_unsigned<common_rep>::value && count < min)
440
0
      throw_duration_error();
441
0
    count *= factor::num;
442
0
  }
443
58.5k
  if FMT_CONSTEXPR20 (factor::den != 1) count /= factor::den;
444
58.5k
  int ec = 0;
445
58.5k
  auto to =
446
58.5k
      To(safe_duration_cast::lossless_integral_conversion<typename To::rep>(
447
58.5k
          count, ec));
448
58.5k
  if (ec) throw_duration_error();
449
58.5k
  return to;
450
58.5k
#endif
451
58.5k
}
_ZN3fmt3v126detail13duration_castINSt3__16chrono8durationIxNS3_5ratioILl1ELl1000000EEEEExNS6_ILl1ELl1EEETnNS3_9enable_ifIXaasr3std11is_integralIT0_EE5valuesr3std11is_integralINT_3repEEE5valueEiE4typeELi0EEESC_NS5_ISB_T1_EE
Line
Count
Source
424
3.97k
auto duration_cast(std::chrono::duration<FromRep, FromPeriod> from) -> To {
425
#if !FMT_SAFE_DURATION_CAST
426
  return std::chrono::duration_cast<To>(from);
427
#else
428
  // The conversion factor: to.count() == factor * from.count().
429
3.97k
  using factor = std::ratio_divide<FromPeriod, typename To::period>;
430
431
3.97k
  using common_rep = typename std::common_type<FromRep, typename To::rep,
432
3.97k
                                               decltype(factor::num)>::type;
433
3.97k
  common_rep count = from.count();  // This conversion is lossless.
434
435
  // Multiply from.count() by factor and check for overflow.
436
3.97k
  if FMT_CONSTEXPR20 (factor::num != 1) {
437
3.97k
    if (count > max_value<common_rep>() / factor::num) throw_duration_error();
438
3.97k
    const auto min = (std::numeric_limits<common_rep>::min)() / factor::num;
439
3.97k
    if (!std::is_unsigned<common_rep>::value && count < min)
440
0
      throw_duration_error();
441
3.97k
    count *= factor::num;
442
3.97k
  }
443
3.97k
  if FMT_CONSTEXPR20 (factor::den != 1) count /= factor::den;
444
3.97k
  int ec = 0;
445
3.97k
  auto to =
446
3.97k
      To(safe_duration_cast::lossless_integral_conversion<typename To::rep>(
447
3.97k
          count, ec));
448
3.97k
  if (ec) throw_duration_error();
449
3.97k
  return to;
450
3.97k
#endif
451
3.97k
}
Unexecuted instantiation: _ZN3fmt3v126detail13duration_castINSt3__16chrono8durationIxNS3_5ratioILl1ELl1EEEEExS7_TnNS3_9enable_ifIXaasr3std11is_integralIT0_EE5valuesr3std11is_integralINT_3repEEE5valueEiE4typeELi0EEESB_NS5_ISA_T1_EE
452
453
template <typename To, typename FromRep, typename FromPeriod,
454
          FMT_ENABLE_IF(std::is_floating_point<FromRep>::value&&
455
                            std::is_floating_point<typename To::rep>::value)>
456
auto duration_cast(std::chrono::duration<FromRep, FromPeriod> from) -> To {
457
#if FMT_SAFE_DURATION_CAST
458
  // Preserve infinity and NaN.
459
  if (!isfinite(from.count())) return static_cast<To>(from.count());
460
  // Throwing version of safe_duration_cast is only available for
461
  // integer to integer or float to float casts.
462
  int ec;
463
  To to = safe_duration_cast::safe_duration_cast<To>(from, ec);
464
  if (ec) throw_duration_error();
465
  return to;
466
#else
467
  // Standard duration cast, may overflow.
468
  return std::chrono::duration_cast<To>(from);
469
#endif
470
}
471
472
template <typename To, typename FromRep, typename FromPeriod,
473
          FMT_ENABLE_IF(
474
              !is_similar_arithmetic_type<FromRep, typename To::rep>::value)>
475
auto duration_cast(std::chrono::duration<FromRep, FromPeriod> from) -> To {
476
  // Mixed integer <-> float cast is not supported by safe duration_cast.
477
  return std::chrono::duration_cast<To>(from);
478
}
479
480
template <typename Duration>
481
9.12k
auto to_time_t(sys_time<Duration> time_point) -> std::time_t {
482
  // Cannot use std::chrono::system_clock::to_time_t since this would first
483
  // require a cast to std::chrono::system_clock::time_point, which could
484
  // overflow.
485
9.12k
  return detail::duration_cast<std::chrono::duration<std::time_t>>(
486
9.12k
             time_point.time_since_epoch())
487
9.12k
      .count();
488
9.12k
}
489
490
}  // namespace detail
491
492
FMT_BEGIN_EXPORT
493
494
/**
495
 * Converts given time since epoch as `std::time_t` value into calendar time,
496
 * expressed in Coordinated Universal Time (UTC). Unlike `std::gmtime`, this
497
 * function is thread-safe on most platforms.
498
 */
499
9.12k
inline auto gmtime(std::time_t time) -> std::tm {
500
9.12k
  struct dispatcher {
501
9.12k
    std::time_t time_;
502
9.12k
    std::tm tm_;
503
504
9.12k
    inline dispatcher(std::time_t t) : time_(t) {}
505
506
9.12k
    inline auto run() -> bool {
507
9.12k
      using namespace fmt::detail;
508
9.12k
      return handle(gmtime_r(&time_, &tm_));
509
9.12k
    }
510
511
9.12k
    inline auto handle(std::tm* tm) -> bool { return tm != nullptr; }
512
513
9.12k
    inline auto handle(detail::null<>) -> bool {
514
0
      using namespace fmt::detail;
515
0
      return fallback(gmtime_s(&tm_, &time_));
516
0
    }
517
518
9.12k
    inline auto fallback(int res) -> bool { return res == 0; }
519
520
9.12k
#if !FMT_MSC_VERSION
521
9.12k
    inline auto fallback(detail::null<>) -> bool {
522
0
      std::tm* tm = std::gmtime(&time_);
523
0
      if (tm) tm_ = *tm;
524
0
      return tm != nullptr;
525
0
    }
526
9.12k
#endif
527
9.12k
  };
528
9.12k
  auto gt = dispatcher(time);
529
  // Too big time values may be unsupported.
530
9.12k
  if (!gt.run()) FMT_THROW(format_error("time_t value out of range"));
531
9.12k
  return gt.tm_;
532
9.12k
}
533
534
template <typename Duration>
535
9.12k
inline auto gmtime(sys_time<Duration> time_point) -> std::tm {
536
9.12k
  return gmtime(detail::to_time_t(time_point));
537
9.12k
}
538
539
namespace detail {
540
541
// Writes two-digit numbers a, b and c separated by sep to buf.
542
// The method by Pavel Novikov based on
543
// https://johnnylee-sde.github.io/Fast-unsigned-integer-to-time-string/.
544
inline void write_digit2_separated(char* buf, unsigned a, unsigned b,
545
8.43k
                                   unsigned c, char sep) {
546
8.43k
  ullong digits = a | (b << 24) | (static_cast<ullong>(c) << 48);
547
  // Convert each value to BCD.
548
  // We have x = a * 10 + b and we want to convert it to BCD y = a * 16 + b.
549
  // The difference is
550
  //   y - x = a * 6
551
  // a can be found from x:
552
  //   a = floor(x / 10)
553
  // then
554
  //   y = x + a * 6 = x + floor(x / 10) * 6
555
  // floor(x / 10) is (x * 205) >> 11 (needs 16 bits).
556
8.43k
  digits += (((digits * 205) >> 11) & 0x000f00000f00000f) * 6;
557
  // Put low nibbles to high bytes and high nibbles to low bytes.
558
8.43k
  digits = ((digits & 0x00f00000f00000f0) >> 4) |
559
8.43k
           ((digits & 0x000f00000f00000f) << 8);
560
8.43k
  auto usep = static_cast<ullong>(sep);
561
  // Add ASCII '0' to each digit byte and insert separators.
562
8.43k
  digits |= 0x3030003030003030 | (usep << 16) | (usep << 40);
563
564
8.43k
  constexpr size_t len = 8;
565
8.43k
  if (is_big_endian()) {
566
0
    char tmp[len];
567
0
    std::memcpy(tmp, &digits, len);
568
0
    std::reverse_copy(tmp, tmp + len, buf);
569
8.43k
  } else {
570
8.43k
    std::memcpy(buf, &digits, len);
571
8.43k
  }
572
8.43k
}
573
574
template <typename Period>
575
FMT_CONSTEXPR inline auto get_units() -> const char* {
576
  if (std::is_same<Period, std::atto>::value) return "as";
577
  if (std::is_same<Period, std::femto>::value) return "fs";
578
  if (std::is_same<Period, std::pico>::value) return "ps";
579
  if (std::is_same<Period, std::nano>::value) return "ns";
580
  if (std::is_same<Period, std::micro>::value)
581
    return detail::use_utf8 ? "µs" : "us";
582
  if (std::is_same<Period, std::milli>::value) return "ms";
583
  if (std::is_same<Period, std::centi>::value) return "cs";
584
  if (std::is_same<Period, std::deci>::value) return "ds";
585
  if (std::is_same<Period, std::ratio<1>>::value) return "s";
586
  if (std::is_same<Period, std::deca>::value) return "das";
587
  if (std::is_same<Period, std::hecto>::value) return "hs";
588
  if (std::is_same<Period, std::kilo>::value) return "ks";
589
  if (std::is_same<Period, std::mega>::value) return "Ms";
590
  if (std::is_same<Period, std::giga>::value) return "Gs";
591
  if (std::is_same<Period, std::tera>::value) return "Ts";
592
  if (std::is_same<Period, std::peta>::value) return "Ps";
593
  if (std::is_same<Period, std::exa>::value) return "Es";
594
  if (std::is_same<Period, std::ratio<60>>::value) return "min";
595
  if (std::is_same<Period, std::ratio<3600>>::value) return "h";
596
  if (std::is_same<Period, std::ratio<86400>>::value) return "d";
597
  return nullptr;
598
}
599
600
enum class numeric_system {
601
  standard,
602
  // Alternative numeric system, e.g. 十二 instead of 12 in ja_JP locale.
603
  alternative
604
};
605
606
// Glibc extensions for formatting numeric values.
607
enum class pad_type {
608
  // Pad a numeric result string with zeros (the default).
609
  zero,
610
  // Do not pad a numeric result string.
611
  none,
612
  // Pad a numeric result string with spaces.
613
  space,
614
};
615
616
template <typename OutputIt>
617
3.65k
auto write_padding(OutputIt out, pad_type pad, int width) -> OutputIt {
618
3.65k
  if (pad == pad_type::none) return out;
619
3.33k
  return detail::fill_n(out, width, pad == pad_type::space ? ' ' : '0');
620
3.65k
}
621
622
template <typename OutputIt>
623
28.9k
auto write_padding(OutputIt out, pad_type pad) -> OutputIt {
624
28.9k
  if (pad != pad_type::none) *out++ = pad == pad_type::space ? ' ' : '0';
625
28.9k
  return out;
626
28.9k
}
627
628
// Parses a put_time-like format string and invokes handler actions.
629
template <typename Char, typename Handler>
630
FMT_CONSTEXPR auto parse_chrono_format(const Char* begin, const Char* end,
631
15.6k
                                       Handler&& handler) -> const Char* {
632
15.6k
  if (begin == end || *begin == '}') return begin;
633
12.9k
  if (*begin != '%') FMT_THROW(format_error("invalid format"));
634
12.8k
  auto ptr = begin;
635
45.0M
  while (ptr != end) {
636
45.0M
    pad_type pad = pad_type::zero;
637
45.0M
    auto c = *ptr;
638
45.0M
    if (c == '}') break;
639
45.0M
    if (c != '%') {
640
44.8M
      ++ptr;
641
44.8M
      continue;
642
44.8M
    }
643
158k
    if (begin != ptr) handler.on_text(begin, ptr);
644
158k
    ++ptr;  // consume '%'
645
158k
    if (ptr == end) FMT_THROW(format_error("invalid format"));
646
158k
    c = *ptr;
647
158k
    switch (c) {
648
760
    case '_':
649
760
      pad = pad_type::space;
650
760
      ++ptr;
651
760
      break;
652
1.25k
    case '-':
653
1.25k
      pad = pad_type::none;
654
1.25k
      ++ptr;
655
1.25k
      break;
656
158k
    }
657
158k
    if (ptr == end) FMT_THROW(format_error("invalid format"));
658
158k
    c = *ptr++;
659
158k
    switch (c) {
660
2.29k
    case '%': handler.on_text(ptr - 1, ptr); break;
661
711
    case 'n': {
662
711
      const Char newline[] = {'\n'};
663
711
      handler.on_text(newline, newline + 1);
664
711
      break;
665
0
    }
666
891
    case 't': {
667
891
      const Char tab[] = {'\t'};
668
891
      handler.on_text(tab, tab + 1);
669
891
      break;
670
0
    }
671
    // Year:
672
1.17k
    case 'Y': handler.on_year(numeric_system::standard, pad); break;
673
1.35k
    case 'y': handler.on_short_year(numeric_system::standard); break;
674
3.37k
    case 'C': handler.on_century(numeric_system::standard); break;
675
774
    case 'G': handler.on_iso_week_based_year(); break;
676
2.77k
    case 'g': handler.on_iso_week_based_short_year(); break;
677
    // Day of the week:
678
558
    case 'a': handler.on_abbr_weekday(); break;
679
792
    case 'A': handler.on_full_weekday(); break;
680
1.19k
    case 'w': handler.on_dec0_weekday(numeric_system::standard); break;
681
1.27k
    case 'u': handler.on_dec1_weekday(numeric_system::standard); break;
682
    // Month:
683
762
    case 'b':
684
1.57k
    case 'h': handler.on_abbr_month(); break;
685
1.43k
    case 'B': handler.on_full_month(); break;
686
493
    case 'm': handler.on_dec_month(numeric_system::standard, pad); break;
687
    // Day of the year/month:
688
512
    case 'U':
689
512
      handler.on_dec0_week_of_year(numeric_system::standard, pad);
690
512
      break;
691
1.02k
    case 'W':
692
1.02k
      handler.on_dec1_week_of_year(numeric_system::standard, pad);
693
1.02k
      break;
694
2.35k
    case 'V': handler.on_iso_week_of_year(numeric_system::standard, pad); break;
695
1.91k
    case 'j': handler.on_day_of_year(pad); break;
696
493
    case 'd': handler.on_day_of_month(numeric_system::standard, pad); break;
697
472
    case 'e':
698
472
      handler.on_day_of_month(numeric_system::standard, pad_type::space);
699
472
      break;
700
    // Hour, minute, second:
701
480
    case 'H': handler.on_24_hour(numeric_system::standard, pad); break;
702
1.18k
    case 'I': handler.on_12_hour(numeric_system::standard, pad); break;
703
791
    case 'M': handler.on_minute(numeric_system::standard, pad); break;
704
702
    case 'S': handler.on_second(numeric_system::standard, pad); break;
705
    // Other:
706
91.5k
    case 'c': handler.on_datetime(numeric_system::standard); break;
707
995
    case 'x': handler.on_loc_date(numeric_system::standard); break;
708
704
    case 'X': handler.on_loc_time(numeric_system::standard); break;
709
889
    case 'D': handler.on_us_date(); break;
710
7.12k
    case 'F': handler.on_iso_date(); break;
711
3.49k
    case 'r': handler.on_12_hour_time(); break;
712
632
    case 'R': handler.on_24_hour_time(); break;
713
5.23k
    case 'T': handler.on_iso_time(); break;
714
503
    case 'p': handler.on_am_pm(); break;
715
1
    case 'Q': handler.on_duration_value(); break;
716
1
    case 'q': handler.on_duration_unit(); break;
717
1.60k
    case 'z': handler.on_utc_offset(numeric_system::standard); break;
718
1.79k
    case 'Z': handler.on_tz_name(); break;
719
    // Alternative representation:
720
4.83k
    case 'E': {
721
4.83k
      if (ptr == end) FMT_THROW(format_error("invalid format"));
722
4.83k
      c = *ptr++;
723
4.83k
      switch (c) {
724
392
      case 'Y': handler.on_year(numeric_system::alternative, pad); break;
725
1.33k
      case 'y': handler.on_offset_year(); break;
726
420
      case 'C': handler.on_century(numeric_system::alternative); break;
727
470
      case 'c': handler.on_datetime(numeric_system::alternative); break;
728
985
      case 'x': handler.on_loc_date(numeric_system::alternative); break;
729
420
      case 'X': handler.on_loc_time(numeric_system::alternative); break;
730
804
      case 'z': handler.on_utc_offset(numeric_system::alternative); break;
731
1
      default:  FMT_THROW(format_error("invalid format"));
732
4.83k
      }
733
4.82k
      break;
734
4.83k
    }
735
8.25k
    case 'O':
736
8.25k
      if (ptr == end) FMT_THROW(format_error("invalid format"));
737
8.25k
      c = *ptr++;
738
8.25k
      switch (c) {
739
1.21k
      case 'y': handler.on_short_year(numeric_system::alternative); break;
740
414
      case 'm': handler.on_dec_month(numeric_system::alternative, pad); break;
741
470
      case 'U':
742
470
        handler.on_dec0_week_of_year(numeric_system::alternative, pad);
743
470
        break;
744
414
      case 'W':
745
414
        handler.on_dec1_week_of_year(numeric_system::alternative, pad);
746
414
        break;
747
483
      case 'V':
748
483
        handler.on_iso_week_of_year(numeric_system::alternative, pad);
749
483
        break;
750
456
      case 'd':
751
456
        handler.on_day_of_month(numeric_system::alternative, pad);
752
456
        break;
753
396
      case 'e':
754
396
        handler.on_day_of_month(numeric_system::alternative, pad_type::space);
755
396
        break;
756
743
      case 'w': handler.on_dec0_weekday(numeric_system::alternative); break;
757
759
      case 'u': handler.on_dec1_weekday(numeric_system::alternative); break;
758
434
      case 'H': handler.on_24_hour(numeric_system::alternative, pad); break;
759
944
      case 'I': handler.on_12_hour(numeric_system::alternative, pad); break;
760
498
      case 'M': handler.on_minute(numeric_system::alternative, pad); break;
761
434
      case 'S': handler.on_second(numeric_system::alternative, pad); break;
762
589
      case 'z': handler.on_utc_offset(numeric_system::alternative); break;
763
2
      default:  FMT_THROW(format_error("invalid format"));
764
8.25k
      }
765
8.25k
      break;
766
8.25k
    default: FMT_THROW(format_error("invalid format"));
767
158k
    }
768
158k
    begin = ptr;
769
158k
  }
770
12.8k
  if (begin != ptr) handler.on_text(begin, ptr);
771
12.8k
  return ptr;
772
12.8k
}
char const* fmt::v12::detail::parse_chrono_format<char, fmt::v12::detail::tm_format_checker>(char const*, char const*, fmt::v12::detail::tm_format_checker&&)
Line
Count
Source
631
6.98k
                                       Handler&& handler) -> const Char* {
632
6.98k
  if (begin == end || *begin == '}') return begin;
633
4.30k
  if (*begin != '%') FMT_THROW(format_error("invalid format"));
634
4.24k
  auto ptr = begin;
635
22.7M
  while (ptr != end) {
636
22.7M
    pad_type pad = pad_type::zero;
637
22.7M
    auto c = *ptr;
638
22.7M
    if (c == '}') break;
639
22.7M
    if (c != '%') {
640
22.6M
      ++ptr;
641
22.6M
      continue;
642
22.6M
    }
643
79.1k
    if (begin != ptr) handler.on_text(begin, ptr);
644
79.1k
    ++ptr;  // consume '%'
645
79.1k
    if (ptr == end) FMT_THROW(format_error("invalid format"));
646
79.1k
    c = *ptr;
647
79.1k
    switch (c) {
648
502
    case '_':
649
502
      pad = pad_type::space;
650
502
      ++ptr;
651
502
      break;
652
685
    case '-':
653
685
      pad = pad_type::none;
654
685
      ++ptr;
655
685
      break;
656
79.1k
    }
657
79.1k
    if (ptr == end) FMT_THROW(format_error("invalid format"));
658
79.1k
    c = *ptr++;
659
79.1k
    switch (c) {
660
1.41k
    case '%': handler.on_text(ptr - 1, ptr); break;
661
358
    case 'n': {
662
358
      const Char newline[] = {'\n'};
663
358
      handler.on_text(newline, newline + 1);
664
358
      break;
665
0
    }
666
486
    case 't': {
667
486
      const Char tab[] = {'\t'};
668
486
      handler.on_text(tab, tab + 1);
669
486
      break;
670
0
    }
671
    // Year:
672
589
    case 'Y': handler.on_year(numeric_system::standard, pad); break;
673
716
    case 'y': handler.on_short_year(numeric_system::standard); break;
674
1.73k
    case 'C': handler.on_century(numeric_system::standard); break;
675
429
    case 'G': handler.on_iso_week_based_year(); break;
676
1.46k
    case 'g': handler.on_iso_week_based_short_year(); break;
677
    // Day of the week:
678
281
    case 'a': handler.on_abbr_weekday(); break;
679
400
    case 'A': handler.on_full_weekday(); break;
680
692
    case 'w': handler.on_dec0_weekday(numeric_system::standard); break;
681
773
    case 'u': handler.on_dec1_weekday(numeric_system::standard); break;
682
    // Month:
683
397
    case 'b':
684
905
    case 'h': handler.on_abbr_month(); break;
685
730
    case 'B': handler.on_full_month(); break;
686
247
    case 'm': handler.on_dec_month(numeric_system::standard, pad); break;
687
    // Day of the year/month:
688
274
    case 'U':
689
274
      handler.on_dec0_week_of_year(numeric_system::standard, pad);
690
274
      break;
691
512
    case 'W':
692
512
      handler.on_dec1_week_of_year(numeric_system::standard, pad);
693
512
      break;
694
1.31k
    case 'V': handler.on_iso_week_of_year(numeric_system::standard, pad); break;
695
1.11k
    case 'j': handler.on_day_of_year(pad); break;
696
247
    case 'd': handler.on_day_of_month(numeric_system::standard, pad); break;
697
236
    case 'e':
698
236
      handler.on_day_of_month(numeric_system::standard, pad_type::space);
699
236
      break;
700
    // Hour, minute, second:
701
272
    case 'H': handler.on_24_hour(numeric_system::standard, pad); break;
702
613
    case 'I': handler.on_12_hour(numeric_system::standard, pad); break;
703
399
    case 'M': handler.on_minute(numeric_system::standard, pad); break;
704
353
    case 'S': handler.on_second(numeric_system::standard, pad); break;
705
    // Other:
706
47.7k
    case 'c': handler.on_datetime(numeric_system::standard); break;
707
560
    case 'x': handler.on_loc_date(numeric_system::standard); break;
708
419
    case 'X': handler.on_loc_time(numeric_system::standard); break;
709
452
    case 'D': handler.on_us_date(); break;
710
1.41k
    case 'F': handler.on_iso_date(); break;
711
1.87k
    case 'r': handler.on_12_hour_time(); break;
712
348
    case 'R': handler.on_24_hour_time(); break;
713
399
    case 'T': handler.on_iso_time(); break;
714
258
    case 'p': handler.on_am_pm(); break;
715
1
    case 'Q': handler.on_duration_value(); break;
716
1
    case 'q': handler.on_duration_unit(); break;
717
841
    case 'z': handler.on_utc_offset(numeric_system::standard); break;
718
1.03k
    case 'Z': handler.on_tz_name(); break;
719
    // Alternative representation:
720
2.81k
    case 'E': {
721
2.81k
      if (ptr == end) FMT_THROW(format_error("invalid format"));
722
2.81k
      c = *ptr++;
723
2.81k
      switch (c) {
724
196
      case 'Y': handler.on_year(numeric_system::alternative, pad); break;
725
746
      case 'y': handler.on_offset_year(); break;
726
210
      case 'C': handler.on_century(numeric_system::alternative); break;
727
243
      case 'c': handler.on_datetime(numeric_system::alternative); break;
728
755
      case 'x': handler.on_loc_date(numeric_system::alternative); break;
729
210
      case 'X': handler.on_loc_time(numeric_system::alternative); break;
730
457
      case 'z': handler.on_utc_offset(numeric_system::alternative); break;
731
1
      default:  FMT_THROW(format_error("invalid format"));
732
2.81k
      }
733
2.81k
      break;
734
2.81k
    }
735
4.39k
    case 'O':
736
4.39k
      if (ptr == end) FMT_THROW(format_error("invalid format"));
737
4.39k
      c = *ptr++;
738
4.39k
      switch (c) {
739
610
      case 'y': handler.on_short_year(numeric_system::alternative); break;
740
211
      case 'm': handler.on_dec_month(numeric_system::alternative, pad); break;
741
235
      case 'U':
742
235
        handler.on_dec0_week_of_year(numeric_system::alternative, pad);
743
235
        break;
744
216
      case 'W':
745
216
        handler.on_dec1_week_of_year(numeric_system::alternative, pad);
746
216
        break;
747
286
      case 'V':
748
286
        handler.on_iso_week_of_year(numeric_system::alternative, pad);
749
286
        break;
750
229
      case 'd':
751
229
        handler.on_day_of_month(numeric_system::alternative, pad);
752
229
        break;
753
198
      case 'e':
754
198
        handler.on_day_of_month(numeric_system::alternative, pad_type::space);
755
198
        break;
756
454
      case 'w': handler.on_dec0_weekday(numeric_system::alternative); break;
757
493
      case 'u': handler.on_dec1_weekday(numeric_system::alternative); break;
758
217
      case 'H': handler.on_24_hour(numeric_system::alternative, pad); break;
759
472
      case 'I': handler.on_12_hour(numeric_system::alternative, pad); break;
760
257
      case 'M': handler.on_minute(numeric_system::alternative, pad); break;
761
217
      case 'S': handler.on_second(numeric_system::alternative, pad); break;
762
298
      case 'z': handler.on_utc_offset(numeric_system::alternative); break;
763
2
      default:  FMT_THROW(format_error("invalid format"));
764
4.39k
      }
765
4.39k
      break;
766
4.39k
    default: FMT_THROW(format_error("invalid format"));
767
79.1k
    }
768
79.1k
    begin = ptr;
769
79.1k
  }
770
4.21k
  if (begin != ptr) handler.on_text(begin, ptr);
771
4.21k
  return ptr;
772
4.24k
}
char const* fmt::v12::detail::parse_chrono_format<char, fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >&>(char const*, char const*, fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >&)
Line
Count
Source
631
8.65k
                                       Handler&& handler) -> const Char* {
632
8.65k
  if (begin == end || *begin == '}') return begin;
633
8.65k
  if (*begin != '%') FMT_THROW(format_error("invalid format"));
634
8.65k
  auto ptr = begin;
635
22.3M
  while (ptr != end) {
636
22.3M
    pad_type pad = pad_type::zero;
637
22.3M
    auto c = *ptr;
638
22.3M
    if (c == '}') break;
639
22.3M
    if (c != '%') {
640
22.2M
      ++ptr;
641
22.2M
      continue;
642
22.2M
    }
643
79.0k
    if (begin != ptr) handler.on_text(begin, ptr);
644
79.0k
    ++ptr;  // consume '%'
645
79.0k
    if (ptr == end) FMT_THROW(format_error("invalid format"));
646
79.0k
    c = *ptr;
647
79.0k
    switch (c) {
648
258
    case '_':
649
258
      pad = pad_type::space;
650
258
      ++ptr;
651
258
      break;
652
568
    case '-':
653
568
      pad = pad_type::none;
654
568
      ++ptr;
655
568
      break;
656
79.0k
    }
657
79.0k
    if (ptr == end) FMT_THROW(format_error("invalid format"));
658
79.0k
    c = *ptr++;
659
79.0k
    switch (c) {
660
879
    case '%': handler.on_text(ptr - 1, ptr); break;
661
353
    case 'n': {
662
353
      const Char newline[] = {'\n'};
663
353
      handler.on_text(newline, newline + 1);
664
353
      break;
665
0
    }
666
405
    case 't': {
667
405
      const Char tab[] = {'\t'};
668
405
      handler.on_text(tab, tab + 1);
669
405
      break;
670
0
    }
671
    // Year:
672
583
    case 'Y': handler.on_year(numeric_system::standard, pad); break;
673
638
    case 'y': handler.on_short_year(numeric_system::standard); break;
674
1.63k
    case 'C': handler.on_century(numeric_system::standard); break;
675
345
    case 'G': handler.on_iso_week_based_year(); break;
676
1.30k
    case 'g': handler.on_iso_week_based_short_year(); break;
677
    // Day of the week:
678
277
    case 'a': handler.on_abbr_weekday(); break;
679
392
    case 'A': handler.on_full_weekday(); break;
680
505
    case 'w': handler.on_dec0_weekday(numeric_system::standard); break;
681
505
    case 'u': handler.on_dec1_weekday(numeric_system::standard); break;
682
    // Month:
683
365
    case 'b':
684
673
    case 'h': handler.on_abbr_month(); break;
685
706
    case 'B': handler.on_full_month(); break;
686
246
    case 'm': handler.on_dec_month(numeric_system::standard, pad); break;
687
    // Day of the year/month:
688
238
    case 'U':
689
238
      handler.on_dec0_week_of_year(numeric_system::standard, pad);
690
238
      break;
691
511
    case 'W':
692
511
      handler.on_dec1_week_of_year(numeric_system::standard, pad);
693
511
      break;
694
1.04k
    case 'V': handler.on_iso_week_of_year(numeric_system::standard, pad); break;
695
800
    case 'j': handler.on_day_of_year(pad); break;
696
246
    case 'd': handler.on_day_of_month(numeric_system::standard, pad); break;
697
236
    case 'e':
698
236
      handler.on_day_of_month(numeric_system::standard, pad_type::space);
699
236
      break;
700
    // Hour, minute, second:
701
208
    case 'H': handler.on_24_hour(numeric_system::standard, pad); break;
702
572
    case 'I': handler.on_12_hour(numeric_system::standard, pad); break;
703
392
    case 'M': handler.on_minute(numeric_system::standard, pad); break;
704
349
    case 'S': handler.on_second(numeric_system::standard, pad); break;
705
    // Other:
706
43.7k
    case 'c': handler.on_datetime(numeric_system::standard); break;
707
435
    case 'x': handler.on_loc_date(numeric_system::standard); break;
708
285
    case 'X': handler.on_loc_time(numeric_system::standard); break;
709
437
    case 'D': handler.on_us_date(); break;
710
5.71k
    case 'F': handler.on_iso_date(); break;
711
1.62k
    case 'r': handler.on_12_hour_time(); break;
712
284
    case 'R': handler.on_24_hour_time(); break;
713
4.83k
    case 'T': handler.on_iso_time(); break;
714
245
    case 'p': handler.on_am_pm(); break;
715
0
    case 'Q': handler.on_duration_value(); break;
716
0
    case 'q': handler.on_duration_unit(); break;
717
760
    case 'z': handler.on_utc_offset(numeric_system::standard); break;
718
755
    case 'Z': handler.on_tz_name(); break;
719
    // Alternative representation:
720
2.01k
    case 'E': {
721
2.01k
      if (ptr == end) FMT_THROW(format_error("invalid format"));
722
2.01k
      c = *ptr++;
723
2.01k
      switch (c) {
724
196
      case 'Y': handler.on_year(numeric_system::alternative, pad); break;
725
593
      case 'y': handler.on_offset_year(); break;
726
210
      case 'C': handler.on_century(numeric_system::alternative); break;
727
227
      case 'c': handler.on_datetime(numeric_system::alternative); break;
728
230
      case 'x': handler.on_loc_date(numeric_system::alternative); break;
729
210
      case 'X': handler.on_loc_time(numeric_system::alternative); break;
730
347
      case 'z': handler.on_utc_offset(numeric_system::alternative); break;
731
0
      default:  FMT_THROW(format_error("invalid format"));
732
2.01k
      }
733
2.01k
      break;
734
2.01k
    }
735
3.85k
    case 'O':
736
3.85k
      if (ptr == end) FMT_THROW(format_error("invalid format"));
737
3.85k
      c = *ptr++;
738
3.85k
      switch (c) {
739
606
      case 'y': handler.on_short_year(numeric_system::alternative); break;
740
203
      case 'm': handler.on_dec_month(numeric_system::alternative, pad); break;
741
235
      case 'U':
742
235
        handler.on_dec0_week_of_year(numeric_system::alternative, pad);
743
235
        break;
744
198
      case 'W':
745
198
        handler.on_dec1_week_of_year(numeric_system::alternative, pad);
746
198
        break;
747
197
      case 'V':
748
197
        handler.on_iso_week_of_year(numeric_system::alternative, pad);
749
197
        break;
750
227
      case 'd':
751
227
        handler.on_day_of_month(numeric_system::alternative, pad);
752
227
        break;
753
198
      case 'e':
754
198
        handler.on_day_of_month(numeric_system::alternative, pad_type::space);
755
198
        break;
756
289
      case 'w': handler.on_dec0_weekday(numeric_system::alternative); break;
757
266
      case 'u': handler.on_dec1_weekday(numeric_system::alternative); break;
758
217
      case 'H': handler.on_24_hour(numeric_system::alternative, pad); break;
759
472
      case 'I': handler.on_12_hour(numeric_system::alternative, pad); break;
760
241
      case 'M': handler.on_minute(numeric_system::alternative, pad); break;
761
217
      case 'S': handler.on_second(numeric_system::alternative, pad); break;
762
291
      case 'z': handler.on_utc_offset(numeric_system::alternative); break;
763
0
      default:  FMT_THROW(format_error("invalid format"));
764
3.85k
      }
765
3.85k
      break;
766
3.85k
    default: FMT_THROW(format_error("invalid format"));
767
79.0k
    }
768
79.0k
    begin = ptr;
769
79.0k
  }
770
8.63k
  if (begin != ptr) handler.on_text(begin, ptr);
771
8.63k
  return ptr;
772
8.65k
}
Unexecuted instantiation: char const* fmt::v12::detail::parse_chrono_format<char, fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >&>(char const*, char const*, fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >&)
773
774
template <typename Derived> struct null_chrono_spec_handler {
775
2
  FMT_CONSTEXPR void unsupported() {
776
2
    static_cast<Derived*>(this)->unsupported();
777
2
  }
778
  FMT_CONSTEXPR void on_year(numeric_system, pad_type) { unsupported(); }
779
  FMT_CONSTEXPR void on_short_year(numeric_system) { unsupported(); }
780
  FMT_CONSTEXPR void on_offset_year() { unsupported(); }
781
  FMT_CONSTEXPR void on_century(numeric_system) { unsupported(); }
782
  FMT_CONSTEXPR void on_iso_week_based_year() { unsupported(); }
783
  FMT_CONSTEXPR void on_iso_week_based_short_year() { unsupported(); }
784
  FMT_CONSTEXPR void on_abbr_weekday() { unsupported(); }
785
  FMT_CONSTEXPR void on_full_weekday() { unsupported(); }
786
  FMT_CONSTEXPR void on_dec0_weekday(numeric_system) { unsupported(); }
787
  FMT_CONSTEXPR void on_dec1_weekday(numeric_system) { unsupported(); }
788
  FMT_CONSTEXPR void on_abbr_month() { unsupported(); }
789
  FMT_CONSTEXPR void on_full_month() { unsupported(); }
790
  FMT_CONSTEXPR void on_dec_month(numeric_system, pad_type) { unsupported(); }
791
  FMT_CONSTEXPR void on_dec0_week_of_year(numeric_system, pad_type) {
792
    unsupported();
793
  }
794
  FMT_CONSTEXPR void on_dec1_week_of_year(numeric_system, pad_type) {
795
    unsupported();
796
  }
797
  FMT_CONSTEXPR void on_iso_week_of_year(numeric_system, pad_type) {
798
    unsupported();
799
  }
800
  FMT_CONSTEXPR void on_day_of_year(pad_type) { unsupported(); }
801
  FMT_CONSTEXPR void on_day_of_month(numeric_system, pad_type) {
802
    unsupported();
803
  }
804
  FMT_CONSTEXPR void on_24_hour(numeric_system) { unsupported(); }
805
  FMT_CONSTEXPR void on_12_hour(numeric_system) { unsupported(); }
806
  FMT_CONSTEXPR void on_minute(numeric_system) { unsupported(); }
807
  FMT_CONSTEXPR void on_second(numeric_system) { unsupported(); }
808
  FMT_CONSTEXPR void on_datetime(numeric_system) { unsupported(); }
809
  FMT_CONSTEXPR void on_loc_date(numeric_system) { unsupported(); }
810
  FMT_CONSTEXPR void on_loc_time(numeric_system) { unsupported(); }
811
  FMT_CONSTEXPR void on_us_date() { unsupported(); }
812
  FMT_CONSTEXPR void on_iso_date() { unsupported(); }
813
  FMT_CONSTEXPR void on_12_hour_time() { unsupported(); }
814
  FMT_CONSTEXPR void on_24_hour_time() { unsupported(); }
815
  FMT_CONSTEXPR void on_iso_time() { unsupported(); }
816
  FMT_CONSTEXPR void on_am_pm() { unsupported(); }
817
1
  FMT_CONSTEXPR void on_duration_value() { unsupported(); }
818
1
  FMT_CONSTEXPR void on_duration_unit() { unsupported(); }
819
  FMT_CONSTEXPR void on_utc_offset(numeric_system) { unsupported(); }
820
  FMT_CONSTEXPR void on_tz_name() { unsupported(); }
821
};
822
823
class tm_format_checker : public null_chrono_spec_handler<tm_format_checker> {
824
 private:
825
  bool has_timezone_ = false;
826
827
 public:
828
  constexpr explicit tm_format_checker(bool has_timezone)
829
6.98k
      : has_timezone_(has_timezone) {}
830
831
2
  FMT_NORETURN inline void unsupported() {
832
2
    FMT_THROW(format_error("no format"));
833
2
  }
834
835
  template <typename Char>
836
11.7k
  FMT_CONSTEXPR void on_text(const Char*, const Char*) {}
837
785
  FMT_CONSTEXPR void on_year(numeric_system, pad_type) {}
838
1.32k
  FMT_CONSTEXPR void on_short_year(numeric_system) {}
839
746
  FMT_CONSTEXPR void on_offset_year() {}
840
1.94k
  FMT_CONSTEXPR void on_century(numeric_system) {}
841
429
  FMT_CONSTEXPR void on_iso_week_based_year() {}
842
1.46k
  FMT_CONSTEXPR void on_iso_week_based_short_year() {}
843
281
  FMT_CONSTEXPR void on_abbr_weekday() {}
844
400
  FMT_CONSTEXPR void on_full_weekday() {}
845
1.14k
  FMT_CONSTEXPR void on_dec0_weekday(numeric_system) {}
846
1.26k
  FMT_CONSTEXPR void on_dec1_weekday(numeric_system) {}
847
905
  FMT_CONSTEXPR void on_abbr_month() {}
848
730
  FMT_CONSTEXPR void on_full_month() {}
849
458
  FMT_CONSTEXPR void on_dec_month(numeric_system, pad_type) {}
850
509
  FMT_CONSTEXPR void on_dec0_week_of_year(numeric_system, pad_type) {}
851
728
  FMT_CONSTEXPR void on_dec1_week_of_year(numeric_system, pad_type) {}
852
1.59k
  FMT_CONSTEXPR void on_iso_week_of_year(numeric_system, pad_type) {}
853
1.11k
  FMT_CONSTEXPR void on_day_of_year(pad_type) {}
854
910
  FMT_CONSTEXPR void on_day_of_month(numeric_system, pad_type) {}
855
489
  FMT_CONSTEXPR void on_24_hour(numeric_system, pad_type) {}
856
1.08k
  FMT_CONSTEXPR void on_12_hour(numeric_system, pad_type) {}
857
656
  FMT_CONSTEXPR void on_minute(numeric_system, pad_type) {}
858
570
  FMT_CONSTEXPR void on_second(numeric_system, pad_type) {}
859
47.9k
  FMT_CONSTEXPR void on_datetime(numeric_system) {}
860
1.31k
  FMT_CONSTEXPR void on_loc_date(numeric_system) {}
861
629
  FMT_CONSTEXPR void on_loc_time(numeric_system) {}
862
452
  FMT_CONSTEXPR void on_us_date() {}
863
1.41k
  FMT_CONSTEXPR void on_iso_date() {}
864
1.87k
  FMT_CONSTEXPR void on_12_hour_time() {}
865
348
  FMT_CONSTEXPR void on_24_hour_time() {}
866
399
  FMT_CONSTEXPR void on_iso_time() {}
867
258
  FMT_CONSTEXPR void on_am_pm() {}
868
1.59k
  FMT_CONSTEXPR void on_utc_offset(numeric_system) {
869
1.59k
    if (!has_timezone_) FMT_THROW(format_error("no timezone"));
870
1.59k
  }
871
1.03k
  FMT_CONSTEXPR void on_tz_name() {
872
1.03k
    if (!has_timezone_) FMT_THROW(format_error("no timezone"));
873
1.03k
  }
874
};
875
876
392
inline auto tm_wday_full_name(int wday) -> const char* {
877
392
  static constexpr const char* full_name_list[] = {
878
392
      "Sunday",   "Monday", "Tuesday", "Wednesday",
879
392
      "Thursday", "Friday", "Saturday"};
880
392
  return wday >= 0 && wday <= 6 ? full_name_list[wday] : "?";
881
392
}
882
44.2k
inline auto tm_wday_short_name(int wday) -> const char* {
883
44.2k
  static constexpr const char* short_name_list[] = {"Sun", "Mon", "Tue", "Wed",
884
44.2k
                                                    "Thu", "Fri", "Sat"};
885
44.2k
  return wday >= 0 && wday <= 6 ? short_name_list[wday] : "???";
886
44.2k
}
887
888
706
inline auto tm_mon_full_name(int mon) -> const char* {
889
706
  static constexpr const char* full_name_list[] = {
890
706
      "January", "February", "March",     "April",   "May",      "June",
891
706
      "July",    "August",   "September", "October", "November", "December"};
892
706
  return mon >= 0 && mon <= 11 ? full_name_list[mon] : "?";
893
706
}
894
44.6k
inline auto tm_mon_short_name(int mon) -> const char* {
895
44.6k
  static constexpr const char* short_name_list[] = {
896
44.6k
      "Jan", "Feb", "Mar", "Apr", "May", "Jun",
897
44.6k
      "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
898
44.6k
  };
899
44.6k
  return mon >= 0 && mon <= 11 ? short_name_list[mon] : "???";
900
44.6k
}
901
902
template <typename T, typename = void>
903
struct has_tm_gmtoff : std::false_type {};
904
template <typename T>
905
struct has_tm_gmtoff<T, void_t<decltype(T::tm_gmtoff)>> : std::true_type {};
906
907
template <typename T, typename = void> struct has_tm_zone : std::false_type {};
908
template <typename T>
909
struct has_tm_zone<T, void_t<decltype(T::tm_zone)>> : std::true_type {};
910
911
template <typename T, FMT_ENABLE_IF(has_tm_zone<T>::value)>
912
439
auto set_tm_zone(T& time, char* tz) -> bool {
913
439
  time.tm_zone = tz;
914
439
  return true;
915
439
}
916
template <typename T, FMT_ENABLE_IF(!has_tm_zone<T>::value)>
917
auto set_tm_zone(T&, char*) -> bool {
918
  return false;
919
}
920
921
439
inline auto utc() -> char* {
922
439
  static char tz[] = "UTC";
923
439
  return tz;
924
439
}
925
926
// Converts value to Int and checks that it's in the range [0, upper).
927
template <typename T, typename Int, FMT_ENABLE_IF(std::is_integral<T>::value)>
928
inline auto to_nonnegative_int(T value, Int upper) -> Int {
929
  if (!std::is_unsigned<Int>::value &&
930
      (value < 0 || to_unsigned(value) > to_unsigned(upper))) {
931
    FMT_THROW(format_error("chrono value is out of range"));
932
  }
933
  return static_cast<Int>(value);
934
}
935
template <typename T, typename Int, FMT_ENABLE_IF(!std::is_integral<T>::value)>
936
inline auto to_nonnegative_int(T value, Int upper) -> Int {
937
  if (value < 0 || value >= static_cast<T>(upper) + 1)
938
    FMT_THROW(format_error("invalid value"));
939
  return static_cast<Int>(value);
940
}
941
942
0
constexpr auto pow10(std::uint32_t n) -> long long {
943
0
  return n == 0 ? 1 : 10 * pow10(n - 1);
944
0
}
945
946
// Counts the number of fractional digits in the range [0, 18] according to the
947
// C++20 spec. If more than 18 fractional digits are required then returns 6 for
948
// microseconds precision.
949
template <long long Num, long long Den, int N = 0,
950
          bool Enabled = (N < 19) && (Num <= max_value<long long>() / 10)>
951
struct count_fractional_digits {
952
  static constexpr int value =
953
      Num % Den == 0 ? N : count_fractional_digits<Num * 10, Den, N + 1>::value;
954
};
955
956
// Base case that doesn't instantiate any more templates
957
// in order to avoid overflow.
958
template <long long Num, long long Den, int N>
959
struct count_fractional_digits<Num, Den, N, false> {
960
  static constexpr int value = (Num % Den == 0) ? N : 6;
961
};
962
963
// Format subseconds which are given as an integer type with an appropriate
964
// number of digits.
965
template <typename Char, typename OutputIt, typename Duration>
966
49.9k
void write_fractional_seconds(OutputIt& out, Duration d, int precision = -1) {
967
49.9k
  constexpr auto num_fractional_digits =
968
49.9k
      count_fractional_digits<Duration::period::num,
969
49.9k
                              Duration::period::den>::value;
970
971
49.9k
  using subsecond_precision = std::chrono::duration<
972
49.9k
      typename std::common_type<typename Duration::rep,
973
49.9k
                                std::chrono::seconds::rep>::type,
974
49.9k
      std::ratio<1, pow10(num_fractional_digits)>>;
975
976
49.9k
  const auto fractional = d - detail::duration_cast<std::chrono::seconds>(d);
977
49.9k
  const auto subseconds =
978
49.9k
      std::chrono::treat_as_floating_point<
979
49.9k
          typename subsecond_precision::rep>::value
980
49.9k
          ? fractional.count()
981
49.9k
          : detail::duration_cast<subsecond_precision>(fractional).count();
982
49.9k
  auto n = static_cast<uint32_or_64_or_128_t<long long>>(subseconds);
983
49.9k
  const int num_digits = count_digits(n);
984
985
49.9k
  int leading_zeroes = (std::max)(0, num_fractional_digits - num_digits);
986
49.9k
  if (precision < 0) {
987
49.9k
    FMT_ASSERT(!std::is_floating_point<typename Duration::rep>::value, "");
988
49.9k
    if (std::ratio_less<typename subsecond_precision::period,
989
49.9k
                        std::chrono::seconds::period>::value) {
990
49.9k
      *out++ = '.';
991
49.9k
      out = detail::fill_n(out, leading_zeroes, '0');
992
49.9k
      out = format_decimal<Char>(out, n, num_digits);
993
49.9k
    }
994
49.9k
  } else if (precision > 0) {
995
0
    *out++ = '.';
996
0
    leading_zeroes = min_of(leading_zeroes, precision);
997
0
    int remaining = precision - leading_zeroes;
998
0
    out = detail::fill_n(out, leading_zeroes, '0');
999
0
    if (remaining < num_digits) {
1000
0
      int num_truncated_digits = num_digits - remaining;
1001
0
      n /= to_unsigned(pow10(to_unsigned(num_truncated_digits)));
1002
0
      if (n != 0) out = format_decimal<Char>(out, n, remaining);
1003
0
      return;
1004
0
    }
1005
0
    if (n != 0) {
1006
0
      out = format_decimal<Char>(out, n, num_digits);
1007
0
      remaining -= num_digits;
1008
0
    }
1009
0
    out = detail::fill_n(out, remaining, '0');
1010
0
  }
1011
49.9k
}
void fmt::v12::detail::write_fractional_seconds<char, fmt::v12::basic_appender<char>, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >(fmt::v12::basic_appender<char>&, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> >, int)
Line
Count
Source
966
49.9k
void write_fractional_seconds(OutputIt& out, Duration d, int precision = -1) {
967
49.9k
  constexpr auto num_fractional_digits =
968
49.9k
      count_fractional_digits<Duration::period::num,
969
49.9k
                              Duration::period::den>::value;
970
971
49.9k
  using subsecond_precision = std::chrono::duration<
972
49.9k
      typename std::common_type<typename Duration::rep,
973
49.9k
                                std::chrono::seconds::rep>::type,
974
49.9k
      std::ratio<1, pow10(num_fractional_digits)>>;
975
976
49.9k
  const auto fractional = d - detail::duration_cast<std::chrono::seconds>(d);
977
49.9k
  const auto subseconds =
978
49.9k
      std::chrono::treat_as_floating_point<
979
49.9k
          typename subsecond_precision::rep>::value
980
49.9k
          ? fractional.count()
981
49.9k
          : detail::duration_cast<subsecond_precision>(fractional).count();
982
49.9k
  auto n = static_cast<uint32_or_64_or_128_t<long long>>(subseconds);
983
49.9k
  const int num_digits = count_digits(n);
984
985
49.9k
  int leading_zeroes = (std::max)(0, num_fractional_digits - num_digits);
986
49.9k
  if (precision < 0) {
987
49.9k
    FMT_ASSERT(!std::is_floating_point<typename Duration::rep>::value, "");
988
49.9k
    if (std::ratio_less<typename subsecond_precision::period,
989
49.9k
                        std::chrono::seconds::period>::value) {
990
49.9k
      *out++ = '.';
991
49.9k
      out = detail::fill_n(out, leading_zeroes, '0');
992
49.9k
      out = format_decimal<Char>(out, n, num_digits);
993
49.9k
    }
994
49.9k
  } else if (precision > 0) {
995
0
    *out++ = '.';
996
0
    leading_zeroes = min_of(leading_zeroes, precision);
997
0
    int remaining = precision - leading_zeroes;
998
0
    out = detail::fill_n(out, leading_zeroes, '0');
999
0
    if (remaining < num_digits) {
1000
0
      int num_truncated_digits = num_digits - remaining;
1001
0
      n /= to_unsigned(pow10(to_unsigned(num_truncated_digits)));
1002
0
      if (n != 0) out = format_decimal<Char>(out, n, remaining);
1003
0
      return;
1004
0
    }
1005
0
    if (n != 0) {
1006
0
      out = format_decimal<Char>(out, n, num_digits);
1007
0
      remaining -= num_digits;
1008
0
    }
1009
0
    out = detail::fill_n(out, remaining, '0');
1010
0
  }
1011
49.9k
}
Unexecuted instantiation: void fmt::v12::detail::write_fractional_seconds<char, fmt::v12::basic_appender<char>, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >(fmt::v12::basic_appender<char>&, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> >, int)
1012
1013
// Format subseconds which are given as a floating point type with an
1014
// appropriate number of digits. We cannot pass the Duration here, as we
1015
// explicitly need to pass the Rep value in the duration_formatter.
1016
template <typename Duration>
1017
void write_floating_seconds(memory_buffer& buf, Duration duration,
1018
0
                            int num_fractional_digits = -1) {
1019
0
  using rep = typename Duration::rep;
1020
0
  FMT_ASSERT(std::is_floating_point<rep>::value, "");
1021
0
1022
0
  auto val = duration.count();
1023
0
1024
0
  if (num_fractional_digits < 0) {
1025
0
    // For `std::round` with fallback to `round`:
1026
0
    // On some toolchains `std::round` is not available (e.g. GCC 6).
1027
0
    using namespace std;
1028
0
    num_fractional_digits =
1029
0
        count_fractional_digits<Duration::period::num,
1030
0
                                Duration::period::den>::value;
1031
0
    if (num_fractional_digits < 6 && static_cast<rep>(round(val)) != val)
1032
0
      num_fractional_digits = 6;
1033
0
  }
1034
0
1035
0
  fmt::format_to(std::back_inserter(buf), FMT_STRING("{:.{}f}"),
1036
0
                 std::fmod(val * static_cast<rep>(Duration::period::num) /
1037
0
                               static_cast<rep>(Duration::period::den),
1038
0
                           static_cast<rep>(60)),
1039
0
                 num_fractional_digits);
1040
0
}
Unexecuted instantiation: void fmt::v12::detail::write_floating_seconds<std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >(fmt::v12::basic_memory_buffer<char, 500ul, fmt::v12::detail::allocator<char> >&, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> >, int)
Unexecuted instantiation: void fmt::v12::detail::write_floating_seconds<std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >(fmt::v12::basic_memory_buffer<char, 500ul, fmt::v12::detail::allocator<char> >&, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> >, int)
1041
1042
template <typename OutputIt, typename Char,
1043
          typename Duration = std::chrono::seconds>
1044
class tm_writer {
1045
 private:
1046
  static constexpr int days_per_week = 7;
1047
1048
  const std::locale& loc_;
1049
  bool is_classic_;
1050
  OutputIt out_;
1051
  const Duration* subsecs_;
1052
  const std::tm& tm_;
1053
1054
51.5k
  auto tm_sec() const noexcept -> int {
1055
51.5k
    FMT_ASSERT(tm_.tm_sec >= 0 && tm_.tm_sec <= 61, "");
1056
51.5k
    return tm_.tm_sec;
1057
51.5k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::tm_sec() const
Line
Count
Source
1054
51.5k
  auto tm_sec() const noexcept -> int {
1055
51.5k
    FMT_ASSERT(tm_.tm_sec >= 0 && tm_.tm_sec <= 61, "");
1056
51.5k
    return tm_.tm_sec;
1057
51.5k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::tm_sec() const
1058
51.8k
  auto tm_min() const noexcept -> int {
1059
51.8k
    FMT_ASSERT(tm_.tm_min >= 0 && tm_.tm_min <= 59, "");
1060
51.8k
    return tm_.tm_min;
1061
51.8k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::tm_min() const
Line
Count
Source
1058
51.8k
  auto tm_min() const noexcept -> int {
1059
51.8k
    FMT_ASSERT(tm_.tm_min >= 0 && tm_.tm_min <= 59, "");
1060
51.8k
    return tm_.tm_min;
1061
51.8k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::tm_min() const
1062
54.5k
  auto tm_hour() const noexcept -> int {
1063
54.5k
    FMT_ASSERT(tm_.tm_hour >= 0 && tm_.tm_hour <= 23, "");
1064
54.5k
    return tm_.tm_hour;
1065
54.5k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::tm_hour() const
Line
Count
Source
1062
54.5k
  auto tm_hour() const noexcept -> int {
1063
54.5k
    FMT_ASSERT(tm_.tm_hour >= 0 && tm_.tm_hour <= 23, "");
1064
54.5k
    return tm_.tm_hour;
1065
54.5k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::tm_hour() const
1066
51.7k
  auto tm_mday() const noexcept -> int {
1067
51.7k
    FMT_ASSERT(tm_.tm_mday >= 1 && tm_.tm_mday <= 31, "");
1068
51.7k
    return tm_.tm_mday;
1069
51.7k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::tm_mday() const
Line
Count
Source
1066
51.7k
  auto tm_mday() const noexcept -> int {
1067
51.7k
    FMT_ASSERT(tm_.tm_mday >= 1 && tm_.tm_mday <= 31, "");
1068
51.7k
    return tm_.tm_mday;
1069
51.7k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::tm_mday() const
1070
52.6k
  auto tm_mon() const noexcept -> int {
1071
52.6k
    FMT_ASSERT(tm_.tm_mon >= 0 && tm_.tm_mon <= 11, "");
1072
52.6k
    return tm_.tm_mon;
1073
52.6k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::tm_mon() const
Line
Count
Source
1070
52.6k
  auto tm_mon() const noexcept -> int {
1071
52.6k
    FMT_ASSERT(tm_.tm_mon >= 0 && tm_.tm_mon <= 11, "");
1072
52.6k
    return tm_.tm_mon;
1073
52.6k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::tm_mon() const
1074
58.1k
  auto tm_year() const noexcept -> long long { return 1900ll + tm_.tm_year; }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::tm_year() const
Line
Count
Source
1074
58.1k
  auto tm_year() const noexcept -> long long { return 1900ll + tm_.tm_year; }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::tm_year() const
1075
50.3k
  auto tm_wday() const noexcept -> int {
1076
50.3k
    FMT_ASSERT(tm_.tm_wday >= 0 && tm_.tm_wday <= 6, "");
1077
50.3k
    return tm_.tm_wday;
1078
50.3k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::tm_wday() const
Line
Count
Source
1075
50.3k
  auto tm_wday() const noexcept -> int {
1076
50.3k
    FMT_ASSERT(tm_.tm_wday >= 0 && tm_.tm_wday <= 6, "");
1077
50.3k
    return tm_.tm_wday;
1078
50.3k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::tm_wday() const
1079
4.87k
  auto tm_yday() const noexcept -> int {
1080
4.87k
    FMT_ASSERT(tm_.tm_yday >= 0 && tm_.tm_yday <= 365, "");
1081
4.87k
    return tm_.tm_yday;
1082
4.87k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::tm_yday() const
Line
Count
Source
1079
4.87k
  auto tm_yday() const noexcept -> int {
1080
4.87k
    FMT_ASSERT(tm_.tm_yday >= 0 && tm_.tm_yday <= 365, "");
1081
4.87k
    return tm_.tm_yday;
1082
4.87k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::tm_yday() const
1083
1084
2.66k
  auto tm_hour12() const noexcept -> int {
1085
2.66k
    auto h = tm_hour();
1086
2.66k
    auto z = h < 12 ? h : h - 12;
1087
2.66k
    return z == 0 ? 12 : z;
1088
2.66k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::tm_hour12() const
Line
Count
Source
1084
2.66k
  auto tm_hour12() const noexcept -> int {
1085
2.66k
    auto h = tm_hour();
1086
2.66k
    auto z = h < 12 ? h : h - 12;
1087
2.66k
    return z == 0 ? 12 : z;
1088
2.66k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::tm_hour12() const
1089
1090
  // POSIX and the C Standard are unclear or inconsistent about what %C and %y
1091
  // do if the year is negative or exceeds 9999. Use the convention that %C
1092
  // concatenated with %y yields the same output as %Y, and that %Y contains at
1093
  // least 4 characters, with more only if necessary.
1094
4.24k
  auto split_year_lower(long long year) const noexcept -> int {
1095
4.24k
    auto l = year % 100;
1096
4.24k
    if (l < 0) l = -l;  // l in [0, 99]
1097
4.24k
    return static_cast<int>(l);
1098
4.24k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::split_year_lower(long long) const
Line
Count
Source
1094
4.24k
  auto split_year_lower(long long year) const noexcept -> int {
1095
4.24k
    auto l = year % 100;
1096
4.24k
    if (l < 0) l = -l;  // l in [0, 99]
1097
4.24k
    return static_cast<int>(l);
1098
4.24k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::split_year_lower(long long) const
1099
1100
  // Algorithm: https://en.wikipedia.org/wiki/ISO_week_date.
1101
2.37k
  auto iso_year_weeks(long long curr_year) const noexcept -> int {
1102
2.37k
    auto prev_year = curr_year - 1;
1103
2.37k
    auto curr_p =
1104
2.37k
        (curr_year + curr_year / 4 - curr_year / 100 + curr_year / 400) %
1105
2.37k
        days_per_week;
1106
2.37k
    auto prev_p =
1107
2.37k
        (prev_year + prev_year / 4 - prev_year / 100 + prev_year / 400) %
1108
2.37k
        days_per_week;
1109
2.37k
    return 52 + ((curr_p == 4 || prev_p == 3) ? 1 : 0);
1110
2.37k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::iso_year_weeks(long long) const
Line
Count
Source
1101
2.37k
  auto iso_year_weeks(long long curr_year) const noexcept -> int {
1102
2.37k
    auto prev_year = curr_year - 1;
1103
2.37k
    auto curr_p =
1104
2.37k
        (curr_year + curr_year / 4 - curr_year / 100 + curr_year / 400) %
1105
2.37k
        days_per_week;
1106
2.37k
    auto prev_p =
1107
2.37k
        (prev_year + prev_year / 4 - prev_year / 100 + prev_year / 400) %
1108
2.37k
        days_per_week;
1109
2.37k
    return 52 + ((curr_p == 4 || prev_p == 3) ? 1 : 0);
1110
2.37k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::iso_year_weeks(long long) const
1111
2.89k
  auto iso_week_num(int tm_yday, int tm_wday) const noexcept -> int {
1112
2.89k
    return (tm_yday + 11 - (tm_wday == 0 ? days_per_week : tm_wday)) /
1113
2.89k
           days_per_week;
1114
2.89k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::iso_week_num(int, int) const
Line
Count
Source
1111
2.89k
  auto iso_week_num(int tm_yday, int tm_wday) const noexcept -> int {
1112
2.89k
    return (tm_yday + 11 - (tm_wday == 0 ? days_per_week : tm_wday)) /
1113
2.89k
           days_per_week;
1114
2.89k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::iso_week_num(int, int) const
1115
1.64k
  auto tm_iso_week_year() const noexcept -> long long {
1116
1.64k
    auto year = tm_year();
1117
1.64k
    auto w = iso_week_num(tm_yday(), tm_wday());
1118
1.64k
    if (w < 1) return year - 1;
1119
1.13k
    if (w > iso_year_weeks(year)) return year + 1;
1120
920
    return year;
1121
1.13k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::tm_iso_week_year() const
Line
Count
Source
1115
1.64k
  auto tm_iso_week_year() const noexcept -> long long {
1116
1.64k
    auto year = tm_year();
1117
1.64k
    auto w = iso_week_num(tm_yday(), tm_wday());
1118
1.64k
    if (w < 1) return year - 1;
1119
1.13k
    if (w > iso_year_weeks(year)) return year + 1;
1120
920
    return year;
1121
1.13k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::tm_iso_week_year() const
1122
1.24k
  auto tm_iso_week_of_year() const noexcept -> int {
1123
1.24k
    auto year = tm_year();
1124
1.24k
    auto w = iso_week_num(tm_yday(), tm_wday());
1125
1.24k
    if (w < 1) return iso_year_weeks(year - 1);
1126
842
    if (w > iso_year_weeks(year)) return 1;
1127
643
    return w;
1128
842
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::tm_iso_week_of_year() const
Line
Count
Source
1122
1.24k
  auto tm_iso_week_of_year() const noexcept -> int {
1123
1.24k
    auto year = tm_year();
1124
1.24k
    auto w = iso_week_num(tm_yday(), tm_wday());
1125
1.24k
    if (w < 1) return iso_year_weeks(year - 1);
1126
842
    if (w > iso_year_weeks(year)) return 1;
1127
643
    return w;
1128
842
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::tm_iso_week_of_year() const
1129
1130
1.87k
  void write1(int value) {
1131
1.87k
    *out_++ = static_cast<char>('0' + to_unsigned(value) % 10);
1132
1.87k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::write1(int)
Line
Count
Source
1130
1.87k
  void write1(int value) {
1131
1.87k
    *out_++ = static_cast<char>('0' + to_unsigned(value) % 10);
1132
1.87k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::write1(int)
1133
105k
  void write2(int value) {
1134
105k
    const char* d = digits2(to_unsigned(value) % 100);
1135
105k
    *out_++ = *d++;
1136
105k
    *out_++ = *d;
1137
105k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::write2(int)
Line
Count
Source
1133
105k
  void write2(int value) {
1134
105k
    const char* d = digits2(to_unsigned(value) % 100);
1135
105k
    *out_++ = *d++;
1136
105k
    *out_++ = *d;
1137
105k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::write2(int)
1138
100k
  void write2(int value, pad_type pad) {
1139
100k
    unsigned int v = to_unsigned(value) % 100;
1140
100k
    if (v >= 10) {
1141
72.1k
      const char* d = digits2(v);
1142
72.1k
      *out_++ = *d++;
1143
72.1k
      *out_++ = *d;
1144
72.1k
    } else {
1145
28.4k
      out_ = detail::write_padding(out_, pad);
1146
28.4k
      *out_++ = static_cast<char>('0' + v);
1147
28.4k
    }
1148
100k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::write2(int, fmt::v12::detail::pad_type)
Line
Count
Source
1138
100k
  void write2(int value, pad_type pad) {
1139
100k
    unsigned int v = to_unsigned(value) % 100;
1140
100k
    if (v >= 10) {
1141
72.1k
      const char* d = digits2(v);
1142
72.1k
      *out_++ = *d++;
1143
72.1k
      *out_++ = *d;
1144
72.1k
    } else {
1145
28.4k
      out_ = detail::write_padding(out_, pad);
1146
28.4k
      *out_++ = static_cast<char>('0' + v);
1147
28.4k
    }
1148
100k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::write2(int, fmt::v12::detail::pad_type)
1149
1150
49.6k
  void write_year_extended(long long year, pad_type pad) {
1151
    // At least 4 characters.
1152
49.6k
    int width = 4;
1153
49.6k
    bool negative = year < 0;
1154
49.6k
    if (negative) {
1155
31.8k
      year = 0 - year;
1156
31.8k
      --width;
1157
31.8k
    }
1158
49.6k
    uint32_or_64_or_128_t<long long> n = to_unsigned(year);
1159
49.6k
    const int num_digits = count_digits(n);
1160
49.6k
    if (negative && pad == pad_type::zero) *out_++ = '-';
1161
49.6k
    if (width > num_digits)
1162
3.65k
      out_ = detail::write_padding(out_, pad, width - num_digits);
1163
49.6k
    if (negative && pad != pad_type::zero) *out_++ = '-';
1164
49.6k
    out_ = format_decimal<Char>(out_, n, num_digits);
1165
49.6k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::write_year_extended(long long, fmt::v12::detail::pad_type)
Line
Count
Source
1150
49.6k
  void write_year_extended(long long year, pad_type pad) {
1151
    // At least 4 characters.
1152
49.6k
    int width = 4;
1153
49.6k
    bool negative = year < 0;
1154
49.6k
    if (negative) {
1155
31.8k
      year = 0 - year;
1156
31.8k
      --width;
1157
31.8k
    }
1158
49.6k
    uint32_or_64_or_128_t<long long> n = to_unsigned(year);
1159
49.6k
    const int num_digits = count_digits(n);
1160
49.6k
    if (negative && pad == pad_type::zero) *out_++ = '-';
1161
49.6k
    if (width > num_digits)
1162
3.65k
      out_ = detail::write_padding(out_, pad, width - num_digits);
1163
49.6k
    if (negative && pad != pad_type::zero) *out_++ = '-';
1164
49.6k
    out_ = format_decimal<Char>(out_, n, num_digits);
1165
49.6k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::write_year_extended(long long, fmt::v12::detail::pad_type)
1166
45.1k
  void write_year(long long year, pad_type pad) {
1167
45.1k
    write_year_extended(year, pad);
1168
45.1k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::write_year(long long, fmt::v12::detail::pad_type)
Line
Count
Source
1166
45.1k
  void write_year(long long year, pad_type pad) {
1167
45.1k
    write_year_extended(year, pad);
1168
45.1k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::write_year(long long, fmt::v12::detail::pad_type)
1169
1170
1.39k
  void write_utc_offset(long long offset, numeric_system ns) {
1171
1.39k
    if (offset < 0) {
1172
0
      *out_++ = '-';
1173
0
      offset = -offset;
1174
1.39k
    } else {
1175
1.39k
      *out_++ = '+';
1176
1.39k
    }
1177
1.39k
    offset /= 60;
1178
1.39k
    write2(static_cast<int>(offset / 60));
1179
1.39k
    if (ns != numeric_system::standard) *out_++ = ':';
1180
1.39k
    write2(static_cast<int>(offset % 60));
1181
1.39k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::write_utc_offset(long long, fmt::v12::detail::numeric_system)
Line
Count
Source
1170
1.39k
  void write_utc_offset(long long offset, numeric_system ns) {
1171
1.39k
    if (offset < 0) {
1172
0
      *out_++ = '-';
1173
0
      offset = -offset;
1174
1.39k
    } else {
1175
1.39k
      *out_++ = '+';
1176
1.39k
    }
1177
1.39k
    offset /= 60;
1178
1.39k
    write2(static_cast<int>(offset / 60));
1179
1.39k
    if (ns != numeric_system::standard) *out_++ = ':';
1180
1.39k
    write2(static_cast<int>(offset % 60));
1181
1.39k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::write_utc_offset(long long, fmt::v12::detail::numeric_system)
1182
1183
  template <typename T, FMT_ENABLE_IF(has_tm_gmtoff<T>::value)>
1184
1.39k
  void format_utc_offset(const T& tm, numeric_system ns) {
1185
1.39k
    write_utc_offset(tm.tm_gmtoff, ns);
1186
1.39k
  }
_ZN3fmt3v126detail9tm_writerINS0_14basic_appenderIcEEcNSt3__16chrono8durationIxNS5_5ratioILl1ELl1000000EEEEEE17format_utc_offsetI2tmTnNS5_9enable_ifIXsr13has_tm_gmtoffIT_EE5valueEiE4typeELi0EEEvRKSF_NS1_14numeric_systemE
Line
Count
Source
1184
1.39k
  void format_utc_offset(const T& tm, numeric_system ns) {
1185
1.39k
    write_utc_offset(tm.tm_gmtoff, ns);
1186
1.39k
  }
Unexecuted instantiation: _ZN3fmt3v126detail9tm_writerINS0_14basic_appenderIcEEcNSt3__16chrono8durationIxNS5_5ratioILl1ELl1EEEEEE17format_utc_offsetI2tmTnNS5_9enable_ifIXsr13has_tm_gmtoffIT_EE5valueEiE4typeELi0EEEvRKSF_NS1_14numeric_systemE
1187
  template <typename T, FMT_ENABLE_IF(!has_tm_gmtoff<T>::value)>
1188
  void format_utc_offset(const T&, numeric_system ns) {
1189
    write_utc_offset(0, ns);
1190
  }
1191
1192
  template <typename T, FMT_ENABLE_IF(has_tm_zone<T>::value)>
1193
755
  void format_tz_name(const T& tm) {
1194
755
    if (!tm.tm_zone) FMT_THROW(format_error("no timezone"));
1195
755
    out_ = write_tm_str<Char>(out_, tm.tm_zone, loc_);
1196
755
  }
_ZN3fmt3v126detail9tm_writerINS0_14basic_appenderIcEEcNSt3__16chrono8durationIxNS5_5ratioILl1ELl1000000EEEEEE14format_tz_nameI2tmTnNS5_9enable_ifIXsr11has_tm_zoneIT_EE5valueEiE4typeELi0EEEvRKSF_
Line
Count
Source
1193
755
  void format_tz_name(const T& tm) {
1194
755
    if (!tm.tm_zone) FMT_THROW(format_error("no timezone"));
1195
755
    out_ = write_tm_str<Char>(out_, tm.tm_zone, loc_);
1196
755
  }
Unexecuted instantiation: _ZN3fmt3v126detail9tm_writerINS0_14basic_appenderIcEEcNSt3__16chrono8durationIxNS5_5ratioILl1ELl1EEEEEE14format_tz_nameI2tmTnNS5_9enable_ifIXsr11has_tm_zoneIT_EE5valueEiE4typeELi0EEEvRKSF_
1197
  template <typename T, FMT_ENABLE_IF(!has_tm_zone<T>::value)>
1198
  void format_tz_name(const T&) {
1199
    out_ = std::copy_n(utc(), 3, out_);
1200
  }
1201
1202
0
  void format_localized(char format, char modifier = 0) {
1203
0
    out_ = write<Char>(out_, tm_, loc_, format, modifier);
1204
0
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::format_localized(char, char)
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::format_localized(char, char)
1205
1206
 public:
1207
  tm_writer(const std::locale& loc, OutputIt out, const std::tm& tm,
1208
            const Duration* subsecs = nullptr)
1209
8.65k
      : loc_(loc),
1210
8.65k
        is_classic_(loc_ == get_classic_locale()),
1211
8.65k
        out_(out),
1212
8.65k
        subsecs_(subsecs),
1213
8.65k
        tm_(tm) {}
1214
1215
  auto out() const -> OutputIt { return out_; }
1216
1217
12.3k
  FMT_CONSTEXPR void on_text(const Char* begin, const Char* end) {
1218
12.3k
    out_ = copy<Char>(begin, end, out_);
1219
12.3k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_text(char const*, char const*)
Line
Count
Source
1217
12.3k
  FMT_CONSTEXPR void on_text(const Char* begin, const Char* end) {
1218
12.3k
    out_ = copy<Char>(begin, end, out_);
1219
12.3k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_text(char const*, char const*)
1220
1221
44.2k
  void on_abbr_weekday() {
1222
44.2k
    if (is_classic_)
1223
44.2k
      out_ = write(out_, tm_wday_short_name(tm_wday()));
1224
0
    else
1225
0
      format_localized('a');
1226
44.2k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_abbr_weekday()
Line
Count
Source
1221
44.2k
  void on_abbr_weekday() {
1222
44.2k
    if (is_classic_)
1223
44.2k
      out_ = write(out_, tm_wday_short_name(tm_wday()));
1224
0
    else
1225
0
      format_localized('a');
1226
44.2k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_abbr_weekday()
1227
392
  void on_full_weekday() {
1228
392
    if (is_classic_)
1229
392
      out_ = write(out_, tm_wday_full_name(tm_wday()));
1230
0
    else
1231
0
      format_localized('A');
1232
392
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_full_weekday()
Line
Count
Source
1227
392
  void on_full_weekday() {
1228
392
    if (is_classic_)
1229
392
      out_ = write(out_, tm_wday_full_name(tm_wday()));
1230
0
    else
1231
0
      format_localized('A');
1232
392
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_full_weekday()
1233
794
  void on_dec0_weekday(numeric_system ns) {
1234
794
    if (is_classic_ || ns == numeric_system::standard) return write1(tm_wday());
1235
0
    format_localized('w', 'O');
1236
0
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_dec0_weekday(fmt::v12::detail::numeric_system)
Line
Count
Source
1233
794
  void on_dec0_weekday(numeric_system ns) {
1234
794
    if (is_classic_ || ns == numeric_system::standard) return write1(tm_wday());
1235
0
    format_localized('w', 'O');
1236
0
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_dec0_weekday(fmt::v12::detail::numeric_system)
1237
771
  void on_dec1_weekday(numeric_system ns) {
1238
771
    if (is_classic_ || ns == numeric_system::standard) {
1239
771
      auto wday = tm_wday();
1240
771
      write1(wday == 0 ? days_per_week : wday);
1241
771
    } else {
1242
0
      format_localized('u', 'O');
1243
0
    }
1244
771
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_dec1_weekday(fmt::v12::detail::numeric_system)
Line
Count
Source
1237
771
  void on_dec1_weekday(numeric_system ns) {
1238
771
    if (is_classic_ || ns == numeric_system::standard) {
1239
771
      auto wday = tm_wday();
1240
771
      write1(wday == 0 ? days_per_week : wday);
1241
771
    } else {
1242
0
      format_localized('u', 'O');
1243
0
    }
1244
771
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_dec1_weekday(fmt::v12::detail::numeric_system)
1245
1246
44.6k
  void on_abbr_month() {
1247
44.6k
    if (is_classic_)
1248
44.6k
      out_ = write(out_, tm_mon_short_name(tm_mon()));
1249
0
    else
1250
0
      format_localized('b');
1251
44.6k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_abbr_month()
Line
Count
Source
1246
44.6k
  void on_abbr_month() {
1247
44.6k
    if (is_classic_)
1248
44.6k
      out_ = write(out_, tm_mon_short_name(tm_mon()));
1249
0
    else
1250
0
      format_localized('b');
1251
44.6k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_abbr_month()
1252
706
  void on_full_month() {
1253
706
    if (is_classic_)
1254
706
      out_ = write(out_, tm_mon_full_name(tm_mon()));
1255
0
    else
1256
0
      format_localized('B');
1257
706
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_full_month()
Line
Count
Source
1252
706
  void on_full_month() {
1253
706
    if (is_classic_)
1254
706
      out_ = write(out_, tm_mon_full_name(tm_mon()));
1255
0
    else
1256
0
      format_localized('B');
1257
706
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_full_month()
1258
1259
44.0k
  void on_datetime(numeric_system ns) {
1260
44.0k
    if (is_classic_) {
1261
44.0k
      on_abbr_weekday();
1262
44.0k
      *out_++ = ' ';
1263
44.0k
      on_abbr_month();
1264
44.0k
      *out_++ = ' ';
1265
44.0k
      on_day_of_month(numeric_system::standard, pad_type::space);
1266
44.0k
      *out_++ = ' ';
1267
44.0k
      on_iso_time();
1268
44.0k
      *out_++ = ' ';
1269
44.0k
      on_year(numeric_system::standard, pad_type::space);
1270
44.0k
    } else {
1271
0
      format_localized('c', ns == numeric_system::standard ? '\0' : 'E');
1272
0
    }
1273
44.0k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_datetime(fmt::v12::detail::numeric_system)
Line
Count
Source
1259
44.0k
  void on_datetime(numeric_system ns) {
1260
44.0k
    if (is_classic_) {
1261
44.0k
      on_abbr_weekday();
1262
44.0k
      *out_++ = ' ';
1263
44.0k
      on_abbr_month();
1264
44.0k
      *out_++ = ' ';
1265
44.0k
      on_day_of_month(numeric_system::standard, pad_type::space);
1266
44.0k
      *out_++ = ' ';
1267
44.0k
      on_iso_time();
1268
44.0k
      *out_++ = ' ';
1269
44.0k
      on_year(numeric_system::standard, pad_type::space);
1270
44.0k
    } else {
1271
0
      format_localized('c', ns == numeric_system::standard ? '\0' : 'E');
1272
0
    }
1273
44.0k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_datetime(fmt::v12::detail::numeric_system)
1274
665
  void on_loc_date(numeric_system ns) {
1275
665
    if (is_classic_)
1276
665
      on_us_date();
1277
0
    else
1278
0
      format_localized('x', ns == numeric_system::standard ? '\0' : 'E');
1279
665
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_loc_date(fmt::v12::detail::numeric_system)
Line
Count
Source
1274
665
  void on_loc_date(numeric_system ns) {
1275
665
    if (is_classic_)
1276
665
      on_us_date();
1277
0
    else
1278
0
      format_localized('x', ns == numeric_system::standard ? '\0' : 'E');
1279
665
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_loc_date(fmt::v12::detail::numeric_system)
1280
495
  void on_loc_time(numeric_system ns) {
1281
495
    if (is_classic_)
1282
495
      on_iso_time();
1283
0
    else
1284
0
      format_localized('X', ns == numeric_system::standard ? '\0' : 'E');
1285
495
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_loc_time(fmt::v12::detail::numeric_system)
Line
Count
Source
1280
495
  void on_loc_time(numeric_system ns) {
1281
495
    if (is_classic_)
1282
495
      on_iso_time();
1283
0
    else
1284
0
      format_localized('X', ns == numeric_system::standard ? '\0' : 'E');
1285
495
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_loc_time(fmt::v12::detail::numeric_system)
1286
1.10k
  void on_us_date() {
1287
1.10k
    char buf[8];
1288
1.10k
    write_digit2_separated(buf, to_unsigned(tm_mon() + 1),
1289
1.10k
                           to_unsigned(tm_mday()),
1290
1.10k
                           to_unsigned(split_year_lower(tm_year())), '/');
1291
1.10k
    out_ = copy<Char>(std::begin(buf), std::end(buf), out_);
1292
1.10k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_us_date()
Line
Count
Source
1286
1.10k
  void on_us_date() {
1287
1.10k
    char buf[8];
1288
1.10k
    write_digit2_separated(buf, to_unsigned(tm_mon() + 1),
1289
1.10k
                           to_unsigned(tm_mday()),
1290
1.10k
                           to_unsigned(split_year_lower(tm_year())), '/');
1291
1.10k
    out_ = copy<Char>(std::begin(buf), std::end(buf), out_);
1292
1.10k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_us_date()
1293
5.71k
  void on_iso_date() {
1294
5.71k
    auto year = tm_year();
1295
5.71k
    char buf[10];
1296
5.71k
    size_t offset = 0;
1297
5.71k
    if (year >= 0 && year < 10000) {
1298
1.21k
      write2digits(buf, static_cast<size_t>(year / 100));
1299
4.50k
    } else {
1300
4.50k
      offset = 4;
1301
4.50k
      write_year_extended(year, pad_type::zero);
1302
4.50k
      year = 0;
1303
4.50k
    }
1304
5.71k
    write_digit2_separated(buf + 2, static_cast<unsigned>(year % 100),
1305
5.71k
                           to_unsigned(tm_mon() + 1), to_unsigned(tm_mday()),
1306
5.71k
                           '-');
1307
5.71k
    out_ = copy<Char>(std::begin(buf) + offset, std::end(buf), out_);
1308
5.71k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_iso_date()
Line
Count
Source
1293
5.71k
  void on_iso_date() {
1294
5.71k
    auto year = tm_year();
1295
5.71k
    char buf[10];
1296
5.71k
    size_t offset = 0;
1297
5.71k
    if (year >= 0 && year < 10000) {
1298
1.21k
      write2digits(buf, static_cast<size_t>(year / 100));
1299
4.50k
    } else {
1300
4.50k
      offset = 4;
1301
4.50k
      write_year_extended(year, pad_type::zero);
1302
4.50k
      year = 0;
1303
4.50k
    }
1304
5.71k
    write_digit2_separated(buf + 2, static_cast<unsigned>(year % 100),
1305
5.71k
                           to_unsigned(tm_mon() + 1), to_unsigned(tm_mday()),
1306
5.71k
                           '-');
1307
5.71k
    out_ = copy<Char>(std::begin(buf) + offset, std::end(buf), out_);
1308
5.71k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_iso_date()
1309
1310
1.39k
  void on_utc_offset(numeric_system ns) { format_utc_offset(tm_, ns); }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_utc_offset(fmt::v12::detail::numeric_system)
Line
Count
Source
1310
1.39k
  void on_utc_offset(numeric_system ns) { format_utc_offset(tm_, ns); }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_utc_offset(fmt::v12::detail::numeric_system)
1311
755
  void on_tz_name() { format_tz_name(tm_); }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_tz_name()
Line
Count
Source
1311
755
  void on_tz_name() { format_tz_name(tm_); }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_tz_name()
1312
1313
44.7k
  void on_year(numeric_system ns, pad_type pad) {
1314
44.7k
    if (is_classic_ || ns == numeric_system::standard)
1315
44.7k
      return write_year(tm_year(), pad);
1316
0
    format_localized('Y', 'E');
1317
0
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_year(fmt::v12::detail::numeric_system, fmt::v12::detail::pad_type)
Line
Count
Source
1313
44.7k
  void on_year(numeric_system ns, pad_type pad) {
1314
44.7k
    if (is_classic_ || ns == numeric_system::standard)
1315
44.7k
      return write_year(tm_year(), pad);
1316
0
    format_localized('Y', 'E');
1317
0
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_year(fmt::v12::detail::numeric_system, fmt::v12::detail::pad_type)
1318
1.24k
  void on_short_year(numeric_system ns) {
1319
1.24k
    if (is_classic_ || ns == numeric_system::standard)
1320
1.24k
      return write2(split_year_lower(tm_year()));
1321
0
    format_localized('y', 'O');
1322
0
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_short_year(fmt::v12::detail::numeric_system)
Line
Count
Source
1318
1.24k
  void on_short_year(numeric_system ns) {
1319
1.24k
    if (is_classic_ || ns == numeric_system::standard)
1320
1.24k
      return write2(split_year_lower(tm_year()));
1321
0
    format_localized('y', 'O');
1322
0
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_short_year(fmt::v12::detail::numeric_system)
1323
593
  void on_offset_year() {
1324
593
    if (is_classic_) return write2(split_year_lower(tm_year()));
1325
0
    format_localized('y', 'E');
1326
0
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_offset_year()
Line
Count
Source
1323
593
  void on_offset_year() {
1324
593
    if (is_classic_) return write2(split_year_lower(tm_year()));
1325
0
    format_localized('y', 'E');
1326
0
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_offset_year()
1327
1328
1.84k
  void on_century(numeric_system ns) {
1329
1.84k
    if (is_classic_ || ns == numeric_system::standard) {
1330
1.84k
      auto year = tm_year();
1331
1.84k
      auto upper = year / 100;
1332
1.84k
      if (year >= -99 && year < 0) {
1333
        // Zero upper on negative year.
1334
293
        *out_++ = '-';
1335
293
        *out_++ = '0';
1336
1.55k
      } else if (upper >= 0 && upper < 100) {
1337
402
        write2(static_cast<int>(upper));
1338
1.15k
      } else {
1339
1.15k
        out_ = write<Char>(out_, upper);
1340
1.15k
      }
1341
1.84k
    } else {
1342
0
      format_localized('C', 'E');
1343
0
    }
1344
1.84k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_century(fmt::v12::detail::numeric_system)
Line
Count
Source
1328
1.84k
  void on_century(numeric_system ns) {
1329
1.84k
    if (is_classic_ || ns == numeric_system::standard) {
1330
1.84k
      auto year = tm_year();
1331
1.84k
      auto upper = year / 100;
1332
1.84k
      if (year >= -99 && year < 0) {
1333
        // Zero upper on negative year.
1334
293
        *out_++ = '-';
1335
293
        *out_++ = '0';
1336
1.55k
      } else if (upper >= 0 && upper < 100) {
1337
402
        write2(static_cast<int>(upper));
1338
1.15k
      } else {
1339
1.15k
        out_ = write<Char>(out_, upper);
1340
1.15k
      }
1341
1.84k
    } else {
1342
0
      format_localized('C', 'E');
1343
0
    }
1344
1.84k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_century(fmt::v12::detail::numeric_system)
1345
1346
449
  void on_dec_month(numeric_system ns, pad_type pad) {
1347
449
    if (is_classic_ || ns == numeric_system::standard)
1348
449
      return write2(tm_mon() + 1, pad);
1349
0
    format_localized('m', 'O');
1350
0
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_dec_month(fmt::v12::detail::numeric_system, fmt::v12::detail::pad_type)
Line
Count
Source
1346
449
  void on_dec_month(numeric_system ns, pad_type pad) {
1347
449
    if (is_classic_ || ns == numeric_system::standard)
1348
449
      return write2(tm_mon() + 1, pad);
1349
0
    format_localized('m', 'O');
1350
0
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_dec_month(fmt::v12::detail::numeric_system, fmt::v12::detail::pad_type)
1351
1352
473
  void on_dec0_week_of_year(numeric_system ns, pad_type pad) {
1353
473
    if (is_classic_ || ns == numeric_system::standard)
1354
473
      return write2((tm_yday() + days_per_week - tm_wday()) / days_per_week,
1355
473
                    pad);
1356
0
    format_localized('U', 'O');
1357
0
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_dec0_week_of_year(fmt::v12::detail::numeric_system, fmt::v12::detail::pad_type)
Line
Count
Source
1352
473
  void on_dec0_week_of_year(numeric_system ns, pad_type pad) {
1353
473
    if (is_classic_ || ns == numeric_system::standard)
1354
473
      return write2((tm_yday() + days_per_week - tm_wday()) / days_per_week,
1355
473
                    pad);
1356
0
    format_localized('U', 'O');
1357
0
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_dec0_week_of_year(fmt::v12::detail::numeric_system, fmt::v12::detail::pad_type)
1358
709
  void on_dec1_week_of_year(numeric_system ns, pad_type pad) {
1359
709
    if (is_classic_ || ns == numeric_system::standard) {
1360
709
      auto wday = tm_wday();
1361
709
      write2((tm_yday() + days_per_week -
1362
709
              (wday == 0 ? (days_per_week - 1) : (wday - 1))) /
1363
709
                 days_per_week,
1364
709
             pad);
1365
709
    } else {
1366
0
      format_localized('W', 'O');
1367
0
    }
1368
709
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_dec1_week_of_year(fmt::v12::detail::numeric_system, fmt::v12::detail::pad_type)
Line
Count
Source
1358
709
  void on_dec1_week_of_year(numeric_system ns, pad_type pad) {
1359
709
    if (is_classic_ || ns == numeric_system::standard) {
1360
709
      auto wday = tm_wday();
1361
709
      write2((tm_yday() + days_per_week -
1362
709
              (wday == 0 ? (days_per_week - 1) : (wday - 1))) /
1363
709
                 days_per_week,
1364
709
             pad);
1365
709
    } else {
1366
0
      format_localized('W', 'O');
1367
0
    }
1368
709
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_dec1_week_of_year(fmt::v12::detail::numeric_system, fmt::v12::detail::pad_type)
1369
1.24k
  void on_iso_week_of_year(numeric_system ns, pad_type pad) {
1370
1.24k
    if (is_classic_ || ns == numeric_system::standard)
1371
1.24k
      return write2(tm_iso_week_of_year(), pad);
1372
0
    format_localized('V', 'O');
1373
0
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_iso_week_of_year(fmt::v12::detail::numeric_system, fmt::v12::detail::pad_type)
Line
Count
Source
1369
1.24k
  void on_iso_week_of_year(numeric_system ns, pad_type pad) {
1370
1.24k
    if (is_classic_ || ns == numeric_system::standard)
1371
1.24k
      return write2(tm_iso_week_of_year(), pad);
1372
0
    format_localized('V', 'O');
1373
0
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_iso_week_of_year(fmt::v12::detail::numeric_system, fmt::v12::detail::pad_type)
1374
1375
345
  void on_iso_week_based_year() {
1376
345
    write_year(tm_iso_week_year(), pad_type::zero);
1377
345
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_iso_week_based_year()
Line
Count
Source
1375
345
  void on_iso_week_based_year() {
1376
345
    write_year(tm_iso_week_year(), pad_type::zero);
1377
345
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_iso_week_based_year()
1378
1.30k
  void on_iso_week_based_short_year() {
1379
1.30k
    write2(split_year_lower(tm_iso_week_year()));
1380
1.30k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_iso_week_based_short_year()
Line
Count
Source
1378
1.30k
  void on_iso_week_based_short_year() {
1379
1.30k
    write2(split_year_lower(tm_iso_week_year()));
1380
1.30k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_iso_week_based_short_year()
1381
1382
800
  void on_day_of_year(pad_type pad) {
1383
800
    auto yday = tm_yday() + 1;
1384
800
    auto digit1 = yday / 100;
1385
800
    if (digit1 != 0)
1386
307
      write1(digit1);
1387
493
    else
1388
493
      out_ = detail::write_padding(out_, pad);
1389
800
    write2(yday % 100, pad);
1390
800
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_day_of_year(fmt::v12::detail::pad_type)
Line
Count
Source
1382
800
  void on_day_of_year(pad_type pad) {
1383
800
    auto yday = tm_yday() + 1;
1384
800
    auto digit1 = yday / 100;
1385
800
    if (digit1 != 0)
1386
307
      write1(digit1);
1387
493
    else
1388
493
      out_ = detail::write_padding(out_, pad);
1389
800
    write2(yday % 100, pad);
1390
800
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_day_of_year(fmt::v12::detail::pad_type)
1391
1392
44.9k
  void on_day_of_month(numeric_system ns, pad_type pad) {
1393
44.9k
    if (is_classic_ || ns == numeric_system::standard)
1394
44.9k
      return write2(tm_mday(), pad);
1395
0
    format_localized('d', 'O');
1396
0
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_day_of_month(fmt::v12::detail::numeric_system, fmt::v12::detail::pad_type)
Line
Count
Source
1392
44.9k
  void on_day_of_month(numeric_system ns, pad_type pad) {
1393
44.9k
    if (is_classic_ || ns == numeric_system::standard)
1394
44.9k
      return write2(tm_mday(), pad);
1395
0
    format_localized('d', 'O');
1396
0
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_day_of_month(fmt::v12::detail::numeric_system, fmt::v12::detail::pad_type)
1397
1398
425
  void on_24_hour(numeric_system ns, pad_type pad) {
1399
425
    if (is_classic_ || ns == numeric_system::standard)
1400
425
      return write2(tm_hour(), pad);
1401
0
    format_localized('H', 'O');
1402
0
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_24_hour(fmt::v12::detail::numeric_system, fmt::v12::detail::pad_type)
Line
Count
Source
1398
425
  void on_24_hour(numeric_system ns, pad_type pad) {
1399
425
    if (is_classic_ || ns == numeric_system::standard)
1400
425
      return write2(tm_hour(), pad);
1401
0
    format_localized('H', 'O');
1402
0
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_24_hour(fmt::v12::detail::numeric_system, fmt::v12::detail::pad_type)
1403
1.04k
  void on_12_hour(numeric_system ns, pad_type pad) {
1404
1.04k
    if (is_classic_ || ns == numeric_system::standard)
1405
1.04k
      return write2(tm_hour12(), pad);
1406
0
    format_localized('I', 'O');
1407
0
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_12_hour(fmt::v12::detail::numeric_system, fmt::v12::detail::pad_type)
Line
Count
Source
1403
1.04k
  void on_12_hour(numeric_system ns, pad_type pad) {
1404
1.04k
    if (is_classic_ || ns == numeric_system::standard)
1405
1.04k
      return write2(tm_hour12(), pad);
1406
0
    format_localized('I', 'O');
1407
0
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_12_hour(fmt::v12::detail::numeric_system, fmt::v12::detail::pad_type)
1408
633
  void on_minute(numeric_system ns, pad_type pad) {
1409
633
    if (is_classic_ || ns == numeric_system::standard)
1410
633
      return write2(tm_min(), pad);
1411
0
    format_localized('M', 'O');
1412
0
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_minute(fmt::v12::detail::numeric_system, fmt::v12::detail::pad_type)
Line
Count
Source
1408
633
  void on_minute(numeric_system ns, pad_type pad) {
1409
633
    if (is_classic_ || ns == numeric_system::standard)
1410
633
      return write2(tm_min(), pad);
1411
0
    format_localized('M', 'O');
1412
0
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_minute(fmt::v12::detail::numeric_system, fmt::v12::detail::pad_type)
1413
1414
49.9k
  void on_second(numeric_system ns, pad_type pad) {
1415
49.9k
    if (is_classic_ || ns == numeric_system::standard) {
1416
49.9k
      write2(tm_sec(), pad);
1417
49.9k
      if (subsecs_) {
1418
49.9k
        if (std::is_floating_point<typename Duration::rep>::value) {
1419
0
          auto buf = memory_buffer();
1420
0
          write_floating_seconds(buf, *subsecs_);
1421
0
          if (buf.size() > 1) {
1422
            // Remove the leading "0", write something like ".123".
1423
0
            out_ = copy<Char>(buf.begin() + 1, buf.end(), out_);
1424
0
          }
1425
49.9k
        } else {
1426
49.9k
          write_fractional_seconds<Char>(out_, *subsecs_);
1427
49.9k
        }
1428
49.9k
      }
1429
49.9k
    } else {
1430
      // Currently no formatting of subseconds when a locale is set.
1431
0
      format_localized('S', 'O');
1432
0
    }
1433
49.9k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_second(fmt::v12::detail::numeric_system, fmt::v12::detail::pad_type)
Line
Count
Source
1414
49.9k
  void on_second(numeric_system ns, pad_type pad) {
1415
49.9k
    if (is_classic_ || ns == numeric_system::standard) {
1416
49.9k
      write2(tm_sec(), pad);
1417
49.9k
      if (subsecs_) {
1418
49.9k
        if (std::is_floating_point<typename Duration::rep>::value) {
1419
0
          auto buf = memory_buffer();
1420
0
          write_floating_seconds(buf, *subsecs_);
1421
0
          if (buf.size() > 1) {
1422
            // Remove the leading "0", write something like ".123".
1423
0
            out_ = copy<Char>(buf.begin() + 1, buf.end(), out_);
1424
0
          }
1425
49.9k
        } else {
1426
49.9k
          write_fractional_seconds<Char>(out_, *subsecs_);
1427
49.9k
        }
1428
49.9k
      }
1429
49.9k
    } else {
1430
      // Currently no formatting of subseconds when a locale is set.
1431
0
      format_localized('S', 'O');
1432
0
    }
1433
49.9k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_second(fmt::v12::detail::numeric_system, fmt::v12::detail::pad_type)
1434
1435
1.62k
  void on_12_hour_time() {
1436
1.62k
    if (is_classic_) {
1437
1.62k
      char buf[8];
1438
1.62k
      write_digit2_separated(buf, to_unsigned(tm_hour12()),
1439
1.62k
                             to_unsigned(tm_min()), to_unsigned(tm_sec()), ':');
1440
1.62k
      out_ = copy<Char>(std::begin(buf), std::end(buf), out_);
1441
1.62k
      *out_++ = ' ';
1442
1.62k
      on_am_pm();
1443
1.62k
    } else {
1444
0
      format_localized('r');
1445
0
    }
1446
1.62k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_12_hour_time()
Line
Count
Source
1435
1.62k
  void on_12_hour_time() {
1436
1.62k
    if (is_classic_) {
1437
1.62k
      char buf[8];
1438
1.62k
      write_digit2_separated(buf, to_unsigned(tm_hour12()),
1439
1.62k
                             to_unsigned(tm_min()), to_unsigned(tm_sec()), ':');
1440
1.62k
      out_ = copy<Char>(std::begin(buf), std::end(buf), out_);
1441
1.62k
      *out_++ = ' ';
1442
1.62k
      on_am_pm();
1443
1.62k
    } else {
1444
0
      format_localized('r');
1445
0
    }
1446
1.62k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_12_hour_time()
1447
49.6k
  void on_24_hour_time() {
1448
49.6k
    write2(tm_hour());
1449
49.6k
    *out_++ = ':';
1450
49.6k
    write2(tm_min());
1451
49.6k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_24_hour_time()
Line
Count
Source
1447
49.6k
  void on_24_hour_time() {
1448
49.6k
    write2(tm_hour());
1449
49.6k
    *out_++ = ':';
1450
49.6k
    write2(tm_min());
1451
49.6k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_24_hour_time()
1452
49.3k
  void on_iso_time() {
1453
49.3k
    on_24_hour_time();
1454
49.3k
    *out_++ = ':';
1455
49.3k
    on_second(numeric_system::standard, pad_type::zero);
1456
49.3k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_iso_time()
Line
Count
Source
1452
49.3k
  void on_iso_time() {
1453
49.3k
    on_24_hour_time();
1454
49.3k
    *out_++ = ':';
1455
49.3k
    on_second(numeric_system::standard, pad_type::zero);
1456
49.3k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_iso_time()
1457
1458
1.86k
  void on_am_pm() {
1459
1.86k
    if (is_classic_) {
1460
1.86k
      *out_++ = tm_hour() < 12 ? 'A' : 'P';
1461
1.86k
      *out_++ = 'M';
1462
1.86k
    } else {
1463
0
      format_localized('p');
1464
0
    }
1465
1.86k
  }
fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_am_pm()
Line
Count
Source
1458
1.86k
  void on_am_pm() {
1459
1.86k
    if (is_classic_) {
1460
1.86k
      *out_++ = tm_hour() < 12 ? 'A' : 'P';
1461
1.86k
      *out_++ = 'M';
1462
1.86k
    } else {
1463
0
      format_localized('p');
1464
0
    }
1465
1.86k
  }
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_am_pm()
1466
1467
  // These apply to chrono durations but not tm.
1468
0
  void on_duration_value() {}
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_duration_value()
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_duration_value()
1469
0
  void on_duration_unit() {}
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::on_duration_unit()
Unexecuted instantiation: fmt::v12::detail::tm_writer<fmt::v12::basic_appender<char>, char, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::on_duration_unit()
1470
};
1471
1472
struct chrono_format_checker : null_chrono_spec_handler<chrono_format_checker> {
1473
  bool has_precision_integral = false;
1474
1475
0
  FMT_NORETURN inline void unsupported() { FMT_THROW(format_error("no date")); }
1476
1477
  template <typename Char>
1478
  FMT_CONSTEXPR void on_text(const Char*, const Char*) {}
1479
0
  FMT_CONSTEXPR void on_day_of_year(pad_type) {}
1480
0
  FMT_CONSTEXPR void on_24_hour(numeric_system, pad_type) {}
1481
0
  FMT_CONSTEXPR void on_12_hour(numeric_system, pad_type) {}
1482
0
  FMT_CONSTEXPR void on_minute(numeric_system, pad_type) {}
1483
0
  FMT_CONSTEXPR void on_second(numeric_system, pad_type) {}
1484
0
  FMT_CONSTEXPR void on_12_hour_time() {}
1485
0
  FMT_CONSTEXPR void on_24_hour_time() {}
1486
0
  FMT_CONSTEXPR void on_iso_time() {}
1487
0
  FMT_CONSTEXPR void on_am_pm() {}
1488
0
  FMT_CONSTEXPR void on_duration_value() const {
1489
0
    if (has_precision_integral)
1490
0
      FMT_THROW(format_error("precision not allowed for this argument type"));
1491
0
  }
1492
0
  FMT_CONSTEXPR void on_duration_unit() {}
1493
};
1494
1495
template <typename T,
1496
          FMT_ENABLE_IF(std::is_integral<T>::value&& has_isfinite<T>::value)>
1497
inline auto isfinite(T) -> bool {
1498
  return true;
1499
}
1500
1501
template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
1502
inline auto mod(T x, int y) -> T {
1503
  return x % static_cast<T>(y);
1504
}
1505
template <typename T, FMT_ENABLE_IF(std::is_floating_point<T>::value)>
1506
inline auto mod(T x, int y) -> T {
1507
  return std::fmod(x, static_cast<T>(y));
1508
}
1509
1510
// If T is an integral type, maps T to its unsigned counterpart, otherwise
1511
// leaves it unchanged (unlike std::make_unsigned).
1512
template <typename T, bool INTEGRAL = std::is_integral<T>::value>
1513
struct make_unsigned_or_unchanged {
1514
  using type = T;
1515
};
1516
1517
template <typename T> struct make_unsigned_or_unchanged<T, true> {
1518
  using type = typename std::make_unsigned<T>::type;
1519
};
1520
1521
template <typename Rep, typename Period,
1522
          FMT_ENABLE_IF(std::is_integral<Rep>::value)>
1523
inline auto get_milliseconds(std::chrono::duration<Rep, Period> d)
1524
    -> std::chrono::duration<Rep, std::milli> {
1525
  // This may overflow and/or the result may not fit in the target type.
1526
#if FMT_SAFE_DURATION_CAST
1527
  using common_seconds_type =
1528
      typename std::common_type<decltype(d), std::chrono::seconds>::type;
1529
  auto d_as_common = detail::duration_cast<common_seconds_type>(d);
1530
  auto d_as_whole_seconds =
1531
      detail::duration_cast<std::chrono::seconds>(d_as_common);
1532
  // This conversion should be nonproblematic.
1533
  auto diff = d_as_common - d_as_whole_seconds;
1534
  auto ms = detail::duration_cast<std::chrono::duration<Rep, std::milli>>(diff);
1535
  return ms;
1536
#else
1537
  auto s = detail::duration_cast<std::chrono::seconds>(d);
1538
  return detail::duration_cast<std::chrono::milliseconds>(d - s);
1539
#endif
1540
}
1541
1542
template <typename Char, typename Rep, typename OutputIt,
1543
          FMT_ENABLE_IF(std::is_integral<Rep>::value)>
1544
auto format_duration_value(OutputIt out, Rep val, int) -> OutputIt {
1545
  return write<Char>(out, val);
1546
}
1547
1548
template <typename Char, typename Rep, typename OutputIt,
1549
          FMT_ENABLE_IF(std::is_floating_point<Rep>::value)>
1550
auto format_duration_value(OutputIt out, Rep val, int precision) -> OutputIt {
1551
  auto specs = format_specs();
1552
  specs.precision = precision;
1553
  specs.set_type(precision >= 0 ? presentation_type::fixed
1554
                                : presentation_type::general);
1555
  return write<Char>(out, val, specs);
1556
}
1557
1558
template <typename Char, typename OutputIt>
1559
auto copy_unit(string_view unit, OutputIt out, Char) -> OutputIt {
1560
  return copy<Char>(unit.begin(), unit.end(), out);
1561
}
1562
1563
template <typename OutputIt>
1564
auto copy_unit(string_view unit, OutputIt out, wchar_t) -> OutputIt {
1565
  // This works when wchar_t is UTF-32 because units only contain characters
1566
  // that have the same representation in UTF-16 and UTF-32.
1567
  utf8_to_utf16 u(unit);
1568
  return copy<wchar_t>(u.c_str(), u.c_str() + u.size(), out);
1569
}
1570
1571
template <typename Char, typename Period, typename OutputIt>
1572
auto format_duration_unit(OutputIt out) -> OutputIt {
1573
  if (const char* unit = get_units<Period>())
1574
    return copy_unit(string_view(unit), out, Char());
1575
  *out++ = '[';
1576
  out = write<Char>(out, Period::num);
1577
  if FMT_CONSTEXPR20 (Period::den != 1) {
1578
    *out++ = '/';
1579
    out = write<Char>(out, Period::den);
1580
  }
1581
  *out++ = ']';
1582
  *out++ = 's';
1583
  return out;
1584
}
1585
1586
class get_locale {
1587
 private:
1588
  union {
1589
    std::locale locale_;
1590
  };
1591
  bool has_locale_ = false;
1592
1593
 public:
1594
8.65k
  inline get_locale(bool localized, locale_ref loc) : has_locale_(localized) {
1595
8.65k
    if (!localized) return;
1596
0
    ignore_unused(loc);
1597
0
    ::new (&locale_) std::locale(
1598
0
#if FMT_USE_LOCALE
1599
0
        loc.template get<std::locale>()
1600
0
#endif
1601
0
    );
1602
0
  }
1603
8.65k
  inline ~get_locale() {
1604
8.65k
    if (has_locale_) locale_.~locale();
1605
8.65k
  }
1606
8.65k
  inline operator const std::locale&() const {
1607
8.65k
    return has_locale_ ? locale_ : get_classic_locale();
1608
8.65k
  }
1609
};
1610
1611
template <typename Char, typename Rep, typename Period>
1612
struct duration_formatter {
1613
  using iterator = basic_appender<Char>;
1614
  iterator out;
1615
  // rep is unsigned to avoid overflow.
1616
  using rep =
1617
      conditional_t<std::is_integral<Rep>::value && sizeof(Rep) < sizeof(int),
1618
                    unsigned, typename make_unsigned_or_unchanged<Rep>::type>;
1619
  rep val;
1620
  int precision;
1621
  locale_ref locale;
1622
  bool localized = false;
1623
  using seconds = std::chrono::duration<rep>;
1624
  seconds s;
1625
  using milliseconds = std::chrono::duration<rep, std::milli>;
1626
  bool negative;
1627
1628
  using tm_writer_type = tm_writer<iterator, Char>;
1629
1630
  duration_formatter(iterator o, std::chrono::duration<Rep, Period> d,
1631
                     locale_ref loc)
1632
      : out(o), val(static_cast<rep>(d.count())), locale(loc), negative(false) {
1633
    if (d.count() < 0) {
1634
      val = 0 - val;
1635
      negative = true;
1636
    }
1637
1638
    // this may overflow and/or the result may not fit in the
1639
    // target type.
1640
    // might need checked conversion (rep!=Rep)
1641
    s = detail::duration_cast<seconds>(std::chrono::duration<rep, Period>(val));
1642
  }
1643
1644
  // returns true if nan or inf, writes to out.
1645
  auto handle_nan_inf() -> bool {
1646
    if (isfinite(val)) return false;
1647
    if (isnan(val)) {
1648
      write_nan();
1649
      return true;
1650
    }
1651
    // must be +-inf
1652
    if (val > 0)
1653
      std::copy_n("inf", 3, out);
1654
    else
1655
      std::copy_n("-inf", 4, out);
1656
    return true;
1657
  }
1658
1659
  auto days() const -> Rep { return static_cast<Rep>(s.count() / 86400); }
1660
  auto hour() const -> Rep {
1661
    return static_cast<Rep>(mod((s.count() / 3600), 24));
1662
  }
1663
1664
  auto hour12() const -> Rep {
1665
    Rep hour = static_cast<Rep>(mod((s.count() / 3600), 12));
1666
    return hour <= 0 ? 12 : hour;
1667
  }
1668
1669
  auto minute() const -> Rep {
1670
    return static_cast<Rep>(mod((s.count() / 60), 60));
1671
  }
1672
  auto second() const -> Rep { return static_cast<Rep>(mod(s.count(), 60)); }
1673
1674
  auto time() const -> std::tm {
1675
    auto time = std::tm();
1676
    time.tm_hour = to_nonnegative_int(hour(), 24);
1677
    time.tm_min = to_nonnegative_int(minute(), 60);
1678
    time.tm_sec = to_nonnegative_int(second(), 60);
1679
    return time;
1680
  }
1681
1682
  void write_sign() {
1683
    if (!negative) return;
1684
    *out++ = '-';
1685
    negative = false;
1686
  }
1687
1688
  void write(Rep value, int width, pad_type pad = pad_type::zero) {
1689
    write_sign();
1690
    if (isnan(value)) return write_nan();
1691
    uint32_or_64_or_128_t<int> n =
1692
        to_unsigned(to_nonnegative_int(value, max_value<int>()));
1693
    int num_digits = detail::count_digits(n);
1694
    if (width > num_digits) {
1695
      out = detail::write_padding(out, pad, width - num_digits);
1696
    }
1697
    out = format_decimal<Char>(out, n, num_digits);
1698
  }
1699
1700
  void write_nan() { std::copy_n("nan", 3, out); }
1701
1702
  template <typename Callback, typename... Args>
1703
  void format_tm(const tm& time, Callback cb, Args... args) {
1704
    if (isnan(val)) return write_nan();
1705
    get_locale loc(localized, locale);
1706
    auto w = tm_writer_type(loc, out, time);
1707
    (w.*cb)(args...);
1708
    out = w.out();
1709
  }
1710
1711
  void on_text(const Char* begin, const Char* end) {
1712
    copy<Char>(begin, end, out);
1713
  }
1714
1715
  // These are not implemented because durations don't have date information.
1716
  void on_abbr_weekday() {}
1717
  void on_full_weekday() {}
1718
  void on_dec0_weekday(numeric_system) {}
1719
  void on_dec1_weekday(numeric_system) {}
1720
  void on_abbr_month() {}
1721
  void on_full_month() {}
1722
  void on_datetime(numeric_system) {}
1723
  void on_loc_date(numeric_system) {}
1724
  void on_loc_time(numeric_system) {}
1725
  void on_us_date() {}
1726
  void on_iso_date() {}
1727
  void on_utc_offset(numeric_system) {}
1728
  void on_tz_name() {}
1729
  void on_year(numeric_system, pad_type) {}
1730
  void on_short_year(numeric_system) {}
1731
  void on_offset_year() {}
1732
  void on_century(numeric_system) {}
1733
  void on_iso_week_based_year() {}
1734
  void on_iso_week_based_short_year() {}
1735
  void on_dec_month(numeric_system, pad_type) {}
1736
  void on_dec0_week_of_year(numeric_system, pad_type) {}
1737
  void on_dec1_week_of_year(numeric_system, pad_type) {}
1738
  void on_iso_week_of_year(numeric_system, pad_type) {}
1739
  void on_day_of_month(numeric_system, pad_type) {}
1740
1741
  void on_day_of_year(pad_type) {
1742
    if (handle_nan_inf()) return;
1743
    write(days(), 0);
1744
  }
1745
1746
  void on_24_hour(numeric_system ns, pad_type pad) {
1747
    if (handle_nan_inf()) return;
1748
1749
    if (ns == numeric_system::standard) return write(hour(), 2, pad);
1750
    auto time = tm();
1751
    time.tm_hour = to_nonnegative_int(hour(), 24);
1752
    format_tm(time, &tm_writer_type::on_24_hour, ns, pad);
1753
  }
1754
1755
  void on_12_hour(numeric_system ns, pad_type pad) {
1756
    if (handle_nan_inf()) return;
1757
1758
    if (ns == numeric_system::standard) return write(hour12(), 2, pad);
1759
    auto time = tm();
1760
    time.tm_hour = to_nonnegative_int(hour12(), 12);
1761
    format_tm(time, &tm_writer_type::on_12_hour, ns, pad);
1762
  }
1763
1764
  void on_minute(numeric_system ns, pad_type pad) {
1765
    if (handle_nan_inf()) return;
1766
1767
    if (ns == numeric_system::standard) return write(minute(), 2, pad);
1768
    auto time = tm();
1769
    time.tm_min = to_nonnegative_int(minute(), 60);
1770
    format_tm(time, &tm_writer_type::on_minute, ns, pad);
1771
  }
1772
1773
  void on_second(numeric_system ns, pad_type pad) {
1774
    if (handle_nan_inf()) return;
1775
1776
    if (ns == numeric_system::standard) {
1777
      if (std::is_floating_point<rep>::value) {
1778
        auto buf = memory_buffer();
1779
        write_floating_seconds(buf, std::chrono::duration<rep, Period>(val),
1780
                               precision);
1781
        if (negative) *out++ = '-';
1782
        if (buf.size() < 2 || buf[1] == '.')
1783
          out = detail::write_padding(out, pad);
1784
        out = copy<Char>(buf.begin(), buf.end(), out);
1785
      } else {
1786
        write(second(), 2, pad);
1787
        write_fractional_seconds<Char>(
1788
            out, std::chrono::duration<rep, Period>(val), precision);
1789
      }
1790
      return;
1791
    }
1792
    auto time = tm();
1793
    time.tm_sec = to_nonnegative_int(second(), 60);
1794
    format_tm(time, &tm_writer_type::on_second, ns, pad);
1795
  }
1796
1797
  void on_12_hour_time() {
1798
    if (handle_nan_inf()) return;
1799
    format_tm(time(), &tm_writer_type::on_12_hour_time);
1800
  }
1801
1802
  void on_24_hour_time() {
1803
    if (handle_nan_inf()) {
1804
      *out++ = ':';
1805
      handle_nan_inf();
1806
      return;
1807
    }
1808
1809
    write(hour(), 2);
1810
    *out++ = ':';
1811
    write(minute(), 2);
1812
  }
1813
1814
  void on_iso_time() {
1815
    on_24_hour_time();
1816
    *out++ = ':';
1817
    if (handle_nan_inf()) return;
1818
    on_second(numeric_system::standard, pad_type::zero);
1819
  }
1820
1821
  void on_am_pm() {
1822
    if (handle_nan_inf()) return;
1823
    format_tm(time(), &tm_writer_type::on_am_pm);
1824
  }
1825
1826
  void on_duration_value() {
1827
    if (handle_nan_inf()) return;
1828
    write_sign();
1829
    out = format_duration_value<Char>(out, val, precision);
1830
  }
1831
1832
  void on_duration_unit() { out = format_duration_unit<Char, Period>(out); }
1833
};
1834
1835
}  // namespace detail
1836
1837
#if defined(__cpp_lib_chrono) && __cpp_lib_chrono >= 201907
1838
using weekday = std::chrono::weekday;
1839
using day = std::chrono::day;
1840
using month = std::chrono::month;
1841
using year = std::chrono::year;
1842
using year_month_day = std::chrono::year_month_day;
1843
#else
1844
// A fallback version of weekday.
1845
class weekday {
1846
 private:
1847
  unsigned char value_;
1848
1849
 public:
1850
  weekday() = default;
1851
  constexpr explicit weekday(unsigned wd) noexcept
1852
0
      : value_(static_cast<unsigned char>(wd != 7 ? wd : 0)) {}
1853
0
  constexpr auto c_encoding() const noexcept -> unsigned { return value_; }
1854
};
1855
1856
class day {
1857
 private:
1858
  unsigned char value_;
1859
1860
 public:
1861
  day() = default;
1862
  constexpr explicit day(unsigned d) noexcept
1863
0
      : value_(static_cast<unsigned char>(d)) {}
1864
0
  constexpr explicit operator unsigned() const noexcept { return value_; }
1865
};
1866
1867
class month {
1868
 private:
1869
  unsigned char value_;
1870
1871
 public:
1872
  month() = default;
1873
  constexpr explicit month(unsigned m) noexcept
1874
0
      : value_(static_cast<unsigned char>(m)) {}
1875
0
  constexpr explicit operator unsigned() const noexcept { return value_; }
1876
};
1877
1878
class year {
1879
 private:
1880
  int value_;
1881
1882
 public:
1883
  year() = default;
1884
0
  constexpr explicit year(int y) noexcept : value_(y) {}
1885
0
  constexpr explicit operator int() const noexcept { return value_; }
1886
};
1887
1888
class year_month_day {
1889
 private:
1890
  fmt::year year_;
1891
  fmt::month month_;
1892
  fmt::day day_;
1893
1894
 public:
1895
  year_month_day() = default;
1896
  constexpr year_month_day(const year& y, const month& m, const day& d) noexcept
1897
0
      : year_(y), month_(m), day_(d) {}
1898
0
  constexpr auto year() const noexcept -> fmt::year { return year_; }
1899
0
  constexpr auto month() const noexcept -> fmt::month { return month_; }
1900
0
  constexpr auto day() const noexcept -> fmt::day { return day_; }
1901
};
1902
#endif  // __cpp_lib_chrono >= 201907
1903
1904
template <typename Char>
1905
struct formatter<weekday, Char> : private formatter<std::tm, Char> {
1906
 private:
1907
  bool use_tm_formatter_ = false;
1908
1909
 public:
1910
  FMT_CONSTEXPR auto parse(parse_context<Char>& ctx) -> const Char* {
1911
    auto it = ctx.begin(), end = ctx.end();
1912
    if (it != end && *it == 'L') {
1913
      ++it;
1914
      this->set_localized();
1915
    }
1916
    use_tm_formatter_ = it != end && *it != '}';
1917
    return use_tm_formatter_ ? formatter<std::tm, Char>::parse(ctx) : it;
1918
  }
1919
1920
  template <typename FormatContext>
1921
  auto format(weekday wd, FormatContext& ctx) const -> decltype(ctx.out()) {
1922
    auto time = std::tm();
1923
    time.tm_wday = static_cast<int>(wd.c_encoding());
1924
    if (use_tm_formatter_) return formatter<std::tm, Char>::format(time, ctx);
1925
    detail::get_locale loc(this->localized(), ctx.locale());
1926
    auto w = detail::tm_writer<decltype(ctx.out()), Char>(loc, ctx.out(), time);
1927
    w.on_abbr_weekday();
1928
    return w.out();
1929
  }
1930
};
1931
1932
template <typename Char>
1933
struct formatter<day, Char> : private formatter<std::tm, Char> {
1934
 private:
1935
  bool use_tm_formatter_ = false;
1936
1937
 public:
1938
  FMT_CONSTEXPR auto parse(parse_context<Char>& ctx) -> const Char* {
1939
    auto it = ctx.begin(), end = ctx.end();
1940
    use_tm_formatter_ = it != end && *it != '}';
1941
    return use_tm_formatter_ ? formatter<std::tm, Char>::parse(ctx) : it;
1942
  }
1943
1944
  template <typename FormatContext>
1945
  auto format(day d, FormatContext& ctx) const -> decltype(ctx.out()) {
1946
    auto time = std::tm();
1947
    time.tm_mday = static_cast<int>(static_cast<unsigned>(d));
1948
    if (use_tm_formatter_) return formatter<std::tm, Char>::format(time, ctx);
1949
    detail::get_locale loc(false, ctx.locale());
1950
    auto w = detail::tm_writer<decltype(ctx.out()), Char>(loc, ctx.out(), time);
1951
    w.on_day_of_month(detail::numeric_system::standard, detail::pad_type::zero);
1952
    return w.out();
1953
  }
1954
};
1955
1956
template <typename Char>
1957
struct formatter<month, Char> : private formatter<std::tm, Char> {
1958
 private:
1959
  bool use_tm_formatter_ = false;
1960
1961
 public:
1962
  FMT_CONSTEXPR auto parse(parse_context<Char>& ctx) -> const Char* {
1963
    auto it = ctx.begin(), end = ctx.end();
1964
    if (it != end && *it == 'L') {
1965
      ++it;
1966
      this->set_localized();
1967
    }
1968
    use_tm_formatter_ = it != end && *it != '}';
1969
    return use_tm_formatter_ ? formatter<std::tm, Char>::parse(ctx) : it;
1970
  }
1971
1972
  template <typename FormatContext>
1973
  auto format(month m, FormatContext& ctx) const -> decltype(ctx.out()) {
1974
    auto time = std::tm();
1975
    time.tm_mon = static_cast<int>(static_cast<unsigned>(m)) - 1;
1976
    if (use_tm_formatter_) return formatter<std::tm, Char>::format(time, ctx);
1977
    detail::get_locale loc(this->localized(), ctx.locale());
1978
    auto w = detail::tm_writer<decltype(ctx.out()), Char>(loc, ctx.out(), time);
1979
    w.on_abbr_month();
1980
    return w.out();
1981
  }
1982
};
1983
1984
template <typename Char>
1985
struct formatter<year, Char> : private formatter<std::tm, Char> {
1986
 private:
1987
  bool use_tm_formatter_ = false;
1988
1989
 public:
1990
  FMT_CONSTEXPR auto parse(parse_context<Char>& ctx) -> const Char* {
1991
    auto it = ctx.begin(), end = ctx.end();
1992
    use_tm_formatter_ = it != end && *it != '}';
1993
    return use_tm_formatter_ ? formatter<std::tm, Char>::parse(ctx) : it;
1994
  }
1995
1996
  template <typename FormatContext>
1997
  auto format(year y, FormatContext& ctx) const -> decltype(ctx.out()) {
1998
    auto time = std::tm();
1999
    time.tm_year = static_cast<int>(y) - 1900;
2000
    if (use_tm_formatter_) return formatter<std::tm, Char>::format(time, ctx);
2001
    detail::get_locale loc(false, ctx.locale());
2002
    auto w = detail::tm_writer<decltype(ctx.out()), Char>(loc, ctx.out(), time);
2003
    w.on_year(detail::numeric_system::standard, detail::pad_type::zero);
2004
    return w.out();
2005
  }
2006
};
2007
2008
template <typename Char>
2009
struct formatter<year_month_day, Char> : private formatter<std::tm, Char> {
2010
 private:
2011
  bool use_tm_formatter_ = false;
2012
2013
 public:
2014
  FMT_CONSTEXPR auto parse(parse_context<Char>& ctx) -> const Char* {
2015
    auto it = ctx.begin(), end = ctx.end();
2016
    use_tm_formatter_ = it != end && *it != '}';
2017
    return use_tm_formatter_ ? formatter<std::tm, Char>::parse(ctx) : it;
2018
  }
2019
2020
  template <typename FormatContext>
2021
  auto format(year_month_day val, FormatContext& ctx) const
2022
      -> decltype(ctx.out()) {
2023
    auto time = std::tm();
2024
    time.tm_year = static_cast<int>(val.year()) - 1900;
2025
    time.tm_mon = static_cast<int>(static_cast<unsigned>(val.month())) - 1;
2026
    time.tm_mday = static_cast<int>(static_cast<unsigned>(val.day()));
2027
    if (use_tm_formatter_) return formatter<std::tm, Char>::format(time, ctx);
2028
    detail::get_locale loc(true, ctx.locale());
2029
    auto w = detail::tm_writer<decltype(ctx.out()), Char>(loc, ctx.out(), time);
2030
    w.on_iso_date();
2031
    return w.out();
2032
  }
2033
};
2034
2035
template <typename Rep, typename Period, typename Char>
2036
struct formatter<std::chrono::duration<Rep, Period>, Char> {
2037
 private:
2038
  format_specs specs_;
2039
  detail::arg_ref<Char> width_ref_;
2040
  detail::arg_ref<Char> precision_ref_;
2041
  basic_string_view<Char> fmt_;
2042
2043
 public:
2044
  FMT_CONSTEXPR auto parse(parse_context<Char>& ctx) -> const Char* {
2045
    auto it = ctx.begin(), end = ctx.end();
2046
    if (it == end || *it == '}') return it;
2047
2048
    it = detail::parse_align(it, end, specs_);
2049
    if (it == end) return it;
2050
2051
    Char c = *it;
2052
    if ((c >= '0' && c <= '9') || c == '{') {
2053
      it = detail::parse_width(it, end, specs_, width_ref_, ctx);
2054
      if (it == end) return it;
2055
    }
2056
2057
    auto checker = detail::chrono_format_checker();
2058
    if (*it == '.') {
2059
      checker.has_precision_integral = !std::is_floating_point<Rep>::value;
2060
      it = detail::parse_precision(it, end, specs_, precision_ref_, ctx);
2061
    }
2062
    if (it != end && *it == 'L') {
2063
      specs_.set_localized();
2064
      ++it;
2065
    }
2066
    end = detail::parse_chrono_format(it, end, checker);
2067
    fmt_ = {it, detail::to_unsigned(end - it)};
2068
    return end;
2069
  }
2070
2071
  template <typename FormatContext>
2072
  auto format(std::chrono::duration<Rep, Period> d, FormatContext& ctx) const
2073
      -> decltype(ctx.out()) {
2074
    auto specs = specs_;
2075
    auto precision = specs.precision;
2076
    specs.precision = -1;
2077
    auto begin = fmt_.begin(), end = fmt_.end();
2078
    // As a possible future optimization, we could avoid extra copying if width
2079
    // is not specified.
2080
    auto buf = basic_memory_buffer<Char>();
2081
    auto out = basic_appender<Char>(buf);
2082
    detail::handle_dynamic_spec(specs.dynamic_width(), specs.width, width_ref_,
2083
                                ctx);
2084
    detail::handle_dynamic_spec(specs.dynamic_precision(), precision,
2085
                                precision_ref_, ctx);
2086
    if (begin == end || *begin == '}') {
2087
      out = detail::format_duration_value<Char>(out, d.count(), precision);
2088
      detail::format_duration_unit<Char, Period>(out);
2089
    } else {
2090
      auto f =
2091
          detail::duration_formatter<Char, Rep, Period>(out, d, ctx.locale());
2092
      f.precision = precision;
2093
      f.localized = specs_.localized();
2094
      detail::parse_chrono_format(begin, end, f);
2095
    }
2096
    return detail::write(
2097
        ctx.out(), basic_string_view<Char>(buf.data(), buf.size()), specs);
2098
  }
2099
};
2100
2101
template <typename Char> struct formatter<std::tm, Char> {
2102
 private:
2103
  format_specs specs_;
2104
  detail::arg_ref<Char> width_ref_;
2105
  basic_string_view<Char> fmt_ =
2106
      detail::string_literal<Char, '%', 'F', ' ', '%', 'T'>();
2107
2108
 protected:
2109
  auto localized() const -> bool { return specs_.localized(); }
2110
  FMT_CONSTEXPR void set_localized() { specs_.set_localized(); }
2111
2112
  FMT_CONSTEXPR auto do_parse(parse_context<Char>& ctx, bool has_timezone)
2113
9.03k
      -> const Char* {
2114
9.03k
    auto it = ctx.begin(), end = ctx.end();
2115
9.03k
    if (it == end || *it == '}') return it;
2116
2117
7.60k
    it = detail::parse_align(it, end, specs_);
2118
7.60k
    if (it == end) return it;
2119
2120
7.55k
    Char c = *it;
2121
7.55k
    if ((c >= '0' && c <= '9') || c == '{') {
2122
3.02k
      it = detail::parse_width(it, end, specs_, width_ref_, ctx);
2123
3.02k
      if (it == end) return it;
2124
3.02k
    }
2125
2126
7.24k
    if (*it == 'L') {
2127
194
      specs_.set_localized();
2128
194
      ++it;
2129
194
    }
2130
2131
7.24k
    end = detail::parse_chrono_format(it, end,
2132
7.24k
                                      detail::tm_format_checker(has_timezone));
2133
    // Replace the default format string only if the new spec is not empty.
2134
7.24k
    if (end != it) fmt_ = {it, detail::to_unsigned(end - it)};
2135
7.24k
    return end;
2136
7.55k
  }
2137
2138
  template <typename Duration, typename FormatContext>
2139
  auto do_format(const std::tm& tm, FormatContext& ctx,
2140
8.68k
                 const Duration* subsecs) const -> decltype(ctx.out()) {
2141
8.68k
    auto specs = specs_;
2142
8.68k
    auto buf = basic_memory_buffer<Char>();
2143
8.68k
    auto out = basic_appender<Char>(buf);
2144
8.68k
    detail::handle_dynamic_spec(specs.dynamic_width(), specs.width, width_ref_,
2145
8.68k
                                ctx);
2146
2147
8.68k
    auto loc_ref = specs.localized() ? ctx.locale() : locale_ref();
2148
8.68k
    detail::get_locale loc(static_cast<bool>(loc_ref), loc_ref);
2149
8.68k
    auto w = detail::tm_writer<basic_appender<Char>, Char, Duration>(
2150
8.68k
        loc, out, tm, subsecs);
2151
8.68k
    detail::parse_chrono_format(fmt_.begin(), fmt_.end(), w);
2152
8.68k
    return detail::write(
2153
8.68k
        ctx.out(), basic_string_view<Char>(buf.data(), buf.size()), specs);
2154
8.68k
  }
decltype (({parm#2}.out)()) fmt::v12::formatter<tm, char, void>::do_format<std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> >, fmt::v12::context>(tm const&, fmt::v12::context&, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > const*) const
Line
Count
Source
2140
8.68k
                 const Duration* subsecs) const -> decltype(ctx.out()) {
2141
8.68k
    auto specs = specs_;
2142
8.68k
    auto buf = basic_memory_buffer<Char>();
2143
8.68k
    auto out = basic_appender<Char>(buf);
2144
8.68k
    detail::handle_dynamic_spec(specs.dynamic_width(), specs.width, width_ref_,
2145
8.68k
                                ctx);
2146
2147
8.68k
    auto loc_ref = specs.localized() ? ctx.locale() : locale_ref();
2148
8.68k
    detail::get_locale loc(static_cast<bool>(loc_ref), loc_ref);
2149
8.68k
    auto w = detail::tm_writer<basic_appender<Char>, Char, Duration>(
2150
8.68k
        loc, out, tm, subsecs);
2151
8.68k
    detail::parse_chrono_format(fmt_.begin(), fmt_.end(), w);
2152
8.68k
    return detail::write(
2153
8.68k
        ctx.out(), basic_string_view<Char>(buf.data(), buf.size()), specs);
2154
8.68k
  }
Unexecuted instantiation: decltype (({parm#2}.out)()) fmt::v12::formatter<tm, char, void>::do_format<std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> >, fmt::v12::context>(tm const&, fmt::v12::context&, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > const*) const
2155
2156
 public:
2157
  FMT_CONSTEXPR auto parse(parse_context<Char>& ctx) -> const Char* {
2158
    return do_parse(ctx, detail::has_tm_gmtoff<std::tm>::value);
2159
  }
2160
2161
  template <typename FormatContext>
2162
  auto format(const std::tm& tm, FormatContext& ctx) const
2163
0
      -> decltype(ctx.out()) {
2164
0
    return do_format<std::chrono::seconds>(tm, ctx, nullptr);
2165
0
  }
2166
};
2167
2168
// DEPRECATED! Reversed order of template parameters.
2169
template <typename Char, typename Duration>
2170
struct formatter<sys_time<Duration>, Char> : private formatter<std::tm, Char> {
2171
9.03k
  FMT_CONSTEXPR auto parse(parse_context<Char>& ctx) -> const Char* {
2172
9.03k
    return this->do_parse(ctx, true);
2173
9.03k
  }
2174
2175
  template <typename FormatContext>
2176
  auto format(sys_time<Duration> val, FormatContext& ctx) const
2177
8.68k
      -> decltype(ctx.out()) {
2178
8.68k
    std::tm tm = gmtime(val);
2179
8.68k
    using period = typename Duration::period;
2180
8.68k
    if FMT_CONSTEXPR20 (period::num == 1 && period::den == 1 &&
2181
0
                        !std::is_floating_point<
2182
0
                            typename Duration::rep>::value) {
2183
0
      detail::set_tm_zone(tm, detail::utc());
2184
0
      return formatter<std::tm, Char>::format(tm, ctx);
2185
0
    }
2186
8.68k
    Duration epoch = val.time_since_epoch();
2187
8.68k
    Duration subsecs = detail::duration_cast<Duration>(
2188
8.68k
        epoch - detail::duration_cast<std::chrono::seconds>(epoch));
2189
8.68k
    if (subsecs.count() < 0) {
2190
3.97k
      auto second = detail::duration_cast<Duration>(std::chrono::seconds(1));
2191
3.97k
      if (tm.tm_sec != 0) {
2192
3.53k
        --tm.tm_sec;
2193
3.53k
      } else {
2194
439
        tm = gmtime(val - second);
2195
439
        detail::set_tm_zone(tm, detail::utc());
2196
439
      }
2197
3.97k
      subsecs += second;
2198
3.97k
    }
2199
8.68k
    return formatter<std::tm, Char>::do_format(tm, ctx, &subsecs);
2200
8.68k
  }
2201
};
2202
2203
template <typename Duration, typename Char>
2204
struct formatter<utc_time<Duration>, Char>
2205
    : formatter<sys_time<Duration>, Char> {
2206
  template <typename FormatContext>
2207
  auto format(utc_time<Duration> val, FormatContext& ctx) const
2208
      -> decltype(ctx.out()) {
2209
    return formatter<sys_time<Duration>, Char>::format(
2210
        detail::utc_clock::to_sys(val), ctx);
2211
  }
2212
};
2213
2214
template <typename Duration, typename Char>
2215
struct formatter<local_time<Duration>, Char>
2216
    : private formatter<std::tm, Char> {
2217
  FMT_CONSTEXPR auto parse(parse_context<Char>& ctx) -> const Char* {
2218
    return this->do_parse(ctx, false);
2219
  }
2220
2221
  template <typename FormatContext>
2222
  auto format(local_time<Duration> val, FormatContext& ctx) const
2223
      -> decltype(ctx.out()) {
2224
    auto time_since_epoch = val.time_since_epoch();
2225
    auto seconds_since_epoch =
2226
        detail::duration_cast<std::chrono::seconds>(time_since_epoch);
2227
    // Use gmtime to prevent time zone conversion since local_time has an
2228
    // unspecified time zone.
2229
    std::tm t = gmtime(seconds_since_epoch.count());
2230
    using period = typename Duration::period;
2231
    if (period::num == 1 && period::den == 1 &&
2232
        !std::is_floating_point<typename Duration::rep>::value) {
2233
      return formatter<std::tm, Char>::format(t, ctx);
2234
    }
2235
    auto subsecs =
2236
        detail::duration_cast<Duration>(time_since_epoch - seconds_since_epoch);
2237
    return formatter<std::tm, Char>::do_format(t, ctx, &subsecs);
2238
  }
2239
};
2240
2241
FMT_END_EXPORT
2242
FMT_END_NAMESPACE
2243
2244
#endif  // FMT_CHRONO_H_