From 861e1fef8fd5fb6c9a9d6e028207f4a8bacf83bb Mon Sep 17 00:00:00 2001 From: zivshek Date: Fri, 29 Mar 2024 23:46:18 -0400 Subject: [PATCH 01/13] implement year_month_day, also changed weekday, day, month, year's formatter to use formatter so they all support the format strings --- include/fmt/chrono.h | 112 ++++++++++++++++++++++++++++++++----------- test/chrono-test.cc | 38 +++++++++++---- 2 files changed, 114 insertions(+), 36 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 65e6c7e03230..ea9848d7b3eb 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -2040,6 +2040,7 @@ using weekday = std::chrono::weekday; using day = std::chrono::day; using month = std::chrono::month; using year = std::chrono::year; +using year_month_day = std::chrono::year_month_day; #else // A fallback version of weekday. class weekday { @@ -2085,91 +2086,119 @@ class year { constexpr explicit operator int() const noexcept { return value_; } }; -class year_month_day {}; +class year_month_day { + private: + year year_; + month month_; + day day_; + + public: + year_month_day() = default; + constexpr year_month_day(const year& y, const month& m, const day& d) noexcept + : year_(y), month_(m), day_(d) {} + constexpr year year() const noexcept { return year_; } + constexpr month month() const noexcept { return month_; } + constexpr day day() const noexcept { return day_; } +}; #endif -// A rudimentary weekday formatter. -template struct formatter { +template +struct formatter : formatter { private: - bool localized = false; + bool use_tm_formatter_{false}; public: FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()) { - auto begin = ctx.begin(), end = ctx.end(); - if (begin != end && *begin == 'L') { - ++begin; - localized = true; - } - return begin; + use_tm_formatter_ = ctx.begin() != nullptr; + return formatter::parse(ctx); } template auto format(weekday wd, FormatContext& ctx) const -> decltype(ctx.out()) { auto time = std::tm(); time.tm_wday = static_cast(wd.c_encoding()); - detail::get_locale loc(localized, ctx.locale()); + if (use_tm_formatter_) { + return formatter::format(time, ctx); + } + detail::get_locale loc(true, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_abbr_weekday(); return w.out(); } }; -template struct formatter { +template +struct formatter : formatter { + private: + bool use_tm_formatter_{false}; + + public: FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()) { - return ctx.begin(); + use_tm_formatter_ = ctx.begin() != nullptr; + return formatter::parse(ctx); } template auto format(day d, FormatContext& ctx) const -> decltype(ctx.out()) { auto time = std::tm(); time.tm_mday = static_cast(static_cast(d)); - detail::get_locale loc(false, ctx.locale()); + if (use_tm_formatter_) { + return formatter::format(time, ctx); + } + detail::get_locale loc(true, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_day_of_month(detail::numeric_system::standard); return w.out(); } }; -template struct formatter { +template +struct formatter : formatter { private: - bool localized = false; + bool use_tm_formatter_{false}; public: FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()) { - auto begin = ctx.begin(), end = ctx.end(); - if (begin != end && *begin == 'L') { - ++begin; - localized = true; - } - return begin; + use_tm_formatter_ = ctx.begin() != nullptr; + return formatter::parse(ctx); } template auto format(month m, FormatContext& ctx) const -> decltype(ctx.out()) { auto time = std::tm(); - // std::chrono::month has a range of 1-12, std::tm requires 0-11 time.tm_mon = static_cast(static_cast(m)) - 1; - detail::get_locale loc(localized, ctx.locale()); + if (use_tm_formatter_) { + return formatter::format(time, ctx); + } + detail::get_locale loc(true, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_abbr_month(); return w.out(); } }; -template struct formatter { +template +struct formatter : formatter { + private: + bool use_tm_formatter_{false}; + + public: FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()) { - return ctx.begin(); + use_tm_formatter_ = ctx.begin() != nullptr; + return formatter::parse(ctx); } template auto format(year y, FormatContext& ctx) const -> decltype(ctx.out()) { auto time = std::tm(); - // std::tm::tm_year is years since 1900 time.tm_year = static_cast(y) - 1900; + if (use_tm_formatter_) { + return formatter::format(time, ctx); + } detail::get_locale loc(true, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_year(detail::numeric_system::standard); @@ -2177,6 +2206,35 @@ template struct formatter { } }; +template +struct formatter : formatter { + private: + bool use_tm_formatter_{false}; + + public: + FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) + -> decltype(ctx.begin()) { + use_tm_formatter_ = ctx.begin() != nullptr; + return formatter::parse(ctx); + } + + template + auto format(year_month_day val, FormatContext& ctx) const + -> decltype(ctx.out()) { + auto time = std::tm(); + time.tm_year = static_cast(val.year()) - 1900; + time.tm_mon = static_cast(static_cast(val.month())) - 1; + time.tm_mday = static_cast(static_cast(val.day())); + if (use_tm_formatter_) { + return formatter::format(time, ctx); + } + detail::get_locale loc(true, ctx.locale()); + auto w = detail::tm_writer(loc, ctx.out(), time); + w.on_iso_date(); + return w.out(); + } +}; + template struct formatter, Char> { private: diff --git a/test/chrono-test.cc b/test/chrono-test.cc index d692e6c7b19a..2eec03c6ca20 100644 --- a/test/chrono-test.cc +++ b/test/chrono-test.cc @@ -749,20 +749,19 @@ TEST(chrono_test, unsigned_duration) { } TEST(chrono_test, weekday) { - auto loc = get_locale("es_ES.UTF-8"); + auto loc = get_locale("en_US.UTF-8"); std::locale::global(loc); auto sat = fmt::weekday(6); - auto tm = std::tm(); - tm.tm_wday = static_cast(sat.c_encoding()); - EXPECT_EQ(fmt::format("{}", sat), "Sat"); - EXPECT_EQ(fmt::format("{:%a}", tm), "Sat"); + EXPECT_EQ(fmt::format("{:%a}", sat), "Sat"); + EXPECT_EQ(fmt::format("{:%A}", sat), "Saturday"); + loc = get_locale("es_ES.UTF-8"); + std::locale::global(loc); if (loc != std::locale::classic()) { auto saturdays = std::vector{"sáb", "sá."}; - EXPECT_THAT(saturdays, Contains(fmt::format(loc, "{:L}", sat))); - EXPECT_THAT(saturdays, Contains(fmt::format(loc, "{:%a}", tm))); + EXPECT_THAT(saturdays, Contains(fmt::format(loc, "{:%a}", sat))); } } @@ -1014,13 +1013,34 @@ TEST(chrono_test, out_of_range) { } TEST(chrono_test, year_month_day) { - auto loc = get_locale("es_ES.UTF-8"); - std::locale::global(loc); + auto loc = get_locale("en_US.UTF-8"); + std::locale::global(loc); + auto year = fmt::year(2024); auto month = fmt::month(1); auto day = fmt::day(1); + auto ymd = fmt::year_month_day(year, month, day); EXPECT_EQ(fmt::format("{}", year), "2024"); + EXPECT_EQ(fmt::format("{:%Y}", year), "2024"); + EXPECT_EQ(fmt::format("{:%y}", year), "24"); + EXPECT_EQ(fmt::format("{}", month), "Jan"); + EXPECT_EQ(fmt::format("{:%m}", month), "01"); + EXPECT_EQ(fmt::format("{:%b}", month), "Jan"); + EXPECT_EQ(fmt::format("{:%B}", month), "January"); + EXPECT_EQ(fmt::format("{}", day), "01"); + EXPECT_EQ(fmt::format("{:%d}", day), "01"); + + EXPECT_EQ(fmt::format("{}", ymd), "2024-01-01"); + EXPECT_EQ(fmt::format("{:%Y-%m-%d}", ymd), "2024-01-01"); + EXPECT_EQ(fmt::format("{:%Y-%b-%d}", ymd), "2024-Jan-01"); + EXPECT_EQ(fmt::format("{:%Y-%B-%d}", ymd), "2024-January-01"); + + loc = get_locale("es_ES.UTF-8"); + std::locale::global(loc); + if (loc != std::locale::classic()) { + EXPECT_EQ(fmt::format(loc, "{:%b}", month), "ene."); + } } From 652b4c952811dfacf0186307c69255072008c17a Mon Sep 17 00:00:00 2001 From: zivshek Date: Sat, 30 Mar 2024 00:02:29 -0400 Subject: [PATCH 02/13] fix build & test issues --- include/fmt/chrono.h | 12 ++++++------ test/chrono-test.cc | 10 ++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index ea9848d7b3eb..36b4740bc5e9 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -2088,17 +2088,17 @@ class year { class year_month_day { private: - year year_; - month month_; - day day_; + fmt::year year_; + fmt::month month_; + fmt::day day_; public: year_month_day() = default; constexpr year_month_day(const year& y, const month& m, const day& d) noexcept : year_(y), month_(m), day_(d) {} - constexpr year year() const noexcept { return year_; } - constexpr month month() const noexcept { return month_; } - constexpr day day() const noexcept { return day_; } + constexpr fmt::year year() const noexcept { return year_; } + constexpr fmt::month month() const noexcept { return month_; } + constexpr fmt::day day() const noexcept { return day_; } }; #endif diff --git a/test/chrono-test.cc b/test/chrono-test.cc index 2eec03c6ca20..f5c7f1bc4fcb 100644 --- a/test/chrono-test.cc +++ b/test/chrono-test.cc @@ -749,15 +749,14 @@ TEST(chrono_test, unsigned_duration) { } TEST(chrono_test, weekday) { - auto loc = get_locale("en_US.UTF-8"); - std::locale::global(loc); + std::locale::global(std::locale::classic()); auto sat = fmt::weekday(6); EXPECT_EQ(fmt::format("{}", sat), "Sat"); EXPECT_EQ(fmt::format("{:%a}", sat), "Sat"); EXPECT_EQ(fmt::format("{:%A}", sat), "Saturday"); - loc = get_locale("es_ES.UTF-8"); + auto loc = get_locale("es_ES.UTF-8"); std::locale::global(loc); if (loc != std::locale::classic()) { auto saturdays = std::vector{"sáb", "sá."}; @@ -1013,8 +1012,7 @@ TEST(chrono_test, out_of_range) { } TEST(chrono_test, year_month_day) { - auto loc = get_locale("en_US.UTF-8"); - std::locale::global(loc); + std::locale::global(std::locale::classic()); auto year = fmt::year(2024); auto month = fmt::month(1); @@ -1038,7 +1036,7 @@ TEST(chrono_test, year_month_day) { EXPECT_EQ(fmt::format("{:%Y-%b-%d}", ymd), "2024-Jan-01"); EXPECT_EQ(fmt::format("{:%Y-%B-%d}", ymd), "2024-January-01"); - loc = get_locale("es_ES.UTF-8"); + auto loc = get_locale("es_ES.UTF-8"); std::locale::global(loc); if (loc != std::locale::classic()) { EXPECT_EQ(fmt::format(loc, "{:%b}", month), "ene."); From 91bb7ad777377cd420365b3f1d3cd77ca4d7a7bc Mon Sep 17 00:00:00 2001 From: zivshek Date: Sat, 30 Mar 2024 01:05:23 -0400 Subject: [PATCH 03/13] support ":L" for month and weekday --- include/fmt/chrono.h | 28 ++++++++++++++++++++-------- test/chrono-test.cc | 9 ++++----- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 36b4740bc5e9..1d75dedde95e 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -2105,13 +2105,19 @@ class year_month_day { template struct formatter : formatter { private: + bool localized{false}; bool use_tm_formatter_{false}; public: FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()) { - use_tm_formatter_ = ctx.begin() != nullptr; - return formatter::parse(ctx); + auto begin = ctx.begin(), end = ctx.end(); + if (begin != end && *begin == 'L') { + ++begin; + localized = true; + } + use_tm_formatter_ = !localized && (begin != nullptr); + return use_tm_formatter_ ? formatter::parse(ctx) : begin; } template @@ -2121,7 +2127,7 @@ struct formatter : formatter { if (use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(true, ctx.locale()); + detail::get_locale loc(localized, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_abbr_weekday(); return w.out(); @@ -2147,7 +2153,7 @@ struct formatter : formatter { if (use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(true, ctx.locale()); + 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); return w.out(); @@ -2157,13 +2163,19 @@ struct formatter : formatter { template struct formatter : formatter { private: + bool localized{false}; bool use_tm_formatter_{false}; public: FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()) { - use_tm_formatter_ = ctx.begin() != nullptr; - return formatter::parse(ctx); + auto begin = ctx.begin(), end = ctx.end(); + if (begin != end && *begin == 'L') { + ++begin; + localized = true; + } + use_tm_formatter_ = !localized && (begin != nullptr); + return use_tm_formatter_ ? formatter::parse(ctx) : begin; } template @@ -2173,7 +2185,7 @@ struct formatter : formatter { if (use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(true, ctx.locale()); + detail::get_locale loc(localized, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_abbr_month(); return w.out(); @@ -2199,7 +2211,7 @@ struct formatter : formatter { if (use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(true, ctx.locale()); + detail::get_locale loc(false, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_year(detail::numeric_system::standard); return w.out(); diff --git a/test/chrono-test.cc b/test/chrono-test.cc index f5c7f1bc4fcb..584deb307fd3 100644 --- a/test/chrono-test.cc +++ b/test/chrono-test.cc @@ -749,17 +749,18 @@ TEST(chrono_test, unsigned_duration) { } TEST(chrono_test, weekday) { - std::locale::global(std::locale::classic()); + auto loc = get_locale("es_ES.UTF-8"); + std::locale::global(loc); + auto sat = fmt::weekday(6); EXPECT_EQ(fmt::format("{}", sat), "Sat"); EXPECT_EQ(fmt::format("{:%a}", sat), "Sat"); EXPECT_EQ(fmt::format("{:%A}", sat), "Saturday"); - auto loc = get_locale("es_ES.UTF-8"); - std::locale::global(loc); if (loc != std::locale::classic()) { auto saturdays = std::vector{"sáb", "sá."}; + EXPECT_THAT(saturdays, Contains(fmt::format(loc, "{:L}", sat))); EXPECT_THAT(saturdays, Contains(fmt::format(loc, "{:%a}", sat))); } } @@ -1012,8 +1013,6 @@ TEST(chrono_test, out_of_range) { } TEST(chrono_test, year_month_day) { - std::locale::global(std::locale::classic()); - auto year = fmt::year(2024); auto month = fmt::month(1); auto day = fmt::day(1); From e0718a2639d9dfc54a6fe3a8bd7275372eff252c Mon Sep 17 00:00:00 2001 From: zivshek Date: Sat, 30 Mar 2024 01:17:58 -0400 Subject: [PATCH 04/13] add locale test for month --- test/chrono-test.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/test/chrono-test.cc b/test/chrono-test.cc index 584deb307fd3..d5b7f0155a8f 100644 --- a/test/chrono-test.cc +++ b/test/chrono-test.cc @@ -1038,6 +1038,7 @@ TEST(chrono_test, year_month_day) { auto loc = get_locale("es_ES.UTF-8"); std::locale::global(loc); if (loc != std::locale::classic()) { + EXPECT_EQ(fmt::format(loc, "{:L}", month), "ene."); EXPECT_EQ(fmt::format(loc, "{:%b}", month), "ene."); } } From 94def7ac8892daa03c863a094178717cb5ce7d01 Mon Sep 17 00:00:00 2001 From: zivshek Date: Sat, 30 Mar 2024 01:25:46 -0400 Subject: [PATCH 05/13] fix locale test for month --- test/chrono-test.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/chrono-test.cc b/test/chrono-test.cc index d5b7f0155a8f..191adccec907 100644 --- a/test/chrono-test.cc +++ b/test/chrono-test.cc @@ -1038,7 +1038,8 @@ TEST(chrono_test, year_month_day) { auto loc = get_locale("es_ES.UTF-8"); std::locale::global(loc); if (loc != std::locale::classic()) { - EXPECT_EQ(fmt::format(loc, "{:L}", month), "ene."); - EXPECT_EQ(fmt::format(loc, "{:%b}", month), "ene."); + auto months = std::vector{"ene.", "ene"}; + EXPECT_THAT(months, Contains(fmt::format(loc, "{:L}", month))); + EXPECT_THAT(months, Contains(fmt::format(loc, "{:%b}", month))); } } From 6cc5d66e7206064bfd9509a2fb93e9c7be9b4177 Mon Sep 17 00:00:00 2001 From: zivshek Date: Sat, 30 Mar 2024 11:12:10 -0400 Subject: [PATCH 06/13] address comments and abstract the calendar elements into a base class so that we can reuse the parse function --- include/fmt/chrono.h | 97 ++++++++++++++------------------------------ 1 file changed, 31 insertions(+), 66 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 1d75dedde95e..1044afb427c5 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -2042,8 +2042,9 @@ using month = std::chrono::month; using year = std::chrono::year; using year_month_day = std::chrono::year_month_day; #else +class calendar_base {}; // A fallback version of weekday. -class weekday { +class weekday : calendar_base { private: unsigned char value_; @@ -2054,7 +2055,7 @@ class weekday { constexpr auto c_encoding() const noexcept -> unsigned { return value_; } }; -class day { +class day : calendar_base { private: unsigned char value_; @@ -2065,7 +2066,7 @@ class day { constexpr explicit operator unsigned() const noexcept { return value_; } }; -class month { +class month : calendar_base { private: unsigned char value_; @@ -2076,7 +2077,7 @@ class month { constexpr explicit operator unsigned() const noexcept { return value_; } }; -class year { +class year : calendar_base { private: int value_; @@ -2086,7 +2087,7 @@ class year { constexpr explicit operator int() const noexcept { return value_; } }; -class year_month_day { +class year_month_day : calendar_base { private: fmt::year year_; fmt::month month_; @@ -2094,7 +2095,8 @@ class year_month_day { public: year_month_day() = default; - constexpr year_month_day(const year& y, const month& m, const day& d) noexcept + constexpr year_month_day(const fmt::year& y, const fmt::month& m, + const fmt::day& d) noexcept : year_(y), month_(m), day_(d) {} constexpr fmt::year year() const noexcept { return year_; } constexpr fmt::month month() const noexcept { return month_; } @@ -2103,23 +2105,28 @@ class year_month_day { #endif template -struct formatter : formatter { - private: - bool localized{false}; +struct formatter : formatter { + protected: + bool localized_{false}; bool use_tm_formatter_{false}; public: FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()) { - auto begin = ctx.begin(), end = ctx.end(); - if (begin != end && *begin == 'L') { - ++begin; - localized = true; + auto it = ctx.begin(), end = ctx.end(); + if (it != end && *it == 'L') { + ++it; + localized_ = true; } - use_tm_formatter_ = !localized && (begin != nullptr); - return use_tm_formatter_ ? formatter::parse(ctx) : begin; + auto empty = (it == end || *it == '}'); + use_tm_formatter_ = !empty && !localized_; + return use_tm_formatter_ ? formatter::parse(ctx) : it; } +}; +template +struct formatter : formatter { + public: template auto format(weekday wd, FormatContext& ctx) const -> decltype(ctx.out()) { auto time = std::tm(); @@ -2127,7 +2134,7 @@ struct formatter : formatter { if (use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(localized, ctx.locale()); + detail::get_locale loc(localized_, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_abbr_weekday(); return w.out(); @@ -2135,17 +2142,8 @@ struct formatter : formatter { }; template -struct formatter : formatter { - private: - bool use_tm_formatter_{false}; - +struct formatter : formatter { public: - FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) - -> decltype(ctx.begin()) { - use_tm_formatter_ = ctx.begin() != nullptr; - return formatter::parse(ctx); - } - template auto format(day d, FormatContext& ctx) const -> decltype(ctx.out()) { auto time = std::tm(); @@ -2153,7 +2151,7 @@ struct formatter : formatter { if (use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(false, ctx.locale()); + detail::get_locale loc(localized_, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_day_of_month(detail::numeric_system::standard); return w.out(); @@ -2161,23 +2159,8 @@ struct formatter : formatter { }; template -struct formatter : formatter { - private: - bool localized{false}; - bool use_tm_formatter_{false}; - +struct formatter : formatter { public: - FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) - -> decltype(ctx.begin()) { - auto begin = ctx.begin(), end = ctx.end(); - if (begin != end && *begin == 'L') { - ++begin; - localized = true; - } - use_tm_formatter_ = !localized && (begin != nullptr); - return use_tm_formatter_ ? formatter::parse(ctx) : begin; - } - template auto format(month m, FormatContext& ctx) const -> decltype(ctx.out()) { auto time = std::tm(); @@ -2185,7 +2168,7 @@ struct formatter : formatter { if (use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(localized, ctx.locale()); + detail::get_locale loc(localized_, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_abbr_month(); return w.out(); @@ -2193,17 +2176,8 @@ struct formatter : formatter { }; template -struct formatter : formatter { - private: - bool use_tm_formatter_{false}; - +struct formatter : formatter { public: - FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) - -> decltype(ctx.begin()) { - use_tm_formatter_ = ctx.begin() != nullptr; - return formatter::parse(ctx); - } - template auto format(year y, FormatContext& ctx) const -> decltype(ctx.out()) { auto time = std::tm(); @@ -2211,7 +2185,7 @@ struct formatter : formatter { if (use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(false, ctx.locale()); + detail::get_locale loc(localized_, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_year(detail::numeric_system::standard); return w.out(); @@ -2219,17 +2193,8 @@ struct formatter : formatter { }; template -struct formatter : formatter { - private: - bool use_tm_formatter_{false}; - +struct formatter : formatter { public: - FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) - -> decltype(ctx.begin()) { - use_tm_formatter_ = ctx.begin() != nullptr; - return formatter::parse(ctx); - } - template auto format(year_month_day val, FormatContext& ctx) const -> decltype(ctx.out()) { @@ -2240,7 +2205,7 @@ struct formatter : formatter { if (use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(true, ctx.locale()); + detail::get_locale loc(localized_, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_iso_date(); return w.out(); From 87357179489df05838a878cff3b194c2bffcd38b Mon Sep 17 00:00:00 2001 From: zivshek Date: Sat, 30 Mar 2024 11:18:31 -0400 Subject: [PATCH 07/13] fix compile issue in g++ --- include/fmt/chrono.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 1044afb427c5..e067fd166405 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -2131,10 +2131,10 @@ struct formatter : formatter { auto format(weekday wd, FormatContext& ctx) const -> decltype(ctx.out()) { auto time = std::tm(); time.tm_wday = static_cast(wd.c_encoding()); - if (use_tm_formatter_) { + if (this->use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(localized_, ctx.locale()); + detail::get_locale loc(this->localized_, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_abbr_weekday(); return w.out(); @@ -2148,10 +2148,10 @@ struct formatter : formatter { auto format(day d, FormatContext& ctx) const -> decltype(ctx.out()) { auto time = std::tm(); time.tm_mday = static_cast(static_cast(d)); - if (use_tm_formatter_) { + if (this->use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(localized_, ctx.locale()); + detail::get_locale loc(this->localized_, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_day_of_month(detail::numeric_system::standard); return w.out(); @@ -2165,10 +2165,10 @@ struct formatter : formatter { auto format(month m, FormatContext& ctx) const -> decltype(ctx.out()) { auto time = std::tm(); time.tm_mon = static_cast(static_cast(m)) - 1; - if (use_tm_formatter_) { + if (this->use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(localized_, ctx.locale()); + detail::get_locale loc(this->localized_, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_abbr_month(); return w.out(); @@ -2182,10 +2182,10 @@ struct formatter : formatter { auto format(year y, FormatContext& ctx) const -> decltype(ctx.out()) { auto time = std::tm(); time.tm_year = static_cast(y) - 1900; - if (use_tm_formatter_) { + if (this->use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(localized_, ctx.locale()); + detail::get_locale loc(this->localized_, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_year(detail::numeric_system::standard); return w.out(); @@ -2202,10 +2202,10 @@ struct formatter : formatter { time.tm_year = static_cast(val.year()) - 1900; time.tm_mon = static_cast(static_cast(val.month())) - 1; time.tm_mday = static_cast(static_cast(val.day())); - if (use_tm_formatter_) { + if (this->use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(localized_, ctx.locale()); + detail::get_locale loc(this->localized_, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_iso_date(); return w.out(); From be4087b8f0928fad11f7c04395c90c67fbb5136c Mon Sep 17 00:00:00 2001 From: zivshek Date: Sat, 30 Mar 2024 11:32:34 -0400 Subject: [PATCH 08/13] Revert "fix compile issue in g++" This reverts commit 87357179489df05838a878cff3b194c2bffcd38b. --- include/fmt/chrono.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index e067fd166405..1044afb427c5 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -2131,10 +2131,10 @@ struct formatter : formatter { auto format(weekday wd, FormatContext& ctx) const -> decltype(ctx.out()) { auto time = std::tm(); time.tm_wday = static_cast(wd.c_encoding()); - if (this->use_tm_formatter_) { + if (use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(this->localized_, ctx.locale()); + detail::get_locale loc(localized_, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_abbr_weekday(); return w.out(); @@ -2148,10 +2148,10 @@ struct formatter : formatter { auto format(day d, FormatContext& ctx) const -> decltype(ctx.out()) { auto time = std::tm(); time.tm_mday = static_cast(static_cast(d)); - if (this->use_tm_formatter_) { + if (use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(this->localized_, ctx.locale()); + detail::get_locale loc(localized_, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_day_of_month(detail::numeric_system::standard); return w.out(); @@ -2165,10 +2165,10 @@ struct formatter : formatter { auto format(month m, FormatContext& ctx) const -> decltype(ctx.out()) { auto time = std::tm(); time.tm_mon = static_cast(static_cast(m)) - 1; - if (this->use_tm_formatter_) { + if (use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(this->localized_, ctx.locale()); + detail::get_locale loc(localized_, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_abbr_month(); return w.out(); @@ -2182,10 +2182,10 @@ struct formatter : formatter { auto format(year y, FormatContext& ctx) const -> decltype(ctx.out()) { auto time = std::tm(); time.tm_year = static_cast(y) - 1900; - if (this->use_tm_formatter_) { + if (use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(this->localized_, ctx.locale()); + detail::get_locale loc(localized_, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_year(detail::numeric_system::standard); return w.out(); @@ -2202,10 +2202,10 @@ struct formatter : formatter { time.tm_year = static_cast(val.year()) - 1900; time.tm_mon = static_cast(static_cast(val.month())) - 1; time.tm_mday = static_cast(static_cast(val.day())); - if (this->use_tm_formatter_) { + if (use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(this->localized_, ctx.locale()); + detail::get_locale loc(localized_, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_iso_date(); return w.out(); From ea3cff944d14dfb576d52547f84cdd81379ec4e8 Mon Sep 17 00:00:00 2001 From: zivshek Date: Sat, 30 Mar 2024 11:33:59 -0400 Subject: [PATCH 09/13] Revert "address comments and abstract the calendar elements into a base class so that we can reuse the parse function" This reverts commit 6cc5d66e7206064bfd9509a2fb93e9c7be9b4177. --- include/fmt/chrono.h | 97 ++++++++++++++++++++++++++++++-------------- 1 file changed, 66 insertions(+), 31 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 1044afb427c5..1d75dedde95e 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -2042,9 +2042,8 @@ using month = std::chrono::month; using year = std::chrono::year; using year_month_day = std::chrono::year_month_day; #else -class calendar_base {}; // A fallback version of weekday. -class weekday : calendar_base { +class weekday { private: unsigned char value_; @@ -2055,7 +2054,7 @@ class weekday : calendar_base { constexpr auto c_encoding() const noexcept -> unsigned { return value_; } }; -class day : calendar_base { +class day { private: unsigned char value_; @@ -2066,7 +2065,7 @@ class day : calendar_base { constexpr explicit operator unsigned() const noexcept { return value_; } }; -class month : calendar_base { +class month { private: unsigned char value_; @@ -2077,7 +2076,7 @@ class month : calendar_base { constexpr explicit operator unsigned() const noexcept { return value_; } }; -class year : calendar_base { +class year { private: int value_; @@ -2087,7 +2086,7 @@ class year : calendar_base { constexpr explicit operator int() const noexcept { return value_; } }; -class year_month_day : calendar_base { +class year_month_day { private: fmt::year year_; fmt::month month_; @@ -2095,8 +2094,7 @@ class year_month_day : calendar_base { public: year_month_day() = default; - constexpr year_month_day(const fmt::year& y, const fmt::month& m, - const fmt::day& d) noexcept + constexpr year_month_day(const year& y, const month& m, const day& d) noexcept : year_(y), month_(m), day_(d) {} constexpr fmt::year year() const noexcept { return year_; } constexpr fmt::month month() const noexcept { return month_; } @@ -2105,28 +2103,23 @@ class year_month_day : calendar_base { #endif template -struct formatter : formatter { - protected: - bool localized_{false}; +struct formatter : formatter { + private: + bool localized{false}; bool use_tm_formatter_{false}; public: FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()) { - auto it = ctx.begin(), end = ctx.end(); - if (it != end && *it == 'L') { - ++it; - localized_ = true; + auto begin = ctx.begin(), end = ctx.end(); + if (begin != end && *begin == 'L') { + ++begin; + localized = true; } - auto empty = (it == end || *it == '}'); - use_tm_formatter_ = !empty && !localized_; - return use_tm_formatter_ ? formatter::parse(ctx) : it; + use_tm_formatter_ = !localized && (begin != nullptr); + return use_tm_formatter_ ? formatter::parse(ctx) : begin; } -}; -template -struct formatter : formatter { - public: template auto format(weekday wd, FormatContext& ctx) const -> decltype(ctx.out()) { auto time = std::tm(); @@ -2134,7 +2127,7 @@ struct formatter : formatter { if (use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(localized_, ctx.locale()); + detail::get_locale loc(localized, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_abbr_weekday(); return w.out(); @@ -2142,8 +2135,17 @@ struct formatter : formatter { }; template -struct formatter : formatter { +struct formatter : formatter { + private: + bool use_tm_formatter_{false}; + public: + FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) + -> decltype(ctx.begin()) { + use_tm_formatter_ = ctx.begin() != nullptr; + return formatter::parse(ctx); + } + template auto format(day d, FormatContext& ctx) const -> decltype(ctx.out()) { auto time = std::tm(); @@ -2151,7 +2153,7 @@ struct formatter : formatter { if (use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(localized_, ctx.locale()); + 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); return w.out(); @@ -2159,8 +2161,23 @@ struct formatter : formatter { }; template -struct formatter : formatter { +struct formatter : formatter { + private: + bool localized{false}; + bool use_tm_formatter_{false}; + public: + FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) + -> decltype(ctx.begin()) { + auto begin = ctx.begin(), end = ctx.end(); + if (begin != end && *begin == 'L') { + ++begin; + localized = true; + } + use_tm_formatter_ = !localized && (begin != nullptr); + return use_tm_formatter_ ? formatter::parse(ctx) : begin; + } + template auto format(month m, FormatContext& ctx) const -> decltype(ctx.out()) { auto time = std::tm(); @@ -2168,7 +2185,7 @@ struct formatter : formatter { if (use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(localized_, ctx.locale()); + detail::get_locale loc(localized, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_abbr_month(); return w.out(); @@ -2176,8 +2193,17 @@ struct formatter : formatter { }; template -struct formatter : formatter { +struct formatter : formatter { + private: + bool use_tm_formatter_{false}; + public: + FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) + -> decltype(ctx.begin()) { + use_tm_formatter_ = ctx.begin() != nullptr; + return formatter::parse(ctx); + } + template auto format(year y, FormatContext& ctx) const -> decltype(ctx.out()) { auto time = std::tm(); @@ -2185,7 +2211,7 @@ struct formatter : formatter { if (use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(localized_, ctx.locale()); + detail::get_locale loc(false, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_year(detail::numeric_system::standard); return w.out(); @@ -2193,8 +2219,17 @@ struct formatter : formatter { }; template -struct formatter : formatter { +struct formatter : formatter { + private: + bool use_tm_formatter_{false}; + public: + FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) + -> decltype(ctx.begin()) { + use_tm_formatter_ = ctx.begin() != nullptr; + return formatter::parse(ctx); + } + template auto format(year_month_day val, FormatContext& ctx) const -> decltype(ctx.out()) { @@ -2205,7 +2240,7 @@ struct formatter : formatter { if (use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(localized_, ctx.locale()); + detail::get_locale loc(true, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_iso_date(); return w.out(); From 6a24da0ed50a2cdaebfaab331977efdb38fcdea6 Mon Sep 17 00:00:00 2001 From: zivshek Date: Sat, 30 Mar 2024 11:40:00 -0400 Subject: [PATCH 10/13] revert and address comments --- include/fmt/chrono.h | 49 ++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 1d75dedde95e..40b98bdeb8ca 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -2105,19 +2105,20 @@ class year_month_day { template struct formatter : formatter { private: - bool localized{false}; + bool localized_{false}; bool use_tm_formatter_{false}; public: FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()) { - auto begin = ctx.begin(), end = ctx.end(); - if (begin != end && *begin == 'L') { - ++begin; - localized = true; + auto it = ctx.begin(), end = ctx.end(); + if (it != end && *it == 'L') { + ++it; + localized_ = true; } - use_tm_formatter_ = !localized && (begin != nullptr); - return use_tm_formatter_ ? formatter::parse(ctx) : begin; + auto empty = (it == end || *it == '}'); + use_tm_formatter_ = !empty && !localized_; + return use_tm_formatter_ ? formatter::parse(ctx) : it; } template @@ -2127,7 +2128,7 @@ struct formatter : formatter { if (use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(localized, ctx.locale()); + detail::get_locale loc(localized_, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_abbr_weekday(); return w.out(); @@ -2142,8 +2143,9 @@ struct formatter : formatter { public: FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()) { - use_tm_formatter_ = ctx.begin() != nullptr; - return formatter::parse(ctx); + auto it = ctx.begin(), end = ctx.end(); + use_tm_formatter_ = !(it == end || *it == '}'); + return use_tm_formatter_ ? formatter::parse(ctx) : it; } template @@ -2163,19 +2165,20 @@ struct formatter : formatter { template struct formatter : formatter { private: - bool localized{false}; + bool localized_{false}; bool use_tm_formatter_{false}; public: FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()) { - auto begin = ctx.begin(), end = ctx.end(); - if (begin != end && *begin == 'L') { - ++begin; - localized = true; + auto it = ctx.begin(), end = ctx.end(); + if (it != end && *it == 'L') { + ++it; + localized_ = true; } - use_tm_formatter_ = !localized && (begin != nullptr); - return use_tm_formatter_ ? formatter::parse(ctx) : begin; + auto empty = (it == end || *it == '}'); + use_tm_formatter_ = !empty && !localized_; + return use_tm_formatter_ ? formatter::parse(ctx) : it; } template @@ -2185,7 +2188,7 @@ struct formatter : formatter { if (use_tm_formatter_) { return formatter::format(time, ctx); } - detail::get_locale loc(localized, ctx.locale()); + detail::get_locale loc(localized_, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_abbr_month(); return w.out(); @@ -2200,8 +2203,9 @@ struct formatter : formatter { public: FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()) { - use_tm_formatter_ = ctx.begin() != nullptr; - return formatter::parse(ctx); + auto it = ctx.begin(), end = ctx.end(); + use_tm_formatter_ = !(it == end || *it == '}'); + return use_tm_formatter_ ? formatter::parse(ctx) : it; } template @@ -2226,8 +2230,9 @@ struct formatter : formatter { public: FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()) { - use_tm_formatter_ = ctx.begin() != nullptr; - return formatter::parse(ctx); + auto it = ctx.begin(), end = ctx.end(); + use_tm_formatter_ = !(it == end || *it == '}'); + return use_tm_formatter_ ? formatter::parse(ctx) : it; } template From d61d9fb7077177be91db1711356804f43168b0b1 Mon Sep 17 00:00:00 2001 From: zivshek Date: Sat, 30 Mar 2024 20:45:27 -0400 Subject: [PATCH 11/13] change to private inheritance for month etc. and address other comments --- include/fmt/chrono.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 40b98bdeb8ca..2616d8e0d0f0 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -2103,7 +2103,7 @@ class year_month_day { #endif template -struct formatter : formatter { +struct formatter : private formatter { private: bool localized_{false}; bool use_tm_formatter_{false}; @@ -2136,7 +2136,7 @@ struct formatter : formatter { }; template -struct formatter : formatter { +struct formatter : private formatter { private: bool use_tm_formatter_{false}; @@ -2144,7 +2144,7 @@ struct formatter : formatter { FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()) { auto it = ctx.begin(), end = ctx.end(); - use_tm_formatter_ = !(it == end || *it == '}'); + use_tm_formatter_ = (it != end && *it != '}'); return use_tm_formatter_ ? formatter::parse(ctx) : it; } @@ -2163,7 +2163,7 @@ struct formatter : formatter { }; template -struct formatter : formatter { +struct formatter : private formatter { private: bool localized_{false}; bool use_tm_formatter_{false}; @@ -2196,7 +2196,7 @@ struct formatter : formatter { }; template -struct formatter : formatter { +struct formatter : private formatter { private: bool use_tm_formatter_{false}; @@ -2204,7 +2204,7 @@ struct formatter : formatter { FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()) { auto it = ctx.begin(), end = ctx.end(); - use_tm_formatter_ = !(it == end || *it == '}'); + use_tm_formatter_ = (it != end && *it != '}'); return use_tm_formatter_ ? formatter::parse(ctx) : it; } @@ -2223,7 +2223,7 @@ struct formatter : formatter { }; template -struct formatter : formatter { +struct formatter : private formatter { private: bool use_tm_formatter_{false}; @@ -2231,7 +2231,7 @@ struct formatter : formatter { FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()) { auto it = ctx.begin(), end = ctx.end(); - use_tm_formatter_ = !(it == end || *it == '}'); + use_tm_formatter_ = (it != end && *it != '}'); return use_tm_formatter_ ? formatter::parse(ctx) : it; } From dd5223314ab3f0ea760c3fee296213d0f87595b8 Mon Sep 17 00:00:00 2001 From: zivshek Date: Mon, 1 Apr 2024 09:12:12 -0400 Subject: [PATCH 12/13] address the comments --- include/fmt/chrono.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 2616d8e0d0f0..250f197cee1c 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -2114,10 +2114,10 @@ struct formatter : private formatter { auto it = ctx.begin(), end = ctx.end(); if (it != end && *it == 'L') { ++it; - localized_ = true; + use_tm_formatter_ = localized_ = true; + return it; } - auto empty = (it == end || *it == '}'); - use_tm_formatter_ = !empty && !localized_; + use_tm_formatter_ = it != end && *it != '}'; return use_tm_formatter_ ? formatter::parse(ctx) : it; } @@ -2144,7 +2144,7 @@ struct formatter : private formatter { FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()) { auto it = ctx.begin(), end = ctx.end(); - use_tm_formatter_ = (it != end && *it != '}'); + use_tm_formatter_ = it != end && *it != '}'; return use_tm_formatter_ ? formatter::parse(ctx) : it; } @@ -2174,10 +2174,10 @@ struct formatter : private formatter { auto it = ctx.begin(), end = ctx.end(); if (it != end && *it == 'L') { ++it; - localized_ = true; + use_tm_formatter_ = localized_ = true; + return it; } - auto empty = (it == end || *it == '}'); - use_tm_formatter_ = !empty && !localized_; + use_tm_formatter_ = it != end && *it != '}'; return use_tm_formatter_ ? formatter::parse(ctx) : it; } @@ -2204,7 +2204,7 @@ struct formatter : private formatter { FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()) { auto it = ctx.begin(), end = ctx.end(); - use_tm_formatter_ = (it != end && *it != '}'); + use_tm_formatter_ = it != end && *it != '}'; return use_tm_formatter_ ? formatter::parse(ctx) : it; } @@ -2231,7 +2231,7 @@ struct formatter : private formatter { FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()) { auto it = ctx.begin(), end = ctx.end(); - use_tm_formatter_ = (it != end && *it != '}'); + use_tm_formatter_ = it != end && *it != '}'; return use_tm_formatter_ ? formatter::parse(ctx) : it; } From 902d6109a135aeb2523fac4772dde9b753ab9a43 Mon Sep 17 00:00:00 2001 From: zivshek Date: Mon, 1 Apr 2024 09:22:52 -0400 Subject: [PATCH 13/13] fix a logic error --- include/fmt/chrono.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 250f197cee1c..2b2543527eca 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -2114,7 +2114,7 @@ struct formatter : private formatter { auto it = ctx.begin(), end = ctx.end(); if (it != end && *it == 'L') { ++it; - use_tm_formatter_ = localized_ = true; + localized_ = true; return it; } use_tm_formatter_ = it != end && *it != '}'; @@ -2174,7 +2174,7 @@ struct formatter : private formatter { auto it = ctx.begin(), end = ctx.end(); if (it != end && *it == 'L') { ++it; - use_tm_formatter_ = localized_ = true; + localized_ = true; return it; } use_tm_formatter_ = it != end && *it != '}';