summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2023-03-24 14:45:54 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-04-14 16:22:06 +0000
commit6f645621c76640272e33a892bc05aa9d0cfd0aab (patch)
tree5ad2e4f8b80957a5a9f37bb2f9b519df937a22d5 /tests
parentd57e3e4e93388c70a55f82304a5a83d6dda0b9e4 (diff)
downloadqtbase-6f645621c76640272e33a892bc05aa9d0cfd0aab.tar.gz
tst_QDateTimeEdit: correct computation of width of gap
Although the zone's daylight time offset is usually the width of the gap, it's possible the transition is (or includes) a change to standard time; so determine the actual gap width by comparing the difference between time a day earlier and later to the usual duration of two days. Also skip the test if the transition isn't really a gap. Change-Id: I56e381c9f74cfa1806d43b3ed5e4637436ebdf57 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 28c6868611fda392bd2ab9b5b509466c4e23ddd7) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp
index 13a47e53b1..940909567e 100644
--- a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp
+++ b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp
@@ -4575,6 +4575,13 @@ static QDateTime findSpring(int year, const QTimeZone &timeZone)
return spring;
};
+
+// Number of missing seconds between a day before and a day after when.
+// If when is the time of a spring-forward transition, this is the width of its gap.
+static int missingSecondsNear(const QDateTime &when)
+{
+ return 2 * 24 * 60 * 60 - when.addDays(-1).secsTo(when.addDays(1));
+}
#endif
/*!
@@ -4598,7 +4605,10 @@ void tst_QDateTimeEdit::springForward_data()
QSKIP("Failed to obtain valid spring forward datetime for 2019!");
const QDate springDate = springTransition.date();
- const int gapWidth = timeZone.daylightTimeOffset(springTransition.addDays(1));
+ const int gapWidth = missingSecondsNear(springTransition);
+ if (gapWidth <= 0)
+ QSKIP("Spring forward transition did not actually skip any time!");
+
const QTime springGap = springTransition.time().addSecs(-gapWidth);
const QTime springGapMiddle = springTransition.time().addSecs(-gapWidth / 2);
const QByteArray startGapTime = springGap.toString("hh:mm").toLocal8Bit();
@@ -4696,7 +4706,10 @@ void tst_QDateTimeEdit::stepIntoDSTGap_data()
QSKIP("Failed to obtain valid spring forward datetime for 2007!");
const QDate spring = springTransition.date();
- const int gapWidth = timeZone.daylightTimeOffset(springTransition.addDays(1));
+ const int gapWidth = missingSecondsNear(springTransition);
+ if (gapWidth <= 0)
+ QSKIP("Spring forward transition did not actually skip any time!");
+
const QTime springGap = springTransition.time().addSecs(-gapWidth);
const QByteArray springTime = springGap.toString("hh:mm").toLocal8Bit();