mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-31 19:24:48 +02:00
Fix default formatting
This commit is contained in:
@@ -389,8 +389,8 @@ struct formatter<std::chrono::duration<Rep, Period>, Char> {
|
|||||||
if (const char *unit = get_units<Period>())
|
if (const char *unit = get_units<Period>())
|
||||||
return format_to(ctx.out(), "{}{}", d.count(), unit);
|
return format_to(ctx.out(), "{}{}", d.count(), unit);
|
||||||
if (Period::den == 1)
|
if (Period::den == 1)
|
||||||
return format_to(ctx.out(), "{}[{}s]", d.count(), Period::num);
|
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, Period::den);
|
d.count(), Period::num, Period::den);
|
||||||
}
|
}
|
||||||
internal::chrono_formatter<FormatContext> f(ctx);
|
internal::chrono_formatter<FormatContext> f(ctx);
|
||||||
|
@@ -83,10 +83,10 @@ TEST(ChronoTest, FormatDefault) {
|
|||||||
fmt::format("{}", std::chrono::duration<int, std::exa>(42)));
|
fmt::format("{}", std::chrono::duration<int, std::exa>(42)));
|
||||||
EXPECT_EQ("42m", fmt::format("{}", std::chrono::minutes(42)));
|
EXPECT_EQ("42m", fmt::format("{}", std::chrono::minutes(42)));
|
||||||
EXPECT_EQ("42h", fmt::format("{}", std::chrono::hours(42)));
|
EXPECT_EQ("42h", fmt::format("{}", std::chrono::hours(42)));
|
||||||
EXPECT_EQ("42[15s]",
|
EXPECT_EQ("42[15]s",
|
||||||
fmt::format("{}",
|
fmt::format("{}",
|
||||||
std::chrono::duration<int, std::ratio<15, 1>>(42)));
|
std::chrono::duration<int, std::ratio<15, 1>>(42)));
|
||||||
EXPECT_EQ("42[15/4s]",
|
EXPECT_EQ("42[15/4]s",
|
||||||
fmt::format("{}",
|
fmt::format("{}",
|
||||||
std::chrono::duration<int, std::ratio<15, 4>>(42)));
|
std::chrono::duration<int, std::ratio<15, 4>>(42)));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user