diff --git a/src/corelib/time/qdatetimeparser.cpp b/src/corelib/time/qdatetimeparser.cpp index 9af92941d6b..31e010de74d 100644 --- a/src/corelib/time/qdatetimeparser.cpp +++ b/src/corelib/time/qdatetimeparser.cpp @@ -1037,6 +1037,18 @@ static QDate actualDate(QDateTimeParser::Sections known, QCalendar calendar, int month = 12; known &= ~QDateTimeParser::MonthSection; } + if (!actual.isValid() && !known.testAnyFlag(QDateTimeParser::YearSectionMask) + && known.testFlags(QDateTimeParser::DaySection | QDateTimeParser::MonthSection) + && !calendar.isLeapYear(year) && day > calendar.daysInMonth(month, year)) { + // See if a leap year works better: + int leap = year + 1, stop = year + 47; + // (Sweden's 1700 plan (abandoned part way through) for Julian-Gregorian + // transition implied no leap year after 1697 until 1744.) + while (!calendar.isLeapYear(leap) && leap < stop) + ++leap; + if (day <= calendar.daysInMonth(month, leap)) + year = leap; + } QDate first(year, month, 1, calendar); int last = known & QDateTimeParser::MonthSection