summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2020-09-18 17:26:37 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2020-10-03 07:09:57 +0200
commit4e675cb85e81b67f36473914f5822dd6e626ddf0 (patch)
tree7b177d90f6d072b97f024bf39423b2742613e9f7 /tests/auto
parentc3cd7603037108ba9e9f6507ec16cdcf0905bf4c (diff)
Handle trailing cruft consistently in Qt::DateFormat parsing
Previously the ISO time format would tolerate trailing cruft at the end in various cases even though there might be an offset specifier after the time, which should *not* be separated from it by anything (not even the spaces we originally planned to still tolerate). The RFC date format is forgiving about space, as is suitable for parsing of RFC-822 headers, but the other formats should match the handling in QDateTimeParser, which rejects any dangling cruft. At the same time, since this required a re-write of fromIsoTimeString() in any case, add support for the ISO format that gives the hour a fractional part and skips minutes and seconds. Previously we only had support for fractional minutes (with no seconds). The hour without even a fractional part is also valid. Reworked the documentation of Qt::DateFormat as it was wrong in places, inconsistent in its formatting and incomplete. Adjusted some tests to match the new behavior. A fraction separator with no following digits should have been recognized as an error previously and now is. [ChangeLog][QtCore][QDateTime] The ISODate and ISODateWithMs formats now reject trailing cruft (including spaces) at the end of a time string. They also gain support for parsing hour-only formats, including the hour-with-fractional-part format. Task-number: QTBUG-86133 Change-Id: I38ad1479ae033407f7df97ffbeb7c4bcd463d04a Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp7
1 files changed, 3 insertions, 4 deletions
diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
index 855b7273c8..b414458466 100644
--- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
@@ -2211,8 +2211,7 @@ void tst_QDateTime::fromStringDateFormat_data()
// Test Qt::ISODate format.
QTest::newRow("trailing space") // QTBUG-80445
- << QString("2000-01-02 03:04:05.678 ")
- << Qt::ISODate << QDateTime(QDate(2000, 1, 2), QTime(3, 4, 5, 678));
+ << QString("2000-01-02 03:04:05.678 ") << Qt::ISODate << QDateTime();
// Invalid spaces (but keeping field widths correct):
QTest::newRow("space before millis")
@@ -2327,8 +2326,8 @@ void tst_QDateTime::fromStringDateFormat_data()
<< Qt::ISODate << QDateTime(QDate(2012, 1, 1), QTime(8, 0, 0, 333), Qt::LocalTime);
QTest::newRow("ISO .00009 of a second (period)") << QString::fromLatin1("2012-01-01T08:00:00.00009")
<< Qt::ISODate << QDateTime(QDate(2012, 1, 1), QTime(8, 0, 0, 0), Qt::LocalTime);
- QTest::newRow("ISO no fract specified") << QString::fromLatin1("2012-01-01T08:00:00.")
- << Qt::ISODate << QDateTime(QDate(2012, 1, 1), QTime(8, 0, 0, 0), Qt::LocalTime);
+ QTest::newRow("ISO no fraction specified")
+ << QString::fromLatin1("2012-01-01T08:00:00.") << Qt::ISODate << QDateTime();
// Test invalid characters (should ignore invalid characters at end of string).
QTest::newRow("ISO invalid character at end") << QString::fromLatin1("2012-01-01T08:00:00!")
<< Qt::ISODate << QDateTime();