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 <thiago.macieira@intel.com>
This commit is contained in:
Edward Welbourne 2023-04-25 15:15:29 +02:00
parent 55fe3ee5e7
commit 6aea6c25a5

View File

@ -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<MSECS_PER_SEC>(local) - utcSecs;
int offset = localSecs - utcSecs;
dst = tmLocal.tm_isdst > 0 ? QDateTimePrivate::DaylightTime : QDateTimePrivate::StandardTime;
qint64 jd;
if (Q_UNLIKELY(!QGregorianCalendar::julianFromParts(