diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 7bd4206d75280..89be0739265a4 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -2088,7 +2088,7 @@ struct formatter, if (subsecs.count() < 0) { auto second = std::chrono::duration_cast(std::chrono::seconds(1)); - if (epoch.count() < ((Duration::min)() + second).count()) + if ((epoch + second).count() < ((Duration::min)() + second).count()) FMT_THROW(format_error("duration is too small")); subsecs += second; val -= second; diff --git a/test/chrono-test.cc b/test/chrono-test.cc index 077606887095a..1c505ec062323 100644 --- a/test/chrono-test.cc +++ b/test/chrono-test.cc @@ -1003,3 +1003,9 @@ TEST(chrono_test, glibc_extensions) { EXPECT_EQ(fmt::format("{:%-S}", d), "3.140000"); } } +TEST(chrono_test, time_min) { + { + const auto t = std::chrono::system_clock::time_point::min(); + EXPECT_EQ(fmt::format("{:%S}", t), "53.224192"); + } +} \ No newline at end of file