summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qdatetime.cpp37
-rw-r--r--src/corelib/tools/qdatetime.h4
2 files changed, 41 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
/*!
diff --git a/src/corelib/tools/qdatetime.h b/src/corelib/tools/qdatetime.h
index 83c5ed8c2e..6880b7bad7 100644
--- a/src/corelib/tools/qdatetime.h
+++ b/src/corelib/tools/qdatetime.h
@@ -288,6 +288,10 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QTime &);
Q_CORE_EXPORT QDebug operator<<(QDebug, const QDateTime &);
#endif
+Q_CORE_EXPORT uint qHash(const QDateTime &key, uint seed = 0);
+Q_CORE_EXPORT uint qHash(const QDate &key, uint seed = 0);
+Q_CORE_EXPORT uint qHash(const QTime &key, uint seed = 0);
+
QT_END_NAMESPACE
QT_END_HEADER