summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/widgets
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2019-11-28 14:22:09 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2019-12-12 11:36:01 +0100
commit2a653fde48f7312ccd2f792d72d305061b410ae3 (patch)
tree398d018623b2649ce90be1fba6cbd141d92ddd8a /tests/auto/widgets/widgets
parent5b193e3dd47704daf56c8817d0157f66363044c3 (diff)
Convert date-time faithfully in QDateTimeEdit::setDateTime()
Previously, setDateTime() was documented to ignore the new date-time's time-spec. It used the date and time (determined using that timespec) with the QDateTimeEdit's configured spec. It is debatable whether that really counts as ignoring its time-spec. All the same, that's what it did. Fixing it is a behavior change. Added tests. [ChangeLog][QtWidgets][QDateTimeEdit] QDateTimeEdit::setDateTime() now converts the new datetime to the QDateTimeEdit's time-spec, rather than combining its date and time (determined using the time spec it came with) with the QDateTimeEdit's date and time. Fixes: QTBUG-71181 Change-Id: Ibf0bd87723c3957ca00a2199d51d992032ef57ee Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Konstantin Shegunov <kshegunov@gmail.com>
Diffstat (limited to 'tests/auto/widgets/widgets')
-rw-r--r--tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp
index 264625777f..9eae1f10ea 100644
--- a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp
+++ b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp
@@ -262,6 +262,8 @@ private slots:
void timeSpec();
void timeSpecBug();
void timeSpecInit();
+ void setDateTime_data();
+ void setDateTime();
void monthEdgeCase();
void setLocale();
@@ -3476,6 +3478,54 @@ void tst_QDateTimeEdit::timeSpecInit()
QCOMPARE(widget.dateTime(), utc);
}
+void tst_QDateTimeEdit::setDateTime_data()
+{
+ QTest::addColumn<Qt::TimeSpec>("spec");
+ QDateTime localNoon(QDate(2019, 12, 24), QTime(12, 0), Qt::LocalTime);
+#if 0 // Not yet supported
+ QTest::addColumn<int>("offset");
+ QTest::addColumn<QByteArray>("zoneName");
+
+ QTest::newRow("OffsetFromUTC/LocalTime")
+ << Qt::OffsetFromUTC << 7200 << ""
+ << localNoon << localNoon.toOffsetFromUtc(7200);
+#if QT_CONFIG(timezone)
+ QTest::newRow("TimeZone/LocalTime")
+ << Qt::TimeZone << 0 << "Europe/Berlin"
+ << localNoon << localNoon.toTimeZone(QTimeZone("Europe/Berlin"));
+#endif
+#endif // unsupported
+ QTest::addColumn<QDateTime>("store");
+ QTest::addColumn<QDateTime>("expect");
+ QTest::newRow("LocalTime/LocalTime")
+ << Qt::LocalTime // << 0 << ""
+ << localNoon << localNoon;
+ QTest::newRow("LocalTime/UTC")
+ << Qt::LocalTime // << 0 << ""
+ << localNoon.toUTC() << localNoon;
+ QTest::newRow("UTC/LocalTime")
+ << Qt::UTC // << 0 << ""
+ << localNoon << localNoon.toUTC();
+ QTest::newRow("UTC/UTC")
+ << Qt::UTC // << 0 << ""
+ << localNoon.toUTC() << localNoon.toUTC();
+}
+
+void tst_QDateTimeEdit::setDateTime()
+{
+ QFETCH(const Qt::TimeSpec, spec);
+#if 0 // Not yet supported
+ QFETCH(const int, offset);
+ QFETCH(const QByteArray, zoneName);
+#endif // configuring the spec, when OffsetFromUTC or TimeZone
+ QFETCH(const QDateTime, store);
+ QFETCH(const QDateTime, expect);
+ QDateTimeEdit editor;
+ editor.setTimeSpec(spec);
+ editor.setDateTime(store);
+ QCOMPARE(editor.dateTime(), expect);
+}
+
void tst_QDateTimeEdit::cachedDayTest()
{
testWidget->setDisplayFormat("MM/dd");