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

Last change on this file since 780 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 9.4 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtXmlPatterns module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this 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 have questions regarding the use of this file, please contact
37** Nokia 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.