summaryrefslogtreecommitdiffstats
path: root/tests/auto
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 /tests/auto
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 'tests/auto')
-rw-r--r--tests/auto/corelib/tools/qtime/tst_qtime.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qtime/tst_qtime.cpp b/tests/auto/corelib/tools/qtime/tst_qtime.cpp
index 864f90b380..3941794202 100644
--- a/tests/auto/corelib/tools/qtime/tst_qtime.cpp
+++ b/tests/auto/corelib/tools/qtime/tst_qtime.cpp
@@ -75,6 +75,8 @@ private slots:
void toStringFormat_data();
void toStringFormat();
void toStringLocale();
+ void msecsSinceStartOfDay_data();
+ void msecsSinceStartOfDay();
private:
QTime invalidTime() { return QTime(-1, -1, -1); }
@@ -732,5 +734,49 @@ void tst_QTime::toStringLocale()
QLocale().toString(time, QLocale::ShortFormat));
}
+void tst_QTime::msecsSinceStartOfDay_data()
+{
+ QTest::addColumn<int>("msecs");
+ QTest::addColumn<bool>("isValid");
+ QTest::addColumn<int>("hour");
+ QTest::addColumn<int>("minute");
+ QTest::addColumn<int>("second");
+ QTest::addColumn<int>("msec");
+
+ QTest::newRow("00:00:00.000") << 0 << true
+ << 0 << 0 << 0 << 0;
+ QTest::newRow("01:00:00.001") << ((1 * 3600 * 1000) + 1) << true
+ << 1 << 0 << 0 << 1;
+ QTest::newRow("03:04:05.678") << ((3 * 3600 + 4 * 60 + 5) * 1000 + 678) << true
+ << 3 << 4 << 5 << 678;
+ QTest::newRow("23:59:59.999") << ((23 * 3600 + 59 * 60 + 59) * 1000 + 999) << true
+ << 23 << 59 << 59 << 999;
+ QTest::newRow("24:00:00.000") << ((24 * 3600) * 1000) << false
+ << -1 << -1 << -1 << -1;
+ QTest::newRow("-1 invalid") << -1 << false
+ << -1 << -1 << -1 << -1;
+}
+
+void tst_QTime::msecsSinceStartOfDay()
+{
+ QFETCH(int, msecs);
+ QFETCH(bool, isValid);
+ QFETCH(int, hour);
+ QFETCH(int, minute);
+ QFETCH(int, second);
+ QFETCH(int, msec);
+
+ QTime time = QTime::fromMSecsSinceStartOfDay(msecs);
+ QCOMPARE(time.isValid(), isValid);
+ if (msecs >= 0)
+ QCOMPARE(time.msecsSinceStartOfDay(), msecs);
+ else
+ QCOMPARE(time.msecsSinceStartOfDay(), 0);
+ QCOMPARE(time.hour(), hour);
+ QCOMPARE(time.minute(), minute);
+ QCOMPARE(time.second(), second);
+ QCOMPARE(time.msec(), msec);
+}
+
QTEST_APPLESS_MAIN(tst_QTime)
#include "tst_qtime.moc"