From 81858bf1722081d99fdea72f55e67c04c5bb3d92 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 4 Nov 2015 10:26:37 +0100 Subject: Don't pretend we know what DST to use for an offset date. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When QDateTime::addDate() and friends sanitize their end-state, they were using the DST status of their start-state (if known) to control it. This lead to misguided results and, in particular, inconsistent results given that a raw-constructed QDateTime comes into being ignorant of its DST, while a .toLocalTime() one knows its DST. Furthermore, the code to do this was triplicated, tricky and poorly explained. So pull it out into a local static function and explain what it's doing, and why, more clearly and only once. Task-number: QTBUG-49008 Change-Id: Ia4bb3c5e9267fff8bb963ea705267998218ed623 Reviewed-by: Jędrzej Nowacki --- tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp') diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index 216c670aee..228ce73c6b 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -1616,9 +1616,7 @@ void tst_QDateTime::springForward_data() 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"); -- cgit v1.2.3 From 722df6e0a2c640f09903f9b4f3b686c5c70e82d9 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 5 Nov 2015 15:13:48 +0100 Subject: Nomenclature corrections relating to CET. There are several European time zones; the only one relevant to the tests here is CET. They won't work with WET, GMT or EET. So name them and related variables for CET, not for Europe. CET's summer-time isn't called CST; and the (existing) spring forward test works only in CET/CEST, not elsewhere in Europe. Change-Id: I55c7544bf792de7495700b749b935ec534831d8b Reviewed-by: Thiago Macieira --- .../auto/corelib/tools/qdatetime/tst_qdatetime.cpp | 74 +++++++++++----------- 1 file changed, 37 insertions(+), 37 deletions(-) (limited to 'tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp') diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index 228ce73c6b..d8934c1604 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -155,7 +155,7 @@ private slots: private: enum { LocalTimeIsUtc = 0, LocalTimeAheadOfUtc = 1, LocalTimeBehindUtc = -1} localTimeType; - bool europeanTimeZone; + bool zoneIsCET; QDate defDate() const { return QDate(1900, 1, 1); } QTime defTime() const { return QTime(0, 0, 0); } QDateTime defDateTime() const { return QDateTime(defDate(), defTime()); } @@ -173,7 +173,7 @@ tst_QDateTime::tst_QDateTime() { uint x1 = QDateTime(QDate(1990, 1, 1), QTime()).toTime_t(); uint x2 = QDateTime(QDate(1990, 6, 1), QTime()).toTime_t(); - europeanTimeZone = (x1 == 631148400 && x2 == 644191200); + zoneIsCET = (x1 == 631148400 && x2 == 644191200); QDateTime dt1 = QDateTime::fromTime_t(0); QDateTime dt2 = QDateTime::fromTime_t(181 * 86400); // six months later, Jul 1 @@ -201,7 +201,7 @@ void tst_QDateTime::initTestCase() break; case LocalTimeAheadOfUtc: typemsg1 = "ahead of"; - typemsg2 = europeanTimeZone ? "and is" : "but isn't"; + typemsg2 = zoneIsCET ? "and is" : "but isn't"; break; } @@ -245,7 +245,7 @@ void tst_QDateTime::ctor() QCOMPARE(dt3.timeSpec(), Qt::UTC); QVERIFY(dt1 == dt2); - if (europeanTimeZone) { + if (zoneIsCET) { QVERIFY(dt1 != dt3); QVERIFY(dt1 < dt3); QVERIFY(dt1.addSecs(3600).toUTC() == dt3); @@ -492,7 +492,7 @@ void tst_QDateTime::setTime_t() dt1.setTime_t(123456); QCOMPARE(dt1, QDateTime(QDate(1970, 1, 2), QTime(10, 17, 36), Qt::UTC)); - if (europeanTimeZone) { + if (zoneIsCET) { QDateTime dt2; dt2.setTime_t(123456); QCOMPARE(dt2, QDateTime(QDate(1970, 1, 2), QTime(11, 17, 36), Qt::LocalTime)); @@ -500,7 +500,7 @@ void tst_QDateTime::setTime_t() dt1.setTime_t((uint)(quint32)-123456); QCOMPARE(dt1, QDateTime(QDate(2106, 2, 5), QTime(20, 10, 40), Qt::UTC)); - if (europeanTimeZone) { + if (zoneIsCET) { QDateTime dt2; dt2.setTime_t((uint)(quint32)-123456); QCOMPARE(dt2, QDateTime(QDate(2106, 2, 5), QTime(21, 10, 40), Qt::LocalTime)); @@ -508,7 +508,7 @@ void tst_QDateTime::setTime_t() dt1.setTime_t(1214567890); QCOMPARE(dt1, QDateTime(QDate(2008, 6, 27), QTime(11, 58, 10), Qt::UTC)); - if (europeanTimeZone) { + if (zoneIsCET) { QDateTime dt2; dt2.setTime_t(1214567890); QCOMPARE(dt2, QDateTime(QDate(2008, 6, 27), QTime(13, 58, 10), Qt::LocalTime)); @@ -516,7 +516,7 @@ void tst_QDateTime::setTime_t() dt1.setTime_t(0x7FFFFFFF); QCOMPARE(dt1, QDateTime(QDate(2038, 1, 19), QTime(3, 14, 7), Qt::UTC)); - if (europeanTimeZone) { + if (zoneIsCET) { QDateTime dt2; dt2.setTime_t(0x7FFFFFFF); QCOMPARE(dt2, QDateTime(QDate(2038, 1, 19), QTime(4, 14, 7), Qt::LocalTime)); @@ -533,7 +533,7 @@ void tst_QDateTime::setMSecsSinceEpoch_data() { QTest::addColumn("msecs"); QTest::addColumn("utc"); - QTest::addColumn("european"); + QTest::addColumn("cet"); QTest::newRow("zero") << Q_INT64_C(0) @@ -584,7 +584,7 @@ void tst_QDateTime::setMSecsSinceEpoch() { QFETCH(qint64, msecs); QFETCH(QDateTime, utc); - QFETCH(QDateTime, european); + QFETCH(QDateTime, cet); QDateTime dt; dt.setTimeSpec(Qt::UTC); @@ -595,8 +595,8 @@ void tst_QDateTime::setMSecsSinceEpoch() QCOMPARE(dt.time(), utc.time()); QCOMPARE(dt.timeSpec(), Qt::UTC); - if (europeanTimeZone) { - QCOMPARE(dt.toLocalTime(), european); + if (zoneIsCET) { + QCOMPARE(dt.toLocalTime(), cet); // Test converting from LocalTime to UTC back to LocalTime. QDateTime localDt; @@ -613,13 +613,13 @@ void tst_QDateTime::setMSecsSinceEpoch() QDateTime dt2; dt2.setTimeZone(europe); dt2.setMSecsSinceEpoch(msecs); - QCOMPARE(dt2.date(), european.date()); + QCOMPARE(dt2.date(), cet.date()); // don't compare the time if the date is too early or too late: prior // to 1916, timezones in Europe were not standardised and some OS APIs // have hard limits. Let's restrict it to the 32-bit Unix range if (dt2.date().year() >= 1970 && dt2.date().year() <= 2037) - QCOMPARE(dt2.time(), european.time()); + QCOMPARE(dt2.time(), cet.time()); QCOMPARE(dt2.timeSpec(), Qt::TimeZone); QCOMPARE(dt2.timeZone(), europe); } @@ -643,7 +643,7 @@ void tst_QDateTime::fromMSecsSinceEpoch() { QFETCH(qint64, msecs); QFETCH(QDateTime, utc); - QFETCH(QDateTime, european); + QFETCH(QDateTime, cet); QDateTime dtLocal = QDateTime::fromMSecsSinceEpoch(msecs, Qt::LocalTime); QDateTime dtUtc = QDateTime::fromMSecsSinceEpoch(msecs, Qt::UTC); @@ -665,10 +665,10 @@ void tst_QDateTime::fromMSecsSinceEpoch() if (msecs != std::numeric_limits::max()) QCOMPARE(dtOffset.time(), utc.time().addMSecs(60*60*1000)); - if (europeanTimeZone) { - QCOMPARE(dtLocal.toLocalTime(), european); - QCOMPARE(dtUtc.toLocalTime(), european); - QCOMPARE(dtOffset.toLocalTime(), european); + if (zoneIsCET) { + QCOMPARE(dtLocal.toLocalTime(), cet); + QCOMPARE(dtUtc.toLocalTime(), cet); + QCOMPARE(dtOffset.toLocalTime(), cet); } else { QSKIP("You must test using Central European (CET/CEST) time zone, e.g. TZ=Europe/Oslo"); } @@ -793,7 +793,7 @@ void tst_QDateTime::toString_rfcDate_data() QTest::addColumn("dt"); QTest::addColumn("formatted"); - if (europeanTimeZone) { + if (zoneIsCET) { QTest::newRow("localtime") << QDateTime(QDate(1978, 11, 9), QTime(13, 28, 34)) << QString("09 Nov 1978 13:28:34 +0100"); @@ -1050,7 +1050,7 @@ void tst_QDateTime::addSecs_data() QTest::newRow("utc9") << QDateTime(QDate(4000, 1, 1), standardTime, Qt::UTC) << 0 << QDateTime(QDate(4000, 1, 1), standardTime, Qt::UTC); - if (europeanTimeZone) { + if (zoneIsCET) { QTest::newRow("cet0") << QDateTime(QDate(2004, 1, 1), standardTime, Qt::LocalTime) << 86400 << QDateTime(QDate(2004, 1, 2), standardTime, Qt::LocalTime); QTest::newRow("cet1") << QDateTime(QDate(2004, 1, 1), standardTime, Qt::LocalTime) << (86400 * 185) @@ -1162,7 +1162,7 @@ void tst_QDateTime::toTimeSpec_data() << QDateTime(QDate(-271821, 4, 20), QTime(23, 0, 0), Qt::UTC) << QDateTime(QDate(-271821, 4, 21), QTime(0, 0, 0), Qt::LocalTime); - if (europeanTimeZone) { + if (zoneIsCET) { QTest::newRow("summer1") << QDateTime(QDate(2004, 6, 30), utcTime, Qt::UTC) << QDateTime(QDate(2004, 6, 30), localDaylightTime, Qt::LocalTime); QTest::newRow("summer2") << QDateTime(QDate(1760, 6, 30), utcTime, Qt::UTC) @@ -1185,7 +1185,7 @@ void tst_QDateTime::toTimeSpec_data() void tst_QDateTime::toTimeSpec() { - if (europeanTimeZone) { + if (zoneIsCET) { QFETCH(QDateTime, fromUtc); QFETCH(QDateTime, fromLocal); @@ -1240,7 +1240,7 @@ void tst_QDateTime::toTimeSpec() QCOMPARE(localToOffset.time(), fromUtc.time()); QCOMPARE(localToOffset.timeSpec(), Qt::UTC); } else { - QSKIP("Not tested with timezone other than Central European (CET/CST)"); + QSKIP("Not tested with timezone other than Central European (CET/CEST)"); } } @@ -1251,7 +1251,7 @@ void tst_QDateTime::toLocalTime_data() void tst_QDateTime::toLocalTime() { - if (europeanTimeZone) { + if (zoneIsCET) { QFETCH(QDateTime, fromUtc); QFETCH(QDateTime, fromLocal); @@ -1262,7 +1262,7 @@ void tst_QDateTime::toLocalTime() QCOMPARE(fromUtc.toLocalTime(), fromLocal); QCOMPARE(fromUtc.toLocalTime(), fromLocal.toLocalTime()); } else { - QSKIP("Not tested with timezone other than Central European (CET/CST)"); + QSKIP("Not tested with timezone other than Central European (CET/CEST)"); } } @@ -1273,7 +1273,7 @@ void tst_QDateTime::toUTC_data() void tst_QDateTime::toUTC() { - if (europeanTimeZone) { + if (zoneIsCET) { QFETCH(QDateTime, fromUtc); QFETCH(QDateTime, fromLocal); @@ -1284,7 +1284,7 @@ void tst_QDateTime::toUTC() QCOMPARE(fromLocal.toUTC(), fromUtc); QCOMPARE(fromUtc.toUTC(), fromLocal.toUTC()); } else { - QSKIP("Not tested with timezone other than Central European (CET/CST)"); + QSKIP("Not tested with timezone other than Central European (CET/CEST)"); } QDateTime dt = QDateTime::currentDateTime(); @@ -1614,9 +1614,9 @@ void tst_QDateTime::springForward_data() QTest::addColumn("step"); // days to step; +ve from before, -ve from after QTest::addColumn("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; - QTest::newRow("Europe from day after") << QDate(2015, 3, 29) << QTime(2, 30, 0) << -1 << 120; + if (zoneIsCET) { + QTest::newRow("CET from day before") << QDate(2015, 3, 29) << QTime(2, 30, 0) << 1 << 60; + QTest::newRow("CET from day after") << QDate(2015, 3, 29) << QTime(2, 30, 0) << -1 << 120; // } else if (otherZone) { } else { QSKIP("No spring forward test data for this TZ"); @@ -1687,7 +1687,7 @@ void tst_QDateTime::operator_eqeq_data() QTest::newRow("invalid == invalid") << invalidDateTime() << invalidDateTime() << true << false; QTest::newRow("invalid == valid #1") << invalidDateTime() << dateTime1 << false << false; - if (europeanTimeZone) { + if (zoneIsCET) { QTest::newRow("data14") << QDateTime(QDate(2004, 1, 2), QTime(2, 2, 3), Qt::LocalTime) << QDateTime(QDate(2004, 1, 2), QTime(1, 2, 3), Qt::UTC) << true << true; } @@ -1719,7 +1719,7 @@ void tst_QDateTime::operator_eqeq() if (equal) QVERIFY(qHash(dt1) == qHash(dt2)); - if (checkEuro && europeanTimeZone) { + if (checkEuro && zoneIsCET) { QVERIFY(dt1.toUTC() == dt2); QVERIFY(dt1 == dt2.toLocalTime()); } @@ -2233,7 +2233,7 @@ void tst_QDateTime::offsetFromUtc() QCOMPARE(dt2.offsetFromUtc(), 0); // LocalTime should vary - if (europeanTimeZone) { + if (zoneIsCET) { // Time definitely in Standard Time so 1 hour ahead QDateTime dt3(QDate(2013, 1, 1), QTime(0, 0, 0), Qt::LocalTime); QCOMPARE(dt3.offsetFromUtc(), 1 * 60 * 60); @@ -2358,7 +2358,7 @@ void tst_QDateTime::timeZoneAbbreviation() QCOMPARE(dt3.timeZoneAbbreviation(), QString("UTC")); // LocalTime should vary - if (europeanTimeZone) { + if (zoneIsCET) { // Time definitely in Standard Time QDateTime dt4(QDate(2013, 1, 1), QTime(0, 0, 0), Qt::LocalTime); #ifdef Q_OS_WIN @@ -2482,7 +2482,7 @@ void tst_QDateTime::isDaylightTime() const QDateTime offset2(QDate(2012, 6, 1), QTime(0, 0, 0), Qt::OffsetFromUTC, 1 * 60 * 60); QVERIFY(!offset2.isDaylightTime()); - if (europeanTimeZone) { + if (zoneIsCET) { QDateTime cet1(QDate(2012, 1, 1), QTime(0, 0, 0)); QVERIFY(!cet1.isDaylightTime()); QDateTime cet2(QDate(2012, 6, 1), QTime(0, 0, 0)); @@ -2494,7 +2494,7 @@ void tst_QDateTime::isDaylightTime() const void tst_QDateTime::daylightTransitions() const { - if (europeanTimeZone) { + if (zoneIsCET) { // CET transitions occur at 01:00:00 UTC on last Sunday in March and October // 2011-03-27 02:00:00 CET became 03:00:00 CEST at msecs = 1301187600000 // 2011-10-30 03:00:00 CEST became 02:00:00 CET at msecs = 1319936400000 -- cgit v1.2.3 From f7d9e34b96926cca9918608c23ead84bd0286db9 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 12 Jan 2016 15:16:25 +0100 Subject: Be fussier about setting tst_QDateTime's globals. Time zones change on the whim of politicians. Consequently, we can seem to be in CET/CEST or on UTC (because we tested sample dates when our zone coincided) when we aren't (i.e. we're in a materially different zone at the time probed by some particular test). Make the initialization of the globals that test this more robust against governmental meddling and document the unfixable problem with Algeria: a DST transition *on the epoch*. Change-Id: I17c5c81d339b80af12f4ffab367e28052dd6c2fa Reviewed-by: Thiago Macieira --- .../auto/corelib/tools/qdatetime/tst_qdatetime.cpp | 77 ++++++++++++++++++---- 1 file changed, 63 insertions(+), 14 deletions(-) (limited to 'tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp') diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index d8934c1604..e4572d7c2c 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -171,21 +171,70 @@ Q_DECLARE_METATYPE(Qt::DateFormat) tst_QDateTime::tst_QDateTime() { - uint x1 = QDateTime(QDate(1990, 1, 1), QTime()).toTime_t(); - uint x2 = QDateTime(QDate(1990, 6, 1), QTime()).toTime_t(); - zoneIsCET = (x1 == 631148400 && x2 == 644191200); - - QDateTime dt1 = QDateTime::fromTime_t(0); - QDateTime dt2 = QDateTime::fromTime_t(181 * 86400); // six months later, Jul 1 - if (dt1.date().year() < 1970 || dt2.date().month() < 7) { - localTimeType = LocalTimeBehindUtc; - } else if (dt1.time().hour() > 0 || dt1.date().day() > 1) { - localTimeType = LocalTimeAheadOfUtc; - } else if (dt2.time().hour() > 0 || dt2.date().day() > 1) { - localTimeType = LocalTimeAheadOfUtc; - } else { - localTimeType = LocalTimeIsUtc; + /* + Due to some jurisdictions changing their zones and rules, it's possible + for a non-CET zone to accidentally match CET at a few tested moments but + be different a few years later or earlier. This would lead to tests + failing if run in the partially-aliasing zone (e.g. Algeria, Lybia). So + test thoroughly; ideally at every mid-winter or mid-summer in whose + half-year any test below assumes zoneIsCET means what it says. (Tests at + or near a DST transition implicate both of the half-years that meet + there.) Years outside the 1970--2038 range, however, are likely not + properly handled by the TZ-database; and QDateTime explicitly handles them + differently, so don't probe them here. + */ + const uint day = 24 * 3600; // in seconds + zoneIsCET = (QDateTime(QDate(2038, 1, 19), QTime(4, 14, 7)).toTime_t() == 0x7fffffff + // Entries a year apart robustly differ by multiples of day. + && QDateTime(QDate(2015, 7, 1), QTime()).toTime_t() == 1435701600 + && QDateTime(QDate(2015, 1, 1), QTime()).toTime_t() == 1420066800 + && QDateTime(QDate(2013, 7, 1), QTime()).toTime_t() == 1372629600 + && QDateTime(QDate(2013, 1, 1), QTime()).toTime_t() == 1356994800 + && QDateTime(QDate(2012, 7, 1), QTime()).toTime_t() == 1341093600 + && QDateTime(QDate(2012, 1, 1), QTime()).toTime_t() == 1325372400 + && QDateTime(QDate(2008, 7, 1), QTime()).toTime_t() == 1214863200 + && QDateTime(QDate(2004, 1, 1), QTime()).toTime_t() == 1072911600 + && QDateTime(QDate(2000, 1, 1), QTime()).toTime_t() == 946681200 + && QDateTime(QDate(1990, 7, 1), QTime()).toTime_t() == 646783200 + && QDateTime(QDate(1990, 1, 1), QTime()).toTime_t() == 631148400 + && QDateTime(QDate(1979, 1, 1), QTime()).toTime_t() == 283993200 + // .toTime_t() returns -1 for everything before this: + && QDateTime(QDate(1970, 1, 1), QTime(1, 0, 0)).toTime_t() == 0); + // Use .toMSecsSinceEpoch() if you really need to test anything earlier. + + /* + Again, rule changes can cause a TZ to look like UTC at some sample dates + but deviate at some date relevant to a test using localTimeType. These + tests mostly use years outside the 1970--2038 range for which TZ data is + credible, so we can't helpfully be exhaustive. So scan a sample of years' + starts and middles. + */ + const int sampled = 3; + // UTC starts of months in 2004, 2038 and 1970: + uint jans[sampled] = { 12418 * day, 24837 * day, 0 }; + uint juls[sampled] = { 12600 * day, 25018 * day, 181 * day }; + localTimeType = LocalTimeIsUtc; + for (int i = sampled; i-- > 0; ) { + QDateTime jan = QDateTime::fromTime_t(jans[i]); + QDateTime jul = QDateTime::fromTime_t(juls[i]); + if (jan.date().year() < 1970 || jul.date().month() < 7) { + localTimeType = LocalTimeBehindUtc; + break; + } else if (jan.time().hour() > 0 || jul.time().hour() > 0 + || jan.date().day() > 1 || jul.date().day() > 1) { + localTimeType = LocalTimeAheadOfUtc; + break; + } } + /* + Even so, TZ=Africa/Algiers will fail fromMSecsSinceEpoch(-1) because it + switched from WET without DST (i.e. UTC) in the late 1960s to WET with DST + for all of 1970 - so they had a DST transition *on the epoch*. They've + since switched to CET with no DST, making life simple; but our tests for + mistakes around the epoch can't tell the difference between what Algeria + really did and the symptoms we can believe a bug might produce: there's + not much we can do about that, that wouldn't hide real bugs. + */ } void tst_QDateTime::initTestCase() -- cgit v1.2.3 From 1967accb64a110a1c84d8f37d413bcd36ab579a1 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 6 Nov 2015 14:55:11 +0100 Subject: Expand springForward_data() to cover a few more time-zones. The important one is EET, for the benefit of our CI system; but other European zones and the USA's coastal zones likely have enough hackers in them to make this worth checking. Change-Id: Idcc703bce29808e1a0a6279680cc8d3cbed38dac Reviewed-by: Thiago Macieira --- .../auto/corelib/tools/qdatetime/tst_qdatetime.cpp | 38 ++++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp') diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index e4572d7c2c..6d88b24eda 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -1663,12 +1663,44 @@ void tst_QDateTime::springForward_data() QTest::addColumn("step"); // days to step; +ve from before, -ve from after QTest::addColumn("adjust"); // minutes ahead of UTC on day stepped from - if (zoneIsCET) { + /* + Zone tests compare a summer and winter moment's time_t to known values. + This could in principle be flawed (two DST-using zones in the same + hemisphere with the same DST and standard times but different transition + times) but no actual example is known where this is a problem. Please + document any such conflicts, if discovered. + + See http://www.timeanddate.com/time/zones/ for data on more candidates to + test. + */ + + uint winter = QDateTime(QDate(2015, 1, 1), QTime()).toTime_t(); + uint summer = QDateTime(QDate(2015, 7, 1), QTime()).toTime_t(); + + if (winter == 1420066800 && summer == 1435701600) { QTest::newRow("CET from day before") << QDate(2015, 3, 29) << QTime(2, 30, 0) << 1 << 60; QTest::newRow("CET from day after") << QDate(2015, 3, 29) << QTime(2, 30, 0) << -1 << 120; - // } else if (otherZone) { + } else if (winter == 1420063200 && summer == 1435698000) { + // e.g. Finland, where our CI runs ... + QTest::newRow("EET from day before") << QDate(2015, 3, 29) << QTime(3, 30, 0) << 1 << 120; + QTest::newRow("EET from day after") << QDate(2015, 3, 29) << QTime(3, 30, 0) << -1 << 180; + } else if (winter == 1420070400 && summer == 1435705200) { + // Western European Time, WET/WEST; a.k.a. GMT/BST + QTest::newRow("WET from day before") << QDate(2015, 3, 29) << QTime(1, 30, 0) << 1 << 0; + QTest::newRow("WET from day after") << QDate(2015, 3, 29) << QTime(1, 30, 0) << -1 << 60; + } else if (winter == 1420099200 && summer == 1435734000) { + // Western USA, Canada: Pacific Time (e.g. US/Pacific) + QTest::newRow("PT from day before") << QDate(2015, 3, 8) << QTime(2, 30, 0) << 1 << -480; + QTest::newRow("PT from day after") << QDate(2015, 3, 8) << QTime(2, 30, 0) << -1 << -420; + } else if (winter == 1420088400 && summer == 1435723200) { + // Eastern USA, Canada: Eastern Time (e.g. US/Eastern) + QTest::newRow("ET from day before") << QDate(2015, 3, 8) << QTime(2, 30, 0) << 1 << -300; + QTest::newRow("ET from day after") << QDate(2015, 3, 8) << QTime(2, 30, 0) << -1 << -240; } else { - QSKIP("No spring forward test data for this TZ"); + // Includes the numbers you need to test for your zone, as above: + QString msg(QString::fromLatin1("No spring forward test data for this TZ (%1, %2)" + ).arg(winter).arg(summer)); + QSKIP(qPrintable(msg)); } } -- cgit v1.2.3