From 04419c2852463e9f0e25e108dd3300a29cd885f8 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 8 Oct 2021 13:20:28 +0200 Subject: [PATCH] Set tm_isdst = -1 before calling mktime() Leaving it set to 0 will cause mktime() to interpret other fields as in standard time, potentially "correcting" them and tm_isdst to represent the equivalent moment in daylight-saving time. Set it to -1 to tell mktime() to let the system work out whether the time is standard or daylight-saving. Change-Id: Id33d4cb0afdb14f236ca5ce04cf605610a30d712 Reviewed-by: Thiago Macieira --- src/corelib/time/qdatetime.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index 0d836fa9367..f8b9724604e 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -2726,6 +2726,7 @@ static auto computeSystemMillisRange() local.tm_year = tmYearFromQYear(1901); local.tm_mon = 11; local.tm_mday = 15; // A day and a bit after the start of 32-bit time_t: + local.tm_isdst = -1; return R{qMkTime(&local) == -1 ? 0 : msecsMin, msecsMax, false, false}; } else { const struct { int year; qint64 millis; } starts[] = { @@ -2754,6 +2755,7 @@ static auto computeSystemMillisRange() local.tm_mday = 31; local.tm_hour = 23; local.tm_min = local.tm_sec = 59; + local.tm_isdst = -1; if (qMkTime(&local) != -1) { stop = c.millis; break; @@ -2766,6 +2768,7 @@ static auto computeSystemMillisRange() local.tm_year = tmYearFromQYear(c.year); local.tm_mon = 1; local.tm_mday = 1; + local.tm_isdst = -1; if (qMkTime(&local) != -1) return R{c.millis, stop, startMin, stopMax}; startMin = false;