diff --git a/src/corelib/doc/snippets/code/src_corelib_time_qdatetime.cpp b/src/corelib/doc/snippets/code/src_corelib_time_qdatetime.cpp index 588e81bab1a..05fbf042ec8 100644 --- a/src/corelib/doc/snippets/code/src_corelib_time_qdatetime.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_time_qdatetime.cpp @@ -150,18 +150,6 @@ qDebug() << "UTC time is:" << UTC; qDebug() << "There are" << local.secsTo(UTC) << "seconds difference between the datetimes."; //! [19] -//! [20] -QString string = "Monday, 23 April 12 22:51:41"; -QString format = "dddd, d MMMM yy hh:mm:ss"; -QDateTime invalid = QDateTime::fromString(string, format); -//! [20] - -//! [21] -QString string = "Tuesday, 23 April 12 22:51:41"; -QString format = "dddd, d MMMM yy hh:mm:ss"; -QDateTime valid = QDateTime::fromString(string, format); -//! [21] - //! [22] // 23 April 2012: QDate date = std::chrono::year_month_day(std::chrono::year(2012), diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index 4cc989c8466..89aba9a53de 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -5883,16 +5883,7 @@ QDateTime QDateTime::fromString(QStringView string, Qt::DateFormat format) two digits. Incorrectly specified fields of the \a string will cause an invalid - QDateTime to be returned. For example, consider the following code, - where the two digit year 12 is read as 1912 (see the table below for all - field defaults); the resulting datetime is invalid because 23 April 1912 - was a Tuesday, not a Monday: - - \snippet code/src_corelib_time_qdatetime.cpp 20 - - The correct code is: - - \snippet code/src_corelib_time_qdatetime.cpp 21 + QDateTime to be returned. \note Day and month names as well as AM/PM indicators must be given in English (C locale). If localized month and day names or localized forms of diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index ce17a562354..bad8837ed24 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -3309,6 +3309,12 @@ void tst_QDateTime::fromStringStringFormat_data() << u"2018 wilful long working block relief 12-19T21:09 cruel"_s << u"yyyy wilful long working block relief MM-ddThh:mm cruel blurb encore flux"_s << 1900 << QDateTime(); + QTest::newRow("fix-century-Mon") + << u"Monday, 23 April 12 22:51:41"_s << u"dddd, d MMMM yy hh:mm:ss"_s << 1900 + << QDateTime(QDate(2012, 4, 23), QTime(22, 51, 41)); + QTest::newRow("fix-century-Tue") + << u"Tuesday, 23 April 12 22:51:41"_s << u"dddd, d MMMM yy hh:mm:ss"_s << 2000 + << QDateTime(QDate(1912, 4, 23), QTime(22, 51, 41)); // test unicode QTest::newRow("unicode handling")