From 73649e80c03872851f3b5ad96e061d1b347612b5 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 27 Jun 2013 14:04:08 +0200 Subject: [PATCH] Fix daylight savings code on Windows altogether Reverted the previous change, the local timezone adjustment should not include the daylight savings, because in a long running program that runs across the DST boundary, the timezone doesn't change, but the DST adjustment does. That is why LocalTZA is always used in conjunction with a call to DaylightSavingTA, which unfortunately had a silly bug on Windows: It was assumed that _localtime64_s returns zero on failure, similar to localtime_r on Unix. However it is exactly the opposite, zero is returned on success and an error code is returned on failure. Change-Id: Ib324f09f290870630b66793882c5b121de445f05 Reviewed-by: Lars Knoll --- src/qml/qml/v4/qv4dateobject.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/qml/qml/v4/qv4dateobject.cpp b/src/qml/qml/v4/qv4dateobject.cpp index b40820a..3cf6cb1 100644 --- a/src/qml/qml/v4/qv4dateobject.cpp +++ b/src/qml/qml/v4/qv4dateobject.cpp @@ -299,7 +299,8 @@ static inline double DaylightSavingTA(double t) struct tm tmtm; #if defined(_MSC_VER) && _MSC_VER >= 1400 __time64_t tt = (__time64_t)(t / msPerSecond); - if (!_localtime64_s(&tmtm, &tt)) + // _localtime_64_s returns non-zero on failure + if (_localtime64_s(&tmtm, &tt) != 0) #else long int tt = (long int)(t / msPerSecond); if (!localtime_r((const time_t*) &tt, &tmtm)) @@ -634,10 +635,8 @@ static double getLocalTZA() return double(locl - globl) * 1000.0; #else TIME_ZONE_INFORMATION tzInfo; - LONG daylightBias = 0; - if (GetTimeZoneInformation(&tzInfo) == TIME_ZONE_ID_DAYLIGHT) - daylightBias = tzInfo.DaylightBias; - return -(tzInfo.Bias + daylightBias)* 60.0 * 1000.0; + GetTimeZoneInformation(&tzInfo); + return -tzInfo.Bias * 60.0 * 1000.0; #endif } -- 2.7.4