diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index b089a7d9..2881ab97 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -1390,7 +1390,7 @@ class tm_writer { } void on_utc_offset(numeric_system ns) { format_utc_offset_impl(tm_, ns); } - void on_tz_name() { out_ = std::copy_n("UTC", 3, out_); } + void on_tz_name() { format_tz_name_impl(tm_); } 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 5b6323f0..3a0c2aac 100644 --- a/test/chrono-test.cc +++ b/test/chrono-test.cc @@ -337,26 +337,43 @@ TEST(chrono_test, local_time) { template ::value)> -bool set_gmtoff(T& time, long offset) { +bool set_tm_gmtoff(T& time, long offset) { time.tm_gmtoff = offset; return true; } template ::value)> -bool set_gmtoff(T&, long) { +bool set_tm_gmtoff(T&, long) { + return false; +} + +template ::value)> +bool set_tm_zone(T& time, char* tz) { + time.tm_zone = tz; + return true; +} +template ::value)> +bool set_tm_zone(T&, char*) { return false; } TEST(chrono_test, tm) { auto time = fmt::gmtime(290088000); test_time(time); - if (set_gmtoff(time, -28800)) { + if (set_tm_gmtoff(time, -28800)) { EXPECT_EQ(fmt::format(fmt::runtime("{:%z}"), time), "-0800"); EXPECT_EQ(fmt::format(fmt::runtime("{:%Ez}"), time), "-08:00"); EXPECT_EQ(fmt::format(fmt::runtime("{:%Oz}"), time), "-08:00"); } else { EXPECT_THROW_MSG((void)fmt::format(fmt::runtime("{:%z}"), time), fmt::format_error, "no timezone"); + } + char tz[] = "EET"; + if (set_tm_zone(time, tz)) { + EXPECT_EQ(fmt::format(fmt::runtime("{:%Z}"), time), "EET"); + } else { EXPECT_THROW_MSG((void)fmt::format(fmt::runtime("{:%Z}"), time), fmt::format_error, "no timezone"); }