diff options
author | Mitch Curtis <mitch.curtis@nokia.com> | 2012-06-28 15:53:41 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-12 01:46:38 +0200 |
commit | 282d81e4e53c41f2b89a41c01e149ef484460df7 (patch) | |
tree | e37352a6057fa1cd13739d554483ce0351698d29 /src/corelib/tools/qdatetime.cpp | |
parent | 623bfe209371b6d35d030a66629b58f0f4f27b0d (diff) |
Write qHash functions for QDate, QTime and QDateTime.
These functions didn't exist - this patch implements them.
Task-number: QTBUG-23079
Change-Id: I9eb6e238531d5cda878f5f2cdd27bab30aa60669
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qdatetime.cpp')
-rw-r--r-- | src/corelib/tools/qdatetime.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index 6c3836e0dc..4c3baa30ce 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -4067,6 +4067,43 @@ QDebug operator<<(QDebug dbg, const QDateTime &date) } #endif +/*! \fn uint qHash(const QDateTime &key, uint seed = 0) + \relates QHash + \since 5.0 + + Returns the hash value for the \a key, using \a seed to seed the calculation. +*/ +uint qHash(const QDateTime &key, uint seed) +{ + // Use to toMSecsSinceEpoch instead of individual qHash functions for + // QDate/QTime/spec/offset because QDateTime::operator== converts both arguments + // to the same timezone. If we don't, qHash would return different hashes for + // two QDateTimes that are equivalent once converted to the same timezone. + return qHash(key.toMSecsSinceEpoch(), seed); +} + +/*! \fn uint qHash(const QDate &key, uint seed = 0) + \relates QHash + \since 5.0 + + Returns the hash value for the \a key, using \a seed to seed the calculation. +*/ +uint qHash(const QDate &key, uint seed) +{ + return qHash(key.toJulianDay(), seed); +} + +/*! \fn uint qHash(const QTime &key, uint seed = 0) + \relates QHash + \since 5.0 + + Returns the hash value for the \a key, using \a seed to seed the calculation. +*/ +uint qHash(const QTime &key, uint seed) +{ + return QTime(0, 0, 0, 0).msecsTo(key) ^ seed; +} + #ifndef QT_BOOTSTRAPPED /*! |