Skip to content

Commit

Permalink
Modernize the "textdate" feature
Browse files Browse the repository at this point in the history
Change-Id: Ic0b6f13e17c301ed66d6a8297c242086c94ac87d
Reviewed-by: Edward Welbourne <[email protected]>
Reviewed-by: Lars Knoll <[email protected]>
  • Loading branch information
liangqi committed Sep 24, 2018
1 parent 6948bf2 commit e226b0f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/corelib/global/qconfig-bootstrapped.h
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions src/corelib/tools/qdatetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand Down Expand Up @@ -200,7 +200,7 @@ static int fromShortMonthName(const QStringRef &monthName)
}
return -1;
}
#endif // QT_NO_TEXTDATE
#endif // textdate

#ifndef QT_NO_DATESTRING
struct ParsedRfcDateTime {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand All @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand All @@ -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()
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/corelib/tools/qdatetime.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Q_CORE_EXPORT QDate
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")
Expand All @@ -90,7 +90,7 @@ class Q_CORE_EXPORT QDate
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
Expand Down
6 changes: 3 additions & 3 deletions src/corelib/tools/qdatetimeparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down

0 comments on commit e226b0f

Please sign in to comment.