mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 10:47:35 +02:00
Cleanup duration formatter
This commit is contained in:
@ -1694,27 +1694,28 @@ class get_locale {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Char, typename OutputIt, typename Rep, typename Period>
|
template <typename Char, typename Rep, typename Period>
|
||||||
struct duration_formatter {
|
struct duration_formatter {
|
||||||
locale_ref locale;
|
using iterator = basic_appender<Char>;
|
||||||
OutputIt out;
|
iterator out;
|
||||||
int precision;
|
|
||||||
bool localized = false;
|
|
||||||
// rep is unsigned to avoid overflow.
|
// rep is unsigned to avoid overflow.
|
||||||
using rep =
|
using rep =
|
||||||
conditional_t<std::is_integral<Rep>::value && sizeof(Rep) < sizeof(int),
|
conditional_t<std::is_integral<Rep>::value && sizeof(Rep) < sizeof(int),
|
||||||
unsigned, typename make_unsigned_or_unchanged<Rep>::type>;
|
unsigned, typename make_unsigned_or_unchanged<Rep>::type>;
|
||||||
rep val;
|
rep val;
|
||||||
|
int precision;
|
||||||
|
locale_ref locale;
|
||||||
|
bool localized = false;
|
||||||
using seconds = std::chrono::duration<rep>;
|
using seconds = std::chrono::duration<rep>;
|
||||||
seconds s;
|
seconds s;
|
||||||
using milliseconds = std::chrono::duration<rep, std::milli>;
|
using milliseconds = std::chrono::duration<rep, std::milli>;
|
||||||
bool negative;
|
bool negative;
|
||||||
|
|
||||||
using tm_writer_type = tm_writer<OutputIt, Char>;
|
using tm_writer_type = tm_writer<iterator, Char>;
|
||||||
|
|
||||||
duration_formatter(locale_ref loc, OutputIt o,
|
duration_formatter(iterator o, std::chrono::duration<Rep, Period> d,
|
||||||
std::chrono::duration<Rep, Period> d)
|
locale_ref loc)
|
||||||
: locale(loc), out(o), val(static_cast<rep>(d.count())), negative(false) {
|
: out(o), val(static_cast<rep>(d.count())), locale(loc), negative(false) {
|
||||||
if (d.count() < 0) {
|
if (d.count() < 0) {
|
||||||
val = 0 - val;
|
val = 0 - val;
|
||||||
negative = true;
|
negative = true;
|
||||||
@ -2172,9 +2173,8 @@ struct formatter<std::chrono::duration<Rep, Period>, Char> {
|
|||||||
out = detail::format_duration_value<Char>(out, d.count(), precision);
|
out = detail::format_duration_value<Char>(out, d.count(), precision);
|
||||||
detail::format_duration_unit<Char, Period>(out);
|
detail::format_duration_unit<Char, Period>(out);
|
||||||
} else {
|
} else {
|
||||||
using duration_formatter =
|
auto f =
|
||||||
detail::duration_formatter<Char, decltype(out), Rep, Period>;
|
detail::duration_formatter<Char, Rep, Period>(out, d, ctx.locale());
|
||||||
auto f = duration_formatter(ctx.locale(), out, d);
|
|
||||||
f.precision = precision;
|
f.precision = precision;
|
||||||
f.localized = specs_.localized();
|
f.localized = specs_.localized();
|
||||||
detail::parse_chrono_format(begin, end, f);
|
detail::parse_chrono_format(begin, end, f);
|
||||||
|
Reference in New Issue
Block a user