summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2024-03-21 17:41:26 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2024-04-19 13:46:49 +0000
commit23b69855c0d2ed747a73b15f72f1788804bdb477 (patch)
tree9581fa908a3db24998d44a7e376c10c8cd77f68f
parentReplace expensive inherits with cheaper qobject_cast (2) (diff)
downloadqtbase-23b69855c0d2ed747a73b15f72f1788804bdb477.tar.xz
qtbase-23b69855c0d2ed747a73b15f72f1788804bdb477.zip
Fix end-of-parse fixup of two-digit year in QDateTimeParser
When a date string contains day of the week, day of the month, month and two-digit year, it was still possible to get a conflicting result in the default century instead of a consistent result in the next (in fact present) century. The actual logic needed to get the right year has to take into account all date fields. This is all worked out already in actualDate(), so delegate to it instead of trying to make do with just the year info. Pick-to: 6.6 6.5 Fixes: QTBUG-123579 Change-Id: Id057128d8a0af9f3a7708d0ee173f854bb1a2a8e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Dennis Oberst <dennis.oberst@qt.io> (cherry picked from commit 3e426182e2e8122d96b208702faaf3177f3a3081) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/corelib/time/qdatetimeparser.cpp6
-rw-r--r--tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp3
2 files changed, 7 insertions, 2 deletions
diff --git a/src/corelib/time/qdatetimeparser.cpp b/src/corelib/time/qdatetimeparser.cpp
index 7c6ec272fb..d6ff29cf7f 100644
--- a/src/corelib/time/qdatetimeparser.cpp
+++ b/src/corelib/time/qdatetimeparser.cpp
@@ -1360,13 +1360,15 @@ QDateTimeParser::scanString(const QDateTime &defaultValue, bool fixup) const
if (parserType != QMetaType::QTime) {
if (year % 100 != year2digits && (isSet & YearSection2Digits)) {
+ const QDate date = actualDate(isSet, calendar, defaultCenturyStart,
+ year, year2digits, month, day, dayofweek);
if (!(isSet & YearSection)) {
- year = yearInCenturyFrom(year2digits, defaultCenturyStart);
+ year = date.year();
} else {
conflicts = true;
const SectionNode &sn = sectionNode(currentSectionIndex);
if (sn.type == YearSection2Digits)
- year = yearInCenturyFrom(year2digits, defaultCenturyStart);
+ year = date.year();
}
}
diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
index 6c0733686d..f9c6afc795 100644
--- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
@@ -3117,6 +3117,9 @@ void tst_QDateTime::fromStringStringFormat_data()
<< u"Thu January 2004"_s << u"ddd MMMM yyyy"_s << 1900
<< QDate(2004, 1, 1).startOfDay();
}
+ QTest::newRow("yy=24/Mar/20") // QTBUG-123579
+ << u"Wed, 20 Mar 24 16:17:00"_s << u"ddd, dd MMM yy HH:mm:ss"_s << 1900
+ << QDateTime(QDate(2024, 3, 20), QTime(16, 17));
QTest::newRow("secs-conflict") << u"1020"_s << u"sss"_s << 1900 << QDateTime();
QTest::newRow("secs-split-conflict")
<< u"10hello20"_s << u"ss'hello'ss"_s << 1900 << QDateTime();