From 3a71e387d9759d87241c0c69b2c54f67ca547e10 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 5 Sep 2019 17:18:56 +0200 Subject: MS TZ data: avoid calculating a date in year 0 There is no year 0 in the proleptic Gregorian calendar, so QDate() won't be happy if asked for a date in it. Tweak scanning of the data we get from MS-Win so as to avoid a date calculation that could otherwise happen in year 0 when constructing QDateTime(QDate(1, 1, 1), QTime(0, 0, 0), QTimeZone("Australia/Sydney")). Added a test for this case, which Oliver Wolff has kindly verified does reproduce the assertion failure. However, Coin is unable to reproduce, as all its MS builds are configured with -release, so Q_ASSERT() does nothing. (The relevant code then skips over year 0, albeit for the wrong reasons, and gets the right results, albeit inefficiently, leaving no other symptom by which to detect the problem.) Fixes: QTBUG-78051 Change-Id: Ife8a7470e5bd450bc421e89b3f1e1211756fc889 Reviewed-by: Qt CI Bot Reviewed-by: Oliver Wolff Reviewed-by: Volker Hilsheimer (cherry picked from commit 8286daba038d3c90d2bc06785ffcf9c0c603cb83) Reviewed-by: Thiago Macieira Reviewed-by: Paul Wicking --- tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index b128ccebc5..42347d6788 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -3319,6 +3319,14 @@ void tst_QDateTime::timeZones() const QCOMPARE(dt3.timeSpec(), dt1.timeSpec()); QCOMPARE(dt3.timeZone(), dt1.timeZone()); + // The start of year 1 should be *describable* in any zone (QTBUG-78051) + dt3 = QDateTime(QDate(1, 1, 1), QTime(0, 0, 0), ausTz); + QVERIFY(dt3.isValid()); + // Likewise the end of year -1 (a.k.a. 1 BCE). + dt3 = dt3.addMSecs(-1); + QVERIFY(dt3.isValid()); + QCOMPARE(dt3, QDateTime(QDate(-1, 12, 31), QTime(23, 59, 59, 999), ausTz)); + // Check datastream serialises the time zone QByteArray tmp; { -- cgit v1.2.3