diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 1ed94ace..46a93fde 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -1838,7 +1838,7 @@ struct chrono_formatter { } else { write(second(), 2); write_fractional_seconds( - out, std::chrono::duration(val)); + out, std::chrono::duration(val)); } return; } diff --git a/test/chrono-test.cc b/test/chrono-test.cc index fbc9fd61..d53ad56b 100644 --- a/test/chrono-test.cc +++ b/test/chrono-test.cc @@ -642,6 +642,15 @@ TEST(chrono_test, cpp20_duration_subsecond_support) { std::chrono::duration>(1)), "00.142857"); + EXPECT_EQ(fmt::format("{:%S}", + std::chrono::duration>(0x80)), + "-01.28"); + + EXPECT_EQ( + fmt::format("{:%M:%S}", + std::chrono::duration>(0x8000)), + "-05:27.68"); + // Check that floating point seconds with ratio<1,1> are printed. EXPECT_EQ(fmt::format("{:%S}", std::chrono::duration{1.5}), "01.500000");