diff options
-rw-r--r-- | src/corelib/time/qtimezoneprivate.cpp | 6 | ||||
-rw-r--r-- | tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp | 12 |
2 files changed, 16 insertions, 2 deletions
diff --git a/src/corelib/time/qtimezoneprivate.cpp b/src/corelib/time/qtimezoneprivate.cpp index 6829951c84..6b92d60f7f 100644 --- a/src/corelib/time/qtimezoneprivate.cpp +++ b/src/corelib/time/qtimezoneprivate.cpp @@ -416,8 +416,10 @@ QTimeZonePrivate::Data QTimeZonePrivate::dataForLocalTime(qint64 forLocalMSecs, utcEpochMSecs = forStd; } else { // Invalid forLocalMSecs: in spring-forward gap. - const int dstStep = daylightTimeOffset(early < late ? imminent : recent) * 1000; - Q_ASSERT(dstStep); // There can't be a transition without it ! + const int dstStep = (offsetInDst - offsetInStd) * 1000; + // That'll typically be the DST offset at imminent, but changes to + // standard time have zero DST offset both before and after. + Q_ASSERT(dstStep > 0); // There can't be a gap without it ! utcEpochMSecs = (hint > 0) ? forStd - dstStep : forDst + dstStep; } } diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index cb93439bad..ef0be8a97c 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -2926,6 +2926,18 @@ void tst_QDateTime::fromStringStringFormat_localTimeZone_data() << QString("2008-10-13 GMT 11.50") << QString("yyyy-MM-dd t hh.mm") << QDateTime(QDate(2008, 10, 13), QTime(11, 50), gmt); } + QTimeZone helsinki("Europe/Helsinki"); + if (helsinki.isValid()) { + // QTBUG-96861: QAsn1Element::toDateTime() tripped over an assert in + // QTimeZonePrivate::dataForLocalTime() on macOS and iOS. + // The first 20m 11s of 1921-05-01 were skipped, so the parser's attempt + // to construct a local time after scanning yyMM tripped up on the start + // of the day, when the zone backend lacked transition data. + QTest::newRow("Helsinki-joins-EET") + << QByteArrayLiteral("Europe/Helsinki") + << QString("210506000000Z") << QString("yyMMddHHmmsst") + << QDateTime(QDate(1921, 5, 6), QTime(0, 0), Qt::UTC); + } #endif } |