Use the short time format of the current locale on Windows
Windows 7 and later have LOCALE_SSHORTTIME, which is what we need. Task-number: QTBUG-33718 Change-Id: I4c3f113d17102a37fb752de56f06b312f27c7887 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
This commit is contained in:
parent
e6abf372c6
commit
68ff352906
@ -82,6 +82,9 @@ static QString winIso3116CtryName(LCID id = LOCALE_USER_DEFAULT);
|
||||
#ifndef LOCALE_SNATIVECOUNTRYNAME
|
||||
# define LOCALE_SNATIVECOUNTRYNAME 0x00000008
|
||||
#endif
|
||||
#ifndef LOCALE_SSHORTTIME
|
||||
# define LOCALE_SSHORTTIME 0x00000079
|
||||
#endif
|
||||
|
||||
struct QSystemLocalePrivate
|
||||
{
|
||||
@ -258,7 +261,9 @@ QVariant QSystemLocalePrivate::timeFormat(QLocale::FormatType type)
|
||||
{
|
||||
switch (type) {
|
||||
case QLocale::ShortFormat:
|
||||
return winToQtFormat(getLocaleInfo(LOCALE_STIMEFORMAT)); //###
|
||||
if (QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS7)
|
||||
return winToQtFormat(getLocaleInfo(LOCALE_SSHORTTIME));
|
||||
// fall through
|
||||
case QLocale::LongFormat:
|
||||
return winToQtFormat(getLocaleInfo(LOCALE_STIMEFORMAT));
|
||||
case QLocale::NarrowFormat:
|
||||
@ -341,7 +346,7 @@ QVariant QSystemLocalePrivate::toString(const QDate &date, QLocale::FormatType t
|
||||
return QString();
|
||||
}
|
||||
|
||||
QVariant QSystemLocalePrivate::toString(const QTime &time, QLocale::FormatType)
|
||||
QVariant QSystemLocalePrivate::toString(const QTime &time, QLocale::FormatType type)
|
||||
{
|
||||
SYSTEMTIME st;
|
||||
memset(&st, 0, sizeof(SYSTEMTIME));
|
||||
@ -351,6 +356,9 @@ QVariant QSystemLocalePrivate::toString(const QTime &time, QLocale::FormatType)
|
||||
st.wMilliseconds = 0;
|
||||
|
||||
DWORD flags = 0;
|
||||
// keep the same conditional as timeFormat() above
|
||||
if (type == QLocale::ShortFormat && QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS7)
|
||||
flags = TIME_NOSECONDS;
|
||||
|
||||
wchar_t buf[255];
|
||||
if (GetTimeFormat(lcid, flags, &st, NULL, buf, 255)) {
|
||||
|
@ -1137,10 +1137,14 @@ void tst_QDate::toStringDateFormat()
|
||||
QFETCH(QString, expectedStr);
|
||||
|
||||
QCOMPARE(date.toString(Qt::SystemLocaleShortDate), QLocale::system().toString(date, QLocale::ShortFormat));
|
||||
QCOMPARE(date.toString(Qt::LocaleDate), QLocale().toString(date, QLocale::ShortFormat));
|
||||
QCOMPARE(date.toString(Qt::DefaultLocaleShortDate), QLocale().toString(date, QLocale::ShortFormat));
|
||||
QCOMPARE(date.toString(Qt::SystemLocaleLongDate), QLocale::system().toString(date, QLocale::LongFormat));
|
||||
QCOMPARE(date.toString(Qt::DefaultLocaleLongDate), QLocale().toString(date, QLocale::LongFormat));
|
||||
QLocale::setDefault(QLocale::German);
|
||||
QCOMPARE(date.toString(Qt::SystemLocaleShortDate), QLocale::system().toString(date, QLocale::ShortFormat));
|
||||
QCOMPARE(date.toString(Qt::LocaleDate), QLocale().toString(date, QLocale::ShortFormat));
|
||||
QCOMPARE(date.toString(Qt::DefaultLocaleShortDate), QLocale().toString(date, QLocale::ShortFormat));
|
||||
QCOMPARE(date.toString(Qt::SystemLocaleLongDate), QLocale::system().toString(date, QLocale::LongFormat));
|
||||
QCOMPARE(date.toString(Qt::DefaultLocaleLongDate), QLocale().toString(date, QLocale::LongFormat));
|
||||
|
||||
QCOMPARE(date.toString(format), expectedStr);
|
||||
}
|
||||
|
@ -723,15 +723,23 @@ void tst_QTime::toStringFormat()
|
||||
void tst_QTime::toStringLocale()
|
||||
{
|
||||
QTime time(18, 30);
|
||||
QCOMPARE(time.toString(Qt::SystemLocaleDate),
|
||||
QCOMPARE(time.toString(Qt::SystemLocaleShortDate),
|
||||
QLocale::system().toString(time, QLocale::ShortFormat));
|
||||
QCOMPARE(time.toString(Qt::LocaleDate),
|
||||
QCOMPARE(time.toString(Qt::DefaultLocaleShortDate),
|
||||
QLocale().toString(time, QLocale::ShortFormat));
|
||||
QCOMPARE(time.toString(Qt::SystemLocaleLongDate),
|
||||
QLocale::system().toString(time, QLocale::LongFormat));
|
||||
QCOMPARE(time.toString(Qt::DefaultLocaleLongDate),
|
||||
QLocale().toString(time, QLocale::LongFormat));
|
||||
QLocale::setDefault(QLocale::German);
|
||||
QCOMPARE(time.toString(Qt::SystemLocaleDate),
|
||||
QCOMPARE(time.toString(Qt::SystemLocaleShortDate),
|
||||
QLocale::system().toString(time, QLocale::ShortFormat));
|
||||
QCOMPARE(time.toString(Qt::LocaleDate),
|
||||
QCOMPARE(time.toString(Qt::DefaultLocaleShortDate),
|
||||
QLocale().toString(time, QLocale::ShortFormat));
|
||||
QCOMPARE(time.toString(Qt::SystemLocaleLongDate),
|
||||
QLocale::system().toString(time, QLocale::LongFormat));
|
||||
QCOMPARE(time.toString(Qt::DefaultLocaleLongDate),
|
||||
QLocale().toString(time, QLocale::LongFormat));
|
||||
}
|
||||
|
||||
void tst_QTime::msecsSinceStartOfDay_data()
|
||||
|
Loading…
Reference in New Issue
Block a user