From cc20c47e19c0e23fc7aea61e51bcae3376af69c7 Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Sat, 30 Oct 2021 19:32:21 +0500 Subject: [PATCH] Make locale-independent and C locale formats consistent among platforms --- include/fmt/chrono.h | 10 ---------- test/chrono-test.cc | 17 +++++++++++------ 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 874dc4d9f0f5c..997bb2d0dd94c 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -1590,11 +1590,6 @@ template class tm_writer { void on_datetime(numeric_system ns) { if (is_classic_) { -#ifdef _WIN32 - on_us_date(); - *out_++ = ' '; - on_iso_time(); -#else on_abbr_weekday(); *out_++ = ' '; on_abbr_month(); @@ -1604,7 +1599,6 @@ template class tm_writer { on_iso_time(); *out_++ = ' '; on_year(numeric_system::standard); -#endif } else { format_localized('c', ns == numeric_system::standard ? '\0' : 'E'); } @@ -1735,16 +1729,12 @@ template class tm_writer { void on_12_hour_time() { if (is_classic_) { -#ifdef _WIN32 - on_iso_time(); -#else char buf[8]; write_digit2_separated(buf, to_unsigned(tm_hour12()), to_unsigned(tm_min()), to_unsigned(tm_sec()), ':'); out_ = copy_str(std::begin(buf), std::end(buf), out_); *out_++ = ' '; on_am_pm(); -#endif } else { format_localized('r'); } diff --git a/test/chrono-test.cc b/test/chrono-test.cc index 6eaf1cfb5d1dd..8a85331b7d15d 100644 --- a/test/chrono-test.cc +++ b/test/chrono-test.cc @@ -248,13 +248,18 @@ TEST(chrono_test, time_point) { EXPECT_EQ(strftime_full(t2), fmt::format("{:%Y-%m-%d %H:%M:%S}", t2)); std::vector spec_list = { - "%%", "%n", "%t", "%Y", "%EY", "%y", "%Oy", "%Ey", "%C", "%EC", - "%G", "%g", "%b", "%h", "%B", "%m", "%Om", "%U", "%OU", "%W", - "%OW", "%V", "%OV", "%j", "%d", "%Od", "%e", "%Oe", "%a", "%A", - "%w", "%Ow", "%u", "%Ou", "%H", "%OH", "%I", "%OI", "%M", "%OM", - "%S", "%OS", "%c", "%Ec", "%x", "%Ex", "%X", "%EX", "%D", "%F", - "%r", "%R", "%T", "%p", "%z", "%Z"}; + "%%", "%n", "%t", "%Y", "%EY", "%y", "%Oy", "%Ey", "%C", + "%EC", "%G", "%g", "%b", "%h", "%B", "%m", "%Om", "%U", + "%OU", "%W", "%OW", "%V", "%OV", "%j", "%d", "%Od", "%e", + "%Oe", "%a", "%A", "%w", "%Ow", "%u", "%Ou", "%H", "%OH", + "%I", "%OI", "%M", "%OM", "%S", "%OS", "%x", "%Ex", "%X", + "%EX", "%D", "%F", "%R", "%T", "%p", "%z", "%Z"}; spec_list.push_back("%Y-%m-%d %H:%M:%S"); +#ifndef _WIN32 + // Disabled on Windows, because this formats is not consistent among platforms + spec_list.insert(spec_list.end(), {"%c", "%Ec", "%r"}); +#endif + for (const auto& spec : spec_list) { auto t = std::chrono::system_clock::to_time_t(t1); auto tm = *std::localtime(&t);