diff options
author | Andreas Buhr <andreas.buhr@qt.io> | 2020-11-27 15:42:36 +0100 |
---|---|---|
committer | Andreas Buhr <andreas.buhr@qt.io> | 2021-02-02 15:34:53 +0100 |
commit | 91695b584ebaec6bac44bf52a4eab44da47d5a59 (patch) | |
tree | 2c5206ed640edf64a883c83cdd1b390c71c61767 /tests | |
parent | 54de6b8a4317d462800d2a711d1fe0c4493522bb (diff) |
Test QDateTime behavior in DST gap
Historic QDateTime behavior when being asked to create a
QDateTime in the DST gap was to interpret the given date
as if it was in the time before that gap, mapping it to a point
in time after the gap. This has changed (after Qt 5.15) with
a04411119ead3d4473e4f0ac4bceedc585977b2f .
Since then, the given date is interpreted as if it was in the
time after the gap, thus being mapped to a point in time
before the gap.
This was not caught (in dev) by Coin because machines ran in
timezone "Atlantic/Reykjavik" which does not have DST since 1967.
This patch changes tests to always run in "Europe/Oslo".
A support function and each test-case thus need to use zone-time
instead of local time.
Fixes: QTBUG-86960
Fixes: QTBUG-89208
Change-Id: Iecce5898bf9711a10e7dfc0a25e4bbeaed1c8ade
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 3d785249ba43cf4bd895ed679bac2791e0130dc5)
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp | 7 | ||||
-rw-r--r-- | tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp | 20 |
2 files changed, 16 insertions, 11 deletions
diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index 4a0fc81a9c..3f0af84e4e 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -2705,6 +2705,9 @@ void tst_QDateTime::fromStringStringFormat() #endif // OffsetFromUTC needs an offset check - we may as well do it for all: QCOMPARE(dt.offsetFromUtc(), expected.offsetFromUtc()); + } else { + QCOMPARE(dt.isValid(), expected.isValid()); + QCOMPARE(dt.toMSecsSinceEpoch(), expected.toMSecsSinceEpoch()); } } @@ -3176,7 +3179,9 @@ void tst_QDateTime::daylightTransitions() const QDateTime missing(QDate(2012, 3, 25), QTime(2, 0, 0)); QVERIFY(!missing.isValid()); QCOMPARE(missing.date(), QDate(2012, 3, 25)); - QCOMPARE(missing.time(), QTime(2, 0, 0)); + QCOMPARE(missing.time(), QTime(2, 0)); + // datetimeparser relies on toMSecsSinceEpoch to still work: + QCOMPARE(missing.toMSecsSinceEpoch(), daylight2012); QDateTime after(QDate(2012, 3, 25), QTime(3, 0, 0)); QVERIFY(after.isValid()); diff --git a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp index 1582835fda..456d0d55e0 100644 --- a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp +++ b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp @@ -4475,7 +4475,7 @@ static QDateTime findSpring(int year, const QTimeZone &timeZone) return QDateTime(); // Southern hemisphere spring is after midsummer - const QDateTime midSummer = QDate(year, 6, 21).startOfDay(); + const QDateTime midSummer = QDate(year, 6, 21).startOfDay(timeZone); const QTimeZone::OffsetData transition = midSummer.isDaylightTime() ? timeZone.previousTransition(midSummer) : timeZone.nextTransition(midSummer); @@ -4596,7 +4596,7 @@ void tst_QDateTimeEdit::stepIntoDSTGap_data() QTest::addColumn<int>("steps"); QTest::addColumn<QDateTime>("end"); - const QTimeZone timeZone = QTimeZone::systemTimeZone(); + const QTimeZone timeZone = QTimeZone("Europe/Oslo"); if (!timeZone.hasDaylightTime()) QSKIP("This test needs to run in a timezone that observes DST!"); @@ -4611,14 +4611,14 @@ void tst_QDateTimeEdit::stepIntoDSTGap_data() // change hour if (springGap.hour() != 0) { QTest::addRow("hour up into %s gap", qPrintable(springGap.toString("hh:mm"))) - << QDateTime(spring, springGap.addSecs(-3600)) + << QDateTime(spring, springGap.addSecs(-3600), timeZone) << QDateTimeEdit::HourSection << +1 << springTransition; // 3:00:10 into 2:00:10 should get us to 1:00:10 QTest::addRow("hour down into %s gap", qPrintable(springGap.toString("hh:mm"))) - << QDateTime(spring, springGap.addSecs(3610)) + << QDateTime(spring, springGap.addSecs(3610), timeZone) << QDateTimeEdit::HourSection << -1 << QDateTime(spring, springGap.addSecs(-3590)); @@ -4628,7 +4628,7 @@ void tst_QDateTimeEdit::stepIntoDSTGap_data() if (spring.day() != 1) { // today's 2:05 is tomorrow's 3:05 QTest::addRow("day up into %s gap", qPrintable(springGap.toString("hh:mm"))) - << QDateTime(spring.addDays(-1), springGap.addSecs(300)) + << QDateTime(spring.addDays(-1), springGap.addSecs(300), timeZone) << QDateTimeEdit::DaySection << +1 << springTransition.addSecs(300); @@ -4636,7 +4636,7 @@ void tst_QDateTimeEdit::stepIntoDSTGap_data() if (spring.day() != spring.daysInMonth()) { QTest::addRow("day down into %s gap", qPrintable(springGap.toString("hh:mm"))) - << QDateTime(spring.addDays(1), springGap) + << QDateTime(spring.addDays(1), springGap, timeZone) << QDateTimeEdit::DaySection << -1 << springTransition; @@ -4644,24 +4644,24 @@ void tst_QDateTimeEdit::stepIntoDSTGap_data() // 2018-03-25 - change month QTest::addRow("month up into %s gap", qPrintable(springGap.toString("hh:mm"))) - << QDateTime(spring.addMonths(-1), springGap) + << QDateTime(spring.addMonths(-1), springGap, timeZone) << QDateTimeEdit::MonthSection << +1 << springTransition; QTest::addRow("month down into %s gap", qPrintable(springGap.toString("hh:mm"))) - << QDateTime(spring.addMonths(1), springGap) + << QDateTime(spring.addMonths(1), springGap, timeZone) << QDateTimeEdit::MonthSection << -1 << springTransition; // 2018-03-25 - change year QTest::addRow("year up into %s gap", qPrintable(springGap.toString("hh:mm"))) - << QDateTime(spring.addYears(-1), springGap) + << QDateTime(spring.addYears(-1), springGap, timeZone) << QDateTimeEdit::YearSection << +1 << springTransition; QTest::addRow("year down into %s gap", qPrintable(springGap.toString("hh:mm"))) - << QDateTime(spring.addYears(1), springGap) + << QDateTime(spring.addYears(1), springGap, timeZone) << QDateTimeEdit::YearSection << -1 << springTransition; |