diff --git a/src/corelib/time/qtimezoneprivate.cpp b/src/corelib/time/qtimezoneprivate.cpp index c90547d0ee..a85617718d 100644 --- a/src/corelib/time/qtimezoneprivate.cpp +++ b/src/corelib/time/qtimezoneprivate.cpp @@ -224,16 +224,15 @@ QTimeZonePrivate::Data QTimeZonePrivate::dataForLocalTime(qint64 forLocalMSecs, std::integral_constant sixteenHoursInMSecs; static_assert(-sixteenHoursInMSecs / 1000 < QTimeZone::MinUtcOffsetSecs && sixteenHoursInMSecs / 1000 > QTimeZone::MaxUtcOffsetSecs); - using Bound = std::numeric_limits; qint64 millis; const qint64 recent = sub_overflow(forLocalMSecs, sixteenHoursInMSecs, &millis) - ? Bound::min() : millis; + ? minMSecs() : millis; const qint64 imminent = add_overflow(forLocalMSecs, sixteenHoursInMSecs, &millis) - ? Bound::max() : millis; + ? maxMSecs() : millis; // At most one of those took the boundary value: - Q_ASSERT(recent < imminent && sixteenHoursInMSecs < imminent - recent); + Q_ASSERT(recent < imminent && sixteenHoursInMSecs < imminent - recent + 1); /* Offsets are Local - UTC, positive to the east of Greenwich, negative to the west; DST offset always exceeds standard offset, when DST applies. diff --git a/src/corelib/time/qtimezoneprivate_p.h b/src/corelib/time/qtimezoneprivate_p.h index 9472586fd9..9637260f94 100644 --- a/src/corelib/time/qtimezoneprivate_p.h +++ b/src/corelib/time/qtimezoneprivate_p.h @@ -137,10 +137,14 @@ public: virtual void serialize(QDataStream &ds) const; // Static Utility Methods - static inline qint64 maxMSecs() { return (std::numeric_limits::max)(); } - static inline qint64 minMSecs() { return (std::numeric_limits::min)() + 1; } - static inline qint64 invalidMSecs() { return (std::numeric_limits::min)(); } - static inline qint64 invalidSeconds() { return (std::numeric_limits::min)(); } + [[nodiscard]] static constexpr qint64 maxMSecs() + { return (std::numeric_limits::max)(); } + [[nodiscard]] static constexpr qint64 minMSecs() + { return (std::numeric_limits::min)() + 1; } + [[nodiscard]] static constexpr qint64 invalidMSecs() + { return (std::numeric_limits::min)(); } + [[nodiscard]] static constexpr qint64 invalidSeconds() + { return (std::numeric_limits::min)(); } static Data invalidData(); static QTimeZone::OffsetData invalidOffsetData(); static QTimeZone::OffsetData toOffsetData(const Data &data); diff --git a/src/corelib/time/qtimezoneprivate_win.cpp b/src/corelib/time/qtimezoneprivate_win.cpp index 41177a0a0a..7ccad273ad 100644 --- a/src/corelib/time/qtimezoneprivate_win.cpp +++ b/src/corelib/time/qtimezoneprivate_win.cpp @@ -310,13 +310,13 @@ qint64 calculateTransitionForYear(const SYSTEMTIME &rule, int year, int bias) const QDate date = calculateTransitionLocalDate(rule, year); const QTime time = QTime(rule.wHour, rule.wMinute, rule.wSecond); qint64 msecs = 0; - using Bound = std::numeric_limits; if (date.isValid() && time.isValid() && !timeToMSecs(date, time, &msecs)) { - // If bias pushes us outside representable range, clip to range - and - // exclude min() from range as it's invalidMSecs(): + // If bias pushes us outside the representable range, clip to range + // (overflow went past the end bias pushed us towards; and + // invalidMSecs() is a representable value less than minMSecs()): return bias && add_overflow(msecs, qint64(bias) * 60000, &msecs) - ? (bias < 0 ? Bound::min() + 1 : Bound::max()) - : (msecs == Bound::min() ? msecs + 1 : msecs); + ? (bias < 0 ? QTimeZonePrivate::minMSecs() : QTimeZonePrivate::maxMSecs()) + : qMax(QTimeZonePrivate::minMSecs(), msecs); } return QTimeZonePrivate::invalidMSecs(); } @@ -730,8 +730,7 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::nextTransition(qint64 afterMSecsSinc QTimeZonePrivate::Data QWinTimeZonePrivate::previousTransition(qint64 beforeMSecsSinceEpoch) const { - const qint64 startOfTime = invalidMSecs() + 1; - if (beforeMSecsSinceEpoch <= startOfTime) + if (beforeMSecsSinceEpoch <= minMSecs()) return invalidData(); int year = msecsToDate(beforeMSecsSinceEpoch).year(); @@ -764,7 +763,7 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::previousTransition(qint64 beforeMSec // 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); + return ruleToData(rule, minMSecs(), QTimeZone::StandardTime, false); } // else: no transition during rule's period if (year >= rule.startYear) { year = rule.startYear - 1; // Seek last transition in new rule