From dfbb952b2ccda738742d3903df159d32f890876e Mon Sep 17 00:00:00 2001 From: Shawn Zhong Date: Mon, 16 Jan 2023 13:48:00 -0600 Subject: [PATCH] Fix empty spec for time point (#3275) --- include/fmt/chrono.h | 2 +- test/chrono-test.cc | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index b48b0d98..680d829e 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -2180,7 +2180,7 @@ template struct formatter { FMT_CONSTEXPR auto do_parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()) { auto begin = ctx.begin(), end = ctx.end(); - if (begin == end || *begin == '}') return end; + if (begin == end || *begin == '}') return begin; begin = detail::parse_align(begin, end, specs); if (begin == end) return end; diff --git a/test/chrono-test.cc b/test/chrono-test.cc index 2d20013f..b3bb22a2 100644 --- a/test/chrono-test.cc +++ b/test/chrono-test.cc @@ -259,6 +259,7 @@ TEST(chrono_test, system_clock_time_point) { std::chrono::system_clock::now()); EXPECT_EQ(strftime_full_utc(t1), fmt::format("{:%Y-%m-%d %H:%M:%S}", t1)); EXPECT_EQ(strftime_full_utc(t1), fmt::format("{}", t1)); + EXPECT_EQ(strftime_full_utc(t1), fmt::format("{:}", t1)); using time_point = std::chrono::time_point; auto t2 = time_point(std::chrono::seconds(42)); @@ -365,6 +366,7 @@ TEST(chrono_test, local_system_clock_time_point) { std::chrono::current_zone()->to_local(std::chrono::system_clock::now())); EXPECT_EQ(strftime_full_local(t1), fmt::format("{:%Y-%m-%d %H:%M:%S}", t1)); EXPECT_EQ(strftime_full_local(t1), fmt::format("{}", t1)); + EXPECT_EQ(strftime_full_local(t1), fmt::format("{:}", t1)); using time_point = std::chrono::local_time; auto t2 = time_point(std::chrono::seconds(86400 + 42)); EXPECT_EQ(strftime_full_local(t2), fmt::format("{:%Y-%m-%d %H:%M:%S}", t2));