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 Change-Id: Ie799958f3942c657f00bc8196588258661ddc1d9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 763884cfb7be0cadd353cfa3b9b760d521851718) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
8eee5acfb2
commit
a765c10436
@ -479,11 +479,13 @@ QVariant QSystemLocalePrivate::toString(QTime time, QLocale::FormatType type)
|
|||||||
|
|
||||||
DWORD flags = 0;
|
DWORD flags = 0;
|
||||||
// keep the same conditional as timeFormat() above
|
// keep the same conditional as timeFormat() above
|
||||||
if (type == QLocale::ShortFormat)
|
const QString format = type == QLocale::ShortFormat
|
||||||
flags = TIME_NOSECONDS;
|
? getLocaleInfo(LOCALE_SSHORTTIME).toString()
|
||||||
|
: QString();
|
||||||
|
auto formatStr = reinterpret_cast<const wchar_t *>(format.isEmpty() ? nullptr : format.utf16());
|
||||||
|
|
||||||
wchar_t buf[255];
|
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);
|
QString text = QString::fromWCharArray(buf);
|
||||||
if (substitution() == SAlways)
|
if (substitution() == SAlways)
|
||||||
text = substituteDigits(std::move(text));
|
text = substituteDigits(std::move(text));
|
||||||
|
@ -2314,7 +2314,7 @@ void tst_QLocale::windowsDefaultLocale()
|
|||||||
locale.toString(QDate(1974, 12, 1), QLocale::ShortFormat));
|
locale.toString(QDate(1974, 12, 1), QLocale::ShortFormat));
|
||||||
QCOMPARE(locale.toString(QDate(1974, 12, 1), QLocale::LongFormat),
|
QCOMPARE(locale.toString(QDate(1974, 12, 1), QLocale::LongFormat),
|
||||||
QStringView(u"\u3021@\u3021\u3022@\u3021\u3029\u3027\u3024"));
|
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::ShortFormat), expectedFormattedShortTime);
|
||||||
QCOMPARE(locale.toString(QTime(1,2,3), QLocale::NarrowFormat),
|
QCOMPARE(locale.toString(QTime(1,2,3), QLocale::NarrowFormat),
|
||||||
locale.toString(QTime(1,2,3), QLocale::ShortFormat));
|
locale.toString(QTime(1,2,3), QLocale::ShortFormat));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user