diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2017-11-07 10:58:03 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2017-11-30 20:20:15 +0000 |
commit | 6deb0f0dcc202e1be08cb6a2284da266cd0fa956 (patch) | |
tree | ffe63e118e345d2abb029905f0853fbbdfa4bb74 | |
parent | 35176c22896a6c633408907e8113c3f1b9a846b0 (diff) |
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>
-rw-r--r-- | src/corelib/tools/qtimezoneprivate_win.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
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 |