diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 06aaaf15..f227dba8 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -22,6 +22,10 @@ #include "format.h" +namespace fmt_detail { +template inline void _tzset(T...) {} +} // namespace fmt_detail + FMT_BEGIN_NAMESPACE // Check if std::chrono::local_t is available. @@ -42,20 +46,6 @@ FMT_BEGIN_NAMESPACE # endif #endif -// Enable tzset. -#ifndef FMT_USE_TZSET -// UWP doesn't provide _tzset. -# if FMT_HAS_INCLUDE("winapifamily.h") -# include -# endif -# if defined(_WIN32) && (!defined(WINAPI_FAMILY) || \ - (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)) -# define FMT_USE_TZSET 1 -# else -# define FMT_USE_TZSET 0 -# endif -#endif - // Enable safe chrono durations, unless explicitly disabled. #ifndef FMT_SAFE_DURATION_CAST # define FMT_SAFE_DURATION_CAST 1 @@ -1060,15 +1050,14 @@ template struct has_member_data_tm_zone> : std::true_type {}; -#if FMT_USE_TZSET inline void tzset_once() { - static bool init = []() -> bool { + static bool init = []() { + using namespace fmt_detail; _tzset(); - return true; + return false; }(); ignore_unused(init); } -#endif // Converts value to Int and checks that it's in the range [0, upper). template ::value)> @@ -1119,7 +1108,7 @@ void write_fractional_seconds(OutputIt& out, Duration d, int precision = -1) { using subsecond_precision = std::chrono::duration< typename std::common_type::type, - std::ratio<1, detail::pow10(num_fractional_digits)>>; + std::ratio<1, pow10(num_fractional_digits)>>; const auto fractional = d - detail::duration_cast(d); const auto subseconds = @@ -1128,7 +1117,7 @@ void write_fractional_seconds(OutputIt& out, Duration d, int precision = -1) { ? fractional.count() : detail::duration_cast(fractional).count(); auto n = static_cast>(subseconds); - const int num_digits = detail::count_digits(n); + const int num_digits = count_digits(n); int leading_zeroes = (std::max)(0, num_fractional_digits - num_digits); if (precision < 0) { @@ -1146,13 +1135,11 @@ void write_fractional_seconds(OutputIt& out, Duration d, int precision = -1) { out = detail::fill_n(out, leading_zeroes, '0'); if (remaining < num_digits) { int num_truncated_digits = num_digits - remaining; - n /= to_unsigned(detail::pow10(to_unsigned(num_truncated_digits))); - if (n) { - out = format_decimal(out, n, remaining); - } + n /= to_unsigned(pow10(to_unsigned(num_truncated_digits))); + if (n != 0) out = format_decimal(out, n, remaining); return; } - if (n) { + if (n != 0) { out = format_decimal(out, n, num_digits); remaining -= num_digits; } @@ -1332,6 +1319,7 @@ class tm_writer { if (ns != numeric_system::standard) *out_++ = ':'; write2(static_cast(offset % 60)); } + template ::value)> void format_utc_offset_impl(const T& tm, numeric_system ns) { write_utc_offset(tm.tm_gmtoff, ns); @@ -1339,9 +1327,7 @@ class tm_writer { template ::value)> void format_utc_offset_impl(const T& tm, numeric_system ns) { #if defined(_WIN32) && defined(_UCRT) -# if FMT_USE_TZSET tzset_once(); -# endif long offset = 0; _get_timezone(&offset); if (tm.tm_isdst) { diff --git a/include/fmt/format.h b/include/fmt/format.h index 622a2042..99596a13 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -586,9 +586,7 @@ FMT_CONSTEXPR auto fill_n(OutputIt out, Size count, const T& value) } template FMT_CONSTEXPR20 auto fill_n(T* out, Size count, char value) -> T* { - if (is_constant_evaluated()) { - return fill_n(out, count, value); - } + if (is_constant_evaluated()) return fill_n(out, count, value); std::memset(out, value, to_unsigned(count)); return out + count; }