diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2021-02-24 13:27:15 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2021-03-01 16:44:43 +0100 |
commit | 5af6b59b6e7d1b88de219570011ea482603ea684 (patch) | |
tree | b3f0acd40bcb4ed97ae719d65f108a910f1ece2a /src/corelib/time/qdatetime.cpp | |
parent | 902505a0584959fed9d0784ab5308f9d70fe68a9 (diff) |
Rework an assertion to eliminate a common sub-expression using a lambda
This take more lines but makes the condition clearer and the lines
shorter, even after converting to use the names for constants in the
condition.
Change-Id: I9e5b7b79ff62095ed11b8723be238444fd32d9c1
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/time/qdatetime.cpp')
-rw-r--r-- | src/corelib/time/qdatetime.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index 9e9f0912a1..6818837e8c 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -3203,14 +3203,15 @@ inline qint64 QDateTimePrivate::zoneMSecsToEpochMSecs(qint64 zoneMSecs, const QT // Get the effective data from QTimeZone QTimeZonePrivate::Data data = zone.d->dataForLocalTime(zoneMSecs, int(hint)); Q_ASSERT(zone.d->offsetFromUtc(data.atMSecsSinceEpoch) == data.offsetFromUtc); - Q_ASSERT((zoneMSecs - data.atMSecsSinceEpoch) / 1000 == data.offsetFromUtc - // If zoneMSecs fell in a spring-forward's gap, we get this instead: - || (zoneMSecs - data.atMSecsSinceEpoch) / 1000 == data.standardTimeOffset - // If we have a second DST, like in Europe/Berlin 1947 (mid-summer time). - // If zoneMSecs fell in a gap at beginning of mid-summer time, we get this instead: - || (zoneMSecs - data.atMSecsSinceEpoch) / 1000 == 2 * data.standardTimeOffset - // If it fell in a skipped day (Pacific date-line crossings), this happens: - || (data.offsetFromUtc - (zoneMSecs - data.atMSecsSinceEpoch) / 1000) % 86400 == 0); + Q_ASSERT(([data](qint64 offset) { + return offset == data.offsetFromUtc + // When zoneMSecs falls in a spring-forward's gap: + || offset == data.standardTimeOffset + // When it falls in the gap leading into double-DST: + || offset == 2 * data.standardTimeOffset + // When it falls in a skipped day (Pacific date-line crossings): + || (data.offsetFromUtc - offset) % SECS_PER_DAY == 0; + })((zoneMSecs - data.atMSecsSinceEpoch) / MSECS_PER_SEC)); // Docs state any time before 1970-01-01 will *not* have any DST applied // but all affected times afterwards will have DST applied. if (data.atMSecsSinceEpoch < 0) { |