diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index bf83ce00..f47f1758 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -676,12 +676,10 @@ enum class numeric_system { // Glibc extensions for formatting numeric values. enum class pad_type { - unspecified, + // Pad a numeric result string with zeros (the default). + zero, // Do not pad a numeric result string. none, - // Pad a numeric result string with zeros even if the conversion specifier - // character uses space-padding by default. - zero, // Pad a numeric result string with spaces. space, }; @@ -706,7 +704,7 @@ FMT_CONSTEXPR auto parse_chrono_format(const Char* begin, const Char* end, if (*begin != '%') FMT_THROW(format_error("invalid format")); auto ptr = begin; while (ptr != end) { - pad_type pad = pad_type::unspecified; + pad_type pad = pad_type::zero; auto c = *ptr; if (c == '}') break; if (c != '%') { @@ -726,10 +724,6 @@ FMT_CONSTEXPR auto parse_chrono_format(const Char* begin, const Char* end, pad = pad_type::none; ++ptr; break; - case '0': - pad = pad_type::zero; - ++ptr; - break; } if (ptr == end) FMT_THROW(format_error("invalid format")); c = *ptr++; @@ -1637,7 +1631,7 @@ class tm_writer { void on_iso_time() { on_24_hour_time(); *out_++ = ':'; - on_second(numeric_system::standard, pad_type::unspecified); + on_second(numeric_system::standard, pad_type::zero); } void on_am_pm() { @@ -1878,7 +1872,7 @@ struct chrono_formatter { } } - void write(Rep value, int width, pad_type pad = pad_type::unspecified) { + void write(Rep value, int width, pad_type pad = pad_type::zero) { write_sign(); if (isnan(value)) return write_nan(); uint32_or_64_or_128_t n = @@ -2011,7 +2005,7 @@ struct chrono_formatter { on_24_hour_time(); *out++ = ':'; if (handle_nan_inf()) return; - on_second(numeric_system::standard, pad_type::unspecified); + on_second(numeric_system::standard, pad_type::zero); } void on_am_pm() { @@ -2151,7 +2145,7 @@ struct formatter : private formatter { detail::get_locale loc(false, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_day_of_month(detail::numeric_system::standard, - detail::pad_type::unspecified); + detail::pad_type::zero); return w.out(); } }; diff --git a/test/chrono-test.cc b/test/chrono-test.cc index 0a70210d..5befcab6 100644 --- a/test/chrono-test.cc +++ b/test/chrono-test.cc @@ -971,13 +971,11 @@ TEST(chrono_test, glibc_extensions) { std::chrono::seconds(3); EXPECT_EQ(fmt::format("{:%I,%H,%M,%S}", d), "01,01,02,03"); - EXPECT_EQ(fmt::format("{:%0I,%0H,%0M,%0S}", d), "01,01,02,03"); EXPECT_EQ(fmt::format("{:%_I,%_H,%_M,%_S}", d), " 1, 1, 2, 3"); EXPECT_EQ(fmt::format("{:%-I,%-H,%-M,%-S}", d), "1,1,2,3"); EXPECT_EQ(fmt::format("{:%-I,%H,%M,%S}", d), "1,01,02,03"); EXPECT_EQ(fmt::format("{:%OI,%OH,%OM,%OS}", d), "01,01,02,03"); - EXPECT_EQ(fmt::format("{:%0OI,%0OH,%0OM,%0OS}", d), "01,01,02,03"); EXPECT_EQ(fmt::format("{:%_OI,%_OH,%_OM,%_OS}", d), " 1, 1, 2, 3"); EXPECT_EQ(fmt::format("{:%-OI,%-OH,%-OM,%-OS}", d), "1,1,2,3"); } @@ -985,12 +983,10 @@ TEST(chrono_test, glibc_extensions) { { const auto tm = make_tm(1970, 1, 1, 1, 2, 3); EXPECT_EQ(fmt::format("{:%I,%H,%M,%S}", tm), "01,01,02,03"); - EXPECT_EQ(fmt::format("{:%0I,%0H,%0M,%0S}", tm), "01,01,02,03"); EXPECT_EQ(fmt::format("{:%_I,%_H,%_M,%_S}", tm), " 1, 1, 2, 3"); EXPECT_EQ(fmt::format("{:%-I,%-H,%-M,%-S}", tm), "1,1,2,3"); EXPECT_EQ(fmt::format("{:%OI,%OH,%OM,%OS}", tm), "01,01,02,03"); - EXPECT_EQ(fmt::format("{:%0OI,%0OH,%0OM,%0OS}", tm), "01,01,02,03"); EXPECT_EQ(fmt::format("{:%_OI,%_OH,%_OM,%_OS}", tm), " 1, 1, 2, 3"); EXPECT_EQ(fmt::format("{:%-OI,%-OH,%-OM,%-OS}", tm), "1,1,2,3"); } @@ -998,7 +994,6 @@ TEST(chrono_test, glibc_extensions) { { const auto d = std::chrono::seconds(3) + std::chrono::milliseconds(140); EXPECT_EQ(fmt::format("{:%S}", d), "03.140"); - EXPECT_EQ(fmt::format("{:%0S}", d), "03.140"); EXPECT_EQ(fmt::format("{:%_S}", d), " 3.140"); EXPECT_EQ(fmt::format("{:%-S}", d), "3.140"); } @@ -1006,7 +1001,6 @@ TEST(chrono_test, glibc_extensions) { { auto d = std::chrono::duration(3.14); EXPECT_EQ(fmt::format("{:%S}", d), "03.140000"); - EXPECT_EQ(fmt::format("{:%0S}", d), "03.140000"); EXPECT_EQ(fmt::format("{:%_S}", d), " 3.140000"); EXPECT_EQ(fmt::format("{:%-S}", d), "3.140000"); } @@ -1015,7 +1009,6 @@ TEST(chrono_test, glibc_extensions) { auto t = std::tm(); t.tm_yday = 7; EXPECT_EQ(fmt::format("{:%U,%W,%V}", t), "02,01,01"); - EXPECT_EQ(fmt::format("{:%0U,%0W,%0V}", t), "02,01,01"); EXPECT_EQ(fmt::format("{:%_U,%_W,%_V}", t), " 2, 1, 1"); EXPECT_EQ(fmt::format("{:%-U,%-W,%-V}", t), "2,1,1"); } @@ -1024,7 +1017,6 @@ TEST(chrono_test, glibc_extensions) { auto t = std::tm(); t.tm_mday = 7; EXPECT_EQ(fmt::format("{:%d}", t), "07"); - EXPECT_EQ(fmt::format("{:%0d}", t), "07"); EXPECT_EQ(fmt::format("{:%_d}", t), " 7"); EXPECT_EQ(fmt::format("{:%-d}", t), "7");