Add some more QDate::{start,end}OfDay() tests

While investigating an assertion failure I noticed that the existing
tests didn't even exercise these methods for local time or zone time.
Of course, we can't robustly test these time-specs, due to vagueries
of offset details and zone availability, but we can at least verify
that they return date-times on the specified date. Add a test-case for
the start of 1900, on which the assertions were first seen; it is the
earliest moment representable with tm_year >= 0, after all.

One of these tests fails on 6.2 but the fix for that (as opposed to
the the assertion) requires 6.3's improvements to the handling of
time_t's fuller range - too risky a change to pick back to 6.2.

Pick-to: 6.3
Task-number: QTBUG-99747
Change-Id: I98f5d7850a701972b2d8ea2ce203a2b3e7071354
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Edward Welbourne 2022-01-12 19:41:51 +01:00
parent 9b2bf17f3e
commit 830fd1908b
1 changed files with 12 additions and 0 deletions

View File

@ -568,6 +568,7 @@ void tst_QDate::startOfDay_endOfDay_fixed_data()
} data[] = {
{ "epoch", QDate(1970, 1, 1) },
{ "y2k-leap-day", QDate(2000, 2, 29) },
{ "start-1900", QDate(1900, 1, 1) }, // QTBUG-99747
// Just outside the start and end of 32-bit time_t:
{ "pre-sign32", QDate(start32sign.date().year(), 1, 1) },
{ "post-sign32", QDate(end32sign.date().year(), 12, 31) },
@ -605,6 +606,17 @@ void tst_QDate::startOfDay_endOfDay_fixed()
QCOMPARE(date.addDays(1).startOfDay(Qt::OffsetFromUTC, offset).addMSecs(-1), end);
QCOMPARE(date.addDays(-1).endOfDay(Qt::OffsetFromUTC, offset).addMSecs(1), start);
}
// Minimal testing for LocalTime and TimeZone
QCOMPARE(date.startOfDay(Qt::LocalTime).date(), date);
QCOMPARE(date.endOfDay(Qt::LocalTime).date(), date);
#if QT_CONFIG(timezone)
const QTimeZone cet("Europe/Oslo");
if (cet.isValid()) {
QCOMPARE(date.startOfDay(cet).date(), date);
QCOMPARE(date.endOfDay(cet).date(), date);
}
#endif
}
void tst_QDate::startOfDay_endOfDay_bounds()