diff --git a/src/corelib/time/qdatetimeparser.cpp b/src/corelib/time/qdatetimeparser.cpp index 64f4e8b7ad5..7d7e120da09 100644 --- a/src/corelib/time/qdatetimeparser.cpp +++ b/src/corelib/time/qdatetimeparser.cpp @@ -785,7 +785,7 @@ QDateTimeParser::parseSection(const QDateTime ¤tValue, int sectionIndex, i const int sectionmaxsize = sectionMaxSize(sectionIndex); const bool negate = (sn.type == YearSection && m_text.size() > offset - && m_text.at(offset) == u'-'); + && calendar.isProleptic() && m_text.at(offset) == u'-'); const int negativeYearOffset = negate ? 1 : 0; QStringView sectionTextRef = @@ -948,6 +948,12 @@ QDateTimeParser::parseSection(const QDateTime ¤tValue, int sectionIndex, i } else { result = ParsedSection(Intermediate, lastVal, used); } + } else if (!lastVal && !calendar.hasYearZero() + && (sn.type == YearSection + || (sn.type == YearSection2Digits && currentValue.isValid() + && currentValue.date().year() / 100 == 0))) { + // Year zero prohibited + result = ParsedSection(unfilled ? Acceptable : Invalid, lastVal, used); } else { result = ParsedSection(Acceptable, lastVal, used); } diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index c2c1ce78ba0..66008e29932 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -3277,6 +3277,8 @@ void tst_QDateTime::fromStringStringFormat_data() << u"2001-09-15T09:33:01.001 "_s << u"yyyy-MM-ddThh:mm:ss.z t"_s << 1900 << QDateTime(); QTest::newRow("invalid-month-year