QDateTime: use new comparison helper macros
The unit-tests were already ported to the new comparison helper functions from QTestPrivate. Task-number: QTBUG-104111 Change-Id: I95fccb33433b3bbf1167545e347a271140727f23 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
ff04c24184
commit
5839aed9bd
@ -692,6 +692,11 @@ void QDateTime::setTimeZone(const QTimeZone &toZone)
|
|||||||
setTimeZone(toZone, TransitionResolution::LegacyBehavior);
|
setTimeZone(toZone, TransitionResolution::LegacyBehavior);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QDateTime::precedes(const QDateTime &other) const
|
||||||
|
{
|
||||||
|
return compareThreeWay(*this, other) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
#include "qdatastream.h"
|
#include "qdatastream.h"
|
||||||
|
|
||||||
QDataStream &QDataStream::readBytes(char *&s, uint &l)
|
QDataStream &QDataStream::readBytes(char *&s, uint &l)
|
||||||
|
@ -5067,26 +5067,19 @@ bool QDateTime::equals(const QDateTime &other) const
|
|||||||
\sa operator==()
|
\sa operator==()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
Qt::weak_ordering compareThreeWay(const QDateTime &lhs, const QDateTime &rhs)
|
||||||
\internal
|
|
||||||
Returns \c true if \a lhs is earlier than the \a rhs
|
|
||||||
datetime; otherwise returns \c false.
|
|
||||||
|
|
||||||
\sa equals(), operator<()
|
|
||||||
*/
|
|
||||||
|
|
||||||
bool QDateTime::precedes(const QDateTime &other) const
|
|
||||||
{
|
{
|
||||||
if (!isValid())
|
if (!lhs.isValid())
|
||||||
return other.isValid();
|
return rhs.isValid() ? Qt::weak_ordering::less : Qt::weak_ordering::equivalent;
|
||||||
if (!other.isValid())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (usesSameOffset(d, other.d))
|
if (!rhs.isValid())
|
||||||
return getMSecs(d) < getMSecs(other.d);
|
return Qt::weak_ordering::greater; // we know that lhs is valid here
|
||||||
|
|
||||||
|
if (usesSameOffset(lhs.d, rhs.d))
|
||||||
|
return Qt::compareThreeWay(getMSecs(lhs.d), getMSecs(rhs.d));
|
||||||
|
|
||||||
// Convert to UTC and compare
|
// Convert to UTC and compare
|
||||||
return toMSecsSinceEpoch() < other.toMSecsSinceEpoch();
|
return Qt::compareThreeWay(lhs.toMSecsSinceEpoch(), rhs.toMSecsSinceEpoch());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -547,17 +547,18 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool equals(const QDateTime &other) const;
|
bool equals(const QDateTime &other) const;
|
||||||
|
#if QT_CORE_REMOVED_SINCE(6, 7)
|
||||||
bool precedes(const QDateTime &other) const;
|
bool precedes(const QDateTime &other) const;
|
||||||
|
#endif
|
||||||
friend class QDateTimePrivate;
|
friend class QDateTimePrivate;
|
||||||
|
|
||||||
Data d;
|
Data d;
|
||||||
|
|
||||||
friend bool operator==(const QDateTime &lhs, const QDateTime &rhs) { return lhs.equals(rhs); }
|
friend bool comparesEqual(const QDateTime &lhs, const QDateTime &rhs)
|
||||||
friend bool operator!=(const QDateTime &lhs, const QDateTime &rhs) { return !(lhs == rhs); }
|
{ return lhs.equals(rhs); }
|
||||||
friend bool operator<(const QDateTime &lhs, const QDateTime &rhs) { return lhs.precedes(rhs); }
|
friend Q_CORE_EXPORT Qt::weak_ordering
|
||||||
friend bool operator<=(const QDateTime &lhs, const QDateTime &rhs) { return !(rhs < lhs); }
|
compareThreeWay(const QDateTime &lhs, const QDateTime &rhs);
|
||||||
friend bool operator>(const QDateTime &lhs, const QDateTime &rhs) { return rhs.precedes(lhs); }
|
Q_DECLARE_WEAKLY_ORDERED(QDateTime)
|
||||||
friend bool operator>=(const QDateTime &lhs, const QDateTime &rhs) { return !(lhs < rhs); }
|
|
||||||
|
|
||||||
#ifndef QT_NO_DATASTREAM
|
#ifndef QT_NO_DATASTREAM
|
||||||
friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QDateTime &);
|
friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QDateTime &);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user