Skip to content

Commit

Permalink
Simplify std::tm formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
phprus committed Nov 12, 2021
1 parent 936c542 commit 6ee9334
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions include/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -1848,18 +1848,6 @@ template <typename Char> struct formatter<std::tm, Char> {
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:
template <typename ParseContext>
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
Expand All @@ -1870,8 +1858,15 @@ template <typename Char> struct formatter<std::tm, Char> {
auto format(const std::tm& tm, FormatContext& ctx) const
-> decltype(ctx.out()) {
const auto loc_ref = ctx.locale();
return this->do_format(
ctx.out(), tm, detail::get_locale{static_cast<bool>(loc_ref), loc_ref});
detail::get_locale loc{static_cast<bool>(loc_ref), loc_ref};
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();
}
};

Expand Down

0 comments on commit 6ee9334

Please sign in to comment.