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>
bb10
Edward Welbourne 2023-03-24 14:45:54 +01:00
parent f06cc22509
commit 28c6868611
1 changed files with 15 additions and 2 deletions

View File

@ -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();