mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 02:37:36 +02:00
Simplify std::tm formatter
This commit is contained in:
committed by
Victor Zverovich
parent
aa5517f6b9
commit
c089f7d497
@ -1847,18 +1847,6 @@ template <typename Char> struct formatter<std::tm, Char> {
|
|||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename It>
|
|
||||||
It do_format(It out, const std::tm& tm, const std::locale& loc) const {
|
|
||||||
auto w = detail::tm_writer<It, Char>(loc, out, tm);
|
|
||||||
if (spec_ == spec::year_month_day)
|
|
||||||
w.on_iso_date();
|
|
||||||
else if (spec_ == spec::hh_mm_ss)
|
|
||||||
w.on_iso_time();
|
|
||||||
else
|
|
||||||
detail::parse_chrono_format(specs.begin(), specs.end(), w);
|
|
||||||
return w.out();
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
template <typename ParseContext>
|
template <typename ParseContext>
|
||||||
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
|
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
|
||||||
@ -1868,9 +1856,16 @@ template <typename Char> struct formatter<std::tm, Char> {
|
|||||||
template <typename FormatContext>
|
template <typename FormatContext>
|
||||||
auto format(const std::tm& tm, FormatContext& ctx) const
|
auto format(const std::tm& tm, FormatContext& ctx) const
|
||||||
-> decltype(ctx.out()) {
|
-> decltype(ctx.out()) {
|
||||||
const auto loc = ctx.locale();
|
const auto loc_ref = ctx.locale();
|
||||||
return this->do_format(ctx.out(), tm,
|
detail::get_locale loc(static_cast<bool>(loc_ref), loc_ref);
|
||||||
detail::get_locale(static_cast<bool>(loc), loc));
|
auto w = detail::tm_writer<decltype(ctx.out()), Char>(loc, ctx.out(), tm);
|
||||||
|
if (spec_ == spec::year_month_day)
|
||||||
|
w.on_iso_date();
|
||||||
|
else if (spec_ == spec::hh_mm_ss)
|
||||||
|
w.on_iso_time();
|
||||||
|
else
|
||||||
|
detail::parse_chrono_format(specs.begin(), specs.end(), w);
|
||||||
|
return w.out();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user