From 305c8e9cf00409770273ab3fd80ba997b9dcb455 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 3 Nov 2023 15:36:17 +0100 Subject: [PATCH] QDTP: minor fixes to handling of two-digit years Although the days in month for a year might be affected by century (if last two digits are 00), actualDate() has at least set the year to its best guess, which will give the right days in the month at least 99% of the time. So take year into account if either year field is set. Adjust a comment's position so that it's clear it's referring to the two-digit case, when (at first sight perversely) using 9999 as the field's max value (it's the datum controlled by it that matters, here). Task-number: QTBUG-46843 Change-Id: Iebebe4b2617eb0820ec57398a774b70bf2ae0898 Reviewed-by: Isak Fyksen Reviewed-by: Thiago Macieira --- src/corelib/time/qdatetimeparser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/time/qdatetimeparser.cpp b/src/corelib/time/qdatetimeparser.cpp index 9da0d1094a1..35448a92c26 100644 --- a/src/corelib/time/qdatetimeparser.cpp +++ b/src/corelib/time/qdatetimeparser.cpp @@ -237,9 +237,9 @@ int QDateTimeParser::absoluteMax(int s, const QDateTime &cur) const case MSecSection: return 999; case YearSection2Digits: - case YearSection: // sectionMaxSize will prevent people from typing in a larger number in // count == 2 sections; stepBy() will work on real years anyway. + case YearSection: return 9999; case MonthSection: return calendar.maximumMonthsInYear(); @@ -1032,7 +1032,7 @@ static QDate actualDate(QDateTimeParser::Sections known, const QCalendar &calend QDate first(year, month, 1, calendar); int last = known & QDateTimeParser::MonthSection - ? (known & QDateTimeParser::YearSection + ? (known.testAnyFlag(QDateTimeParser::YearSectionMask) ? calendar.daysInMonth(month, year) : calendar.daysInMonth(month)) : 0; // We can only fix DOW if we know year as well as month (hence last):