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 <thiago.macieira@intel.com>
This commit is contained in:
parent
0eea2238f3
commit
763884cfb7
@ -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<const wchar_t *>(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));
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user