diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2023-01-11 14:09:44 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2023-01-12 19:03:16 +0100 |
commit | f5437a9d58874d4faebf1f6815056c4d8b176bbb (patch) | |
tree | 26fbee53f61fb608a67bec5a7c25ba8bcdd65186 /src | |
parent | 17a59f661398bf56aeaba4187f55d07eea09c578 (diff) |
Include tzInfo.StandardBias in getCurrentStandardUtcOffset()
It's usually zero, but in principle we should include it (when it's
not flagged to be ignored), see
https://learn.microsoft.com/en-us/windows/win32/api/timezoneapi/ns-timezoneapi-time_zone_information#members
https://learn.microsoft.com/en-us/windows/win32/api/timezoneapi/nf-timezoneapi-gettimezoneinformation
for details.
Task-number: QTBUG-109974
Change-Id: I8b6e0ea31a1cbd0e88f23ab01854e69258b0056b
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/time/qlocaltime.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/corelib/time/qlocaltime.cpp b/src/corelib/time/qlocaltime.cpp index 2314c799c8..cd3c7e5120 100644 --- a/src/corelib/time/qlocaltime.cpp +++ b/src/corelib/time/qlocaltime.cpp @@ -244,8 +244,14 @@ int getCurrentStandardUtcOffset() { #ifdef Q_OS_WIN TIME_ZONE_INFORMATION tzInfo; - GetTimeZoneInformation(&tzInfo); - return -tzInfo.Bias * SECS_PER_MIN; + if (GetTimeZoneInformation(&tzInfo) != TIME_ZONE_ID_INVALID) { + int bias = tzInfo.Bias; // In minutes. + // StandardBias is usually zero, but include it if given: + if (tzInfo.StandardDate.wMonth) // Zero month means ignore StandardBias. + bias += tzInfo.StandardBias; + // MS's bias is +ve in the USA, so minutes *behind* UTC - we want seconds *ahead*: + return -bias * SECS_PER_MIN; + } #else qTzSet(); const time_t curr = time(nullptr); @@ -270,9 +276,10 @@ int getCurrentStandardUtcOffset() return curr - qMkTime(&t); } # endif +#endif // Platform choice + qDebug("Unable to determine current standard time offset from UTC"); // We can't tell, presume UTC. return 0; -#endif // Platform choice } // This is local time's offset (in seconds), at the specified time, including |