Raise the upper bound on years to 9999
Test-case taken from bug-report; fits in as an easy row in an existing data-driven test. Add similar tests for date-time and time; and an isValid test on the end of year 9999. The date-time parser was using the end of year 7999 as maximum value for dates and date-times; extend this to year 9999, as I can see no reason not to. [ChangeLog][QtCore][QDateTime] Years up to 9999 can now be parsed without error (previously 8000 and beyond were treated as invalid) in all formats (not only in ISO format). Widgets handling dates now support dates to 9999, likewise. Task-number: QTBUG-64401 Change-Id: I518cfa6c2cb4ecc5a85b896dc9e56b4fdd8a8bb1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
ba19363529
commit
a755c2e521
@ -1455,8 +1455,8 @@ QDateTimeParser::parse(QString input, int position, const QDateTime &defaultValu
|
||||
} else {
|
||||
if (context == FromString) {
|
||||
// optimization
|
||||
Q_ASSERT(maximum.date().toJulianDay() == 4642999);
|
||||
if (scan.value.date().toJulianDay() > 4642999)
|
||||
Q_ASSERT(maximum.date().toJulianDay() == 5373484);
|
||||
if (scan.value.date().toJulianDay() > 5373484)
|
||||
scan.state = Invalid;
|
||||
} else {
|
||||
if (scan.value > maximum)
|
||||
|
@ -69,7 +69,7 @@ QT_REQUIRE_CONFIG(datetimeparser);
|
||||
#define QDATETIMEEDIT_TIME_MAX QTime(23, 59, 59, 999)
|
||||
#define QDATETIMEEDIT_DATE_MIN QDate(100, 1, 1)
|
||||
#define QDATETIMEEDIT_COMPAT_DATE_MIN QDate(1752, 9, 14)
|
||||
#define QDATETIMEEDIT_DATE_MAX QDate(7999, 12, 31)
|
||||
#define QDATETIMEEDIT_DATE_MAX QDate(9999, 12, 31)
|
||||
#define QDATETIMEEDIT_DATETIME_MIN QDateTime(QDATETIMEEDIT_DATE_MIN, QDATETIMEEDIT_TIME_MIN)
|
||||
#define QDATETIMEEDIT_COMPAT_DATETIME_MIN QDateTime(QDATETIMEEDIT_COMPAT_DATE_MIN, QDATETIMEEDIT_TIME_MIN)
|
||||
#define QDATETIMEEDIT_DATETIME_MAX QDateTime(QDATETIMEEDIT_DATE_MAX, QDATETIMEEDIT_TIME_MAX)
|
||||
|
@ -982,7 +982,7 @@ QCalendarModel::QCalendarModel(QObject *parent)
|
||||
m_firstRow(1),
|
||||
m_date(QDate::currentDate()),
|
||||
m_minimumDate(QDate::fromJulianDay(1)),
|
||||
m_maximumDate(7999, 12, 31),
|
||||
m_maximumDate(9999, 12, 31),
|
||||
m_shownYear(m_date.year()),
|
||||
m_shownMonth(m_date.month()),
|
||||
m_firstDay(QLocale().firstDayOfWeek()),
|
||||
|
@ -363,7 +363,7 @@ void QDateTimeEdit::setMinimumDateTime(const QDateTime &dt)
|
||||
clearMaximumDateTime().
|
||||
|
||||
By default, this property contains a date that refers to 31 December,
|
||||
7999 and a time of 23:59:59 and 999 milliseconds.
|
||||
9999 and a time of 23:59:59 and 999 milliseconds.
|
||||
|
||||
\sa minimumDateTime(), minimumTime(), maximumTime(), minimumDate(),
|
||||
maximumDate(), setDateTimeRange(), setDateRange(), setTimeRange(),
|
||||
@ -466,7 +466,7 @@ void QDateTimeEdit::clearMinimumDate()
|
||||
necessary to ensure that the range remains valid. If the date is
|
||||
not a valid QDate object, this function does nothing.
|
||||
|
||||
By default, this property contains a date that refers to December 31, 7999.
|
||||
By default, this property contains a date that refers to December 31, 9999.
|
||||
|
||||
\sa minimumDate, minimumTime, maximumTime, setDateRange()
|
||||
*/
|
||||
|
@ -152,6 +152,9 @@ void tst_QDate::isValid_data()
|
||||
QTest::newRow("400-years leap 1600") << 1600 << 2 << 29 << qint64(2305507) << true;
|
||||
QTest::newRow("year 0") << 0 << 2 << 27 << nullJd << false;
|
||||
|
||||
// Test end of four-digit years:
|
||||
QTest::newRow("late") << 9999 << 12 << 31 << qint64(5373484) << true;
|
||||
|
||||
// test the number of days in months:
|
||||
QTest::newRow("jan") << 2000 << 1 << 31 << qint64(2451575) << true;
|
||||
QTest::newRow("feb") << 2000 << 2 << 29 << qint64(2451604) << true; // same data as 400-years leap
|
||||
@ -1098,6 +1101,8 @@ void tst_QDate::fromStringFormat_data()
|
||||
QTest::newRow("data41") << QString("21/5/06") << QString("d/M/yy") << QDate(1906,5,21);
|
||||
QTest::newRow("data42") << QString("20060521") << QString("yyyyMMdd") << QDate(2006,5,21);
|
||||
QTest::newRow("data43") << QString("060521") << QString("yyMMdd") << QDate(1906,5,21);
|
||||
QTest::newRow("lateMarch") << QString("9999-03-06") << QString("yyyy-MM-dd") << QDate(9999, 3, 6);
|
||||
QTest::newRow("late") << QString("9999-12-31") << QString("yyyy-MM-dd") << QDate(9999, 12, 31);
|
||||
}
|
||||
|
||||
|
||||
|
@ -2377,6 +2377,9 @@ void tst_QDateTime::fromStringStringFormat_data()
|
||||
QTest::newRow("data16") << QString("2005-06-28T07:57:30.001Z")
|
||||
<< QString("yyyy-MM-ddThh:mm:ss.zZ")
|
||||
<< QDateTime(QDate(2005, 06, 28), QTime(07, 57, 30, 1));
|
||||
QTest::newRow("late") << QString("9999-12-31T23:59:59.999Z")
|
||||
<< QString("yyyy-MM-ddThh:mm:ss.zZ")
|
||||
<< QDateTime(QDate(9999, 12, 31), QTime(23, 59, 59, 999));
|
||||
}
|
||||
|
||||
void tst_QDateTime::fromStringStringFormat()
|
||||
|
@ -562,6 +562,7 @@ void tst_QTime::fromStringFormat_data()
|
||||
QTest::newRow("data11") << QString("02:23pm") << QString("hh:mmap") << QTime(14,23,0,0);
|
||||
QTest::newRow("short-msecs-lt100") << QString("10:12:34:045") << QString("hh:m:ss:z") << QTime(10,12,34,45);
|
||||
QTest::newRow("short-msecs-gt100") << QString("10:12:34:45") << QString("hh:m:ss:z") << QTime(10,12,34,450);
|
||||
QTest::newRow("late") << QString("23:59:59.999") << QString("hh:mm:ss.z") << QTime(23, 59, 59, 999);
|
||||
}
|
||||
|
||||
void tst_QTime::fromStringFormat()
|
||||
|
@ -336,7 +336,7 @@ void tst_QDateTimeEdit::constructor_qwidget()
|
||||
QCOMPARE(dte.dateTime(), QDateTime(QDate(2000, 1, 1), QTime(0, 0, 0, 0)));
|
||||
QCOMPARE(dte.minimumDate(), QDate(1752, 9, 14));
|
||||
QCOMPARE(dte.minimumTime(), QTime(0, 0, 0, 0));
|
||||
QCOMPARE(dte.maximumDate(), QDate(7999, 12, 31));
|
||||
QCOMPARE(dte.maximumDate(), QDate(9999, 12, 31));
|
||||
QCOMPARE(dte.maximumTime(), QTime(23, 59, 59, 999));
|
||||
}
|
||||
|
||||
@ -352,12 +352,12 @@ void tst_QDateTimeEdit::constructor_qdatetime_data()
|
||||
QTest::newRow("normal") << QDateTime(QDate(2004, 6, 16), QTime(13, 46, 32, 764))
|
||||
<< QDateTime(QDate(2004, 6, 16), QTime(13, 46, 32, 764))
|
||||
<< QDate(1752, 9, 14) << QTime(0, 0, 0, 0)
|
||||
<< QDate(7999, 12, 31) << QTime(23, 59, 59, 999);
|
||||
<< QDate(9999, 12, 31) << QTime(23, 59, 59, 999);
|
||||
|
||||
QTest::newRow("invalid") << QDateTime(QDate(9999, 99, 99), QTime(13, 46, 32, 764))
|
||||
<< QDateTime(QDate(2000, 1, 1), QTime(0, 0, 0, 0))
|
||||
<< QDate(1752, 9, 14) << QTime(0, 0, 0, 0)
|
||||
<< QDate(7999, 12, 31) << QTime(23, 59, 59, 999);
|
||||
<< QDate(9999, 12, 31) << QTime(23, 59, 59, 999);
|
||||
}
|
||||
|
||||
void tst_QDateTimeEdit::constructor_qdatetime()
|
||||
@ -392,12 +392,12 @@ void tst_QDateTimeEdit::constructor_qdate_data()
|
||||
QTest::newRow("normal") << QDate(2004, 6, 16)
|
||||
<< QDateTime(QDate(2004, 6, 16), QTime(0, 0, 0, 0))
|
||||
<< QDate(1752, 9, 14) << QTime(0, 0, 0, 0)
|
||||
<< QDate(7999, 12, 31) << QTime(23, 59, 59, 999);
|
||||
<< QDate(9999, 12, 31) << QTime(23, 59, 59, 999);
|
||||
|
||||
QTest::newRow("invalid") << QDate(9999, 99, 99)
|
||||
<< QDateTime(QDate(2000, 1, 1), QTime(0, 0, 0, 0))
|
||||
<< QDate(1752, 9, 14) << QTime(0, 0, 0, 0)
|
||||
<< QDate(7999, 12, 31) << QTime(23, 59, 59, 999);
|
||||
<< QDate(9999, 12, 31) << QTime(23, 59, 59, 999);
|
||||
}
|
||||
|
||||
void tst_QDateTimeEdit::constructor_qdate()
|
||||
@ -467,7 +467,7 @@ void tst_QDateTimeEdit::minimumDate_data()
|
||||
|
||||
QTest::newRow("normal-0") << QDate(2004, 5, 10) << QDate(2004, 5, 10);
|
||||
QTest::newRow("normal-1") << QDate(2002, 3, 15) << QDate(2002, 3, 15);
|
||||
QTest::newRow("normal-2") << QDate(7999, 12, 31) << QDate(7999, 12, 31);
|
||||
QTest::newRow("normal-2") << QDate(9999, 12, 31) << QDate(9999, 12, 31);
|
||||
QTest::newRow("normal-3") << QDate(1753, 1, 1) << QDate(1753, 1, 1);
|
||||
QTest::newRow("invalid-0") << QDate(0, 0, 0) << QDate(1752, 9, 14);
|
||||
QTest::newRow("old") << QDate(1492, 8, 3) << QDate(1492, 8, 3);
|
||||
@ -528,7 +528,7 @@ void tst_QDateTimeEdit::maximumDateTime_data()
|
||||
<< QDateTime(QDate(2007, 5, 10), QTime(22, 23, 23));
|
||||
QTest::newRow("normal-4") << QDateTime(QDate(2008, 5, 10), QTime(2, 3, 1))
|
||||
<< QDateTime(QDate(2008, 5, 10), QTime(2, 3, 1));
|
||||
QTest::newRow("invalid-0") << QDateTime() << QDateTime(QDate(7999, 12, 31), QTime(23, 59, 59, 999));
|
||||
QTest::newRow("invalid-0") << QDateTime() << QDateTime(QDate(9999, 12, 31), QTime(23, 59, 59, 999));
|
||||
}
|
||||
|
||||
void tst_QDateTimeEdit::maximumDateTime()
|
||||
@ -547,9 +547,9 @@ void tst_QDateTimeEdit::maximumDate_data()
|
||||
|
||||
QTest::newRow("normal-0") << QDate(2004, 05, 10) << QDate(2004, 5, 10);
|
||||
QTest::newRow("normal-1") << QDate(2002, 03, 15) << QDate(2002, 3, 15);
|
||||
QTest::newRow("normal-2") << QDate(7999, 12, 31) << QDate(7999, 12, 31);
|
||||
QTest::newRow("normal-2") << QDate(9999, 12, 31) << QDate(9999, 12, 31);
|
||||
QTest::newRow("normal-3") << QDate(1753, 1, 1) << QDate(1753, 1, 1);
|
||||
QTest::newRow("invalid-0") << QDate(0, 0, 0) << QDate(7999, 12, 31);
|
||||
QTest::newRow("invalid-0") << QDate(0, 0, 0) << QDate(9999, 12, 31);
|
||||
}
|
||||
|
||||
void tst_QDateTimeEdit::maximumDate()
|
||||
@ -569,7 +569,7 @@ void tst_QDateTimeEdit::clearMinimumDate_data()
|
||||
|
||||
QTest::newRow("normal-0") << QDate(2004, 05, 10) << true << QDate(1752, 9, 14);
|
||||
QTest::newRow("normal-1") << QDate(2002, 3, 15) << true << QDate(1752, 9, 14);
|
||||
QTest::newRow("normal-2") << QDate(7999, 12, 31) << true << QDate(1752, 9, 14);
|
||||
QTest::newRow("normal-2") << QDate(9999, 12, 31) << true << QDate(1752, 9, 14);
|
||||
QTest::newRow("normal-3") << QDate(1753, 1, 1) << true << QDate(1752, 9, 14);
|
||||
QTest::newRow("invalid-0") << QDate(0, 0, 0) << false << QDate(1752, 9, 14);
|
||||
}
|
||||
@ -597,7 +597,7 @@ void tst_QDateTimeEdit::clearMinimumDateTime_data()
|
||||
<< true << QDateTime(QDate(1752, 9, 14), QTime(0, 0));
|
||||
QTest::newRow("normal-1") << QDateTime(QDate(2002, 3, 15), QTime(13, 13, 13))
|
||||
<< true << QDateTime(QDate(1752, 9, 14), QTime(0, 0));
|
||||
QTest::newRow("normal-2") << QDateTime(QDate(7999, 12, 31), QTime(14, 14, 14))
|
||||
QTest::newRow("normal-2") << QDateTime(QDate(9999, 12, 31), QTime(14, 14, 14))
|
||||
<< true << QDateTime(QDate(1752, 9, 14), QTime(0, 0));
|
||||
QTest::newRow("normal-3") << QDateTime(QDate(1753, 1, 1), QTime(15, 15, 15))
|
||||
<< true << QDateTime(QDate(1752, 9, 14), QTime(0, 0));
|
||||
@ -626,15 +626,15 @@ void tst_QDateTimeEdit::clearMaximumDateTime_data()
|
||||
QTest::addColumn<QDateTime>("expectedMinDateTimeAfterClear");
|
||||
|
||||
QTest::newRow("normal-0") << QDateTime(QDate(2004, 05, 10), QTime(12, 12, 12))
|
||||
<< true << QDateTime(QDate(7999, 12, 31), QTime(23, 59, 59, 999));
|
||||
<< true << QDateTime(QDate(9999, 12, 31), QTime(23, 59, 59, 999));
|
||||
QTest::newRow("normal-1") << QDateTime(QDate(2002, 3, 15), QTime(13, 13, 13))
|
||||
<< true << QDateTime(QDate(7999, 12, 31), QTime(23, 59, 59, 999));
|
||||
QTest::newRow("normal-2") << QDateTime(QDate(7999, 12, 31), QTime(14, 14, 14))
|
||||
<< true << QDateTime(QDate(7999, 12, 31), QTime(23, 59, 59, 999));
|
||||
<< true << QDateTime(QDate(9999, 12, 31), QTime(23, 59, 59, 999));
|
||||
QTest::newRow("normal-2") << QDateTime(QDate(9999, 12, 31), QTime(14, 14, 14))
|
||||
<< true << QDateTime(QDate(9999, 12, 31), QTime(23, 59, 59, 999));
|
||||
QTest::newRow("normal-3") << QDateTime(QDate(1753, 1, 1), QTime(15, 15, 15))
|
||||
<< true << QDateTime(QDate(7999, 12, 31), QTime(23, 59, 59, 999));
|
||||
<< true << QDateTime(QDate(9999, 12, 31), QTime(23, 59, 59, 999));
|
||||
QTest::newRow("invalid-0") << QDateTime()
|
||||
<< false << QDateTime(QDate(7999, 12, 31), QTime(23, 59, 59, 999));
|
||||
<< false << QDateTime(QDate(9999, 12, 31), QTime(23, 59, 59, 999));
|
||||
}
|
||||
|
||||
void tst_QDateTimeEdit::clearMaximumDateTime()
|
||||
@ -656,11 +656,11 @@ void tst_QDateTimeEdit::clearMaximumDate_data()
|
||||
QTest::addColumn<bool>("valid");
|
||||
QTest::addColumn<QDate>("expectedMaxDateAfterClear");
|
||||
|
||||
QTest::newRow("normal-0") << QDate(2004, 05, 10) << true << QDate(7999, 12, 31);
|
||||
QTest::newRow("normal-1") << QDate(2002, 03, 15) << true << QDate(7999, 12, 31);
|
||||
QTest::newRow("normal-2") << QDate(7999, 12, 31) << true << QDate(7999, 12, 31);
|
||||
QTest::newRow("normal-3") << QDate(2000, 1, 1) << true << QDate(7999, 12, 31);
|
||||
QTest::newRow("invalid-0") << QDate(0, 0, 0) << false << QDate(7999, 12, 31);
|
||||
QTest::newRow("normal-0") << QDate(2004, 05, 10) << true << QDate(9999, 12, 31);
|
||||
QTest::newRow("normal-1") << QDate(2002, 03, 15) << true << QDate(9999, 12, 31);
|
||||
QTest::newRow("normal-2") << QDate(9999, 12, 31) << true << QDate(9999, 12, 31);
|
||||
QTest::newRow("normal-3") << QDate(2000, 1, 1) << true << QDate(9999, 12, 31);
|
||||
QTest::newRow("invalid-0") << QDate(0, 0, 0) << false << QDate(9999, 12, 31);
|
||||
}
|
||||
|
||||
void tst_QDateTimeEdit::clearMaximumDate()
|
||||
|
Loading…
Reference in New Issue
Block a user