diff options
author | Edward Welbourne <edward.welbourne@theqtcompany.com> | 2015-11-04 12:20:34 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@theqtcompany.com> | 2015-11-09 08:41:25 +0000 |
commit | acb9db32b20344c74109ecbe5b4da493c9d7afc3 (patch) | |
tree | 3aa94c2544e7bd89f08e152241bc6c6eb68e53e1 | |
parent | 4a2b9e086eb3d16403620b31a4d05bef529910d3 (diff) |
Add spring-forward test
Test that stepping into the missing hour lands us somewhere sane.
Check that raw instance and product of .toLocalTime() agree.
Task-number: QTBUG-49008
Change-Id: I430382ae223bcb43b151d2d6054ecbdd7edc8a47
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index 6cf73c85de..833dfe87d7 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -69,6 +69,8 @@ private slots: void toTime_t_data(); void toTime_t(); void daylightSavingsTimeChange(); + void springForward_data(); + void springForward(); void setDate(); void setTime_data(); void setTime(); @@ -1593,6 +1595,48 @@ void tst_QDateTime::daylightSavingsTimeChange() QCOMPARE(dt.time(), QTime(0, 0, 1)); } +void tst_QDateTime::springForward_data() +{ + QTest::addColumn<QDate>("day"); // day of DST transition + QTest::addColumn<QTime>("time"); // in the "missing hour" + QTest::addColumn<int>("step"); // days to step; +ve from before, -ve from after + QTest::addColumn<int>("adjust"); // minutes ahead of UTC on day stepped from + + if (europeanTimeZone) { + QTest::newRow("Europe from day before") << QDate(2015, 3, 29) << QTime(2, 30, 0) << 1 << 60; +#if 0 // FIXME: fails + QTest::newRow("Europe from day after") << QDate(2015, 3, 29) << QTime(2, 30, 0) << -1 << 120; +#endif + // } else if (otherZone) { + } else { + QSKIP("No spring forward test data for this TZ"); + } +} + +void tst_QDateTime::springForward() +{ + QFETCH(QDate, day); + QFETCH(QTime, time); + QFETCH(int, step); + QFETCH(int, adjust); + + QDateTime direct = QDateTime(day.addDays(-step), time, Qt::LocalTime).addDays(step); + QCOMPARE(direct.date(), day); + QCOMPARE(direct.time().minute(), time.minute()); + QCOMPARE(direct.time().second(), time.second()); + int off = direct.time().hour() - time.hour(); + QVERIFY(off == 1 || off == -1); + // Note: function doc claims always +1, but this should be reviewed ! + + // Repeat, but getting there via .toLocalTime(): + QDateTime detour = QDateTime(day.addDays(-step), + time.addSecs(-60 * adjust), + Qt::UTC).toLocalTime(); + QCOMPARE(detour.time(), time); + detour = detour.addDays(step); + QCOMPARE(detour, direct); // Insist on consistency. +} + void tst_QDateTime::operator_eqeq_data() { QTest::addColumn<QDateTime>("dt1"); |