Deprecate QLocale::toTime() variants taking a calendar

The calendar is ignored, so adding these methods was a mistake.

[ChangeLog][QtCore][QLocale] Deprecated toTime() variants taking a
calendar. The calendar is ignored in time parsing.

Change-Id: I79fa994ce88f13fdb931163b447eb1a9ad655c09
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Edward Welbourne 2020-01-28 19:45:35 +01:00
parent d6ba2ae441
commit 6c4e0f2d2d
2 changed files with 25 additions and 3 deletions

View File

@ -2353,14 +2353,19 @@ QTime QLocale::toTime(const QString &string, FormatType format) const
return toTime(string, timeFormat(format));
}
#if QT_DEPRECATED_SINCE(5, 15)
/*!
\since 5.14
\overload
\deprecated
*/
QTime QLocale::toTime(const QString &string, FormatType format, QCalendar cal) const
{
QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED
return toTime(string, timeFormat(format), cal);
QT_WARNING_POP
}
#endif
/*!
\since 4.4
@ -2425,12 +2430,24 @@ QDateTime QLocale::toDateTime(const QString &string, FormatType format, QCalenda
*/
QTime QLocale::toTime(const QString &string, const QString &format) const
{
return toTime(string, format, QCalendar());
QTime time;
#if QT_CONFIG(datetimeparser)
QDateTimeParser dt(QMetaType::QTime, QDateTimeParser::FromString, QCalendar());
dt.setDefaultLocale(*this);
if (dt.parseFormat(format))
dt.fromString(string, nullptr, &time);
#else
Q_UNUSED(string);
Q_UNUSED(format);
#endif
return time;
}
#if QT_DEPRECATED_SINCE(5, 15)
/*!
\since 5.14
\overload
\deprecated
*/
QTime QLocale::toTime(const QString &string, const QString &format, QCalendar cal) const
{
@ -2447,6 +2464,7 @@ QTime QLocale::toTime(const QString &string, const QString &format, QCalendar ca
#endif
return time;
}
#endif
/*!
\since 4.4

View File

@ -1037,11 +1037,15 @@ public:
QDateTime toDateTime(const QString &string, const QString &format) const;
// Calendar-aware API
QDate toDate(const QString &string, FormatType format, QCalendar cal) const;
QTime toTime(const QString &string, FormatType format, QCalendar cal) const;
QDateTime toDateTime(const QString &string, FormatType format, QCalendar cal) const;
QDate toDate(const QString &string, const QString &format, QCalendar cal) const;
QTime toTime(const QString &string, const QString &format, QCalendar cal) const;
QDateTime toDateTime(const QString &string, const QString &format, QCalendar cal) const;
# if QT_DEPRECATED_SINCE(5, 15)
QT_DEPRECATED_X("Calendar is ignored when parsing times")
QTime toTime(const QString &string, FormatType format, QCalendar cal) const;
QT_DEPRECATED_X("Calendar is ignored when parsing times")
QTime toTime(const QString &string, const QString &format, QCalendar cal) const;
# endif // 5.15
#endif
// ### Qt 6: We need to return QString from these function since