Repository: fmtlib/fmt
File: include/fmt/chrono.h (C/C++)

Code before:
    return hour <= 0 ? 12 : hour;
  }

  Rep minute() const { return static_cast<Rep>(mod((s.count() / 60), 60)); }
  Rep second() const { return static_cast<Rep>(mod(s.count(), 60)); }

  std::tm time() const {
    auto time = std::tm();
    time.tm_hour = to_nonnegative_int(hour(), 24);
    time.tm_min = to_nonnegative_int(minute(), 60);
    time.tm_sec = to_nonnegative_int(second(), 60);
    return time;
  }

  void write_sign() {
    if (negative) {
      *out++ = '-';
      negative = false;
    }
  }

  template <typename RepType> void write(RepType value, int width) {
    write_sign();
    if (isnan(value)) return write_nan();
    uint32_or_64_or_128_t<std::intmax_t> n =
        to_unsigned(to_nonnegative_int(value, max_value<std::intmax_t>()));
    int num_digits = detail::count_digits(n);
    if (width > num_digits) out = std::fill_n(out, width - num_digits, '0');
    out = format_decimal<char_type>(out, n, num_digits).end;
  }

  void write_nan() { std::copy_n("nan", 3, out); }
  void write_pinf() { std::copy_n("inf", 3, out); }
  void write_ninf() { std::copy_n("-inf", 4, out); }

  template <typename Callback, typename... Args>
  void format_tm(const tm& time, Callback cb, Args... args) {
    if (isnan(val)) return write_nan();
    get_locale loc(localized, context.locale());
    auto w = tm_writer_type(loc, out, time);
    (w.*cb)(args...);
    out = w.out();
  }

  void on_text(const char_type* begin, const char_type* end) {
    std::copy(begin, end, out);
  }

  // These are not implemented because durations don't have date information.
  void on_abbr_weekday() {}
  void on_full_weekday() {}

Review comment (suggestion):
Let's use `long long` instead of `intmax_t` because it's a built-in type and can also handle 18 digits of precision.

Code after:
    }
  }

  void write(Rep value, int width) {
    write_sign();
    if (isnan(value)) return write_nan();
    uint32_or_64_or_128_t<int> n =
        to_unsigned(to_nonnegative_int(value, max_value<int>()));
    int num_digits = detail::count_digits(n);
    if (width > num_digits) out = std::fill_n(out, width - num_digits, '0');
    out = format_decimal<char_type>(out, n, num_digits).end;
  }

  template <class Duration> void write_fractional_seconds(Duration d) {
    constexpr auto fractional_width =
        detail::num_digits(Duration::period::num, Duration::period::den);

    using subsecond_precision = std::chrono::duration<
        typename std::common_type<typename Duration::rep,
                                  std::chrono::seconds::rep>::type,
        std::ratio<1, detail::pow10(fractional_width)>>;
    // We could use c++ 17 if constexpr here.
    if (std::ratio_less<typename subsecond_precision::period,
                        std::chrono::seconds::period>::value) {
      *out++ = '.';
      const auto subseconds =
          std::chrono::treat_as_floating_point<
              typename subsecond_precision::rep>::value
              ? (detail::abs(d) -
                 std::chrono::duration_cast<std::chrono::seconds>(d))
                    .count()
              : std::chrono::duration_cast<subsecond_precision>(
                    detail::abs(d) -
                    std::chrono::duration_cast<std::chrono::seconds>(d))
                    .count();
      uint32_or_64_or_128_t<long long> n =
          to_unsigned(to_nonnegative_int(subseconds, max_value<long long>()));
      int num_digits = detail::count_digits(n);
      if (fractional_width > num_digits) {
        out = std::fill_n(out, fractional_width - num_digits, '0');
      }
      out = format_decimal<char_type>(out, n, num_digits).end;
    }
  }

  void write_nan() { std::copy_n("nan", 3, out); }
  void write_pinf() { std::copy_n("inf", 3, out); }
  void write_ninf() { std::copy_n("-inf", 4, out); }

  template <typename Callback, typename... Args>
  void format_tm(const tm& time, Callback cb, Args... args) {