From 763884cfb7be0cadd353cfa3b9b760d521851718 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Wed, 25 Jan 2023 22:29:33 +0400 Subject: [PATCH] Pass short time format to GetTimeFormat from GetLocaleInfo TIME_NOSECONDS doesn't really switches to short time format, just removes the seconds from long time format Fixes: QTBUG-110627 Pick-to: 6.5 6.4 6.2 5.15 Change-Id: Ie799958f3942c657f00bc8196588258661ddc1d9 Reviewed-by: Thiago Macieira --- src/corelib/text/qlocale_win.cpp | 8 +++++--- tests/auto/corelib/text/qlocale/tst_qlocale.cpp | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/corelib/text/qlocale_win.cpp b/src/corelib/text/qlocale_win.cpp index ce482c1977..550f7dd464 100644 --- a/src/corelib/text/qlocale_win.cpp +++ b/src/corelib/text/qlocale_win.cpp @@ -482,11 +482,13 @@ 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).toString() + : QString(); + auto formatStr = reinterpret_cast(format.isEmpty() ? nullptr : format.utf16()); wchar_t buf[255]; - if (getTimeFormat(flags, &st, NULL, buf, 255)) { + if (getTimeFormat(flags, &st, formatStr, buf, int(std::size(buf)))) { QString text = QString::fromWCharArray(buf); if (substitution() == SAlways) text = substituteDigits(std::move(text)); diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index 52be69e30a..7a71947c17 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -2395,7 +2395,7 @@ void tst_QLocale::windowsDefaultLocale() locale.toString(QDate(1974, 12, 1), QLocale::ShortFormat)); QCOMPARE(locale.toString(QDate(1974, 12, 1), QLocale::LongFormat), QStringView(u"\u3021@\u3021\u3022@\u3021\u3029\u3027\u3024")); - const QString expectedFormattedShortTime = QStringView(u"\u3021^\u3022").toString(); + const QString expectedFormattedShortTime = QStringView(u"\u3021^\u3022^\u3023").toString(); 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));