From b4a875544ba8f2d11e183d67f45891d6149203ed Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 18 Feb 2021 17:24:18 +0100 Subject: Extend time_t-based handling all the way to the end of time_t At least some modern 64-bit systems have widened time_t to 64 bits fixing the "Unix time" problem. (This is even the default on MS-Win, although the system functions artificially limit the accepted range to 1970 through 3000.) Even the 32-bit range extends into January 2038 but the code was artificially cutting this off at the end of 2037. This is a preparation for using the same also all the way back to the start of time_t. In the process, simplify and tidy up the logic of the existing code, update the docs (this includes correcting some misinformation) and revise some tests. Fixes: QTBUG-73225 Change-Id: Ib8001b5a982386c747eda3dea2b5a26eedd499ad Reviewed-by: Qt CI Bot Reviewed-by: Thiago Macieira --- tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index c2f4e82896..166ce260a5 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -615,7 +615,7 @@ void tst_QDateTime::setMSecsSinceEpoch_data() << Q_INT64_C(-123456789) << QDateTime(QDate(1969, 12, 30), QTime(13, 42, 23, 211), Qt::UTC) << QDateTime(QDate(1969, 12, 30), QTime(14, 42, 23, 211), Qt::LocalTime); - QTest::newRow("non-time_t") + QTest::newRow("post-32-bit-time_t") << (Q_INT64_C(1000) << 32) << QDateTime(QDate(2106, 2, 7), QTime(6, 28, 16), Qt::UTC) << QDateTime(QDate(2106, 2, 7), QTime(7, 28, 16)); @@ -713,10 +713,7 @@ void tst_QDateTime::setMSecsSinceEpoch() } QCOMPARE(dt.toMSecsSinceEpoch(), msecs); - - if (quint64(msecs / 1000) < 0xFFFFFFFF) { - QCOMPARE(qint64(dt.toSecsSinceEpoch()), msecs / 1000); - } + QCOMPARE(qint64(dt.toSecsSinceEpoch()), msecs / 1000); QDateTime reference(QDate(1970, 1, 1), QTime(0, 0), Qt::UTC); QCOMPARE(dt, reference.addMSecs(msecs)); @@ -766,11 +763,10 @@ void tst_QDateTime::fromMSecsSinceEpoch() QCOMPARE(dtUtc.toMSecsSinceEpoch(), msecs); QCOMPARE(dtOffset.toMSecsSinceEpoch(), msecs); - if (quint64(msecs / 1000) < 0xFFFFFFFF) { + if (!localOverflow) QCOMPARE(qint64(dtLocal.toSecsSinceEpoch()), msecs / 1000); - QCOMPARE(qint64(dtUtc.toSecsSinceEpoch()), msecs / 1000); - QCOMPARE(qint64(dtOffset.toSecsSinceEpoch()), msecs / 1000); - } + QCOMPARE(qint64(dtUtc.toSecsSinceEpoch()), msecs / 1000); + QCOMPARE(qint64(dtOffset.toSecsSinceEpoch()), msecs / 1000); QDateTime reference(QDate(1970, 1, 1), QTime(0, 0), Qt::UTC); if (!localOverflow) -- cgit v1.2.3