diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2022-01-11 15:01:22 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-01-13 19:53:26 +0000 |
commit | 84ab463aa3e75c2b78f99d62c95577c6a0b5950f (patch) | |
tree | 2bb2839d91e86337d7a38c3a7d95f2ad8c824f03 /tests | |
parent | 9ab362b7787bea71c64de7e211c125b763f8127b (diff) |
Fix an assertion failure in massageAdjustedDateTime()
The QDateTimeData &d it's passed is a copy that's about to be
modified; before we do so, we haven't detached so its internals have a
ref-count of two, contradicting an assertion in the non-const
Data::operator->(); so just directly access d.d->m_timezone, since we
know that spec == TimeZone implies !isShort().
Added test that triggered the assertion and now doesn't.
Fixes: QTBUG-99668
Change-Id: I07321ad91be5adce524be18e4ab82eee7110dc6a
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit 5d228beb520d92c985497fb43fa91d2920db6cb0)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index 1b12abdcf9..844dead504 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -1134,6 +1134,18 @@ void tst_QDateTime::addDays() QCOMPARE(dt2.timeSpec(), Qt::OffsetFromUTC); QCOMPARE(dt2.offsetFromUtc(), 60 * 60); +#if QT_CONFIG(timezone) + const QTimeZone cet("Europe/Oslo"); + if (cet.isValid()) { + dt1 = QDate(2022, 1, 10).startOfDay(cet); + dt2 = dt1.addDays(2); // QTBUG-99668: should not assert + QCOMPARE(dt2.date(), QDate(2022, 1, 12)); + QCOMPARE(dt2.time(), QTime(0, 0)); + QCOMPARE(dt2.timeSpec(), Qt::TimeZone); + QCOMPARE(dt2.timeZone(), cet); + } +#endif + // Test last UTC second of 1969 *is* valid (despite being time_t(-1)) dt1 = QDateTime(QDate(1969, 12, 30), QTime(23, 59, 59), Qt::UTC).toLocalTime().addDays(1); QVERIFY(dt1.isValid()); |