summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/time
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2023-04-24 17:09:44 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2023-05-02 17:03:27 +0200
commitc888153655ae2615eb9efa2dfc683e1b7d5ae46c (patch)
treef96a8c7b64a4fece92bd704e6be77f7f0f3cd43a /tests/auto/corelib/time
parent6aea6c25a5e4e6fa93e44d62139f4f9acc30bd93 (diff)
Fix problem with Australasian zones in fromSecsSinceEpoch() test
It seems glibc's extrapolation of existing DST-rules cuts off at some point in the distant future, where the IANA DB gives no end-time for such rules, leading QTimeZone to keep applying them. This lead to tst_QDateTime::fromSecsSinceEpoch() not getting an invalid date in one of its bounds-probing tests, due to a within-bounds datetime getting glibc's offset and then the out-of-bounds one falling back to the IANA rule's offset that put it back within the bounds. This directly affected Australasian zones (which glibc locks into daylight-saving time in this distant future) which were fixed by using the IANA DB's offset; but the relevant date is in August so other zones, north of the equator, that glibc locks into standard time, then had the reverse problem, so we have to take the minimum of the two sources' offsets to get all zones on board. Change-Id: I0c94af2ba108dea31bee46aafa4a8cca8d373a5c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io> Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Diffstat (limited to 'tests/auto/corelib/time')
-rw-r--r--tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
index b257aa14e1..a5ab0192b1 100644
--- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
@@ -930,7 +930,22 @@ void tst_QDateTime::fromSecsSinceEpoch()
QVERIFY(!QDateTime::fromSecsSinceEpoch(-maxSeconds - 1, UTC).isValid());
// Local time: need to adjust for its zone offset
- const qint64 last = maxSeconds - qMax(late.addYears(-1).toLocalTime().offsetFromUtc(), 0);
+ const int lateOffset = late.addYears(-1).toLocalTime().offsetFromUtc();
+#if QT_CONFIG(timezone)
+ // Check what system zone believes in, as it's used as fall-back to cope
+ // with times outside the system time_t functions' range, or overflow on the
+ // results of using those functions. (It seems glibc's handling of
+ // Australasian zones parts company with the IANA DB after about 5881580 CE,
+ // leaving NZ in permanent DST after that, for example.) Of course, if
+ // that's less than lateOffset (as it is for glibc's similar handling of
+ // MET), the fall-back code will also fail when the primary code fails, so
+ // use the lesser of these late offsets.
+ const int lateZone = qMin(QTimeZone::systemTimeZone().offsetFromUtc(late), lateOffset);
+#else
+ const int lateZone = lateOffset;
+#endif
+
+ const qint64 last = maxSeconds - qMax(lateZone, 0);
QVERIFY(QDateTime::fromSecsSinceEpoch(last).isValid());
QVERIFY(!QDateTime::fromSecsSinceEpoch(last + 1).isValid());
const qint64 first = -maxSeconds - qMin(early.addYears(1).toLocalTime().offsetFromUtc(), 0);