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>bb10
parent
ef1ff65b0a
commit
538535d88f
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue