diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2023-03-24 14:45:54 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2023-04-14 15:19:02 +0200 |
commit | 28c6868611fda392bd2ab9b5b509466c4e23ddd7 (patch) | |
tree | 70a886d452ac53e776ec6300975e582b2585e6ca /tests/auto/widgets/widgets/qdatetimeedit | |
parent | f06cc225090c2230e0cc21f03c8395a0aebe5194 (diff) |
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.
Pick-to: 6.5
Change-Id: I56e381c9f74cfa1806d43b3ed5e4637436ebdf57
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto/widgets/widgets/qdatetimeedit')
-rw-r--r-- | tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp | 17 |
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 66522062bd..cbeea365a2 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 QByteArray springTime = springGap.toString("hh:mm").toLocal8Bit(); const QTime springGapMiddle = springTransition.time().addSecs(-gapWidth/2); @@ -4695,7 +4705,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(); |