Skip to content

Commit

Permalink
Fix overflow error (#3143)
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>

Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
  • Loading branch information
phprus committed Oct 16, 2022
1 parent 51d3685 commit cd7202e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -1838,7 +1838,7 @@ struct chrono_formatter {
} else {
write(second(), 2);
write_fractional_seconds<char_type>(
out, std::chrono::duration<Rep, Period>(val));
out, std::chrono::duration<rep, Period>(val));
}
return;
}
Expand Down
9 changes: 9 additions & 0 deletions test/chrono-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,15 @@ TEST(chrono_test, cpp20_duration_subsecond_support) {
std::chrono::duration<long long, std::ratio<1, 7>>(1)),
"00.142857");

EXPECT_EQ(fmt::format("{:%S}",
std::chrono::duration<char, std::ratio<1, 100>>(0x80)),
"-01.28");

EXPECT_EQ(
fmt::format("{:%M:%S}",
std::chrono::duration<short, std::ratio<1, 100>>(0x8000)),
"-05:27.68");

// Check that floating point seconds with ratio<1,1> are printed.
EXPECT_EQ(fmt::format("{:%S}", std::chrono::duration<double>{1.5}),
"01.500000");
Expand Down

0 comments on commit cd7202e

Please sign in to comment.