From 6a186bcd66bd2a808aae23588bcaf7861b95e638 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 21 Dec 2022 14:51:23 -0800 Subject: [PATCH] Localize FMT_USE_LOCAL_TIME --- include/fmt/chrono.h | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 8a1e5a9b..a40576a1 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -462,7 +462,6 @@ auto write(OutputIt out, const std::tm& time, const std::locale& loc, FMT_MODULE_EXPORT_BEGIN -#if FMT_USE_LOCAL_TIME /** Converts given time since epoch as ``std::time_t`` value into calendar time, expressed in local time. Unlike ``std::localtime``, this function is @@ -504,10 +503,11 @@ inline std::tm localtime(std::time_t time) { return lt.tm_; } -template -inline std::tm localtime( - std::chrono::local_time time_point) { - return localtime(std::chrono::system_clock::to_time_t(std::chrono::current_zone()->to_sys(time_point))); +#if FMT_USE_LOCAL_TIME +template +inline auto localtime(std::chrono::local_time time) -> std::tm { + return localtime(std::chrono::system_clock::to_time_t( + std::chrono::current_zone()->to_sys(time))); } #endif @@ -2124,20 +2124,19 @@ struct formatter, epoch - std::chrono::duration_cast(epoch)); return formatter::do_format( - gmtime(std::chrono::time_point_cast(val)), - ctx, &subsecs); + gmtime(std::chrono::time_point_cast(val)), ctx, + &subsecs); } return formatter::format( - gmtime(std::chrono::time_point_cast(val)), - ctx); + gmtime(std::chrono::time_point_cast(val)), ctx); } }; #if FMT_USE_LOCAL_TIME template -struct formatter, - Char> : formatter { +struct formatter, Char> + : formatter { FMT_CONSTEXPR formatter() { basic_string_view default_specs = detail::string_literal{}; @@ -2145,8 +2144,8 @@ struct formatter, } template - auto format(std::chrono::local_time val, - FormatContext& ctx) const -> decltype(ctx.out()) { + auto format(std::chrono::local_time val, FormatContext& ctx) const + -> decltype(ctx.out()) { using period = typename Duration::period; if (period::num != 1 || period::den != 1 || std::is_floating_point::value) {