summaryrefslogtreecommitdiffstats
path: root/src/corelib/time/qdatetimeparser_p.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/time/qdatetimeparser_p.h')
-rw-r--r--src/corelib/time/qdatetimeparser_p.h104
1 files changed, 35 insertions, 69 deletions
diff --git a/src/corelib/time/qdatetimeparser_p.h b/src/corelib/time/qdatetimeparser_p.h
index 0cee907ff5..faf383f3d7 100644
--- a/src/corelib/time/qdatetimeparser_p.h
+++ b/src/corelib/time/qdatetimeparser_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDATETIMEPARSER_P_H
#define QDATETIMEPARSER_P_H
@@ -82,9 +46,8 @@ public:
FromString,
DateTimeEdit
};
- QDateTimeParser(QMetaType::Type t, Context ctx, const QCalendar &cal = QCalendar())
- : currentSectionIndex(-1), cachedDay(-1), parserType(t),
- fixday(false), context(ctx), calendar(cal)
+ QDateTimeParser(QMetaType::Type t, Context ctx, QCalendar cal = QCalendar())
+ : parserType(t), context(ctx), calendar(cal)
{
defaultLocale = QLocale::system();
first.type = FirstSection;
@@ -141,7 +104,7 @@ public:
struct Q_CORE_EXPORT SectionNode {
Section type;
mutable int pos;
- int count;
+ int count; // (used as Case(count) indicator for AmPmSection)
int zeroesAdded;
static QString name(Section s);
@@ -160,7 +123,6 @@ public:
StateNode() : state(Invalid), padded(0), conflicts(false) {}
StateNode(const QDateTime &val, State ok=Acceptable, int pad=0, bool bad=false)
: value(val), state(ok), padded(pad), conflicts(bad) {}
- QString input;
QDateTime value;
State state;
int padded;
@@ -172,15 +134,12 @@ public:
PmText
};
- enum Case {
- UpperCase,
- LowerCase
- };
-
- StateNode parse(QString input, int position, const QDateTime &defaultValue, bool fixup) const;
- bool fromString(const QString &text, QDate *date, QTime *time) const;
- bool fromString(const QString &text, QDateTime* datetime) const;
- bool parseFormat(const QString &format);
+ StateNode parse(const QString &input, int position,
+ const QDateTime &defaultValue, bool fixup) const;
+ bool fromString(const QString &text, QDate *date, QTime *time,
+ int baseYear = QLocale::DefaultTwoDigitBaseYear) const;
+ bool fromString(const QString &text, QDateTime *datetime, int baseYear) const;
+ bool parseFormat(QStringView format);
enum FieldInfoFlag {
Numeric = 0x01,
@@ -193,14 +152,13 @@ public:
FieldInfo fieldInfo(int index) const;
void setDefaultLocale(const QLocale &loc) { defaultLocale = loc; }
- virtual QString displayText() const { return text; }
- void setCalendar(const QCalendar &calendar);
+ virtual QString displayText() const { return m_text; }
+ void setCalendar(QCalendar calendar);
private:
int sectionMaxSize(Section s, int count) const;
QString sectionText(const QString &text, int sectionIndex, int index) const;
- StateNode scanString(const QDateTime &defaultValue,
- bool fixup, QString *input) const;
+ StateNode scanString(const QDateTime &defaultValue, bool fixup) const;
struct ParsedSection {
int value;
int used;
@@ -211,18 +169,15 @@ private:
: value(ok == Invalid ? -1 : val), used(read), zeroes(zs), state(ok)
{}
};
- ParsedSection parseSection(const QDateTime &currentValue, int sectionIndex,
- int offset, QString *text) const;
- int findMonth(const QString &str1, int monthstart, int sectionIndex,
+ ParsedSection parseSection(const QDateTime &currentValue, int sectionIndex, int offset) const;
+ int findMonth(QStringView str, int monthstart, int sectionIndex,
int year, QString *monthName = nullptr, int *used = nullptr) const;
- int findDay(const QString &str1, int intDaystart, int sectionIndex,
+ int findDay(QStringView str, int intDaystart, int sectionIndex,
QString *dayName = nullptr, int *used = nullptr) const;
- ParsedSection findUtcOffset(QStringView str) const;
+ ParsedSection findUtcOffset(QStringView str, int mode) const;
ParsedSection findTimeZoneName(QStringView str, const QDateTime &when) const;
ParsedSection findTimeZone(QStringView str, const QDateTime &when,
- int maxVal, int minVal) const;
- // Implemented in qdatetime.cpp:
- static int startsWithLocalTimeZone(const QStringView name);
+ int maxVal, int minVal, int mode) const;
enum AmPmFinder {
Neither = -1,
@@ -242,6 +197,17 @@ private:
return potentialValue(QStringView(str), min, max, index, currentValue, insert);
}
+ enum Case {
+ NativeCase,
+ LowerCase,
+ UpperCase
+ };
+
+ QString getAmPmText(AmPm ap, Case cs) const;
+ QDateTime baseDate(const QTimeZone &zone) const;
+
+ friend class QDTPUnitTestParser;
+
protected: // for the benefit of QDateTimeEditPrivate
int sectionSize(int index) const;
int sectionMaxSize(int index) const;
@@ -263,14 +229,14 @@ protected: // for the benefit of QDateTimeEditPrivate
return skipToNextSection(section, current, QStringView(sectionText));
}
QString stateName(State s) const;
- QString getAmPmText(AmPm ap, Case cs) const;
virtual QDateTime getMinimum() const;
virtual QDateTime getMaximum() const;
virtual int cursorPosition() const { return -1; }
virtual QLocale locale() const { return defaultLocale; }
- mutable int currentSectionIndex;
+ mutable int currentSectionIndex = int(NoSectionIndex);
+ mutable int defaultCenturyStart = QLocale::DefaultTwoDigitBaseYear;
Sections display;
/*
This stores the most recently selected day.
@@ -285,15 +251,15 @@ protected: // for the benefit of QDateTimeEditPrivate
This is good for when users have selected their desired day and are scrolling up or down in the month or year section
and do not want smaller months (or non-leap years) to alter the day that they chose.
*/
- mutable int cachedDay;
- mutable QString text;
+ mutable int cachedDay = -1;
+ mutable QString m_text;
QList<SectionNode> sectionNodes;
SectionNode first, last, none, popup;
QStringList separators;
QString displayFormat;
QLocale defaultLocale;
QMetaType::Type parserType;
- bool fixday;
+ bool fixday = false;
Context context;
QCalendar calendar;
};