diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 18616b22..79ceaba4 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -876,6 +876,8 @@ template struct make_unsigned_or_unchanged { }; #if FMT_USE_CONSTEXPR +// Taken from MSVC STL implementation +// Copyright (c) Microsoft Corporation 2021 template FMT_CONSTEXPR unsigned int get_fractional_width() { static_assert(Duration::period::num > 0 && Duration::period::den > 0, "Numerator and denominator can't be less than 1."); @@ -938,14 +940,16 @@ To fmt_safe_duration_cast(std::chrono::duration from) { #endif template struct subsecond_helper { - static constexpr std::uintmax_t fractional_width = + static constexpr std::uint64_t fractional_width = #if FMT_USE_CONSTEXPR get_fractional_width(); #else - width::value; + width::value > 18 + ? 6 + : width::value; #endif - static constexpr std::uintmax_t fractional_width_pow10 = + static constexpr std::uint64_t fractional_width_pow10 = #if FMT_USE_CONSTEXPR pow10(fractional_width); #else @@ -1204,11 +1208,12 @@ struct chrono_formatter { const auto tmpval = std::chrono::duration(val); #endif using subsec_helper = detail::subsecond_helper; - const std::uintmax_t subseconds = + const std::uint64_t subseconds = subsec_helper::get_subseconds(tmpval).count(); if (subseconds > 0) { *out++ = '.'; - const auto num_digits = detail::count_digits(subseconds); + const std::uint32_t num_digits = + detail::count_digits(static_cast(subseconds)); if (subsec_helper::fractional_width > num_digits) { out = std::fill_n(out, subsec_helper::fractional_width - num_digits, '0');