From b28214487d60cab1a9996a4b4e99d17d3ff86000 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 12 Apr 2025 08:37:15 -0700 Subject: [PATCH] Fix handling of %Z --- .github/workflows/windows.yml | 2 +- include/fmt/chrono.h | 2 +- test/chrono-test.cc | 18 ++---------------- 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index d2bb205c..2f3f676e 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -39,7 +39,7 @@ jobs: - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Set timezone - run: tzutil /s "Ekaterinburg Standard Time" + run: tzutil /s "Pacific Standard Time" - name: Create Build Environment run: cmake -E make_directory ${{runner.workspace}}/build diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 252bfd3d..d44a1a24 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -1393,7 +1393,7 @@ class tm_writer { } void on_utc_offset(numeric_system ns) { format_utc_offset_impl(tm_, ns); } - void on_tz_name() { format_tz_name_impl(tm_); } + void on_tz_name() { out_ = std::copy_n("UTC", 3, out_); } void on_year(numeric_system ns, pad_type pad) { if (is_classic_ || ns == numeric_system::standard) diff --git a/test/chrono-test.cc b/test/chrono-test.cc index 1e73a146..5364bfde 100644 --- a/test/chrono-test.cc +++ b/test/chrono-test.cc @@ -263,8 +263,7 @@ auto strftime_full_utc(TimePoint tp) -> std::string { return system_strftime("%Y-%m-%d %H:%M:%S", &tm); } -template -void test_time(Time time) { +template void test_time(Time time) { EXPECT_EQ(fmt::format("{}", time), "1979-03-12 12:00:00"); EXPECT_EQ(fmt::format("{:}", time), "1979-03-12 12:00:00"); @@ -333,20 +332,7 @@ TEST(chrono_test, sys_time) { EXPECT_EQ(fmt::format("{:%z}", time), "+0000"); EXPECT_EQ(fmt::format("{:%Ez}", time), "+00:00"); EXPECT_EQ(fmt::format("{:%Oz}", time), "+00:00"); - - auto t1 = std::chrono::time_point_cast( - std::chrono::system_clock::now()); - - // Separate tests for UTC, since std::time_put can use local time and ignoring - // the timezone in std::tm (if it presents on platform). - if (fmt::detail::has_member_data_tm_zone::value) { - auto t = std::chrono::system_clock::to_time_t(t1); - auto tm = *std::gmtime(&t); - - std::vector tz_names = {"GMT", "UTC"}; - EXPECT_THAT(tz_names, Contains(fmt::format("{:%Z}", t1))); - EXPECT_THAT(tz_names, Contains(fmt::format("{:%Z}", tm))); - } + EXPECT_EQ(fmt::format("{:%Z}", time), "UTC"); } TEST(chrono_test, local_time) {