diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2022-01-25 16:14:04 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2022-02-02 19:36:43 +0100 |
commit | d98b43005eed051a77beacb252c7a9eb7f5c4493 (patch) | |
tree | 19bd82ae26584da9d8f156009db2087af2158161 /src/corelib/time/qtimezoneprivate_win.cpp | |
parent | 830fd1908ba14d434d1715304a430b62d0281eee (diff) |
Nail down handling of nextTransition() when before the first rule
Avoid, for years before the first rule, a whole lot of complications
needed when handling dates later than that rule's start. It is not
entirely clear the code would previously have Done The Right Thing; it
now is clear what it does.
Change-Id: I00a79c0a4733f1deb0bbfecb03e1c64a104d08a3
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/corelib/time/qtimezoneprivate_win.cpp')
-rw-r--r-- | src/corelib/time/qtimezoneprivate_win.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/corelib/time/qtimezoneprivate_win.cpp b/src/corelib/time/qtimezoneprivate_win.cpp index f6ee2c60d9..eda46f8b9b 100644 --- a/src/corelib/time/qtimezoneprivate_win.cpp +++ b/src/corelib/time/qtimezoneprivate_win.cpp @@ -412,7 +412,7 @@ QLocale::Territory userTerritory() : QLocale::AnyTerritory; } -// Index of last rule in rules with .startYear <= year: +// Index of last rule in rules with .startYear <= year, or 0 if none satisfies that: int ruleIndexForYear(const QList<QWinTimeZonePrivate::QWinTransitionRule> &rules, int year) { if (rules.last().startYear <= year) @@ -671,8 +671,17 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::nextTransition(qint64 afterMSecsSinc const QWinTransitionRule &rule = m_tranRules.at(ruleIndex); // Does this rule's period include any transition at all ? if (rule.standardTimeRule.wMonth > 0 || rule.daylightTimeRule.wMonth > 0) { - if (year < rule.startYear) - year = rule.startYear; // Seek first transition in this rule. + if (year < rule.startYear) { + Q_ASSERT(ruleIndex == 0); + // Find first transition in this first rule. + // Initial guess: first rule starts in standard time. + TransitionTimePair pair(rule, rule.startYear, rule.standardTimeBias); + // Year starts in daylightTimeRule iff it has a valid transition + // out of DST before it has a transition into it. + if (pair.std != invalidMSecs() && pair.std < pair.dst) + return ruleToData(rule, pair.dst, QTimeZone::DaylightTime, pair.fakesDst()); + return ruleToData(rule, pair.std, QTimeZone::StandardTime, pair.fakesDst()); + } const int endYear = ruleIndex + 1 < m_tranRules.count() ? qMin(m_tranRules.at(ruleIndex + 1).startYear, year + 2) : (year + 2); int prior = year == 1 ? -1 : year - 1; // No year 0. |