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>
bb10
Edward Welbourne 2015-11-04 12:20:34 +01:00
parent 4a2b9e086e
commit acb9db32b2
1 changed files with 44 additions and 0 deletions

View File

@ -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");