diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2022-02-23 12:22:44 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2022-03-08 14:08:58 +0100 |
commit | 08bfd7455587c027dcef354c45530af487da32df (patch) | |
tree | 88d0569a3131c09e174b6a86bb6ba75e6ac2594f /src | |
parent | 5dabd52a4ae2b33cec762dba538bfeaf05df03a1 (diff) |
Clip dataForLocalTime()'s bracketing window's start to minMSecs() + 1
The minMSecs() itself is one more than the type's min(), which is used
as invalidMSecs(). As (at least) the Windows back-end uses minMSecs()
as the time of a start-of-time transition (that we'd like to find as
our current transition), use one more than it as lower-bound for where
to search from for a previous transition, so that we do find that
first ever transition.
Change-Id: Iae861e740e02bd38ffb2af77aff625d3b48182d2
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit 4959f8a34b6eacd7c726d9166d04954376a7e5bf)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/time/qtimezoneprivate.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/corelib/time/qtimezoneprivate.cpp b/src/corelib/time/qtimezoneprivate.cpp index a85617718d..e3f392230a 100644 --- a/src/corelib/time/qtimezoneprivate.cpp +++ b/src/corelib/time/qtimezoneprivate.cpp @@ -225,14 +225,18 @@ QTimeZonePrivate::Data QTimeZonePrivate::dataForLocalTime(qint64 forLocalMSecs, static_assert(-sixteenHoursInMSecs / 1000 < QTimeZone::MinUtcOffsetSecs && sixteenHoursInMSecs / 1000 > QTimeZone::MaxUtcOffsetSecs); qint64 millis; + // Clip the bracketing times to the bounds of the supported range. Exclude + // minMSecs(), because at least one backend (Windows) uses it for a + // start-of-time fake transition, that we want previousTransition() to find. const qint64 recent = - sub_overflow(forLocalMSecs, sixteenHoursInMSecs, &millis) - ? minMSecs() : millis; + sub_overflow(forLocalMSecs, sixteenHoursInMSecs, &millis) || millis <= minMSecs() + ? minMSecs() + 1 : millis; // Necessarily <= forLocalMSecs + 2. + // (Given that minMSecs() is std::numeric_limits<qint64>::min() + 1.) const qint64 imminent = add_overflow(forLocalMSecs, sixteenHoursInMSecs, &millis) - ? maxMSecs() : millis; - // At most one of those took the boundary value: - Q_ASSERT(recent < imminent && sixteenHoursInMSecs < imminent - recent + 1); + ? maxMSecs() : millis; // Necessarily >= forLocalMSecs + // At most one of those was clipped to its boundary value: + Q_ASSERT(recent < imminent && sixteenHoursInMSecs < imminent - recent + 2); /* Offsets are Local - UTC, positive to the east of Greenwich, negative to the west; DST offset always exceeds standard offset, when DST applies. |