Fix overflow error (#3143)

Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>

Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
This commit is contained in:
Vladislav Shchapov 2022-10-17 02:04:55 +05:00 committed by GitHub
parent 51d3685efe
commit cd7202e039
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -1838,7 +1838,7 @@ struct chrono_formatter {
} else { } else {
write(second(), 2); write(second(), 2);
write_fractional_seconds<char_type>( write_fractional_seconds<char_type>(
out, std::chrono::duration<Rep, Period>(val)); out, std::chrono::duration<rep, Period>(val));
} }
return; return;
} }

View File

@ -642,6 +642,15 @@ TEST(chrono_test, cpp20_duration_subsecond_support) {
std::chrono::duration<long long, std::ratio<1, 7>>(1)), std::chrono::duration<long long, std::ratio<1, 7>>(1)),
"00.142857"); "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. // Check that floating point seconds with ratio<1,1> are printed.
EXPECT_EQ(fmt::format("{:%S}", std::chrono::duration<double>{1.5}), EXPECT_EQ(fmt::format("{:%S}", std::chrono::duration<double>{1.5}),
"01.500000"); "01.500000");