From 8061c7c8c4f39a2791fee4686877e99ae864b296 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 16 Apr 2025 07:10:16 -0700 Subject: [PATCH] Cleanup duration formatter --- include/fmt/chrono.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index e3855880..e0c81589 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -1694,27 +1694,28 @@ class get_locale { } }; -template +template struct duration_formatter { - locale_ref locale; - OutputIt out; - int precision; - bool localized = false; + using iterator = basic_appender; + iterator out; // rep is unsigned to avoid overflow. using rep = conditional_t::value && sizeof(Rep) < sizeof(int), unsigned, typename make_unsigned_or_unchanged::type>; rep val; + int precision; + locale_ref locale; + bool localized = false; using seconds = std::chrono::duration; seconds s; using milliseconds = std::chrono::duration; bool negative; - using tm_writer_type = tm_writer; + using tm_writer_type = tm_writer; - duration_formatter(locale_ref loc, OutputIt o, - std::chrono::duration d) - : locale(loc), out(o), val(static_cast(d.count())), negative(false) { + duration_formatter(iterator o, std::chrono::duration d, + locale_ref loc) + : out(o), val(static_cast(d.count())), locale(loc), negative(false) { if (d.count() < 0) { val = 0 - val; negative = true; @@ -2172,9 +2173,8 @@ struct formatter, Char> { out = detail::format_duration_value(out, d.count(), precision); detail::format_duration_unit(out); } else { - using duration_formatter = - detail::duration_formatter; - auto f = duration_formatter(ctx.locale(), out, d); + auto f = + detail::duration_formatter(out, d, ctx.locale()); f.precision = precision; f.localized = specs_.localized(); detail::parse_chrono_format(begin, end, f);