From aa3b5aba41b368e98acad4c75120bf252446d4b0 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 6 Dec 2018 16:12:10 -0800 Subject: [PATCH] Implement locale-specific minute formatting --- include/fmt/time.h | 8 ++++++-- test/time-test.cc | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/fmt/time.h b/include/fmt/time.h index 60da3e46..1a72ebf6 100644 --- a/include/fmt/time.h +++ b/include/fmt/time.h @@ -206,9 +206,13 @@ struct chrono_formatter { format_localized(time, 'I'); } - void on_minute(numeric_system) { + void on_minute(numeric_system ns) { auto minute = to_int((s.count() / 60) % 60); - write(minute, 2); + if (ns == numeric_system::standard) + return write(minute, 2); + auto time = tm(); + time.tm_minute = minute; + format_localized(time, 'M'); } void on_second(numeric_system) { diff --git a/test/time-test.cc b/test/time-test.cc index 1caf32fb..940ae252 100644 --- a/test/time-test.cc +++ b/test/time-test.cc @@ -107,5 +107,8 @@ TEST(TimeTest, ChronoLocale) { EXPECT_EQ(str(), fmt::format(loc, "{:%OH}", std::chrono::hours(14))); os << std::put_time(&time, "%OI"); EXPECT_EQ(str(), fmt::format(loc, "{:%OI}", std::chrono::hours(14))); + time.tm_minute = 42; + os << std::put_time(&time, "%OM"); + EXPECT_EQ(str(), fmt::format(loc, "{:%OM}", std::chrono::minutes(42))); } #endif