summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Layt <jlayt@kde.org>2013-08-13 14:17:08 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-13 22:06:26 +0200
commit92b0a7fa3ee874bc4a9a39da112896fa7e3a97e9 (patch)
tree180907eca0248aed0b3fe44c238a96c56978cd4a /src
parent63a382a93073a96457a41118753ae88547023cac (diff)
QTime - Add public api for get/set msecs since start of day
Add new public api to get and set the number of msecs since the start of the day. Modify QDateTime to use the new msecs api. [ChangeLog][QtCore][QTime] Added new methods fromMSecsSinceStartOfDay() to create a new QTime from an msecs value, and msecsSinceStartOfDay() to return the QTime as the number of msecs since the start of the day. Change-Id: I285b725b883f1f5524fda87ca81bd64ed99fe6f4 Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Mitch Curtis <mitch.curtis@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qdatetime.cpp23
-rw-r--r--src/corelib/tools/qdatetime.h3
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);