Skip to content

Commit

Permalink
Deprecate QDate methods using MonthNameType
Browse files Browse the repository at this point in the history
These introduce an unwanted locale-dependency; clients should use
suitable QLocale methods instead.

Task-number: QTBUG-28581
Change-Id: Ie7dfe712c50b9f5da94e4b20af7b231d8963cbc9
Reviewed-by: Thiago Macieira <[email protected]>
  • Loading branch information
ediosyncratic committed Aug 22, 2017
1 parent 8b3a120 commit b6a6121
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
16 changes: 10 additions & 6 deletions src/corelib/tools/qdatetime.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2017 The Qt Company Ltd.
** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
Expand Down Expand Up @@ -193,7 +193,7 @@ static int fromShortMonthName(const QStringRef &monthName)
return month;
// If English names can't be found, search the localized ones
for (int i = 1; i <= 12; ++i) {
if (monthName == QDate::shortMonthName(i))
if (monthName == QLocale::system().monthName(i, QLocale::ShortFormat))
return i;
}
return -1;
Expand Down Expand Up @@ -611,9 +611,10 @@ int QDate::weekNumber(int *yearNumber) const
return week;
}

#ifndef QT_NO_TEXTDATE
#if QT_DEPRECATED_SINCE(5, 11) && !defined(QT_NO_TEXTDATE)
/*!
\since 4.5
\deprecated
Returns the short name of the \a month for the representation specified
by \a type.
Expand Down Expand Up @@ -656,6 +657,7 @@ QString QDate::shortMonthName(int month, QDate::MonthNameType type)

/*!
\since 4.5
\deprecated
Returns the long name of the \a month for the representation specified
by \a type.
Expand Down Expand Up @@ -698,6 +700,7 @@ QString QDate::longMonthName(int month, MonthNameType type)

/*!
\since 4.5
\deprecated
Returns the short name of the \a weekday for the representation specified
by \a type.
Expand Down Expand Up @@ -735,6 +738,7 @@ QString QDate::shortDayName(int weekday, MonthNameType type)

/*!
\since 4.5
\deprecated
Returns the long name of the \a weekday for the representation specified
by \a type.
Expand Down Expand Up @@ -769,7 +773,7 @@ QString QDate::longDayName(int weekday, MonthNameType type)
}
return QString();
}
#endif //QT_NO_TEXTDATE
#endif // QT_NO_TEXTDATE && deprecated

#ifndef QT_NO_DATESTRING

Expand All @@ -778,8 +782,8 @@ static QString toStringTextDate(QDate date)
{
const ParsedDate pd = getDateFromJulianDay(date.toJulianDay());
static const QLatin1Char sp(' ');
return date.shortDayName(date.dayOfWeek()) + sp
+ date.shortMonthName(pd.month) + sp
return QLocale::system().dayName(date.dayOfWeek(), QLocale::ShortFormat) + sp
+ QLocale::system().monthName(pd.month, QLocale::ShortFormat) + sp
+ QString::number(pd.day) + sp
+ QString::number(pd.year);
}
Expand Down
20 changes: 12 additions & 8 deletions src/corelib/tools/qdatetime.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2017 The Qt Company Ltd.
** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
Expand Down Expand Up @@ -59,7 +59,7 @@ class QTimeZone;
class Q_CORE_EXPORT QDate
{
public:
enum MonthNameType {
enum MonthNameType { // ### Qt 6: remove, along with methods using it
DateFormat = 0,
StandaloneFormat
};
Expand All @@ -81,12 +81,16 @@ class Q_CORE_EXPORT QDate
int daysInYear() const;
int weekNumber(int *yearNum = Q_NULLPTR) const;

#ifndef QT_NO_TEXTDATE
static QString shortMonthName(int month, MonthNameType type = DateFormat);
static QString shortDayName(int weekday, MonthNameType type = DateFormat);
static QString longMonthName(int month, MonthNameType type = DateFormat);
static QString longDayName(int weekday, MonthNameType type = DateFormat);
#endif // QT_NO_TEXTDATE
#if QT_DEPRECATED_SINCE(5, 11) && !defined QT_NO_TEXTDATE
QT_DEPRECATED_X("Use QLocale::monthName or QLocale::standaloneMonthName")
static QString shortMonthName(int month, MonthNameType type = DateFormat);
QT_DEPRECATED_X("Use QLocale::dayName or QLocale::standaloneDayName")
static QString shortDayName(int weekday, MonthNameType type = DateFormat);
QT_DEPRECATED_X("Use QLocale::monthName or QLocale::standaloneMonthName")
static QString longMonthName(int month, MonthNameType type = DateFormat);
QT_DEPRECATED_X("Use QLocale::dayName or QLocale::standaloneDayName")
static QString longDayName(int weekday, MonthNameType type = DateFormat);
#endif // QT_NO_TEXTDATE && deprecated
#ifndef QT_NO_DATESTRING
QString toString(Qt::DateFormat f = Qt::TextDate) const;
#if QT_STRINGVIEW_LEVEL < 2
Expand Down

0 comments on commit b6a6121

Please sign in to comment.