diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2024-03-21 17:41:26 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2024-04-19 12:39:41 +0100 |
commit | 3e426182e2e8122d96b208702faaf3177f3a3081 (patch) | |
tree | 474d9455f2cb32218c67fae009c81b115c1fc7f7 /src/corelib | |
parent | b87db4296cb5d41a9915f04cc7638f975836c046 (diff) |
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.7 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>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/time/qdatetimeparser.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/corelib/time/qdatetimeparser.cpp b/src/corelib/time/qdatetimeparser.cpp index d8b6b17db0..cd237705d2 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(); } } |