- 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
This commit is contained in:
parent
6cdab9e840
commit
04ce6e5feb
@ -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<int>(tm.tm_gmtoff / 60);
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user