From 9a0949a25b647aa9fc4f03d85e2f0f22cf1289ce Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 14 Feb 2022 15:19:46 +0100 Subject: [PATCH] Correct handling of start-of-rule situations in QTZP_win A recent change made sure the handling of a time before the first rule would be handled correctly; but I wrongly supposed relevant code would only be exercised in that case. However, it is also run when the moment after which we want a transition is after the last transition in the rule for its year: we fall through to the next rule and need to find its first transition. This amends commit d98b43005eed051a77beacb252c7a9eb7f5c4493. Change-Id: Idb9114a2e272ff9cdb80312f33a0b1e6cd02d582 Reviewed-by: Thiago Macieira --- src/corelib/time/qtimezoneprivate_win.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/corelib/time/qtimezoneprivate_win.cpp b/src/corelib/time/qtimezoneprivate_win.cpp index 9f65ca8d01d..41177a0a0aa 100644 --- a/src/corelib/time/qtimezoneprivate_win.cpp +++ b/src/corelib/time/qtimezoneprivate_win.cpp @@ -684,19 +684,21 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::nextTransition(qint64 afterMSecsSinc for (int ruleIndex = ruleIndexForYear(m_tranRules, year); ruleIndex < m_tranRules.count(); ++ruleIndex) { const QWinTransitionRule &rule = m_tranRules.at(ruleIndex); + // Initial guess: rule starts in standard time (unsound in southern hemisphere). + int newYearOffset = rule.standardTimeBias; // Does this rule's period include any transition at all ? if (rule.standardTimeRule.wMonth > 0 || rule.daylightTimeRule.wMonth > 0) { 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); + // Either before first rule's start, or we fell off the end of + // the rule for year because afterMSecsSinceEpoch is after any + // transitions in it. Find first transition in this rule. + TransitionTimePair pair(rule, rule.startYear, newYearOffset); return pair.ruleToData(rule, this, pair.startsInDst()); } 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. - int newYearOffset = (year <= rule.startYear && ruleIndex > 0) + newYearOffset = (year <= rule.startYear && ruleIndex > 0) ? yearEndOffset(m_tranRules.at(ruleIndex - 1), prior) : yearEndOffset(rule, prior); while (year < endYear) {