Add a ValidWhenMask to QDateTimePrivate::StatusFlag

This saves some repetition of verbose status-setting code.
At the same time, save the function that uses it a repeated
getStatus() call hidden inside its getSpec() by inlining getSpec().

Change-Id: I32aee521c1885408f822ecb47ab1ed76f92852a1
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Edward Welbourne 2020-09-07 14:46:10 +02:00
parent e33b0d4bb0
commit 42500dd9ca
2 changed files with 6 additions and 14 deletions

View File

@ -3839,23 +3839,17 @@ qint64 QDateTime::toSecsSinceEpoch() const
*/
void QDateTime::setMSecsSinceEpoch(qint64 msecs)
{
const auto spec = getSpec(d);
auto status = getStatus(d);
const auto spec = extractSpec(status);
status &= ~QDateTimePrivate::ValidityMask;
switch (spec) {
case Qt::UTC:
status = status
| QDateTimePrivate::ValidDate
| QDateTimePrivate::ValidTime
| QDateTimePrivate::ValidDateTime;
status |= QDateTimePrivate::ValidWhenMask;
break;
case Qt::OffsetFromUTC:
msecs = msecs + (d->m_offsetFromUtc * 1000);
status = status
| QDateTimePrivate::ValidDate
| QDateTimePrivate::ValidTime
| QDateTimePrivate::ValidDateTime;
status |= QDateTimePrivate::ValidWhenMask;
break;
case Qt::TimeZone:
Q_ASSERT(!d.isShort());
@ -3876,10 +3870,7 @@ void QDateTime::setMSecsSinceEpoch(qint64 msecs)
d->m_offsetFromUtc = d->m_timeZone.d->standardTimeOffset(msecs);
}
msecs = msecs + (d->m_offsetFromUtc * 1000);
status = status
| QDateTimePrivate::ValidDate
| QDateTimePrivate::ValidTime
| QDateTimePrivate::ValidDateTime;
status |= QDateTimePrivate::ValidWhenMask;
#endif // timezone
break;
case Qt::LocalTime: {

View File

@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2020 The Qt Company Ltd.
** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
@ -96,6 +96,7 @@ public:
ValidDate = 0x02,
ValidTime = 0x04,
ValidDateTime = 0x08,
ValidWhenMask = ValidDate | ValidTime | ValidDateTime,
TimeSpecMask = 0x30,