diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2021-05-26 18:12:40 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2021-11-18 18:13:20 +0100 |
commit | 8926eb86c62595a0fdac3126c389916db1b451bc (patch) | |
tree | c938c2ef93a61bc338a3b6455119809bc987b4ed /tests/auto/corelib/text/qlocale | |
parent | 2bf5a60bfa8b21c5939b87f0f556c728fa4d8c39 (diff) |
Fix formatting of dates before 1601 in MS system locale
The relevant MS system calls (say they) don't support date formatting
for years < 1601 (but apparently do in fact) and the year field of the
data structure is unsigned, so can't support years < 0. As a result,
the windows back-end for QSystemLocale failed for negative years.
So replace year < 1601 with a place-holder and substitute after
formatting.
Added new tests (based loosely on one in qtdeclarative that failed) to
verify that this actually works. These reveal that macOS also fails to
handle negative years; marked as expected failure there pending a fix.
Change-Id: I9b63cefd5f0b77a39cf1238549412de3e26ca1bd
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/text/qlocale')
-rw-r--r-- | tests/auto/corelib/text/qlocale/tst_qlocale.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index c5ba003363..cd3682a207 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -2630,6 +2630,30 @@ void tst_QLocale::dateFormat() const auto sys = QLocale::system(); // QTBUG-92018, ru_RU on MS const QDate date(2021, 3, 17); QCOMPARE(sys.toString(date, sys.dateFormat(QLocale::LongFormat)), sys.toString(date)); + + // Check that system locale can format a date with year < 1601 (MS cut-off): + QString old = sys.toString(QDate(1564, 2, 15), QLocale::LongFormat); + QVERIFY(!old.isEmpty()); + QVERIFY2(old.contains(u"1564"), qPrintable(old + QLatin1String(" for locale ") + sys.name())); + old = sys.toString(QDate(1564, 2, 15), QLocale::ShortFormat); + QVERIFY(!old.isEmpty()); + QVERIFY2(old.contains(u"64"), qPrintable(old + QLatin1String(" for locale ") + sys.name())); + + // Including one with year % 100 < 12 (lest we substitute year for month or day) + old = sys.toString(QDate(1511, 11, 11), QLocale::LongFormat); + QVERIFY(!old.isEmpty()); + QVERIFY2(old.contains(u"1511"), qPrintable(old + QLatin1String(" for locale ") + sys.name())); + old = sys.toString(QDate(1511, 11, 11), QLocale::ShortFormat); + QVERIFY(!old.isEmpty()); + QVERIFY2(old.contains(u"11"), qPrintable(old + QLatin1String(" for locale ") + sys.name())); + + // And, indeed, one for a negative year: + old = sys.toString(QDate(-1173, 5, 1), QLocale::LongFormat); + QVERIFY(!old.isEmpty()); +#ifdef Q_OS_DARWIN // bug in qlocale_mac.mm, fix coming shortly + QEXPECT_FAIL("", "Darwin converts year to positive", Continue); +#endif + QVERIFY2(old.contains(u"-1173"), qPrintable(old + QLatin1String(" for locale ") + sys.name())); } void tst_QLocale::timeFormat() |