summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/time
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2023-08-11 16:12:47 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2023-10-11 22:06:20 +0200
commit29af4b1833e76ae1eeeca6ed9f0b9f8a9cb8c03f (patch)
tree0bf98aacae9b40d0d6e6209eba7b1daaa9cbf7b6 /tests/auto/corelib/time
parentc23d00078c8801d2bc215bf0554899cc871bba33 (diff)
Sort out an anomaly in tst_QDateTime::springForward()
It noted that an unspecified function claimed the offset it was checking should be +1, while testing it against that or -1. The function turns out to be QDateTime::addDays(), whose doc did indeed, misleadingly, say that it lands after a gap it would have hit. It in fact overshoots the gap in the direction of its change. Amend its docs, likewise those of addMonths() and addYears(), to reflect the true behavior. Amend the test to look at the direction of the step its taking and anticipate that the adjustment will be in the same direction; then compare the actual adjustment to that. Change-Id: I9ab918fac0ab2195ef014983f37fccc435bf0498 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests/auto/corelib/time')
-rw-r--r--tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp9
1 files changed, 2 insertions, 7 deletions
diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
index 71719a183e..4cf8c3d5f7 100644
--- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
@@ -2290,13 +2290,8 @@ void tst_QDateTime::springForward()
QCOMPARE(direct.date(), day);
QCOMPARE(direct.time().minute(), time.minute());
QCOMPARE(direct.time().second(), time.second());
- // Note: function doc claims always +1, but this should be reviewed !
- int off = direct.time().hour() - time.hour();
- auto report = qScopeGuard([off]() {
- qDebug("Offset %d found where 1 or -1 expected", off);
- });
- QVERIFY(off == 1 || off == -1);
- report.dismiss();
+ const int off = step < 0 ? -1 : 1;
+ QCOMPARE(direct.time().hour() - time.hour(), off);
// adjust is the offset on the other side of the gap:
QCOMPARE(direct.offsetFromUtc(), (adjust + off * 60) * 60);
}