Deprecate locale-related DateFormat enum members

Qt 6 shall remove all locale-dependence from Q(Date|Time)+.

Task-number: QTBUG-80441
Change-Id: Iebaaa2bd776bccfe0d73c15f36cbdd456b71ca59
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Edward Welbourne 2020-01-22 16:12:24 +01:00
parent 05ce1821cd
commit d6d98f782a
7 changed files with 132 additions and 74 deletions

View File

@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2016 The Qt Company Ltd. ** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
** This file is part of the QtCore module of the Qt Toolkit. ** This file is part of the QtCore module of the Qt Toolkit.
@ -1267,14 +1267,16 @@ public:
enum DateFormat { enum DateFormat {
TextDate, // default Qt TextDate, // default Qt
ISODate, // ISO 8601 ISODate, // ISO 8601
SystemLocaleDate, // deprecated #if QT_DEPRECATED_SINCE(5, 15)
LocalDate = SystemLocaleDate, // deprecated SystemLocaleDate Q_DECL_ENUMERATOR_DEPRECATED_X("Use QLocale"),
LocaleDate, // deprecated LocalDate Q_DECL_ENUMERATOR_DEPRECATED_X("Use QLocale") = 2, // i.e. SystemLocaleDate
SystemLocaleShortDate, LocaleDate Q_DECL_ENUMERATOR_DEPRECATED_X("Use QLocale"),
SystemLocaleLongDate, SystemLocaleShortDate Q_DECL_ENUMERATOR_DEPRECATED_X("Use QLocale"),
DefaultLocaleShortDate, SystemLocaleLongDate Q_DECL_ENUMERATOR_DEPRECATED_X("Use QLocale"),
DefaultLocaleLongDate, DefaultLocaleShortDate Q_DECL_ENUMERATOR_DEPRECATED_X("Use QLocale"),
RFC2822Date, // RFC 2822 (+ 850 and 1036 during parsing) DefaultLocaleLongDate Q_DECL_ENUMERATOR_DEPRECATED_X("Use QLocale"),
#endif
RFC2822Date = 8, // RFC 2822 (+ 850 and 1036 during parsing)
ISODateWithMs ISODateWithMs
}; };

View File

@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2019 The Qt Company Ltd. ** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
** This file is part of the documentation of the Qt Toolkit. ** This file is part of the documentation of the Qt Toolkit.
@ -709,26 +709,38 @@
\value ISODateWithMs \l{ISO 8601} extended format, including milliseconds if applicable. \value ISODateWithMs \l{ISO 8601} extended format, including milliseconds if applicable.
\value SystemLocaleShortDate The \l{QLocale::ShortFormat}{short format} used \value SystemLocaleShortDate \e{This enum value is deprecated and
by the \l{QLocale::system()}{operating system}. shall be removed in Qt 6.} Use QLocale's methods for converting
dates and times to and from strings, with the
\l{QLocale::ShortFormat}{short format} of
\l{QLocale::system()}{the locale used by the operating system}.
\value SystemLocaleLongDate The \l{QLocale::LongFormat}{long format} used \value SystemLocaleLongDate \e{This enum value is deprecated and
by the \l{QLocale::system()}{operating system}. shall be removed in Qt 6.} Use QLocale's methods for converting
dates and times to and from strings, with the
\l{QLocale::LongFormat}{long format} of \l{QLocale::system()}{the
locale used by the operating system}.
\value DefaultLocaleShortDate The \l{QLocale::ShortFormat}{short format} specified \value DefaultLocaleShortDate \e{This enum value is deprecated and
by the \l{QLocale::setDefault()}{application's locale}. shall be removed in Qt 6.} Use QLocale's methods for converting
dates and times to and from strings, with the
\l{QLocale::ShortFormat}{short format} of
\l{QLocale::setDefault()}{the application's locale}.
\value DefaultLocaleLongDate The \l{QLocale::LongFormat}{long format} used \value DefaultLocaleLongDate \e{This enum value is deprecated and
by the \l{QLocale::setDefault()}{application's locale}. shall be removed in Qt 6.} Use QLocale's methods for converting
dates and times to and from strings, with the
\l{QLocale::LongFormat}{long format} \l{QLocale::setDefault()}{the
application's locale}.
\value SystemLocaleDate \e{This enum value is deprecated.} Use Qt::SystemLocaleShortDate \value SystemLocaleDate \e{This enum value is deprecated and shall
instead (or Qt::SystemLocaleLongDate if you want long dates). be removed in Qt 6.} It is equivalent to SystemLocaleShortDate.
\value LocaleDate \e{This enum value is deprecated.} Use Qt::DefaultLocaleShortDate \value LocaleDate \e{This enum value is deprecated and shall be
instead (or Qt::DefaultLocaleLongDate if you want long dates). removed in Qt 6.} It is equivalent to DefaultLocaleShortDate.
\value LocalDate \e{This enum value is deprecated.} Use Qt::SystemLocaleShortDate \value LocalDate \e{This enum value is deprecated and shall be
instead (or Qt::SystemLocaleLongDate if you want long dates). removed in Qt 6.} It is equivalent to SystemLocaleShortDate.
\value RFC2822Date \l{RFC 2822}, \l{RFC 850} and \l{RFC 1036} format: \value RFC2822Date \l{RFC 2822}, \l{RFC 850} and \l{RFC 1036} format:
either \c{[ddd,] dd MMM yyyy [hh:mm[:ss]][ ±tzoff]} either \c{[ddd,] dd MMM yyyy [hh:mm[:ss]][ ±tzoff]}

View File

@ -2025,6 +2025,9 @@ QString QLocale::toString(const QDate &date, QStringView format) const
/*! /*!
Returns a localized string representation of the given \a date according Returns a localized string representation of the given \a date according
to the specified \a format. to the specified \a format.
\note Some locales may use formats that limit the range of years they can
represent.
*/ */
QString QLocale::toString(const QDate &date, FormatType format) const QString QLocale::toString(const QDate &date, FormatType format) const
@ -2179,6 +2182,9 @@ QString QLocale::toString(const QDateTime &dateTime, QStringView format, QCalend
Returns a localized string representation of the given \a dateTime according Returns a localized string representation of the given \a dateTime according
to the specified \a format. to the specified \a format.
\note Some locales may use formats that limit the range of years they can
represent.
*/ */
QString QLocale::toString(const QDateTime &dateTime, FormatType format) const QString QLocale::toString(const QDateTime &dateTime, FormatType format) const

View File

@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2019 The Qt Company Ltd. ** Copyright (C) 2020 The Qt Company Ltd.
** Copyright (C) 2016 Intel Corporation. ** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
@ -1150,18 +1150,16 @@ static QString toStringIsoDate(const QDate &date)
year, MM is the month of the year (between 01 and 12), and dd is year, MM is the month of the year (between 01 and 12), and dd is
the day of the month between 01 and 31. the day of the month between 01 and 31.
If the \a format is Qt::SystemLocaleShortDate or The \a format options Qt::SystemLocaleDate, Qt::SystemLocaleShortDate and
Qt::SystemLocaleLongDate, the string format depends on the locale Qt::SystemLocaleLongDate shall be removed in Qt 6. Their use should be
settings of the system. Identical to calling replaced with
QLocale::system().toString(date, QLocale::ShortFormat) or \l {QLocale::toString()}{QLocale::system().toString(date, QLocale::ShortFormat)} or
QLocale::system().toString(date, QLocale::LongFormat). \l {QLocale::toString()}{QLocale::system().toString(date, QLocale::LongFormat)}.
If the \a format is Qt::DefaultLocaleShortDate or The \a format options Qt::LocaleDate, Qt::DefaultLocaleShortDate and
Qt::DefaultLocaleLongDate, the string format depends on the Qt::DefaultLocaleLongDate shall be removed in Qt 6. Their use should be
default application locale. This is the locale set with replaced with
QLocale::setDefault(), or the system locale if no default locale \l {QLocale::toString()}{QLocale().toString(date, QLocale::ShortFormat)} or
has been set. Identical to calling
\l {QLocale::toString()}{QLocale().toString(date, QLocale::ShortFormat) } or
\l {QLocale::toString()}{QLocale().toString(date, QLocale::LongFormat)}. \l {QLocale::toString()}{QLocale().toString(date, QLocale::LongFormat)}.
If the \a format is Qt::RFC2822Date, the string is formatted in If the \a format is Qt::RFC2822Date, the string is formatted in
@ -1171,8 +1169,7 @@ static QString toStringIsoDate(const QDate &date)
If the date is invalid, an empty string will be returned. If the date is invalid, an empty string will be returned.
\warning The Qt::ISODate format is only valid for years in the \warning The Qt::ISODate format is only valid for years in the
range 0 to 9999. This restriction may apply to locale-aware range 0 to 9999.
formats as well, depending on the locale settings.
\sa fromString(), QLocale::toString() \sa fromString(), QLocale::toString()
*/ */
@ -1182,6 +1179,7 @@ QString QDate::toString(Qt::DateFormat format) const
return QString(); return QString();
switch (format) { switch (format) {
#if QT_DEPRECATED_SINCE(5, 15)
case Qt::SystemLocaleDate: case Qt::SystemLocaleDate:
case Qt::SystemLocaleShortDate: case Qt::SystemLocaleShortDate:
return QLocale::system().toString(*this, QLocale::ShortFormat); return QLocale::system().toString(*this, QLocale::ShortFormat);
@ -1192,6 +1190,7 @@ QString QDate::toString(Qt::DateFormat format) const
return QLocale().toString(*this, QLocale::ShortFormat); return QLocale().toString(*this, QLocale::ShortFormat);
case Qt::DefaultLocaleLongDate: case Qt::DefaultLocaleLongDate:
return QLocale().toString(*this, QLocale::LongFormat); return QLocale().toString(*this, QLocale::LongFormat);
#endif // 5.15
case Qt::RFC2822Date: case Qt::RFC2822Date:
return QLocale::c().toString(*this, u"dd MMM yyyy"); return QLocale::c().toString(*this, u"dd MMM yyyy");
default: default:
@ -1284,6 +1283,7 @@ QString QDate::toString(Qt::DateFormat format, QCalendar cal) const
return QString(); return QString();
switch (format) { switch (format) {
#if QT_DEPRECATED_SINCE(5, 15)
case Qt::SystemLocaleDate: case Qt::SystemLocaleDate:
case Qt::SystemLocaleShortDate: case Qt::SystemLocaleShortDate:
return QLocale::system().toString(*this, QLocale::ShortFormat, cal); return QLocale::system().toString(*this, QLocale::ShortFormat, cal);
@ -1294,6 +1294,7 @@ QString QDate::toString(Qt::DateFormat format, QCalendar cal) const
return QLocale().toString(*this, QLocale::ShortFormat, cal); return QLocale().toString(*this, QLocale::ShortFormat, cal);
case Qt::DefaultLocaleLongDate: case Qt::DefaultLocaleLongDate:
return QLocale().toString(*this, QLocale::LongFormat, cal); return QLocale().toString(*this, QLocale::LongFormat, cal);
#endif // 5.15
case Qt::RFC2822Date: case Qt::RFC2822Date:
return QLocale::c().toString(*this, QStringView(u"dd MMM yyyy"), cal); return QLocale::c().toString(*this, QStringView(u"dd MMM yyyy"), cal);
default: default:
@ -1659,9 +1660,14 @@ ParsedInt readInt(QStringView text)
\a format given, or an invalid date if the string cannot be \a format given, or an invalid date if the string cannot be
parsed. parsed.
Note for Qt::TextDate: It is recommended that you use the Note for Qt::TextDate: It is recommended that you use the English short
English short month names (e.g. "Jan"). Although localized month month names (e.g. "Jan"). Although localized month names can also be used in
names can also be used, they depend on the user's locale settings. Qt 5, they depend on the user's locale settings.
\note Support for localized dates, including the format options
Qt::SystemLocaleDate, Qt::SystemLocaleShortDate, Qt::SystemLocaleLongDate,
Qt::LocaleDate, Qt::DefaultLocaleShortDate, and Qt::DefaultLocaleLongDate,
shall be removed in Qt 6. Use QLocale::toDate() instead.
\sa toString(), QLocale::toDate() \sa toString(), QLocale::toDate()
*/ */
@ -1672,6 +1678,7 @@ QDate QDate::fromString(const QString &string, Qt::DateFormat format)
return QDate(); return QDate();
switch (format) { switch (format) {
#if QT_DEPRECATED_SINCE(5, 15)
case Qt::SystemLocaleDate: case Qt::SystemLocaleDate:
case Qt::SystemLocaleShortDate: case Qt::SystemLocaleShortDate:
return QLocale::system().toDate(string, QLocale::ShortFormat); return QLocale::system().toDate(string, QLocale::ShortFormat);
@ -1682,6 +1689,7 @@ QDate QDate::fromString(const QString &string, Qt::DateFormat format)
return QLocale().toDate(string, QLocale::ShortFormat); return QLocale().toDate(string, QLocale::ShortFormat);
case Qt::DefaultLocaleLongDate: case Qt::DefaultLocaleLongDate:
return QLocale().toDate(string, QLocale::LongFormat); return QLocale().toDate(string, QLocale::LongFormat);
#endif // 5.15
case Qt::RFC2822Date: case Qt::RFC2822Date:
return rfcDateImpl(string).date; return rfcDateImpl(string).date;
default: default:
@ -2035,18 +2043,15 @@ int QTime::msec() const
date, use the \a format Qt::ISODateWithMs, which corresponds to date, use the \a format Qt::ISODateWithMs, which corresponds to
HH:mm:ss.zzz. HH:mm:ss.zzz.
If the \a format is Qt::SystemLocaleShortDate or The \a format options Qt::SystemLocaleDate:, Qt::SystemLocaleShortDate and
Qt::SystemLocaleLongDate, the string format depends on the locale Qt::SystemLocaleLongDate shall be removed in Qt 6. Their use should be
settings of the system. Identical to calling replaced with:
QLocale::system().toString(time, QLocale::ShortFormat) or \l {QLocale::toString()}{QLocale::system().toString(time, QLocale::ShortFormat)} or
QLocale::system().toString(time, QLocale::LongFormat). \l {QLocale::toString()}{QLocale::system().toString(time, QLocale::LongFormat)}.
If the \a format is Qt::DefaultLocaleShortDate or
Qt::DefaultLocaleLongDate, the string format depends on the
default application locale. This is the locale set with
QLocale::setDefault(), or the system locale if no default locale
has been set. Identical to calling
The \a format options Qt::LocaleDate, Qt::DefaultLocaleShortDate and
Qt::DefaultLocaleLongDate shall be removed in Qt 6. Their use should be
replaced with:
\l {QLocale::toString()}{QLocale().toString(time, QLocale::ShortFormat)} or \l {QLocale::toString()}{QLocale().toString(time, QLocale::ShortFormat)} or
\l {QLocale::toString()}{QLocale().toString(time, QLocale::LongFormat)}. \l {QLocale::toString()}{QLocale().toString(time, QLocale::LongFormat)}.
@ -2065,6 +2070,7 @@ QString QTime::toString(Qt::DateFormat format) const
return QString(); return QString();
switch (format) { switch (format) {
#if QT_DEPRECATED_SINCE(5, 15)
case Qt::SystemLocaleDate: case Qt::SystemLocaleDate:
case Qt::SystemLocaleShortDate: case Qt::SystemLocaleShortDate:
return QLocale::system().toString(*this, QLocale::ShortFormat); return QLocale::system().toString(*this, QLocale::ShortFormat);
@ -2075,6 +2081,7 @@ QString QTime::toString(Qt::DateFormat format) const
return QLocale().toString(*this, QLocale::ShortFormat); return QLocale().toString(*this, QLocale::ShortFormat);
case Qt::DefaultLocaleLongDate: case Qt::DefaultLocaleLongDate:
return QLocale().toString(*this, QLocale::LongFormat); return QLocale().toString(*this, QLocale::LongFormat);
#endif // 5.15
case Qt::ISODateWithMs: case Qt::ISODateWithMs:
return QString::asprintf("%02d:%02d:%02d.%03d", hour(), minute(), second(), msec()); return QString::asprintf("%02d:%02d:%02d.%03d", hour(), minute(), second(), msec());
case Qt::RFC2822Date: case Qt::RFC2822Date:
@ -2450,6 +2457,12 @@ static QTime fromIsoTimeString(QStringView string, Qt::DateFormat format, bool *
fails for the default locale). This should be considered an fails for the default locale). This should be considered an
implementation detail. implementation detail.
\note Support for localized dates, including the format options
Qt::SystemLocaleDate, Qt::SystemLocaleShortDate, Qt::SystemLocaleLongDate,
Qt::LocaleDate, Qt::DefaultLocaleShortDate, and Qt::DefaultLocaleLongDate,
shall be removed in Qt 6. Use QLocale::toTime() instead.
\sa toString(), QLocale::toTime() \sa toString(), QLocale::toTime()
*/ */
QTime QTime::fromString(const QString &string, Qt::DateFormat format) QTime QTime::fromString(const QString &string, Qt::DateFormat format)
@ -2458,6 +2471,7 @@ QTime QTime::fromString(const QString &string, Qt::DateFormat format)
return QTime(); return QTime();
switch (format) { switch (format) {
#if QT_DEPRECATED_SINCE(5, 15)
case Qt::SystemLocaleDate: case Qt::SystemLocaleDate:
case Qt::SystemLocaleShortDate: case Qt::SystemLocaleShortDate:
return QLocale::system().toTime(string, QLocale::ShortFormat); return QLocale::system().toTime(string, QLocale::ShortFormat);
@ -2468,6 +2482,7 @@ QTime QTime::fromString(const QString &string, Qt::DateFormat format)
return QLocale().toTime(string, QLocale::ShortFormat); return QLocale().toTime(string, QLocale::ShortFormat);
case Qt::DefaultLocaleLongDate: case Qt::DefaultLocaleLongDate:
return QLocale().toTime(string, QLocale::LongFormat); return QLocale().toTime(string, QLocale::LongFormat);
#endif // 5.15
case Qt::RFC2822Date: case Qt::RFC2822Date:
return rfcDateImpl(string).time; return rfcDateImpl(string).time;
case Qt::ISODate: case Qt::ISODate:
@ -4326,19 +4341,17 @@ void QDateTime::setTime_t(uint secsSince1Jan1970UTC)
date, use the \a format Qt::ISODateWithMs, which corresponds to date, use the \a format Qt::ISODateWithMs, which corresponds to
yyyy-MM-ddTHH:mm:ss.zzz[Z|[+|-]HH:mm]. yyyy-MM-ddTHH:mm:ss.zzz[Z|[+|-]HH:mm].
If the \a format is Qt::SystemLocaleShortDate or The \a format options Qt::SystemLocaleDate, Qt::SystemLocaleShortDate and
Qt::SystemLocaleLongDate, the string format depends on the locale Qt::SystemLocaleLongDate shall be removed in Qt 6. Their use should be
settings of the system. Identical to calling replaced with
QLocale::system().toString(datetime, QLocale::ShortFormat) or \l {QLocale::toString()}{QLocale::system().toString(datetime, QLocale::ShortFormat)} or
QLocale::system().toString(datetime, QLocale::LongFormat). \l {QLocale::toString()}{QLocale::system().toString(datetime, QLocale::LongFormat)}.
If the \a format is Qt::DefaultLocaleShortDate or The \a format options Qt::LocaleDate, Qt::DefaultLocaleShortDate and
Qt::DefaultLocaleLongDate, the string format depends on the Qt::DefaultLocaleLongDate shall be removed in Qt 6. Their use should be
default application locale. This is the locale set with replaced with
QLocale::setDefault(), or the system locale if no default locale \l {QLocale::toString()}{QLocale().toString(datetime, QLocale::ShortFormat)} or
has been set. Identical to calling QLocale().toString(datetime, \l {QLocale::toString()}{QLocale().toString(datetime, QLocale::LongFormat)}.
QLocale::ShortFormat) or QLocale().toString(datetime,
QLocale::LongFormat).
If the \a format is Qt::RFC2822Date, the string is formatted If the \a format is Qt::RFC2822Date, the string is formatted
following \l{RFC 2822}. following \l{RFC 2822}.
@ -4346,8 +4359,7 @@ void QDateTime::setTime_t(uint secsSince1Jan1970UTC)
If the datetime is invalid, an empty string will be returned. If the datetime is invalid, an empty string will be returned.
\warning The Qt::ISODate format is only valid for years in the \warning The Qt::ISODate format is only valid for years in the
range 0 to 9999. This restriction may apply to locale-aware range 0 to 9999.
formats as well, depending on the locale settings.
\sa fromString(), QDate::toString(), QTime::toString(), \sa fromString(), QDate::toString(), QTime::toString(),
QLocale::toString() QLocale::toString()
@ -4365,6 +4377,7 @@ QString QDateTime::toString(Qt::DateFormat format, QCalendar cal) const
return buf; return buf;
switch (format) { switch (format) {
#if QT_DEPRECATED_SINCE(5, 15)
case Qt::SystemLocaleDate: case Qt::SystemLocaleDate:
case Qt::SystemLocaleShortDate: case Qt::SystemLocaleShortDate:
return QLocale::system().toString(*this, QLocale::ShortFormat, cal); return QLocale::system().toString(*this, QLocale::ShortFormat, cal);
@ -4375,6 +4388,7 @@ QString QDateTime::toString(Qt::DateFormat format, QCalendar cal) const
return QLocale().toString(*this, QLocale::ShortFormat, cal); return QLocale().toString(*this, QLocale::ShortFormat, cal);
case Qt::DefaultLocaleLongDate: case Qt::DefaultLocaleLongDate:
return QLocale().toString(*this, QLocale::LongFormat, cal); return QLocale().toString(*this, QLocale::LongFormat, cal);
#endif // 5.15
case Qt::RFC2822Date: { case Qt::RFC2822Date: {
buf = QLocale::c().toString(*this, u"dd MMM yyyy hh:mm:ss ", cal); buf = QLocale::c().toString(*this, u"dd MMM yyyy hh:mm:ss ", cal);
buf += toOffsetString(Qt::TextDate, offsetFromUtc()); buf += toOffsetString(Qt::TextDate, offsetFromUtc());
@ -5239,9 +5253,14 @@ int QDateTime::utcOffset() const
Returns the QDateTime represented by the \a string, using the Returns the QDateTime represented by the \a string, using the
\a format given, or an invalid datetime if this is not possible. \a format given, or an invalid datetime if this is not possible.
Note for Qt::TextDate: It is recommended that you use the Note for Qt::TextDate: It is recommended that you use the English short
English short month names (e.g. "Jan"). Although localized month month names (e.g. "Jan"). Although localized month names can also be used in
names can also be used, they depend on the user's locale settings. Qt 5, they depend on the user's locale settings.
\note Support for localized dates, including the format options
Qt::SystemLocaleDate, Qt::SystemLocaleShortDate, Qt::SystemLocaleLongDate,
Qt::LocaleDate, Qt::DefaultLocaleShortDate, and Qt::DefaultLocaleLongDate,
shall be removed in Qt 6. Use QLocale::toDateTime() instead.
\sa toString(), QLocale::toDateTime() \sa toString(), QLocale::toDateTime()
*/ */
@ -5251,6 +5270,7 @@ QDateTime QDateTime::fromString(const QString &string, Qt::DateFormat format)
return QDateTime(); return QDateTime();
switch (format) { switch (format) {
#if QT_DEPRECATED_SINCE(5, 15)
case Qt::SystemLocaleDate: case Qt::SystemLocaleDate:
case Qt::SystemLocaleShortDate: case Qt::SystemLocaleShortDate:
return QLocale::system().toDateTime(string, QLocale::ShortFormat); return QLocale::system().toDateTime(string, QLocale::ShortFormat);
@ -5261,6 +5281,7 @@ QDateTime QDateTime::fromString(const QString &string, Qt::DateFormat format)
return QLocale().toDateTime(string, QLocale::ShortFormat); return QLocale().toDateTime(string, QLocale::ShortFormat);
case Qt::DefaultLocaleLongDate: case Qt::DefaultLocaleLongDate:
return QLocale().toDateTime(string, QLocale::LongFormat); return QLocale().toDateTime(string, QLocale::LongFormat);
#endif // 5.15
case Qt::RFC2822Date: { case Qt::RFC2822Date: {
const ParsedRfcDateTime rfc = rfcDateImpl(string); const ParsedRfcDateTime rfc = rfcDateImpl(string);

View File

@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2019 The Qt Company Ltd. ** Copyright (C) 2020 The Qt Company Ltd.
** Copyright (C) 2016 Intel Corporation. ** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
@ -1352,6 +1352,7 @@ void tst_QDate::toStringDateFormat()
QFETCH(Qt::DateFormat, format); QFETCH(Qt::DateFormat, format);
QFETCH(QString, expectedStr); QFETCH(QString, expectedStr);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCOMPARE(date.toString(Qt::SystemLocaleShortDate), QLocale::system().toString(date, QLocale::ShortFormat)); QCOMPARE(date.toString(Qt::SystemLocaleShortDate), QLocale::system().toString(date, QLocale::ShortFormat));
QCOMPARE(date.toString(Qt::DefaultLocaleShortDate), 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::SystemLocaleLongDate), QLocale::system().toString(date, QLocale::LongFormat));
@ -1361,6 +1362,7 @@ void tst_QDate::toStringDateFormat()
QCOMPARE(date.toString(Qt::DefaultLocaleShortDate), 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::SystemLocaleLongDate), QLocale::system().toString(date, QLocale::LongFormat));
QCOMPARE(date.toString(Qt::DefaultLocaleLongDate), QLocale().toString(date, QLocale::LongFormat)); QCOMPARE(date.toString(Qt::DefaultLocaleLongDate), QLocale().toString(date, QLocale::LongFormat));
#endif // ### Qt 6: remove
QCOMPARE(date.toString(format), expectedStr); QCOMPARE(date.toString(format), expectedStr);
} }

View File

@ -127,8 +127,10 @@ private slots:
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
void fromString_LOCALE_ILDATE(); void fromString_LOCALE_ILDATE();
#endif #endif
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void fromStringToStringLocale_data(); void fromStringToStringLocale_data();
void fromStringToStringLocale(); void fromStringToStringLocale();
#endif // ### Qt 6: remove
void offsetFromUtc(); void offsetFromUtc();
void setOffsetFromUtc(); void setOffsetFromUtc();
@ -295,9 +297,9 @@ void tst_QDateTime::initTestCase()
void tst_QDateTime::init() void tst_QDateTime::init()
{ {
#if defined(Q_OS_WIN32) #if defined(Q_OS_WIN32) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
SetThreadLocale(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT)); SetThreadLocale(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT));
#endif #endif // ### Qt 6: remove
} }
QString tst_QDateTime::str( int y, int month, int d, int h, int min, int s ) QString tst_QDateTime::str( int y, int month, int d, int h, int min, int s )
@ -834,8 +836,10 @@ void tst_QDateTime::toString_isoDate()
QFETCH(Qt::DateFormat, format); QFETCH(Qt::DateFormat, format);
QFETCH(QString, expected); QFETCH(QString, expected);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QLocale oldLocale; QLocale oldLocale;
QLocale::setDefault(QLocale("en_US")); QLocale::setDefault(QLocale("en_US"));
#endif // ### Qt 6: remove
QString result = datetime.toString(format); QString result = datetime.toString(format);
QCOMPARE(result, expected); QCOMPARE(result, expected);
@ -854,7 +858,9 @@ void tst_QDateTime::toString_isoDate()
QCOMPARE(resultDatetime, QDateTime()); QCOMPARE(resultDatetime, QDateTime());
} }
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QLocale::setDefault(oldLocale); QLocale::setDefault(oldLocale);
#endif // ### Qt 6: remove
} }
void tst_QDateTime::toString_isoDate_extra() void tst_QDateTime::toString_isoDate_extra()
@ -1763,7 +1769,7 @@ void tst_QDateTime::daylightSavingsTimeChange()
// because some functions did not reset the flag when moving in or out of DST. // because some functions did not reset the flag when moving in or out of DST.
// WARNING: This only tests anything if there's a Daylight Savings Time change // WARNING: This only tests anything if there's a Daylight Savings Time change
// in the current locale between inDST and outDST. // in the current time-zone between inDST and outDST.
// This is true for Central European Time and may be elsewhere. // This is true for Central European Time and may be elsewhere.
QFETCH(QDate, inDST); QFETCH(QDate, inDST);
@ -2612,6 +2618,9 @@ void tst_QDateTime::fromString_LOCALE_ILDATE()
} }
#endif #endif
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED
void tst_QDateTime::fromStringToStringLocale_data() void tst_QDateTime::fromStringToStringLocale_data()
{ {
QTest::addColumn<QLocale>("locale"); QTest::addColumn<QLocale>("locale");
@ -2643,6 +2652,8 @@ void tst_QDateTime::fromStringToStringLocale()
#undef ROUNDTRIP #undef ROUNDTRIP
QLocale::setDefault(def); QLocale::setDefault(def);
} }
QT_WARNING_POP
#endif // ### Qt 6: remove
void tst_QDateTime::offsetFromUtc() void tst_QDateTime::offsetFromUtc()
{ {

View File

@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2016 The Qt Company Ltd. ** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
** This file is part of the test suite of the Qt Toolkit. ** This file is part of the test suite of the Qt Toolkit.
@ -77,7 +77,9 @@ private slots:
void toStringDateFormat(); void toStringDateFormat();
void toStringFormat_data(); void toStringFormat_data();
void toStringFormat(); void toStringFormat();
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void toStringLocale(); void toStringLocale();
#endif // ### Qt 6: remove
void msecsSinceStartOfDay_data(); void msecsSinceStartOfDay_data();
void msecsSinceStartOfDay(); void msecsSinceStartOfDay();
@ -770,6 +772,7 @@ void tst_QTime::toStringFormat()
QCOMPARE( t.toString( format ), str ); QCOMPARE( t.toString( format ), str );
} }
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void tst_QTime::toStringLocale() void tst_QTime::toStringLocale()
{ {
QTime time(18, 30); QTime time(18, 30);
@ -791,6 +794,7 @@ void tst_QTime::toStringLocale()
QCOMPARE(time.toString(Qt::DefaultLocaleLongDate), QCOMPARE(time.toString(Qt::DefaultLocaleLongDate),
QLocale().toString(time, QLocale::LongFormat)); QLocale().toString(time, QLocale::LongFormat));
} }
#endif // ### Qt 6: remove
void tst_QTime::msecsSinceStartOfDay_data() void tst_QTime::msecsSinceStartOfDay_data()
{ {