From 3d6e3fe2034523be0827a22ba478f2084b969083 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Wed, 25 Jan 2023 22:29:33 +0400 Subject: Pass short time format to GetTimeFormat from GetLocaleInfo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TIME_NOSECONDS doesn't really switch to short time format, just removes the seconds from long time format. On picking to 5.15, getLocaleInfo() is templated to return QString, not QVariant, so drop its return's toString() in the new code. Also rename a later local variable to avoid shadowing format (and, incidentally, match dev so as to avoid conflicts there on any later patches). Fixes: QTBUG-110627 Change-Id: Ie799958f3942c657f00bc8196588258661ddc1d9 Reviewed-by: Thiago Macieira (cherry picked from commit 763884cfb7be0cadd353cfa3b9b760d521851718) Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Mate Barany --- src/corelib/text/qlocale_win.cpp | 14 ++++++++------ tests/auto/corelib/text/qlocale/tst_qlocale.cpp | 3 +-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/corelib/text/qlocale_win.cpp b/src/corelib/text/qlocale_win.cpp index b397d258c0..47f80bfb8a 100644 --- a/src/corelib/text/qlocale_win.cpp +++ b/src/corelib/text/qlocale_win.cpp @@ -489,15 +489,17 @@ QVariant QSystemLocalePrivate::toString(QTime time, QLocale::FormatType type) DWORD flags = 0; // keep the same conditional as timeFormat() above - if (type == QLocale::ShortFormat) - flags = TIME_NOSECONDS; + const QString format = type == QLocale::ShortFormat + ? getLocaleInfo(LOCALE_SSHORTTIME) + : QString(); + auto formatStr = reinterpret_cast(format.isEmpty() ? nullptr : format.utf16()); wchar_t buf[255]; - if (getTimeFormat(flags, &st, NULL, buf, 255)) { - QString format = QString::fromWCharArray(buf); + if (getTimeFormat(flags, &st, formatStr, buf, int(std::size(buf)))) { + QString text = QString::fromWCharArray(buf); if (substitution() == SAlways) - substituteDigits(format); - return format; + substituteDigits(text); + return text; } return QString(); } diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index 4ee6c6df75..6bd9e5c25a 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -2108,8 +2108,7 @@ void tst_QLocale::windowsDefaultLocale() QCOMPARE(locale.toString(QDate(1974, 12, 1), QLocale::NarrowFormat), locale.toString(QDate(1974, 12, 1), QLocale::ShortFormat)); QCOMPARE(locale.toString(QDate(1974, 12, 1), QLocale::LongFormat), QString("1@12@1974")); - const QString expectedFormattedShortTimeSeconds = QStringLiteral("1^2^3"); - const QString expectedFormattedShortTime = QStringLiteral("1^2"); + const QString expectedFormattedShortTime = QStringLiteral("1^2^3"); QCOMPARE(locale.toString(QTime(1,2,3), QLocale::ShortFormat), expectedFormattedShortTime); QCOMPARE(locale.toString(QTime(1,2,3), QLocale::NarrowFormat), locale.toString(QTime(1,2,3), QLocale::ShortFormat)); -- cgit v1.2.3