From 6aea6c25a5e4e6fa93e44d62139f4f9acc30bd93 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 25 Apr 2023 15:15:29 +0200 Subject: [PATCH] QLocalTime: get offset from correct local time minus UTC time In mapLocalTime(), we've constructed tmLocal from localSeconds, so that's the local time mktime()'s returned utcSecs corresponds to. So use that, rather than freshly dividing the original local milliseconds by 1000 (now rounding down, instead of towards zero), which could lead to an off-by-one error. The intermediate offset miscomputed this way was only used in overflow cases, before being replaced by a more reliable result, but this saves some computation as well as getting those right. Change-Id: Ie34cf53cd2191e277835388fcd62dcf68eaf39c3 Reviewed-by: Thiago Macieira --- src/corelib/time/qlocaltime.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/time/qlocaltime.cpp b/src/corelib/time/qlocaltime.cpp index 84a96a48d48..d2f106cd861 100644 --- a/src/corelib/time/qlocaltime.cpp +++ b/src/corelib/time/qlocaltime.cpp @@ -310,7 +310,7 @@ QDateTimePrivate::ZoneState mapLocalTime(qint64 local, QDateTimePrivate::Dayligh // TODO: for glibc, we could use tmLocal.tm_gmtoff // That would give us offset directly, hence localSecs = offset + utcSecs // Provisional offset, until we have a revised localSeconds: - int offset = QRoundingDown::qDiv(local) - utcSecs; + int offset = localSecs - utcSecs; dst = tmLocal.tm_isdst > 0 ? QDateTimePrivate::DaylightTime : QDateTimePrivate::StandardTime; qint64 jd; if (Q_UNLIKELY(!QGregorianCalendar::julianFromParts(