Remove duplicate implementation (#3144)

Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>

Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
This commit is contained in:
Vladislav Shchapov 2022-10-17 23:15:28 +05:00 committed by GitHub
parent cd7202e039
commit f67dbc9811
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2071,9 +2071,9 @@ struct formatter<std::chrono::time_point<std::chrono::system_clock, Duration>,
const auto subsecs = std::chrono::duration_cast<Duration>( const auto subsecs = std::chrono::duration_cast<Duration>(
epoch - std::chrono::duration_cast<std::chrono::seconds>(epoch)); epoch - std::chrono::duration_cast<std::chrono::seconds>(epoch));
return formatter<std::tm, Char>::format( return formatter<std::tm, Char>::do_format(
localtime(std::chrono::time_point_cast<std::chrono::seconds>(val)), localtime(std::chrono::time_point_cast<std::chrono::seconds>(val)),
ctx, subsecs); ctx, &subsecs);
} }
return formatter<std::tm, Char>::format( return formatter<std::tm, Char>::format(
@ -2117,6 +2117,22 @@ template <typename Char> struct formatter<std::tm, Char> {
return end; return end;
} }
template <typename FormatContext, typename Duration>
auto do_format(const std::tm& tm, FormatContext& ctx,
const Duration* subsecs) const -> decltype(ctx.out()) {
const auto loc_ref = ctx.locale();
detail::get_locale loc(static_cast<bool>(loc_ref), loc_ref);
auto w = detail::tm_writer<decltype(ctx.out()), Char, Duration>(
loc, ctx.out(), tm, subsecs);
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:
FMT_CONSTEXPR auto parse(basic_format_parse_context<Char>& ctx) FMT_CONSTEXPR auto parse(basic_format_parse_context<Char>& ctx)
-> decltype(ctx.begin()) { -> decltype(ctx.begin()) {
@ -2134,32 +2150,7 @@ 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_ref = ctx.locale(); return do_format<FormatContext, std::chrono::seconds>(tm, ctx, nullptr);
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();
}
template <typename FormatContext, typename Duration>
auto format(const std::tm& tm, FormatContext& ctx,
const Duration& subsecs) const -> decltype(ctx.out()) {
const auto loc_ref = ctx.locale();
detail::get_locale loc(static_cast<bool>(loc_ref), loc_ref);
auto w = detail::tm_writer<decltype(ctx.out()), Char, Duration>(
loc, ctx.out(), tm, &subsecs);
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();
} }
}; };