diff options
author | Oleg Yadrov <oleg.yadrov@qt.io> | 2017-12-11 16:25:45 -0200 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2017-12-15 09:42:37 +0000 |
commit | 15c909f4170450cdbe01218a0d7cbea55b70fae5 (patch) | |
tree | 2d6488db691b6f006327510ae358f2e33b06c148 /tests/auto | |
parent | 37592ad9c6df35bdd37609569963fe7361cdad85 (diff) | |
download | qtquickcontrols-15c909f4170450cdbe01218a0d7cbea55b70fae5.tar.gz |
Calendar: fix bug when NaN is displayed instead of date
I fixed a similar issue last year on the JavaScript side:
094ad30c94a72784449f43ef06d2172d644ab0fd
At this time the same thing has been happening in C++. See QTBUG-54559
and the patch for a detailed explanation of the issue. In short,
the problem with Calendar is that internally it uses QDate which does
not keep information about time, whereas in the JavaScript world date
is always combined with time. So, QDate(2017-10-15) is valid, but when
during QDate -> JS Date transformation we add time to it (which defaults
to midnight (00:00)), it becomes invalid in time zones where the Daylight
Saving Time -> Standard Time transition takes place at midnight.
To avoid switching the entire QQuickCalendarModel1
to using QDateTime, I modified its date(...) and dateAt(...) methods to
return QDateTime with the time part always set to 12:00.
That transformation required more changes in QQuickRangedDate1, because
Calendar::selectedDate internally is QQuickRangedDate1::selectedDate,
and I also had to fix "selected" property binding in the Base Calendar
Style as it did take into account the time part of the date, which
resulted in wrong behavior with my changes.
Task-number: QTBUG-64068
Change-Id: Ia2f7703ff4e5811ef79438c97739da1d8001a7f5
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/controls/data/tst_calendar.qml | 29 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_rangeddate.qml | 5 |
2 files changed, 26 insertions, 8 deletions
diff --git a/tests/auto/controls/data/tst_calendar.qml b/tests/auto/controls/data/tst_calendar.qml index 1185aca9..d47f62ba 100644 --- a/tests/auto/controls/data/tst_calendar.qml +++ b/tests/auto/controls/data/tst_calendar.qml @@ -129,7 +129,10 @@ Item { compare(calendar.minimumDate, new Date(1, 0, 1)); compare(calendar.maximumDate, new Date(4000, 0, 1)); - compare(calendar.selectedDate, new Date(new Date().setHours(0, 0, 0, 0))); + var expectedDate = new Date(); + compare(calendar.selectedDate.getFullYear(), expectedDate.getFullYear()); + compare(calendar.selectedDate.getMonth(), expectedDate.getMonth()); + compare(calendar.selectedDate.getDate(), expectedDate.getDate()); compare(calendar.frameVisible, true); compare(calendar.dayOfWeekFormat, Locale.ShortFormat); compare(calendar.__locale, Qt.locale()); @@ -406,7 +409,9 @@ Item { expectedDate.setDate(expectedDate.getDate() + cellIndex); mousePress(calendar, toPixelsX(day), toPixelsY(week), Qt.LeftButton); - compare(calendar.selectedDate, expectedDate); + compare(calendar.selectedDate.getFullYear(), expectedDate.getFullYear()); + compare(calendar.selectedDate.getMonth(), expectedDate.getMonth()); + compare(calendar.selectedDate.getDate(), expectedDate.getDate()); compare(calendar.__panel.pressedCellIndex, cellIndex); compare(pressedSignalSpy.count, 1); compare(releasedSignalSpy.count, 0); @@ -434,7 +439,9 @@ Item { // Ensure released event does not trigger date selection. calendar.selectedDate = startDate; mousePress(calendar, toPixelsX(1), toPixelsY(0), Qt.LeftButton); - compare(calendar.selectedDate, new Date(2012, 11, 31)); + compare(calendar.selectedDate.getFullYear(), 2012); + compare(calendar.selectedDate.getMonth(), 11); + compare(calendar.selectedDate.getDate(), 31); compare(calendar.__panel.pressedCellIndex, 1); compare(pressedSignalSpy.count, 1); compare(releasedSignalSpy.count, 0); @@ -445,7 +452,9 @@ Item { clickedSignalSpy.clear(); mouseRelease(calendar, toPixelsX(1), toPixelsY(0), Qt.LeftButton); - compare(calendar.selectedDate, new Date(2012, 11, 31)); + compare(calendar.selectedDate.getFullYear(), 2012); + compare(calendar.selectedDate.getMonth(), 11); + compare(calendar.selectedDate.getDate(), 31); compare(calendar.__panel.pressedCellIndex, -1); compare(pressedSignalSpy.count, 0); compare(releasedSignalSpy.count, 1); @@ -534,7 +543,9 @@ Item { calendar.__locale = Qt.locale("en_GB"); calendar.selectedDate = new Date(2014, 11, 1); mousePress(calendar, toPixelsX(0), toPixelsY(0), Qt.LeftButton); - compare(calendar.selectedDate, new Date(2014, 10, 24)); + compare(calendar.selectedDate.getFullYear(), 2014); + compare(calendar.selectedDate.getMonth(), 10); + compare(calendar.selectedDate.getDate(), 24); mouseRelease(calendar, toPixelsX(0), toPixelsY(0), Qt.LeftButton); } @@ -585,7 +596,9 @@ Item { function dragTo(cellX, cellY, expectedCellIndex, expectedDate) { mouseMove(calendar, toPixelsX(cellX), toPixelsY(cellY)); - compare(calendar.selectedDate, expectedDate); + compare(calendar.selectedDate.getFullYear(), expectedDate.getFullYear()); + compare(calendar.selectedDate.getMonth(), expectedDate.getMonth()); + compare(calendar.selectedDate.getDate(), expectedDate.getDate()); compare(calendar.__panel.pressedCellIndex, expectedCellIndex); compare(hoveredSignalSpy.count, 1); compare(pressedSignalSpy.count, 1); @@ -627,7 +640,9 @@ Item { 3 4 5 6 7 8 9 3 4 5 6 7 8 9 */ mousePress(calendar, toPixelsX(5), toPixelsY(0), Qt.LeftButton); - compare(calendar.selectedDate, new Date(2014, 1, 1)); + compare(calendar.selectedDate.getFullYear(), 2014); + compare(calendar.selectedDate.getMonth(), 1); + compare(calendar.selectedDate.getDate(), 1); compare(calendar.__panel.pressedCellIndex, 5); compare(pressedSignalSpy.count, 1); compare(releasedSignalSpy.count, 0); diff --git a/tests/auto/controls/data/tst_rangeddate.qml b/tests/auto/controls/data/tst_rangeddate.qml index cad94eb4..a1874441 100644 --- a/tests/auto/controls/data/tst_rangeddate.qml +++ b/tests/auto/controls/data/tst_rangeddate.qml @@ -69,7 +69,10 @@ Item { function test_defaultConstruction() { // rangedDate.date should be the current date. - compare(rangedDate.date.getTime(), new Date(Date.now()).setHours(0, 0, 0, 0)); + var expectedDate = new Date(); + compare(rangedDate.date.getFullYear(), expectedDate.getFullYear()); + compare(rangedDate.date.getMonth(), expectedDate.getMonth()); + compare(rangedDate.date.getDate(), expectedDate.getDate()); } function test_minMax() { |