diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2022-02-24 12:01:29 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2022-03-10 13:42:35 +0100 |
commit | 23302149f24548f1bf658f630def4cde8374af2b (patch) | |
tree | 6b529601c8babfcc79dd6f96f801c9f00d25125b | |
parent | 9be188b0e49a59cbce8469209c468c85e1579c08 (diff) | |
download | qtbase-23302149f24548f1bf658f630def4cde8374af2b.tar.gz |
Fix handling of out-of-range years in QTZP_win
A transition outside the range of qint64 would be mapped to
invalidMSecs(), the same as the fake-detection sets a fake transition
to. This would have lead to a year at the boundary of qint64's range
being mistaken for a fake-DST year. So replace the fakesDst() method,
that compared transition times to invalidMSecs(), with an actual
boolean member that gets set when detecting fake DST, so that the
detection is correctly done.
Change-Id: Iadc80973bc033915733c4a4f4ccfdd3863025fb4
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 8a52555d3fdecae11955dada101f91dc96bc865f)
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
-rw-r--r-- | src/corelib/time/qtimezoneprivate_win.cpp | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/corelib/time/qtimezoneprivate_win.cpp b/src/corelib/time/qtimezoneprivate_win.cpp index 25a2ba5a39..d71508a806 100644 --- a/src/corelib/time/qtimezoneprivate_win.cpp +++ b/src/corelib/time/qtimezoneprivate_win.cpp @@ -344,6 +344,7 @@ struct TransitionTimePair qint64 std, dst; // If either is invalidMSecs(), which shall then be < the other, there is no // DST and the other describes a change in actual standard offset. + bool fakesDst = false; TransitionTimePair(const QWinTimeZonePrivate::QWinTransitionRule &rule, int year, int oldYearOffset) @@ -401,19 +402,17 @@ struct TransitionTimePair if (rule.standardTimeBias + rule.daylightTimeBias == oldYearOffset && isAtStartOfYear(rule.daylightTimeRule, year)) { dst = QTimeZonePrivate::invalidMSecs(); + fakesDst = true; } if (rule.standardTimeBias == oldYearOffset && isAtStartOfYear(rule.standardTimeRule, year)) { + Q_ASSERT_X(!fakesDst, "TransitionTimePair", + "Year with (DST bias zero and) both transitions fake !"); std = QTimeZonePrivate::invalidMSecs(); + fakesDst = true; } } - bool fakesDst() const - { - return std == QTimeZonePrivate::invalidMSecs() - || dst == QTimeZonePrivate::invalidMSecs(); - } - bool startsInDst() const { // Year starts in daylightTimeRule iff it has a valid transition out of @@ -428,9 +427,9 @@ struct TransitionTimePair auto time = isDst ? dst : std; // The isDst we're asked for may be set to the valid one of dst and // std, when fake, but not always - so make sure: - if (time == QTimeZonePrivate::invalidMSecs()) + if (fakesDst && time == QTimeZonePrivate::invalidMSecs()) time = isDst ? std : dst; - return tzp->ruleToData(rule, time, type, fakesDst()); + return tzp->ruleToData(rule, time, type, fakesDst); } }; @@ -681,7 +680,7 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::data(qint64 forMSecsSinceEpoch) cons } return ruleToData(rule, forMSecsSinceEpoch, isDst ? QTimeZone::DaylightTime : QTimeZone::StandardTime, - pair.fakesDst()); + pair.fakesDst); } // Fell off start of rule, try previous rule. } else { |