Use QDateTimePrivate's methods in preference to std::numeric_limits
The methods give them more appropriate names. This revealed one place where the min() that's actually invalidMSecs() was being used for a time that should have been in the supported range, so amend that to use minMSecs(). Replaced a use of invalidMSecs() + 1 with minMSecs(), to which it is equal, as that was the meaning it was used for. At the same time, make those methods constexpr (because they are) and [[nodiscard]], since their values should be used, while dropping their fatuous inline (the bodies are inline in the declarations). Pick-to: 6.3 Change-Id: Idcd51c55850573372b44e6fcf08d5d2665b8a60e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
5133ed072a
commit
8024498a36
@ -224,16 +224,15 @@ QTimeZonePrivate::Data QTimeZonePrivate::dataForLocalTime(qint64 forLocalMSecs,
|
||||
std::integral_constant<qint64, 16 * 3600 * 1000> sixteenHoursInMSecs;
|
||||
static_assert(-sixteenHoursInMSecs / 1000 < QTimeZone::MinUtcOffsetSecs
|
||||
&& sixteenHoursInMSecs / 1000 > QTimeZone::MaxUtcOffsetSecs);
|
||||
using Bound = std::numeric_limits<qint64>;
|
||||
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.
|
||||
|
@ -137,10 +137,14 @@ public:
|
||||
virtual void serialize(QDataStream &ds) const;
|
||||
|
||||
// Static Utility Methods
|
||||
static inline qint64 maxMSecs() { return (std::numeric_limits<qint64>::max)(); }
|
||||
static inline qint64 minMSecs() { return (std::numeric_limits<qint64>::min)() + 1; }
|
||||
static inline qint64 invalidMSecs() { return (std::numeric_limits<qint64>::min)(); }
|
||||
static inline qint64 invalidSeconds() { return (std::numeric_limits<int>::min)(); }
|
||||
[[nodiscard]] static constexpr qint64 maxMSecs()
|
||||
{ return (std::numeric_limits<qint64>::max)(); }
|
||||
[[nodiscard]] static constexpr qint64 minMSecs()
|
||||
{ return (std::numeric_limits<qint64>::min)() + 1; }
|
||||
[[nodiscard]] static constexpr qint64 invalidMSecs()
|
||||
{ return (std::numeric_limits<qint64>::min)(); }
|
||||
[[nodiscard]] static constexpr qint64 invalidSeconds()
|
||||
{ return (std::numeric_limits<int>::min)(); }
|
||||
static Data invalidData();
|
||||
static QTimeZone::OffsetData invalidOffsetData();
|
||||
static QTimeZone::OffsetData toOffsetData(const Data &data);
|
||||
|
@ -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<qint64>;
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user