Merge 61bfea60baa4b1c90034e845f95a04e900000e83 into 6ba294f5a60de2ae36fb47f3fa1b2836f6c67436

This commit is contained in:
Nathan Chandrasekar 2026-10-18 15:46:17 +02:00 committed by GitHub
commit c79dddaeb6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -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 {

View File

@ -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,