From 4398836817dbfcf51c153d53414b2b04c1eab087 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 23 Oct 2020 14:52:41 +0200 Subject: Make QDateTime's operators hidden friends Update docs to match. Change-Id: I0ece9bcdba69c5dca48743894fe3347d9666f4e4 Reviewed-by: Volker Hilsheimer --- src/corelib/time/qdatetime.cpp | 69 +++++++++++++++++++++++++++++------------- src/corelib/time/qdatetime.h | 16 +++++----- 2 files changed, 57 insertions(+), 28 deletions(-) (limited to 'src/corelib/time') diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index 4ab1a9c995..5a546e2380 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -4434,16 +4434,14 @@ QDateTime QDateTime::toTimeZone(const QTimeZone &timeZone) const #endif // timezone /*! + \internal Returns \c true if this datetime is equal to the \a other datetime; otherwise returns \c false. - Since 5.14, all invalid datetimes are equal to one another and differ from - all other datetimes. - - \sa operator!=() + \sa precedes(), operator==() */ -bool QDateTime::operator==(const QDateTime &other) const +bool QDateTime::equals(const QDateTime &other) const { if (!isValid()) return !other.isValid(); @@ -4458,24 +4456,39 @@ bool QDateTime::operator==(const QDateTime &other) const } /*! - \fn bool QDateTime::operator!=(const QDateTime &other) const + \fn bool QDateTime::operator==(const QDateTime &lhs, const QDateTime &rhs) - Returns \c true if this datetime is different from the \a other - datetime; otherwise returns \c false. + Returns \c true if \a lhs is the same as \a rhs; otherwise returns \c false. Two datetimes are different if either the date, the time, or the time zone - components are different. Since 5.14, any invalid datetime is less than all - valid datetimes. + components are different. Since 5.14, all invalid datetime are equal (and + less than all valid datetimes). + + \sa operator!=(), operator<(), operator<=(), operator>(), operator>=() +*/ + +/*! + \fn bool QDateTime::operator!=(const QDateTime &lhs, const QDateTime &rhs) + + Returns \c true if \a lhs is different from \a rhs; otherwise returns \c + false. + + Two datetimes are different if either the date, the time, or the time zone + components are different. Since 5.14, all invalid datetime are equal (and + less than all valid datetimes). \sa operator==() */ /*! - Returns \c true if this datetime is earlier than the \a other + \internal + Returns \c true if \a lhs is earlier than the \a rhs datetime; otherwise returns \c false. + + \sa equals(), operator<() */ -bool QDateTime::operator<(const QDateTime &other) const +bool QDateTime::precedes(const QDateTime &other) const { if (!isValid()) return other.isValid(); @@ -4490,24 +4503,38 @@ bool QDateTime::operator<(const QDateTime &other) const } /*! - \fn bool QDateTime::operator<=(const QDateTime &other) const + \fn bool QDateTime::operator<(const QDateTime &lhs, const QDateTime &rhs) - Returns \c true if this datetime is earlier than or equal to the - \a other datetime; otherwise returns \c false. + Returns \c true if \a lhs is earlier than \a rhs; + otherwise returns \c false. + + \sa operator==() */ /*! - \fn bool QDateTime::operator>(const QDateTime &other) const + \fn bool QDateTime::operator<=(const QDateTime &lhs, const QDateTime &rhs) - Returns \c true if this datetime is later than the \a other datetime; - otherwise returns \c false. + Returns \c true if \a lhs is earlier than or equal to \a rhs; otherwise + returns \c false. + + \sa operator==() +*/ + +/*! + \fn bool QDateTime::operator>(const QDateTime &lhs, const QDateTime &rhs) + + Returns \c true if \a lhs is later than \a rhs; otherwise returns \c false. + + \sa operator==() */ /*! - \fn bool QDateTime::operator>=(const QDateTime &other) const + \fn bool QDateTime::operator>=(const QDateTime &lhs, const QDateTime &rhs) - Returns \c true if this datetime is later than or equal to the - \a other datetime; otherwise returns \c false. + Returns \c true if \a lhs is later than or equal to \a rhs; + otherwise returns \c false. + + \sa operator==() */ /*! diff --git a/src/corelib/time/qdatetime.h b/src/corelib/time/qdatetime.h index e80a5b96d4..7ce7c5f43b 100644 --- a/src/corelib/time/qdatetime.h +++ b/src/corelib/time/qdatetime.h @@ -340,13 +340,6 @@ public: qint64 secsTo(const QDateTime &) const; qint64 msecsTo(const QDateTime &) const; - bool operator==(const QDateTime &other) const; - inline bool operator!=(const QDateTime &other) const { return !(*this == other); } - bool operator<(const QDateTime &other) const; - inline bool operator<=(const QDateTime &other) const { return !(other < *this); } - inline bool operator>(const QDateTime &other) const { return other < *this; } - inline bool operator>=(const QDateTime &other) const { return !(*this < other); } - static QDateTime currentDateTime(); static QDateTime currentDateTimeUtc(); #if QT_CONFIG(datestring) @@ -390,10 +383,19 @@ public: enum class YearRange : qint32 { First = -292275056, Last = +292278994 }; private: + bool equals(const QDateTime &other) const; + bool precedes(const QDateTime &other) const; friend class QDateTimePrivate; Data d; + friend bool operator==(const QDateTime &lhs, const QDateTime &rhs) { return lhs.equals(rhs); } + friend bool operator!=(const QDateTime &lhs, const QDateTime &rhs) { return !(lhs == rhs); } + friend bool operator<(const QDateTime &lhs, const QDateTime &rhs) { return lhs.precedes(rhs); } + friend bool operator<=(const QDateTime &lhs, const QDateTime &rhs) { return !(rhs < lhs); } + friend bool operator>(const QDateTime &lhs, const QDateTime &rhs) { return rhs.precedes(lhs); } + friend bool operator>=(const QDateTime &lhs, const QDateTime &rhs) { return !(lhs < rhs); } + #ifndef QT_NO_DATASTREAM friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QDateTime &); friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QDateTime &); -- cgit v1.2.3