diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 517f9576..e4bc1ce4 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -1192,6 +1192,7 @@ class tm_writer { template ::value)> void format_tz_name(const T& tm) { + if (!tm.tm_zone) FMT_THROW(format_error("no timezone")); out_ = write_tm_str(out_, tm.tm_zone, loc_); } template ::value)> diff --git a/test/chrono-test.cc b/test/chrono-test.cc index 7b4bf402..a9153598 100644 --- a/test/chrono-test.cc +++ b/test/chrono-test.cc @@ -358,6 +358,9 @@ TEST(chrono_test, tm) { char tz[] = "EET"; if (fmt::detail::set_tm_zone(time, tz)) { EXPECT_EQ(fmt::format(fmt::runtime("{:%Z}"), time), "EET"); + fmt::detail::set_tm_zone(time, nullptr); + EXPECT_THROW_MSG((void)fmt::format(fmt::runtime("{:%Z}"), time), + fmt::format_error, "no timezone"); } else { EXPECT_THROW_MSG((void)fmt::format(fmt::runtime("{:%Z}"), time), fmt::format_error, "no timezone");