Qt 4.8
qgyearmonth.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qbuiltintypes_p.h"
43 
44 #include "qgyearmonth_p.h"
45 
47 
48 using namespace QPatternist;
49 
51 {
52 }
53 
55 {
56  static const CaptureTable captureTable( // STATIC DATA
57  /* The extra paranthesis is a build fix for GCC 3.3. */
59  "^\\s*" /* Any preceding whitespace. */
60  "(-?)" /* Any preceding minus. */
61  "(\\d{4,})" /* The year part. */
62  "-" /* Delimiter. */
63  "(\\d{2})" /* The month part. */
64  "(?:(\\+|-)(\\d{2}):(\\d{2})|(Z))?" /* The zone offset, "+08:24". */
65  "\\s*$" /* Any terminating whitespace. */))),
66  /*zoneOffsetSignP*/ 4,
67  /*zoneOffsetHourP*/ 5,
68  /*zoneOffsetMinuteP*/ 6,
69  /*zoneOffsetUTCSymbolP*/ 7,
70  /*yearP*/ 2,
71  /*monthP*/ 3,
72  /*dayP*/ -1,
73  /*hourP*/ -1,
74  /*minutesP*/ -1,
75  /*secondsP*/ -1,
76  /*msecondsP*/ -1,
77  /*yearSign*/ 1);
78 
79  AtomicValue::Ptr err;
80  const QDateTime retval(create(err, lexical, captureTable));
81 
82  return err ? err : GYearMonth::Ptr(new GYearMonth(retval));
83 }
84 
86 {
87  QDateTime result(QDate(dt.date().year(), dt.date().month(), DefaultDay));
88  copyTimeSpec(dt, result);
89 
90  return GYearMonth::Ptr(new GYearMonth(result));
91 }
92 
94 {
95  return m_dateTime.toString(QLatin1String("yyyy-MM")) + zoneOffsetToString();
96 }
97 
99 {
101 }
102 
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
Base class for classes implementing values related to time, date or both.
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
int month() const
Returns the number corresponding to the month of this date, using the following convention: ...
Definition: qdatetime.cpp:382
static const AtomicType::Ptr xsGYearMonth
virtual ItemType::Ptr type() const
Definition: qgyearmonth.cpp:98
The QDate class provides date functions.
Definition: qdatetime.h:55
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
static GYearMonth::Ptr fromDateTime(const QDateTime &dt)
Definition: qgyearmonth.cpp:85
QString toString(Qt::DateFormat f=Qt::TextDate) const
Returns the datetime as a string in the format given.
Definition: qdatetime.cpp:2628
static QDateTime create(AtomicValue::Ptr &errorMessage, const QString &lexicalSource, const CaptureTable &captTable)
static GYearMonth::Ptr fromLexical(const QString &string)
Definition: qgyearmonth.cpp:54
GYearMonth(const QDateTime &dateTime)
Definition: qgyearmonth.cpp:50
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
Acts as a mapping table for AbstractDateTime::create() and describes where certain fields in a QRegEx...
The namespace for the internal API of QtXmlPatterns.
static void copyTimeSpec(const QDateTime &from, QDateTime &to)
Makes the QDateTime::timeSpec() and QDateTime::zoneOffset() of ot * consistent to from...
QDate date() const
Returns the date part of the datetime.
Definition: qdatetime.cpp:2357
virtual QString stringValue() const
Definition: qgyearmonth.cpp:93
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
AtomicValue::Ptr Ptr
Definition: qgyearmonth_p.h:72
int year() const
Returns the year of this date.
Definition: qdatetime.cpp:353