From 830fd1908ba14d434d1715304a430b62d0281eee Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 12 Jan 2022 19:41:51 +0100 Subject: [PATCH] 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 Reviewed-by: Marc Mutz Reviewed-by: Thiago Macieira --- tests/auto/corelib/time/qdate/tst_qdate.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/auto/corelib/time/qdate/tst_qdate.cpp b/tests/auto/corelib/time/qdate/tst_qdate.cpp index 911ad90a7a..4a5725c42e 100644 --- a/tests/auto/corelib/time/qdate/tst_qdate.cpp +++ b/tests/auto/corelib/time/qdate/tst_qdate.cpp @@ -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()