summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2022-01-25 16:14:04 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2022-03-04 16:32:47 +0000
commitacecf05f2147de0a7813b981d921fcc0d159c1f7 (patch)
tree776cf154ac5a45c12e20b20540b97d4169060cd8
parent6253fae4eaf45754f6338b2e9314d4bc8d98271a (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> (cherry picked from commit d98b43005eed051a77beacb252c7a9eb7f5c4493) Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
-rw-r--r--src/corelib/time/qtimezoneprivate_win.cpp15
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.