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 <thiago.macieira@intel.com>
This commit is contained in:
Edward Welbourne 2022-02-14 15:19:46 +01:00
parent aafefc094d
commit 9a0949a25b

View File

@ -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) {