diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index d44a1a24..f34db132 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -2206,7 +2206,8 @@ template struct formatter { detail::arg_ref width_ref_; protected: - basic_string_view fmt_; + basic_string_view fmt_ = + detail::string_literal(); template auto do_format(const std::tm& tm, FormatContext& ctx, @@ -2261,10 +2262,6 @@ template struct formatter { template struct formatter, Char> : formatter { - FMT_CONSTEXPR formatter() { - this->fmt_ = detail::string_literal(); - } - template auto format(sys_time val, FormatContext& ctx) const -> decltype(ctx.out()) { @@ -2303,10 +2300,6 @@ struct formatter, Char> template struct formatter, Char> : formatter { - FMT_CONSTEXPR formatter() { - this->fmt_ = detail::string_literal(); - } - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { return this->do_parse(ctx, true); } diff --git a/test/chrono-test.cc b/test/chrono-test.cc index 43f05909..8754587c 100644 --- a/test/chrono-test.cc +++ b/test/chrono-test.cc @@ -16,6 +16,7 @@ using fmt::runtime; using fmt::sys_time; +using fmt::sys_time; using testing::Contains; #if defined(__MINGW32__) && !defined(_UCRT) @@ -238,8 +239,6 @@ TEST(chrono_test, format_to_empty_container) { EXPECT_EQ(s, "42"); } -TEST(chrono_test, empty_result) { EXPECT_EQ(fmt::format("{}", std::tm()), ""); } - TEST(chrono_test, gmtime) { auto t = std::time(nullptr); auto expected = *std::gmtime(&t); @@ -337,6 +336,11 @@ TEST(chrono_test, local_time) { fmt::format_error, "no timezone"); } +TEST(chrono_test, tm) { + auto time = fmt::gmtime(290088000); + test_time(time); +} + TEST(chrono_test, daylight_savings_time_end) { // 2024-10-27 03:05 as the number of seconds since epoch in Europe/Kyiv time. // It is slightly after the DST end and passing it to to_sys will result in