From 538535d88fbf749555f49ba277254ea819498cdc Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 22 Aug 2022 19:57:23 +0200 Subject: [PATCH] Use QRoundingDown when converting UTC to local time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It simplifies the code. Also add a comment on why the result is then checked for consistency. Change-Id: Ic2d408c0ea39bc164e9a725284044b7dbd1f287c Reviewed-by: Thiago Macieira Reviewed-by: MÃ¥rten Nordheim --- src/corelib/time/qlocaltime.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/corelib/time/qlocaltime.cpp b/src/corelib/time/qlocaltime.cpp index 19aaeb2540..2314c799c8 100644 --- a/src/corelib/time/qlocaltime.cpp +++ b/src/corelib/time/qlocaltime.cpp @@ -305,11 +305,10 @@ inline bool secondsAndMillisOverflow(qint64 epochSeconds, qint64 millis, qint64 // returns the local milliseconds, offset from UTC and DST status. QDateTimePrivate::ZoneState utcToLocal(qint64 utcMillis) { - const int signFix = utcMillis % MSECS_PER_SEC && utcMillis < 0 ? 1 : 0; - const time_t epochSeconds = utcMillis / MSECS_PER_SEC - signFix; - const int msec = utcMillis % MSECS_PER_SEC + signFix * MSECS_PER_SEC; + const time_t epochSeconds = QRoundingDown::qDiv(utcMillis, MSECS_PER_SEC); + const int msec = utcMillis - epochSeconds * MSECS_PER_SEC; Q_ASSERT(msec >= 0 && msec < MSECS_PER_SEC); - if (qint64(epochSeconds) * MSECS_PER_SEC + msec != utcMillis) + if (qint64(epochSeconds) * MSECS_PER_SEC + msec != utcMillis) // time_t range too narrow return {utcMillis}; tm local;