1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtCore module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
56 #include "qplatformdefs.h"
57 #include "QtCore/qatomic.h"
58 #include "QtCore/qdatetime.h"
59 #include "QtCore/qstringlist.h"
60 #include "QtCore/qlocale.h"
61 #ifndef QT_BOOTSTRAPPED
62 # include "QtCore/qvariant.h"
64 #include "QtCore/qvector.h"
67 #define QDATETIMEEDIT_TIME_MIN QTime(0, 0, 0, 0)
68 #define QDATETIMEEDIT_TIME_MAX QTime(23, 59, 59, 999)
69 #define QDATETIMEEDIT_DATE_MIN QDate(100, 1, 1)
70 #define QDATETIMEEDIT_COMPAT_DATE_MIN QDate(1752, 9, 14)
71 #define QDATETIMEEDIT_DATE_MAX QDate(7999, 12, 31)
72 #define QDATETIMEEDIT_DATETIME_MIN QDateTime(QDATETIMEEDIT_DATE_MIN, QDATETIMEEDIT_TIME_MIN)
73 #define QDATETIMEEDIT_COMPAT_DATETIME_MIN QDateTime(QDATETIMEEDIT_COMPAT_DATE_MIN, QDATETIMEEDIT_TIME_MIN)
74 #define QDATETIMEEDIT_DATETIME_MAX QDateTime(QDATETIMEEDIT_DATE_MAX, QDATETIMEEDIT_TIME_MAX)
75 #define QDATETIMEEDIT_DATE_INITIAL QDate(2000, 1, 1)
79 class QDateTimePrivate : public QSharedData
82 enum Spec { LocalUnknown = -1, LocalStandard = 0, LocalDST = 1, UTC = 2, OffsetFromUTC = 3};
84 QDateTimePrivate() : spec(LocalUnknown), utcOffset(0) {}
85 QDateTimePrivate(const QDateTimePrivate &other)
86 : QSharedData(other), date(other.date), time(other.time), spec(other.spec), utcOffset(other.utcOffset)
96 The offset in seconds. Applies only when timeSpec() is OffsetFromUTC.
100 Spec getLocal(QDate &outDate, QTime &outTime) const;
101 void getUTC(QDate &outDate, QTime &outTime) const;
102 static QDateTime addMSecs(const QDateTime &dt, qint64 msecs);
103 static void addMSecs(QDate &utcDate, QTime &utcTime, qint64 msecs);
106 #ifndef QT_BOOTSTRAPPED
108 class Q_CORE_EXPORT QDateTimeParser
115 QDateTimeParser(QVariant::Type t, Context ctx)
116 : currentSectionIndex(-1), display(0), cachedDay(-1), parserType(t),
117 fixday(false), spec(Qt::LocalTime), context(ctx)
119 defaultLocale = QLocale::system();
120 first.type = FirstSection;
123 last.type = FirstSection;
126 none.type = NoSection;
130 virtual ~QDateTimeParser() {}
142 AmPmSection = 0x00001,
143 MSecSection = 0x00002,
144 SecondSection = 0x00004,
145 MinuteSection = 0x00008,
146 Hour12Section = 0x00010,
147 Hour24Section = 0x00020,
148 TimeSectionMask = (AmPmSection|MSecSection|SecondSection|MinuteSection|Hour12Section|Hour24Section),
150 DaySection = 0x00100,
151 MonthSection = 0x00200,
152 YearSection = 0x00400,
153 YearSection2Digits = 0x00800,
154 DayOfWeekSection = 0x01000,
155 DateSectionMask = (DaySection|MonthSection|YearSection|YearSection2Digits|DayOfWeekSection),
156 FirstSection = 0x02000|Internal,
157 LastSection = 0x04000|Internal,
158 CalendarPopupSection = 0x08000|Internal,
161 FirstSectionIndex = -2,
162 LastSectionIndex = -3,
163 CalendarPopupIndex = -4
164 }; // duplicated from qdatetimeedit.h
165 Q_DECLARE_FLAGS(Sections, Section)
173 enum State { // duplicated from QValidator
180 StateNode() : state(Invalid), conflicts(false) {}
197 #ifndef QT_NO_DATESTRING
198 StateNode parse(QString &input, int &cursorPosition, const QDateTime ¤tValue, bool fixup) const;
200 int sectionMaxSize(int index) const;
201 int sectionSize(int index) const;
202 int sectionMaxSize(Section s, int count) const;
203 int sectionPos(int index) const;
204 int sectionPos(const SectionNode &sn) const;
206 const SectionNode §ionNode(int index) const;
207 Section sectionType(int index) const;
208 QString sectionText(int sectionIndex) const;
209 QString sectionText(const QString &text, int sectionIndex, int index) const;
210 int getDigit(const QDateTime &dt, int index) const;
211 bool setDigit(QDateTime &t, int index, int newval) const;
212 int parseSection(const QDateTime ¤tValue, int sectionIndex, QString &txt, int &cursorPosition,
213 int index, QDateTimeParser::State &state, int *used = 0) const;
214 int absoluteMax(int index, const QDateTime &value = QDateTime()) const;
215 int absoluteMin(int index) const;
216 bool parseFormat(const QString &format);
217 #ifndef QT_NO_DATESTRING
218 bool fromString(const QString &text, QDate *date, QTime *time) const;
221 #ifndef QT_NO_TEXTDATE
222 int findMonth(const QString &str1, int monthstart, int sectionIndex,
223 QString *monthName = 0, int *used = 0) const;
224 int findDay(const QString &str1, int intDaystart, int sectionIndex,
225 QString *dayName = 0, int *used = 0) const;
227 int findAmPm(QString &str1, int index, int *used = 0) const;
228 int maxChange(int s) const;
229 bool potentialValue(const QString &str, int min, int max, int index,
230 const QDateTime ¤tValue, int insert) const;
231 bool skipToNextSection(int section, const QDateTime ¤t, const QString §ionText) const;
232 QString sectionName(int s) const;
233 QString stateName(int s) const;
235 QString sectionFormat(int index) const;
236 QString sectionFormat(Section s, int count) const;
244 Q_DECLARE_FLAGS(FieldInfo, FieldInfoFlag)
246 FieldInfo fieldInfo(int index) const;
248 virtual QDateTime getMinimum() const;
249 virtual QDateTime getMaximum() const;
250 virtual int cursorPosition() const { return -1; }
251 virtual QString displayText() const { return text; }
252 virtual QString getAmPmText(AmPm ap, Case cs) const;
253 virtual QLocale locale() const { return defaultLocale; }
255 mutable int currentSectionIndex;
257 mutable int cachedDay;
258 mutable QString text;
259 QVector<SectionNode> sectionNodes;
260 SectionNode first, last, none, popup;
261 QStringList separators;
262 QString displayFormat;
263 QLocale defaultLocale;
264 QVariant::Type parserType;
268 Qt::TimeSpec spec; // spec if used by QDateTimeEdit
272 Q_CORE_EXPORT bool operator==(const QDateTimeParser::SectionNode &s1, const QDateTimeParser::SectionNode &s2);
274 Q_DECLARE_OPERATORS_FOR_FLAGS(QDateTimeParser::Sections)
275 Q_DECLARE_OPERATORS_FOR_FLAGS(QDateTimeParser::FieldInfo)
277 #endif // QT_BOOTSTRAPPED
281 #endif // QDATETIME_P_H