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

Code before:
    FMT_ASSERT(tm_.tm_mday >= 1 && tm_.tm_mday <= 31,
               "tm_mday not in range [1, 31]");
    return to_unsigned(tm_.tm_mday);
  }
  auto tm_mon() const noexcept -> unsigned {
    FMT_ASSERT(tm_.tm_mon >= 0 && tm_.tm_mon <= 11,
               "tm_mon not in range [0, 11]");
    return to_unsigned(tm_.tm_mon);
  }
  auto tm_year() const noexcept -> long long {
    return 1900ll + static_cast<long long>(tm_.tm_year);
  }
  auto tm_wday() const noexcept -> unsigned {
    FMT_ASSERT(tm_.tm_wday >= 0 && tm_.tm_wday <= 6,
               "tm_wday not in range [0, 6]");
    return to_unsigned(tm_.tm_wday);
  }
  auto tm_yday() const noexcept -> unsigned {
    FMT_ASSERT(tm_.tm_yday >= 0 && tm_.tm_yday <= 365,
               "tm_yday not in range [0, 365]");
    return to_unsigned(tm_.tm_yday);
  }

  auto tm_hour12() const noexcept -> unsigned {
    auto hour = tm_hour() % 12;
    return hour == 0 ? 12 : hour;
  }

  FMT_CONSTEXPR const Char* tm_day_of_week_name() const noexcept {
    auto wday = tm_wday();
    return (wday >= 0 && wday <= 6) ? day_of_week[wday] : invalid;
  }
  FMT_CONSTEXPR const Char* tm_mon_name() const noexcept {
    auto mon = tm_mon();
    return (mon >= 0 && mon <= 11) ? month[mon] : invalid;
  }

  // POSIX and the C Standard are unclear or inconsistent about what %C and %y
  // do if the year is negative or exceeds 9999. Use the convention that %C
  // concatenated with %y yields the same output as %Y, and that %Y contains at
  // least 4 characters, with more only if necessary.
  auto split_year_lower(const long long year) const noexcept -> unsigned {
    auto l = year % 100;
    if (l < 0) l = -l;  // l in [0, 99]
    return static_cast<unsigned>(l);
  }

  // Algorithm:
  // https://en.wikipedia.org/wiki/ISO_week_date#Calculating_the_week_number_from_a_month_and_day_of_the_month_or_ordinal_date
  auto iso_year_weeks(const long long curr_year) const noexcept -> unsigned {
    const long long prev_year = curr_year - 1;

Review comment (suggestion):
Consider using branchless version
```c++
return 12 - (24 - tm_hour()) % 12;
```
which works for value range [0..24] and is roughly twice as fast on average than the current one.

Benchmarks:
Clang: https://quick-bench.com/q/7HNDvGkhn9nHbhPWucYRkwopb8c
GCC: https://quick-bench.com/q/UzDaMCckWht4nKXu1zgkXuhfs7o

Code after:
    FMT_ASSERT(tm_.tm_mday >= 1 && tm_.tm_mday <= 31, "");
    return tm_.tm_mday;
  }
  auto tm_mon() const noexcept -> int {
    FMT_ASSERT(tm_.tm_mon >= 0 && tm_.tm_mon <= 11, "");
    return tm_.tm_mon;
  }
  auto tm_year() const noexcept -> long long { return 1900ll + tm_.tm_year; }
  auto tm_wday() const noexcept -> int {
    FMT_ASSERT(tm_.tm_wday >= 0 && tm_.tm_wday <= 6, "");
    return tm_.tm_wday;
  }
  auto tm_yday() const noexcept -> int {
    FMT_ASSERT(tm_.tm_yday >= 0 && tm_.tm_yday <= 365, "");
    return tm_.tm_yday;
  }

  auto tm_hour12() const noexcept -> int {
    const auto h = tm_hour();
    const auto z = h < 12 ? h : h - 12;
    return z == 0 ? 12 : z;
  }

  // POSIX and the C Standard are unclear or inconsistent about what %C and %y
  // do if the year is negative or exceeds 9999. Use the convention that %C
  // concatenated with %y yields the same output as %Y, and that %Y contains at
  // least 4 characters, with more only if necessary.
  auto split_year_lower(long long year) const noexcept -> int {
    auto l = year % 100;
    if (l < 0) l = -l;  // l in [0, 99]
    return static_cast<int>(l);
  }

  // Algorithm:
  // https://en.wikipedia.org/wiki/ISO_week_date#Calculating_the_week_number_from_a_month_and_day_of_the_month_or_ordinal_date
  auto iso_year_weeks(long long curr_year) const noexcept -> int {
    const auto prev_year = curr_year - 1;
    const auto curr_p =
        (curr_year + curr_year / 4 - curr_year / 100 + curr_year / 400) %
        days_per_week;
    const auto prev_p =
        (prev_year + prev_year / 4 - prev_year / 100 + prev_year / 400) %
        days_per_week;
    return 52 + ((curr_p == 4 || prev_p == 3) ? 1 : 0);
  }
  auto iso_week_num(int tm_yday, int tm_wday) const noexcept -> int {
    return (tm_yday + 11 - (tm_wday == 0 ? days_per_week : tm_wday)) /
           days_per_week;
  }
  auto tm_iso_week_year() const noexcept -> long long {
    const auto year = tm_year();