diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 6610e62e..65f5b5a5 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -389,8 +389,8 @@ struct formatter, Char> { if (const char *unit = get_units()) return format_to(ctx.out(), "{}{}", d.count(), unit); if (Period::den == 1) - return format_to(ctx.out(), "{}[{}s]", d.count(), Period::num); - return format_to(ctx.out(), "{}[{}/{}s]", + return format_to(ctx.out(), "{}[{}]s", d.count(), Period::num); + return format_to(ctx.out(), "{}[{}/{}]s", d.count(), Period::num, Period::den); } internal::chrono_formatter f(ctx); diff --git a/test/chrono-test.cc b/test/chrono-test.cc index ca25d18c..4e6e97e1 100644 --- a/test/chrono-test.cc +++ b/test/chrono-test.cc @@ -83,10 +83,10 @@ TEST(ChronoTest, FormatDefault) { fmt::format("{}", std::chrono::duration(42))); EXPECT_EQ("42m", fmt::format("{}", std::chrono::minutes(42))); EXPECT_EQ("42h", fmt::format("{}", std::chrono::hours(42))); - EXPECT_EQ("42[15s]", + EXPECT_EQ("42[15]s", fmt::format("{}", std::chrono::duration>(42))); - EXPECT_EQ("42[15/4s]", + EXPECT_EQ("42[15/4]s", fmt::format("{}", std::chrono::duration>(42))); }