summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/controls/Private/qquickrangeddate.cpp35
-rw-r--r--src/controls/Private/qquickrangeddate_p.h8
-rw-r--r--tests/auto/controls/data/tst_calendar.qml24
-rw-r--r--tests/auto/controls/data/tst_rangeddate.qml64
4 files changed, 73 insertions, 58 deletions
diff --git a/src/controls/Private/qquickrangeddate.cpp b/src/controls/Private/qquickrangeddate.cpp
index df7958ac..67b80e35 100644
--- a/src/controls/Private/qquickrangeddate.cpp
+++ b/src/controls/Private/qquickrangeddate.cpp
@@ -42,8 +42,8 @@
QT_BEGIN_NAMESPACE
// JavaScript Date > QDate conversion is not correct for large negative dates.
-Q_GLOBAL_STATIC_WITH_ARGS(const QDateTime, jsMinimumDate, (QDateTime(QDate(1, 1, 1), QTime())))
-Q_GLOBAL_STATIC_WITH_ARGS(const QDateTime, jsMaximumDate, (QDateTime(QDate(275759, 10, 25), QTime())))
+Q_GLOBAL_STATIC_WITH_ARGS(const QDate, jsMinimumDate, (1, 1, 1))
+Q_GLOBAL_STATIC_WITH_ARGS(const QDate, jsMaximumDate, (275759, 10, 25))
QQuickRangedDate1::QQuickRangedDate1() :
QObject(0),
@@ -61,10 +61,11 @@ void QQuickRangedDate1::setDate(const QDateTime &date)
if (date == mDate)
return;
- if (date < mMinimumDate) {
- mDate = mMinimumDate;
- } else if (date > mMaximumDate) {
- mDate = mMaximumDate;
+ const QDate tmpDate = date.date();
+ if (tmpDate < mMinimumDate) {
+ mDate = minimumDate();
+ } else if (tmpDate > mMaximumDate) {
+ mDate = maximumDate();
} else {
mDate = date;
}
@@ -75,17 +76,18 @@ void QQuickRangedDate1::setDate(const QDateTime &date)
/*! \internal
\qmlproperty date QQuickRangedDate::minimumDate
*/
-void QQuickRangedDate1::setMinimumDate(const QDateTime &minimumDate)
+void QQuickRangedDate1::setMinimumDate(const QDateTime &minDate)
{
- if (minimumDate == mMinimumDate)
+ const QDate tmpDate = minDate.date();
+ if (tmpDate == mMinimumDate)
return;
- mMinimumDate = qMax(minimumDate, *jsMinimumDate);
+ mMinimumDate = qMax(tmpDate, *jsMinimumDate);
emit minimumDateChanged();
// If the new minimumDate makes date invalid, clamp date to it.
- if (mDate < mMinimumDate) {
- mDate = mMinimumDate;
+ if (mDate < minimumDate()) {
+ mDate = minimumDate();
emit dateChanged();
}
}
@@ -93,19 +95,20 @@ void QQuickRangedDate1::setMinimumDate(const QDateTime &minimumDate)
/*! \internal
\qmlproperty date QQuickRangedDate::maximumDate
*/
-void QQuickRangedDate1::setMaximumDate(const QDateTime &maximumDate)
+void QQuickRangedDate1::setMaximumDate(const QDateTime &maxDate)
{
- if (maximumDate == mMaximumDate)
+ const QDate tmpDate = maxDate.date();
+ if (tmpDate == mMaximumDate)
return;
// If the new maximumDate is smaller than minimumDate, clamp maximumDate to it.
// If the new maximumDate is larger than jsMaximumDate, also clamp it.
- mMaximumDate = maximumDate < mMinimumDate ? mMinimumDate : qMin(maximumDate, *jsMaximumDate);
+ mMaximumDate = tmpDate < mMinimumDate ? mMinimumDate : qMin(tmpDate, *jsMaximumDate);
emit maximumDateChanged();
// If the new maximumDate makes the date invalid, clamp it.
- if (mDate > mMaximumDate) {
- mDate = mMaximumDate;
+ if (mDate > maximumDate()) {
+ mDate = maximumDate();
emit dateChanged();
}
}
diff --git a/src/controls/Private/qquickrangeddate_p.h b/src/controls/Private/qquickrangeddate_p.h
index 836daa4c..048d7edd 100644
--- a/src/controls/Private/qquickrangeddate_p.h
+++ b/src/controls/Private/qquickrangeddate_p.h
@@ -60,11 +60,11 @@ public:
void setDate(const QDateTime &date);
void resetDate() {}
- QDateTime minimumDate() const { return mMinimumDate; }
+ QDateTime minimumDate() const { return QDateTime(mMinimumDate, QTime()); }
void setMinimumDate(const QDateTime &minimumDate);
void resetMinimumDate() {}
- QDateTime maximumDate() const { return mMaximumDate; }
+ QDateTime maximumDate() const { return QDateTime(mMaximumDate, QTime(23, 59, 59, 999)); }
void setMaximumDate(const QDateTime &maximumDate);
void resetMaximumDate() {}
@@ -75,8 +75,8 @@ Q_SIGNALS:
private:
QDateTime mDate;
- QDateTime mMinimumDate;
- QDateTime mMaximumDate;
+ QDate mMinimumDate;
+ QDate mMaximumDate;
};
QT_END_NAMESPACE
diff --git a/tests/auto/controls/data/tst_calendar.qml b/tests/auto/controls/data/tst_calendar.qml
index 17b2b9b4..1f8d9a8d 100644
--- a/tests/auto/controls/data/tst_calendar.qml
+++ b/tests/auto/controls/data/tst_calendar.qml
@@ -124,11 +124,19 @@ Item {
}
function test_defaultConstructed() {
- calendar.minimumDate = new Date(1, 0, 1);
- calendar.maximumDate = new Date(4000, 0, 1);
-
- compare(calendar.minimumDate, new Date(1, 0, 1));
- compare(calendar.maximumDate, new Date(4000, 0, 1));
+ // Minimum date needs to be at least 1921-05-01 due to date problems in < JS7 which
+ // causes problems with the Finnish timezone in CI. So use 1922 to avoid those
+ // causing an invalid failure
+
+ // The minimum and maximum are set with "different" times
+ // to confirm that they have no bearing from what it will
+ // return later on as we only care about the date part
+ // and not the specific time in the range.
+ calendar.minimumDate = new Date(22, 0, 1, 23, 59, 59, 999);
+ calendar.maximumDate = new Date(4000, 0, 1, 0, 0, 0, 0);
+
+ compare(calendar.minimumDate, new Date(22, 0, 1));
+ compare(calendar.maximumDate, new Date(4000, 0, 1, 23, 59, 59, 999));
var expectedDate = new Date();
compare(calendar.selectedDate.getFullYear(), expectedDate.getFullYear());
compare(calendar.selectedDate.getMonth(), expectedDate.getMonth());
@@ -139,15 +147,15 @@ Item {
}
function test_setAfterConstructed() {
- calendar.minimumDate = new Date(1900, 0, 1);
+ calendar.minimumDate = new Date(1922, 0, 1);
calendar.maximumDate = new Date(1999, 11, 31);
calendar.selectedDate = new Date(1980, 0, 1);
calendar.frameVisible = false;
calendar.dayOfWeekFormat = Locale.NarrowFormat;
calendar.locale = Qt.locale("de_DE");
- compare(calendar.minimumDate, new Date(1900, 0, 1));
- compare(calendar.maximumDate, new Date(1999, 11, 31));
+ compare(calendar.minimumDate, new Date(1922, 0, 1));
+ compare(calendar.maximumDate, new Date(1999, 11, 31, 23, 59, 59, 999));
compare(calendar.selectedDate, new Date(1980, 0, 1));
compare(calendar.frameVisible, false);
compare(calendar.locale, Qt.locale("de_DE"));
diff --git a/tests/auto/controls/data/tst_rangeddate.qml b/tests/auto/controls/data/tst_rangeddate.qml
index a1874441..a7d48d85 100644
--- a/tests/auto/controls/data/tst_rangeddate.qml
+++ b/tests/auto/controls/data/tst_rangeddate.qml
@@ -86,45 +86,49 @@ Item {
}
function test_constructionPropertyOrder() {
+ // Minimum date needs to be at least 1921-05-01 due to date problems in < JS7 which
+ // causes problems with the Finnish timezone in CI. So use 1922 to avoid those
+ // causing an invalid failure
+
// All values are valid; fine.
rangedDate = Qt.createQmlObject(importsStr + " RangedDate { "
- + "date: new Date(1900, 0, 2); "
- + "minimumDate: new Date(1900, 0, 1); "
- + "maximumDate: new Date(1900, 0, 3); "
+ + "date: new Date(1922, 0, 2); "
+ + "minimumDate: new Date(1922, 0, 1); "
+ + "maximumDate: new Date(1922, 0, 3); "
+ " }", container, "");
- compare(rangedDate.date.getTime(), new Date(1900, 0, 2).getTime());
- compare(rangedDate.minimumDate.getTime(), new Date(1900, 0, 1).getTime());
- compare(rangedDate.maximumDate.getTime(), new Date(1900, 0, 3).getTime());
+ compare(rangedDate.date.getTime(), new Date(1922, 0, 2).getTime());
+ compare(rangedDate.minimumDate.getTime(), new Date(1922, 0, 1).getTime());
+ compare(rangedDate.maximumDate.getTime(), new Date(1922, 0, 3, 23, 59, 59, 999).getTime());
// All values are the same; doesn't make sense, but is fine [1].
rangedDate = Qt.createQmlObject(importsStr + " RangedDate { "
- + "date: new Date(1900, 0, 1);"
- + "minimumDate: new Date(1900, 0, 1);"
- + "maximumDate: new Date(1900, 0, 1);"
+ + "date: new Date(1922, 0, 1);"
+ + "minimumDate: new Date(1922, 0, 1);"
+ + "maximumDate: new Date(1922, 0, 1);"
+ " }", container, "");
- compare(rangedDate.date.getTime(), new Date(1900, 0, 1).getTime());
- compare(rangedDate.minimumDate.getTime(), new Date(1900, 0, 1).getTime());
- compare(rangedDate.maximumDate.getTime(), new Date(1900, 0, 1).getTime());
+ compare(rangedDate.date.getTime(), new Date(1922, 0, 1).getTime());
+ compare(rangedDate.minimumDate.getTime(), new Date(1922, 0, 1).getTime());
+ compare(rangedDate.maximumDate.getTime(), new Date(1922, 0, 1, 23, 59, 59, 999).getTime());
// date is lower than min - should be clamped to min.
rangedDate = Qt.createQmlObject(importsStr + " RangedDate { "
+ "date: new Date(1899, 0, 1);"
- + "minimumDate: new Date(1900, 0, 1);"
- + "maximumDate: new Date(1900, 0, 1);"
+ + "minimumDate: new Date(1922, 0, 1);"
+ + "maximumDate: new Date(1922, 0, 1);"
+ " }", container, "");
- compare(rangedDate.date.getTime(), new Date(1900, 0, 1).getTime());
- compare(rangedDate.minimumDate.getTime(), new Date(1900, 0, 1).getTime());
- compare(rangedDate.maximumDate.getTime(), new Date(1900, 0, 1).getTime());
+ compare(rangedDate.date.getTime(), new Date(1922, 0, 1).getTime());
+ compare(rangedDate.minimumDate.getTime(), new Date(1922, 0, 1).getTime());
+ compare(rangedDate.maximumDate.getTime(), new Date(1922, 0, 1, 23, 59, 59, 999).getTime());
// date is higher than max - should be clamped to max.
rangedDate = Qt.createQmlObject(importsStr + " RangedDate { "
- + "date: new Date(1900, 0, 2);"
- + "minimumDate: new Date(1900, 0, 1);"
- + "maximumDate: new Date(1900, 0, 1);"
+ + "date: new Date(1922, 0, 2);"
+ + "minimumDate: new Date(1922, 0, 1);"
+ + "maximumDate: new Date(1922, 0, 1);"
+ " }", container, "");
- compare(rangedDate.date.getTime(), new Date(1900, 0, 1).getTime());
- compare(rangedDate.minimumDate.getTime(), new Date(1900, 0, 1).getTime());
- compare(rangedDate.maximumDate.getTime(), new Date(1900, 0, 1).getTime());
+ compare(rangedDate.date.getTime(), new Date(1922, 0, 1, 23, 59, 59, 999).getTime());
+ compare(rangedDate.minimumDate.getTime(), new Date(1922, 0, 1).getTime());
+ compare(rangedDate.maximumDate.getTime(), new Date(1922, 0, 1, 23, 59, 59, 999).getTime());
// If the order of property construction is undefined (as it should be if it's declarative),
// then is min considered higher than max or max lower than min? Which should be changed?
@@ -132,13 +136,13 @@ Item {
// For now, max will always be the one that's changed. It will be set to min,
// as min may already be the largest possible date (See [1]).
rangedDate = Qt.createQmlObject(importsStr + " RangedDate { "
- + "date: new Date(1900, 0, 1);"
- + "minimumDate: new Date(1900, 0, 2);"
- + "maximumDate: new Date(1900, 0, 1);"
+ + "date: new Date(1922, 0, 1);"
+ + "minimumDate: new Date(1922, 0, 2);"
+ + "maximumDate: new Date(1922, 0, 1);"
+ " }", container, "");
- compare(rangedDate.date.getTime(), new Date(1900, 0, 2).getTime());
- compare(rangedDate.minimumDate.getTime(), new Date(1900, 0, 2).getTime());
- compare(rangedDate.maximumDate.getTime(), new Date(1900, 0, 2).getTime());
+ compare(rangedDate.date.getTime(), new Date(1922, 0, 2).getTime());
+ compare(rangedDate.minimumDate.getTime(), new Date(1922, 0, 2).getTime());
+ compare(rangedDate.maximumDate.getTime(), new Date(1922, 0, 2, 23, 59, 59, 999).getTime());
// [1] Do we want to enforce min and max being different? E.g. if min
// is (1900, 0, 1) and max is (1900, 0, 1), max should be set (1900, 0, 2).
@@ -159,7 +163,7 @@ Item {
rangedDate.minimumDate = new Date(1990, 0, 1);
compare(rangedDate.minimumDate.getTime(), new Date(1990, 0, 1).getTime());
rangedDate.maximumDate = new Date(1999, 0, 1);
- compare(rangedDate.maximumDate.getTime(), new Date(1999, 0, 1).getTime());
+ compare(rangedDate.maximumDate.getTime(), new Date(1999, 0, 1, 23, 59, 59, 999).getTime());
// MIN DATE MAX
// [ 1996 | 1996 | 1999 ]