From 6deb0f0dcc202e1be08cb6a2284da266cd0fa956 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 7 Nov 2017 10:58:03 +0100 Subject: 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 --- src/corelib/tools/qtimezoneprivate_win.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/tools/qtimezoneprivate_win.cpp b/src/corelib/tools/qtimezoneprivate_win.cpp index 56fdd5b181..8de95e9c73 100644 --- a/src/corelib/tools/qtimezoneprivate_win.cpp +++ b/src/corelib/tools/qtimezoneprivate_win.cpp @@ -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 -- cgit v1.2.3