diff options
| author | Edward Welbourne <edward.welbourne@qt.io> | 2022-08-22 19:57:23 +0200 |
|---|---|---|
| committer | Edward Welbourne <edward.welbourne@qt.io> | 2022-08-25 20:34:54 +0200 |
| commit | 538535d88fbf749555f49ba277254ea819498cdc (patch) | |
| tree | f537f08056809ea7b41f06c7222944c9b21a4f5c /src/corelib/time/qlocaltime.cpp | |
| parent | ef1ff65b0a3da280a33dacf94e9c3d54ba42671d (diff) | |
Use QRoundingDown when converting UTC to local time
It simplifies the code.
Also add a comment on why the result is then checked for consistency.
Change-Id: Ic2d408c0ea39bc164e9a725284044b7dbd1f287c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/time/qlocaltime.cpp')
| -rw-r--r-- | src/corelib/time/qlocaltime.cpp | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/corelib/time/qlocaltime.cpp b/src/corelib/time/qlocaltime.cpp index 19aaeb25408..2314c799c82 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; |
