From 2842b98bd9f044c3fb81c8a6a08b94d634134bc7 Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Thu, 23 Dec 2021 17:17:47 +0500 Subject: [PATCH] Fix issue #2670 --- include/fmt/chrono.h | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 5285d4201439..73ad85583b57 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -1076,34 +1076,41 @@ template class tm_writer { write2(static_cast(offset / 60)); write2(static_cast(offset % 60)); } - void format_utc_offset_impl(std::true_type) { - write_utc_offset(tm_.tm_gmtoff); + template ::value)> + void format_utc_offset_impl(const T& tm) { + write_utc_offset(tm.tm_gmtoff); } - void format_utc_offset_impl(std::false_type) { + template ::value)> + void format_utc_offset_impl(const T& tm) { #if defined(_WIN32) # if FMT_USE_TZSET tzset_once(); # endif long offset = 0; _get_timezone(&offset); - if (tm_.tm_isdst) { + if (tm.tm_isdst) { long dstbias = 0; _get_dstbias(&dstbias); offset += dstbias; } write_utc_offset(-offset); #else + ignore_unused(tm); format_localized('z'); #endif } - void format_tz_name_impl(std::true_type) { + template ::value)> + void format_tz_name_impl(const T& tm) { if (is_classic_) - out_ = write_tm_str(out_, tm_.tm_zone, loc_); + out_ = write_tm_str(out_, tm.tm_zone, loc_); else format_localized('Z'); } - void format_tz_name_impl(std::false_type) { format_localized('Z'); } + template ::value)> + void format_tz_name_impl(const T&) { + format_localized('Z'); + } void format_localized(char format, char modifier = 0) { out_ = write(out_, tm_, loc_, format, modifier); @@ -1211,10 +1218,8 @@ template class tm_writer { out_ = copy_str(std::begin(buf) + offset, std::end(buf), out_); } - void on_utc_offset() { - format_utc_offset_impl(has_member_data_tm_gmtoff{}); - } - void on_tz_name() { format_tz_name_impl(has_member_data_tm_zone{}); } + void on_utc_offset() { format_utc_offset_impl(tm_); } + void on_tz_name() { format_tz_name_impl(tm_); } void on_year(numeric_system ns) { if (is_classic_ || ns == numeric_system::standard)