summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2017-02-25 11:21:44 -0800
committerEdward Welbourne <edward.welbourne@qt.io>2017-02-28 10:40:40 +0000
commit04b8db3d57970631351fc6330af9553e94f1b14d (patch)
tree87b19362b62bc19b37bc0bc18783a0af6f323094 /tests/auto
parent2ae8292d03beab5869a1319e3d18ea281a5d014c (diff)
Fix parsing of day-of-week names that start with another name
Task-number: QTBUG-59159 Change-Id: I95c9e502ccc74af3bcf0fffd14a69e0cd27ce96b Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp50
1 files changed, 50 insertions, 0 deletions
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<QString>("string");
+ QTest::addColumn<QString>("format");
+ QTest::addColumn<QLocale>("locale");
+ QTest::addColumn<QDateTime>("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()