From 04b8db3d57970631351fc6330af9553e94f1b14d Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sat, 25 Feb 2017 11:21:44 -0800 Subject: Fix parsing of day-of-week names that start with another name Task-number: QTBUG-59159 Change-Id: I95c9e502ccc74af3bcf0fffd14a69e0cd27ce96b Reviewed-by: Edward Welbourne --- .../auto/corelib/tools/qdatetime/tst_qdatetime.cpp | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'tests/auto/corelib/tools') diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index 33844feafe..b6c740998e 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -117,6 +117,8 @@ private slots: void fromStringDateFormat(); void fromStringStringFormat_data(); void fromStringStringFormat(); + void fromStringStringFormatLocale_data(); + void fromStringStringFormatLocale(); #ifdef Q_OS_WIN void fromString_LOCALE_ILDATE(); #endif @@ -2337,6 +2339,54 @@ void tst_QDateTime::fromStringStringFormat() QCOMPARE(dt, expected); } +void tst_QDateTime::fromStringStringFormatLocale_data() +{ + QTest::addColumn("string"); + QTest::addColumn("format"); + QTest::addColumn("locale"); + QTest::addColumn("expected"); + + QLocale c = QLocale::c(); + QDateTime dt(QDate(2017, 02, 25), QTime(17, 21, 25)); + + // The formats correspond to the locale formats, with the timezone removed. + // We hardcode them in case an update to the locale DB changes them. + + QTest::newRow("C:long") << "Saturday, 25 February 2017 17:21:25" << "dddd, d MMMM yyyy HH:mm:ss" << c << dt; + QTest::newRow("C:short") << "25 Feb 2017 17:21:25" << "d MMM yyyy HH:mm:ss" << c << dt; + QTest::newRow("C:narrow") << "25 Feb 2017 17:21:25" << "d MMM yyyy HH:mm:ss" << c << dt; + + QLocale fr(QLocale::French); + QTest::newRow("fr:long") << "Samedi 25 février 2017 17:21:25" << "dddd d MMMM yyyy HH:mm:ss" << fr << dt; + QTest::newRow("fr:short") << "25/02/2017 17:21" << "dd/MM/yyyy HH:mm" << fr << dt.addSecs(-25); + + // In Turkish, the word for Friday ("Cuma") is a prefix for the word for + // Saturday ("Cumartesi") + QLocale tr(QLocale::Turkish); + QTest::newRow("tr:long") << "25 Şubat 2017 Cumartesi 17:21:25" << "d MMMM yyyy dddd HH:mm:ss" << tr << dt; + QTest::newRow("tr:long2") << "24 Şubat 2017 Cuma 17:21:25" << "d MMMM yyyy dddd HH:mm:ss" << tr << dt.addDays(-1); + QTest::newRow("tr:mashed") << "25 Şubat2017 Cumartesi17:21:25" << "d MMMMyyyy ddddHH:mm:ss" << tr << dt; + QTest::newRow("tr:mashed2") << "24 Şubat2017 Cuma17:21:25" << "d MMMMyyyy ddddHH:mm:ss" << tr << dt.addDays(-1); + QTest::newRow("tr:short") << "25.02.2017 17:21" << "d.MM.yyyy HH:mm" << tr << dt.addSecs(-25); +} + +void tst_QDateTime::fromStringStringFormatLocale() +{ + QFETCH(QString, string); + QFETCH(QString, format); + QFETCH(QLocale, locale); + QFETCH(QDateTime, expected); + + QDateTime parsed = locale.toDateTime(string, format); + QCOMPARE(parsed, expected); + + parsed = locale.toDateTime(string.toLower(), format); + QCOMPARE(parsed, expected); + + parsed = locale.toDateTime(string.toUpper(), format); + QCOMPARE(parsed, expected); +} + #ifdef Q_OS_WIN // Windows only void tst_QDateTime::fromString_LOCALE_ILDATE() -- cgit v1.2.3