summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp')
-rw-r--r--tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp48
1 files changed, 46 insertions, 2 deletions
diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
index da5039ce3b..906129d1af 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();
@@ -188,10 +190,10 @@ tst_QDateTime::tst_QDateTime()
void tst_QDateTime::initTestCase()
{
// Never construct a message like this in an i18n context...
- const char *typemsg1, *typemsg2 = "and therefore not";
+ const char *typemsg1 = "exactly";
+ const char *typemsg2 = "and therefore not";
switch (localTimeType) {
case LocalTimeIsUtc:
- typemsg1 = "exactly";
break;
case LocalTimeBehindUtc:
typemsg1 = "behind";
@@ -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");