diff options
author | Edward Welbourne <edward.welbourne@theqtcompany.com> | 2016-01-19 19:34:52 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@theqtcompany.com> | 2016-01-29 10:35:03 +0000 |
commit | 2736d7921dfcedaa88382e8279dc23e9b1fd3214 (patch) | |
tree | bfcd07e5ff9532b388cfa2f50503580419573a59 | |
parent | ee6463ffd3d12f9d5b4c90d22ca9fcab30483ebc (diff) |
Don't let a good day cause date-time parser to forget a conflict.
Setting conflicts to isSet & DaySection cleared it if we hadn't seen
the day stipulated, even if there had been a conflict (e.g. over year)
before we hit the day-of-week that didn't match the (unset, so
defaulting to) 1st of the month. Explicitly test for conflict and
only set conflicts (to true) if there is a conflict. Added regression
test.
Change-Id: I7363eb66a8bb808d341738d14969039834f50db8
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
-rw-r--r-- | src/corelib/tools/qdatetimeparser.cpp | 6 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp | 4 |
2 files changed, 7 insertions, 3 deletions
diff --git a/src/corelib/tools/qdatetimeparser.cpp b/src/corelib/tools/qdatetimeparser.cpp index 26c17b24ce..cf4fcd4929 100644 --- a/src/corelib/tools/qdatetimeparser.cpp +++ b/src/corelib/tools/qdatetimeparser.cpp @@ -997,8 +997,10 @@ QDateTimeParser::StateNode QDateTimeParser::parse(QString &input, int &cursorPos const QDate date(year, month, day); const int diff = dayofweek - date.dayOfWeek(); - if (diff != 0 && state == Acceptable && isSet & (DayOfWeekSectionShort|DayOfWeekSectionLong)) { - conflicts = isSet & DaySection; + if (diff != 0 && state == Acceptable + && isSet & (DayOfWeekSectionShort | DayOfWeekSectionLong)) { + if (isSet & DaySection) + conflicts = true; const SectionNode &sn = sectionNode(currentSectionIndex); if (sn.type & (DayOfWeekSectionShort|DayOfWeekSectionLong) || currentSectionIndex == -1) { // dayofweek should be preferred diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index 1078aef6ad..f6f1c05814 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -2286,7 +2286,9 @@ void tst_QDateTime::fromStringStringFormat_data() QTest::newRow("data5") << QString("10") << QString("'") << invalidDateTime(); QTest::newRow("data6") << QString("pm") << QString("ap") << QDateTime(defDate(), QTime(12, 0, 0)); QTest::newRow("data7") << QString("foo") << QString("ap") << invalidDateTime(); - QTest::newRow("data8") << QString("101010") << QString("dMyy") << QDateTime(QDate(1910, 10, 10), QTime()); + // Day non-conflict should not hide earlier year conflict (1963-03-01 was a + // Friday; asking for Thursday moves this, without conflict, to the 7th): + QTest::newRow("data8") << QString("77 03 1963 " + thu) << QString("yy MM yyyy ddd") << invalidDateTime(); QTest::newRow("data9") << QString("101010") << QString("dMyy") << QDateTime(QDate(1910, 10, 10), QTime()); QTest::newRow("data10") << QString("101010") << QString("dMyy") << QDateTime(QDate(1910, 10, 10), QTime()); QTest::newRow("data11") << date << QString("dd MMM yy") << QDateTime(QDate(1910, 10, 10), QTime()); |