From f5437a9d58874d4faebf1f6815056c4d8b176bbb Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 11 Jan 2023 14:09:44 +0100 Subject: [PATCH] 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 --- src/corelib/time/qlocaltime.cpp | 13 ++++++++++--- 1 file 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