diff options
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qdatetime.cpp | 23 | ||||
-rw-r--r-- | src/corelib/tools/qdatetime.h | 3 |
2 files changed, 24 insertions, 2 deletions
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index 6c8fb85233..174b694eee 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -1864,6 +1864,25 @@ int QTime::msecsTo(const QTime &t) const */ /*! + \fn QTime QTime::fromMSecsSinceStartOfDay(int msecs) + + Returns a new QTime instance with the time set to the number of \a msecs + since the start of the day, i.e. since 00:00:00. + + If \a msecs falls outside the valid range an invalid QTime will be returned. + + \sa msecsSinceStartOfDay() +*/ + +/*! + \fn int QTime::msecsSinceStartOfDay() const + + Returns the number of msecs since the start of the day, i.e. since 00:00:00. + + \sa fromMSecsSinceStartOfDay() +*/ + +/*! \fn QTime::currentTime() Returns the current time as reported by the system clock. @@ -2695,7 +2714,7 @@ void QDateTime::setMSecsSinceEpoch(qint64 msecs) } d->date = QDate(1970, 1, 1).addDays(ddays); - d->time = QTime(0, 0, 0).addMSecs(msecs); + d->time = QTime::fromMSecsSinceStartOfDay(msecs); if (d->spec == QDateTimePrivate::OffsetFromUTC) utcToOffset(&d->date, &d->time, d->m_offsetFromUtc); @@ -4449,7 +4468,7 @@ uint qHash(const QDate &key, uint seed) Q_DECL_NOTHROW */ uint qHash(const QTime &key, uint seed) Q_DECL_NOTHROW { - return qHash(QTime(0, 0, 0, 0).msecsTo(key), seed); + return qHash(key.msecsSinceStartOfDay(), seed); } QT_END_NAMESPACE diff --git a/src/corelib/tools/qdatetime.h b/src/corelib/tools/qdatetime.h index 8b63c5a377..779aae5b5b 100644 --- a/src/corelib/tools/qdatetime.h +++ b/src/corelib/tools/qdatetime.h @@ -168,6 +168,9 @@ public: bool operator>(const QTime &other) const { return mds > other.mds; } bool operator>=(const QTime &other) const { return mds >= other.mds; } + static inline QTime fromMSecsSinceStartOfDay(int msecs) { QTime t; t.mds = msecs; return t; } + inline int msecsSinceStartOfDay() const { return mds == NullTime ? 0 : mds; } + static QTime currentTime(); #ifndef QT_NO_DATESTRING static QTime fromString(const QString &s, Qt::DateFormat f = Qt::TextDate); |