diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2022-02-15 10:19:52 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2022-03-08 13:08:58 +0000 |
commit | 2473f4ca36f7d14d9f200b875289b0c71ee1d2e3 (patch) | |
tree | 23d239bae9194f2babb4cf2723fe07c2fc7fedcb /src | |
parent | 08bfd7455587c027dcef354c45530af487da32df (diff) |
Extract functions: move some code to TransitionTimePair
Documenting the case where a year starts in DST belongs on the pair
whose job is to work that out. The selection of which transition to
report based on an isDst flag could be said once instead of thrice if
made into a method there, too.
Change-Id: Ice59bb8594097c53bc2fefe1706434462b225274
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit aafefc094d1ef8419893805e64a8e1296889d392)
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/time/qtimezoneprivate_p.h | 7 | ||||
-rw-r--r-- | src/corelib/time/qtimezoneprivate_win.cpp | 29 |
2 files changed, 22 insertions, 14 deletions
diff --git a/src/corelib/time/qtimezoneprivate_p.h b/src/corelib/time/qtimezoneprivate_p.h index cc46ba5e2f..9637260f94 100644 --- a/src/corelib/time/qtimezoneprivate_p.h +++ b/src/corelib/time/qtimezoneprivate_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2021 The Qt Company Ltd. +** Copyright (C) 2022 The Qt Company Ltd. ** Copyright (C) 2013 John Layt <jlayt@kde.org> ** Contact: https://www.qt.io/licensing/ ** @@ -459,10 +459,11 @@ public: QList<QByteArray> availableTimeZoneIds() const override; -private: - void init(const QByteArray &ianaId); + // For use within implementation's TransitionTimePair: QTimeZonePrivate::Data ruleToData(const QWinTransitionRule &rule, qint64 atMSecsSinceEpoch, QTimeZone::TimeType type, bool fakeDst = false) const; +private: + void init(const QByteArray &ianaId); QByteArray m_windowsId; QString m_displayName; diff --git a/src/corelib/time/qtimezoneprivate_win.cpp b/src/corelib/time/qtimezoneprivate_win.cpp index a6ab9dc778..bf9bcd51d0 100644 --- a/src/corelib/time/qtimezoneprivate_win.cpp +++ b/src/corelib/time/qtimezoneprivate_win.cpp @@ -388,6 +388,21 @@ struct TransitionTimePair return std == QTimeZonePrivate::invalidMSecs() || dst == QTimeZonePrivate::invalidMSecs(); } + + bool startsInDst() const + { + // Year starts in daylightTimeRule iff it has a valid transition out of + // DST before it has a transition into it. + return std != QTimeZonePrivate::invalidMSecs() && std < dst; + } + + QTimeZonePrivate::Data ruleToData(const QWinTimeZonePrivate::QWinTransitionRule &rule, + const QWinTimeZonePrivate *tzp, bool isDst) const + { + if (isDst) + return tzp->ruleToData(rule, dst, QTimeZone::DaylightTime, fakesDst()); + return tzp->ruleToData(rule, std, QTimeZone::StandardTime, fakesDst()); + } }; int yearEndOffset(const QWinTimeZonePrivate::QWinTransitionRule &rule, int year) @@ -676,11 +691,7 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::nextTransition(qint64 afterMSecsSinc // Find first transition in this first rule. // Initial guess: first rule starts in standard time. TransitionTimePair pair(rule, rule.startYear, rule.standardTimeBias); - // Year starts in daylightTimeRule iff it has a valid transition - // out of DST before it has a transition into it. - if (pair.std != invalidMSecs() && pair.std < pair.dst) - return ruleToData(rule, pair.dst, QTimeZone::DaylightTime, pair.fakesDst()); - return ruleToData(rule, pair.std, QTimeZone::StandardTime, pair.fakesDst()); + 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); @@ -706,9 +717,7 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::nextTransition(qint64 afterMSecsSinc continue; } - if (isDst) - return ruleToData(rule, pair.dst, QTimeZone::DaylightTime, pair.fakesDst()); - return ruleToData(rule, pair.std, QTimeZone::StandardTime, pair.fakesDst()); + return pair.ruleToData(rule, this, isDst); } // Fell off end of rule, try next rule. } // else: no transition during rule's period @@ -745,9 +754,7 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::previousTransition(qint64 beforeMSec prior = year == 1 ? -1 : year - 1; // No year 0. continue; } - if (isDst) - return ruleToData(rule, pair.dst, QTimeZone::DaylightTime, pair.fakesDst()); - return ruleToData(rule, pair.std, QTimeZone::StandardTime, pair.fakesDst()); + return pair.ruleToData(rule, this, isDst); } // Fell off start of rule, try previous rule. } else if (ruleIndex == 0) { |