summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlya Fedin <fedin-ilja2010@ya.ru>2023-01-25 22:29:33 +0400
committerEdward Welbourne <edward.welbourne@qt.io>2023-02-03 15:05:28 +0100
commit3d6e3fe2034523be0827a22ba478f2084b969083 (patch)
treedeb146ec1a2d07c30dc2e4271bf68105805ece38
parentecaa0f1aceaae571101d6358e29d8dee8b2cc439 (diff)
Pass short time format to GetTimeFormat from GetLocaleInfo
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 <thiago.macieira@intel.com> (cherry picked from commit 763884cfb7be0cadd353cfa3b9b760d521851718) Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Mate Barany <mate.barany@qt.io>
-rw-r--r--src/corelib/text/qlocale_win.cpp14
-rw-r--r--tests/auto/corelib/text/qlocale/tst_qlocale.cpp3
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<const wchar_t *>(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));