Fake a "first transition" at the start of time

QTimeZonePrivate::dataForLocalTime() needs a transition before the
time it starts at; MS's time-zone data tends to omit old zones (before
2007, in the case of Win7 for Casablanca - which had interesting
transitions before that), so all we can do is extrapolate backwards
from there; but a first rule is indeed apt to be a no-transition rule,
describing the zone's status up to the first known transition.  So
fake a "start of time" transition to return for this case, that
describes this prefix of history.

Change-Id: Iaf178cbebc3b1e599cbde3437a0af75d9f6ca432
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Edward Welbourne 2017-11-07 10:58:03 +01:00
parent 35176c2289
commit 6deb0f0dcc
1 changed files with 9 additions and 0 deletions

View File

@ -815,6 +815,10 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::nextTransition(qint64 afterMSecsSinc
QTimeZonePrivate::Data QWinTimeZonePrivate::previousTransition(qint64 beforeMSecsSinceEpoch) const
{
const qint64 startOfTime = invalidMSecs() + 1;
if (beforeMSecsSinceEpoch <= startOfTime)
return invalidData();
int year = msecsToDate(beforeMSecsSinceEpoch).year();
for (int ruleIndex = ruleIndexForYear(m_tranRules, year);
ruleIndex >= 0; --ruleIndex) {
@ -841,6 +845,11 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::previousTransition(qint64 beforeMSec
return ruleToData(rule, pair.std, QTimeZone::StandardTime, pair.fakesDst());
}
// Fell off start of rule, try previous rule.
} else if (ruleIndex == 0) {
// Treat a no-transition first rule as a transition at the start of
// time, so that a scan through all rules *does* see it as the first
// rule:
return ruleToData(rule, startOfTime, QTimeZone::StandardTime, false);
} // else: no transition during rule's period
if (year >= rule.startYear)
year = rule.startYear - 1; // Seek last transition in new rule