From 04ce6e5febc3a2898321c8deac079ce163038786 Mon Sep 17 00:00:00 2001 From: Andrey Glebov Date: Wed, 6 Jan 2016 19:57:00 +0300 Subject: [PATCH] - fixed false error (returning -1) in time zones without daylight saving (checking against TIME_ZONE_ID_INVALID instead of 0) - accounts for daylight saving only when tm::tm_isdst is true - accounts for standard time offset ([DYNAMIC_]TIME_ZONE_INFORMATION::StandardBias) in time zones that need it --- include/spdlog/details/os.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index 4fadb431..bbf84225 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -170,7 +170,6 @@ inline int utc_minutes_offset(const std::tm& tm = details::os::localtime()) { #ifdef _WIN32 - (void)tm; // avoid unused param warning #if _WIN32_WINNT < _WIN32_WINNT_WS08 TIME_ZONE_INFORMATION tzinfo; auto rv = GetTimeZoneInformation(&tzinfo); @@ -178,9 +177,14 @@ inline int utc_minutes_offset(const std::tm& tm = details::os::localtime()) DYNAMIC_TIME_ZONE_INFORMATION tzinfo; auto rv = GetDynamicTimeZoneInformation(&tzinfo); #endif - if (!rv) + if (rv == TIME_ZONE_ID_INVALID) return -1; - return -1 * (tzinfo.Bias + tzinfo.DaylightBias); + int offset = -tzinfo.Bias; + if (tm.tm_isdst) + offset -= tzinfo.DaylightBias; + else + offset -= tzinfo.StandardBias; + return offset; #else return static_cast(tm.tm_gmtoff / 60); #endif