summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/time
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2023-08-18 17:15:37 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2023-10-11 22:06:19 +0200
commitc23d00078c8801d2bc215bf0554899cc871bba33 (patch)
treefe9ea981aaf86126762743d34f65aef9e6c70ac9 /tests/auto/corelib/time
parent4aba97e0628bc6b44604e5750e3a594ddf2ea4ec (diff)
Let QDateTime::offsetFromUtc() work for invalid date-times
The implementation previously worked for non-short date-times, where the offset has been remembered since construction. This included the case of zoned times (and local times more than 2^55 msec away from the start of 1970) that hit a spring-forward's gap; but excluded local times that did the same (within 2^55 msec of the epoch). This precluded an offset check in a spring-forward test, now added. We can in fact determine the offset whenever we got a valid date and time (we do so in the course of initializing the object, and when asked for toMSecsSinceEpoch(), even when invalid), and we should not use the value of the recorded offset if we didn't get a valid date and time, so amend to always return 0 if we didn't get valid date and time and always report the correct offset otherwise. In the process, amend offsetFromUtc()'s computation to directly resolve the date-time, rather than doing so via toMSecsSinceEpoch(), which has to repeat decision-making offsetFromUtc() has already done by the time it calls it. Also amend toMSecsSinceEpoch() to return 0 if we didn't have a valid date and time to begin with, so it only attempts to produce a useful result in the case where construction attempted to resolve the date-time. Change-Id: I6574e362275ccc4fbd8de6f0fa875d2e50f3bffe Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests/auto/corelib/time')
-rw-r--r--tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
index 4e81476e65..71719a183e 100644
--- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
@@ -4229,6 +4229,7 @@ void tst_QDateTime::timeZones() const
inGap = QDateTime(QDate(2013, 3, 31), QTime(2, 30));
QVERIFY(!inGap.isValid());
QCOMPARE(inGap.date(), QDate(2013, 3, 31));
+ QCOMPARE(inGap.offsetFromUtc(), 7200);
QCOMPARE(inGap.time(), QTime(3, 30));
}