mirror of
https://github.com/fmtlib/fmt.git
synced 2026-10-29 02:17:28 +08:00
Merge 61bfea60baa4b1c90034e845f95a04e900000e83 into 6ba294f5a60de2ae36fb47f3fa1b2836f6c67436
This commit is contained in:
commit
c79dddaeb6
@ -1681,7 +1681,7 @@ struct duration_formatter {
|
||||
|
||||
auto hour12() const -> Rep {
|
||||
Rep hour = static_cast<Rep>(mod((s.count() / 3600), 12));
|
||||
return hour <= 0 ? 12 : hour;
|
||||
return hour < 1 ? 12 : hour;
|
||||
}
|
||||
|
||||
auto minute() const -> Rep {
|
||||
|
||||
@ -507,6 +507,15 @@ TEST(chrono_test, format_specs) {
|
||||
EXPECT_EQ(fmt::format("{:%q}", std::chrono::seconds(12345)), "s");
|
||||
}
|
||||
|
||||
TEST(chrono_test, format_12_hour_fp) {
|
||||
using seconds = std::chrono::duration<double>;
|
||||
EXPECT_EQ(fmt::format("{:%I:%M:%S %p}", seconds(1)), "12:00:01 AM");
|
||||
EXPECT_EQ(fmt::format("{:%I:%M:%S %p}", seconds(43201)), "12:00:01 PM");
|
||||
EXPECT_EQ(fmt::format("{:%I}", seconds(3599)), "12");
|
||||
EXPECT_EQ(fmt::format("{:%I}", seconds(3600)), "01");
|
||||
EXPECT_EQ(fmt::format("{:%I}", seconds(86401)), "12");
|
||||
}
|
||||
|
||||
TEST(chrono_test, invalid_specs) {
|
||||
auto sec = std::chrono::seconds(0);
|
||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{:%a}"), sec), fmt::format_error,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user