source: trunk/src/xmlpatterns/data/qabstractdatetime_p.h@ 98

Last change on this file since 98 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 9.4 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42//
43// W A R N I N G
44// -------------
45//
46// This file is not part of the Qt API. It exists purely as an
47// implementation detail. This header file may change from version to
48// version without notice, or even be removed.
49//
50// We mean it.
51
52#ifndef Patternist_AbstractDateTime_H
53#define Patternist_AbstractDateTime_H
54
55#include <QDateTime>
56#include <QRegExp>
57
58#include "qitem_p.h"
59
60QT_BEGIN_HEADER
61
62QT_BEGIN_NAMESPACE
63
64namespace QPatternist
65{
66 /**
67 * @short Base class for classes implementing values related to time, date or both.
68 *
69 * @see <a href="http://www.w3.org/TR/xmlschema-2/#dateTime">XML Schema
70 * Part 2: Datatypes Second Edition, 3.2.7 dateTime</a>
71 * @see <a href="http://www.w3.org/TR/xpath-datamodel/#dates-and-times">XQuery
72 * 1.0 and XPath 2.0 Data Model (XDM), 3.3.2 Dates and Times</a>
73 * @see <a href="http://www.cl.cam.ac.uk/~mgk25/iso-time.html">A summary of
74 * the international standard date and time notation, Markus Kuhn</a>
75 * @see <a href="http://en.wikipedia.org/wiki/Iso_date">ISO 8601,
76 * From Wikipedia, the free encyclopedia</a>
77 * @author Frans Englich <[email protected]>
78 * @ingroup Patternist_xdm
79 */
80 class AbstractDateTime : public AtomicValue
81 {
82 public:
83 typedef QExplicitlySharedDataPointer<AbstractDateTime> Ptr;
84
85 AbstractDateTime(const QDateTime &dateTime);
86
87 enum
88 {
89 DefaultYear = 2000,
90 DefaultMonth = 1,
91 DefaultDay = 1
92 };
93
94 /**
95 * @returns the date time this class represents, as a QDateTime.
96 */
97 inline const QDateTime &toDateTime() const
98 {
99 return m_dateTime;
100 }
101
102
103 /**
104 * @short Acts as a mapping table for AbstractDateTime::create()
105 * and describes where certain fields in a QRegExp pattern can be found
106 * for a particular W3C XML Schema date/time type.
107 *
108 * @author Frans Englich <[email protected]>
109 * @ingroup Patternist_xdm
110 */
111 class CaptureTable
112 {
113 public:
114 CaptureTable(const QRegExp &exp,
115 const qint8 zoneOffsetSignP,
116 const qint8 zoneOffsetHourP,
117 const qint8 zoneOffsetMinuteP,
118 const qint8 zoneOffsetUTCSymbolP,
119 const qint8 yearP,
120 const qint8 monthP = -1,
121 const qint8 dayP = -1,
122 const qint8 hourP = -1,
123 const qint8 minutesP = -1,
124 const qint8 secondsP = -1,
125 const qint8 msecondsP = -1,
126 const qint8 yearSignP = -1) : regExp(exp)
127 , zoneOffsetSign(zoneOffsetSignP)
128 , zoneOffsetHour(zoneOffsetHourP)
129 , zoneOffsetMinute(zoneOffsetMinuteP)
130 , zoneOffsetUTCSymbol(zoneOffsetUTCSymbolP)
131 , year(yearP)
132 , month(monthP)
133 , day(dayP)
134 , hour(hourP)
135 , minutes(minutesP)
136 , seconds(secondsP)
137 , mseconds(msecondsP)
138 , yearSign(yearSignP)
139 {
140 Q_ASSERT(exp.isValid());
141 }
142
143 const QRegExp regExp;
144 const qint8 zoneOffsetSign;
145 const qint8 zoneOffsetHour;
146 const qint8 zoneOffsetMinute;
147 const qint8 zoneOffsetUTCSymbol;
148 const qint8 year;
149 const qint8 month;
150 const qint8 day;
151 const qint8 hour;
152 const qint8 minutes;
153 const qint8 seconds;
154 const qint8 mseconds;
155 const qint8 yearSign;
156
157 private:
158 Q_DISABLE_COPY(CaptureTable)
159 };
160
161 /**
162 * @returns m_dateTime's time part converted to string. This is for
163 * example "12" or "01.023".
164 */
165 QString timeToString() const;
166
167 /**
168 * @returns m_dateTime's date part converted to string. This is for
169 * example "2004-05-12" or "-2004-05-12".
170 */
171 QString dateToString() const;
172
173 /**
174 * Serializes the milli seconds @p msecs into a string representation. For
175 * example, if @p msecs is 1, ".001" is returned; if @p msecs is 100 then
176 * is ".1" returned.
177 */
178 static QString serializeMSeconds(const MSecondProperty msecs);
179
180 /**
181 * A factory function for creating instances that are of the dynamic
182 * type of this class, that represents @p dt.
183 *
184 * The default implementation performs an assert() call. This function
185 * is not pure virtual because all sub-classes do not use it.
186 */
187 virtual Item fromValue(const QDateTime &dt) const;
188
189 /**
190 * Determines whether @p dt is a date-time that can be represented,
191 * and isn't too early or too late. If it is valid, @c true is returned. Otherwise,
192 * @c false is returned and @p message is set to contain a translated message for
193 * human consumption, describing the error.
194 */
195 static bool isRangeValid(const QDate &date,
196 QString &message);
197
198 protected:
199
200 /**
201 * @returns m_dateTime' zone offset converted to string, as per the
202 * the W3C XML Schema types. This is for
203 * example "Z" or "+12.00"(depending on m_dateTime).
204 */
205 QString zoneOffsetToString() const;
206
207 static QDateTime create(AtomicValue::Ptr &errorMessage,
208 const QString &lexicalSource,
209 const CaptureTable &captTable);
210
211 /**
212 * @short Makes the QDateTime::timeSpec() and QDateTime::zoneOffset()
213 * of @p ot * consistent to @p from.
214 */
215 static void copyTimeSpec(const QDateTime &from,
216 QDateTime &to);
217
218 const QDateTime m_dateTime;
219
220 private:
221 enum ZoneOffsetParseResult
222 {
223 /**
224 * syntax or logical error was encountered.
225 */
226 Error,
227 /**
228 * It's a valid offset from UTC.
229 */
230 Offset,
231
232 /**
233 * No zone offset was specified, it's an implementation defined zone offset.
234 */
235 LocalTime,
236 UTC
237 };
238
239 /**
240 * @short Parses the zone offset. All types use zone offsets.
241 *
242 * If result is set to Offset, the offset is returned, otherwise
243 * the return value is undefined.
244 *
245 * The offset is in seconds.
246 */
247 static ZOTotal parseZoneOffset(ZoneOffsetParseResult &result,
248 const QStringList &capts,
249 const CaptureTable &captTable);
250
251 static inline void setUtcOffset(QDateTime &result,
252 const ZoneOffsetParseResult zoResult,
253 const int zoOffset);
254 };
255}
256
257QT_END_NAMESPACE
258
259QT_END_HEADER
260
261#endif
Note: See TracBrowser for help on using the repository browser.