summaryrefslogtreecommitdiffstats
path: root/src/corelib/time/qdatetime.cpp
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2023-05-23 15:59:40 +0200
committerIvan Solovev <ivan.solovev@qt.io>2023-11-28 21:30:52 +0100
commit5839aed9bdf0e44398e729c8371935d9bfe8cd87 (patch)
tree9e2495bb1d4ceb2e76e8c50e20e4106770d74e6f /src/corelib/time/qdatetime.cpp
parentff04c24184c103aab9e56f8adac70784db9ef6c5 (diff)
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>
Diffstat (limited to 'src/corelib/time/qdatetime.cpp')
-rw-r--r--src/corelib/time/qdatetime.cpp25
1 files changed, 9 insertions, 16 deletions
diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp
index 6b260a36ec..4fef0190b6 100644
--- a/src/corelib/time/qdatetime.cpp
+++ b/src/corelib/time/qdatetime.cpp
@@ -5067,26 +5067,19 @@ bool QDateTime::equals(const QDateTime &other) const
\sa operator==()
*/
-/*!
- \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
+Qt::weak_ordering compareThreeWay(const QDateTime &lhs, const QDateTime &rhs)
{
- if (!isValid())
- return other.isValid();
- if (!other.isValid())
- return false;
+ if (!lhs.isValid())
+ return rhs.isValid() ? Qt::weak_ordering::less : Qt::weak_ordering::equivalent;
- if (usesSameOffset(d, other.d))
- return getMSecs(d) < getMSecs(other.d);
+ if (!rhs.isValid())
+ 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
- return toMSecsSinceEpoch() < other.toMSecsSinceEpoch();
+ return Qt::compareThreeWay(lhs.toMSecsSinceEpoch(), rhs.toMSecsSinceEpoch());
}
/*!