Modernize the "textdate" feature

Change-Id: Ic0b6f13e17c301ed66d6a8297c242086c94ac87d
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Liang Qi 2018-09-19 13:28:13 +02:00
parent 6948bf20a7
commit e226b0f94a
4 changed files with 19 additions and 18 deletions

View File

@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
@ -114,6 +114,7 @@
#define QT_NO_SYSTEMLOCALE
#define QT_FEATURE_systemsemaphore -1
#define QT_FEATURE_temporaryfile 1
#define QT_FEATURE_textdate 1
#define QT_NO_THREAD
#define QT_FEATURE_timezone -1
#define QT_FEATURE_topleveldomain -1

View File

@ -171,7 +171,7 @@ static ParsedDate getDateFromJulianDay(qint64 julianDay)
static const char monthDays[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
#ifndef QT_NO_TEXTDATE
#if QT_CONFIG(textdate)
static const char qt_shortMonthNames[][4] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
@ -200,7 +200,7 @@ static int fromShortMonthName(const QStringRef &monthName)
}
return -1;
}
#endif // QT_NO_TEXTDATE
#endif // textdate
#ifndef QT_NO_DATESTRING
struct ParsedRfcDateTime {
@ -613,7 +613,7 @@ int QDate::weekNumber(int *yearNumber) const
return week;
}
#if QT_DEPRECATED_SINCE(5, 11) && !defined(QT_NO_TEXTDATE)
#if QT_DEPRECATED_SINCE(5, 11) && QT_CONFIG(textdate)
/*!
\since 4.5
\deprecated
@ -775,11 +775,11 @@ QString QDate::longDayName(int weekday, MonthNameType type)
}
return QString();
}
#endif // QT_NO_TEXTDATE && deprecated
#endif // textdate && deprecated
#ifndef QT_NO_DATESTRING
#ifndef QT_NO_TEXTDATE
#if QT_CONFIG(textdate)
static QString toStringTextDate(QDate date)
{
const ParsedDate pd = getDateFromJulianDay(date.toJulianDay());
@ -789,7 +789,7 @@ static QString toStringTextDate(QDate date)
+ QString::number(pd.day) + sp
+ QString::number(pd.year);
}
#endif // QT_NO_TEXTDATE
#endif // textdate
static QString toStringIsoDate(qint64 jd)
{
@ -865,7 +865,7 @@ QString QDate::toString(Qt::DateFormat format) const
case Qt::RFC2822Date:
return QLocale::c().toString(*this, QStringViewLiteral("dd MMM yyyy"));
default:
#ifndef QT_NO_TEXTDATE
#if QT_CONFIG(textdate)
case Qt::TextDate:
return toStringTextDate(*this);
#endif
@ -1234,7 +1234,7 @@ QDate QDate::fromString(const QString& string, Qt::DateFormat format)
case Qt::RFC2822Date:
return rfcDateImpl(string).date;
default:
#ifndef QT_NO_TEXTDATE
#if QT_CONFIG(textdate)
case Qt::TextDate: {
QVector<QStringRef> parts = string.splitRef(QLatin1Char(' '), QString::SkipEmptyParts);
@ -1255,7 +1255,7 @@ QDate QDate::fromString(const QString& string, Qt::DateFormat format)
return QDate(year, month, parts.at(2).toInt());
}
#endif // QT_NO_TEXTDATE
#endif // textdate
case Qt::ISODate: {
// Semi-strict parsing, must be long enough and have non-numeric separators
if (string.size() < 10 || string.at(4).isDigit() || string.at(7).isDigit()
@ -3848,7 +3848,7 @@ QString QDateTime::toString(Qt::DateFormat format) const
return buf;
}
default:
#ifndef QT_NO_TEXTDATE
#if QT_CONFIG(textdate)
case Qt::TextDate: {
const QPair<QDate, QTime> p = getDateTime(d);
buf = p.first.toString(Qt::TextDate);
@ -4827,7 +4827,7 @@ QDateTime QDateTime::fromString(const QString& string, Qt::DateFormat format)
date = date.addDays(1);
return QDateTime(date, time, spec, offset);
}
#if !defined(QT_NO_TEXTDATE)
#if QT_CONFIG(textdate)
case Qt::TextDate: {
QVector<QStringRef> parts = string.splitRef(QLatin1Char(' '), QString::SkipEmptyParts);
@ -4936,7 +4936,7 @@ QDateTime QDateTime::fromString(const QString& string, Qt::DateFormat format)
return QDateTime(date, time, Qt::UTC);
}
}
#endif //QT_NO_TEXTDATE
#endif // textdate
}
return QDateTime();

View File

@ -81,7 +81,7 @@ public:
int daysInYear() const;
int weekNumber(int *yearNum = nullptr) const;
#if QT_DEPRECATED_SINCE(5, 10) && !defined QT_NO_TEXTDATE
#if QT_DEPRECATED_SINCE(5, 10) && QT_CONFIG(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")
@ -90,7 +90,7 @@ public:
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
#endif // textdate && deprecated
#ifndef QT_NO_DATESTRING
QString toString(Qt::DateFormat f = Qt::TextDate) const;
#if QT_STRINGVIEW_LEVEL < 2

View File

@ -612,7 +612,7 @@ int QDateTimeParser::sectionSize(int sectionIndex) const
int QDateTimeParser::sectionMaxSize(Section s, int count) const
{
#ifndef QT_NO_TEXTDATE
#if QT_CONFIG(textdate)
int mcount = 12;
#endif
@ -636,14 +636,14 @@ int QDateTimeParser::sectionMaxSize(Section s, int count) const
case DaySection: return 2;
case DayOfWeekSectionShort:
case DayOfWeekSectionLong:
#ifdef QT_NO_TEXTDATE
#if !QT_CONFIG(textdate)
return 2;
#else
mcount = 7;
Q_FALLTHROUGH();
#endif
case MonthSection:
#ifdef QT_NO_TEXTDATE
#if !QT_CONFIG(textdate)
return 2;
#else
if (count <= 2)