Qt 4.8
qdatetimefns.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 
48 template<typename TSubClass>
50 {
51  const Item item(m_operands.first()->evaluateSingleton(context));
52  if(item)
53  {
54  return static_cast<const TSubClass *>(this)->
55  extract(item.as<AbstractDuration>());
56  }
57  else
58  return Item();
59 }
60 
61 Item YearsFromDurationFN::extract(const AbstractDuration *const duration) const
62 {
63  return Integer::fromValue(duration->years() * (duration->isPositive() ? 1 : -1));
64 }
65 
66 Item MonthsFromDurationFN::extract(const AbstractDuration *const duration) const
67 {
68  return Integer::fromValue(duration->months() * (duration->isPositive() ? 1 : -1));
69 }
70 
71 Item DaysFromDurationFN::extract(const AbstractDuration *const duration) const
72 {
73  return Integer::fromValue(duration->days() * (duration->isPositive() ? 1 : -1));
74 }
75 
76 Item HoursFromDurationFN::extract(const AbstractDuration *const duration) const
77 {
78  return Integer::fromValue(duration->hours() * (duration->isPositive() ? 1 : -1));
79 }
80 
81 Item MinutesFromDurationFN::extract(const AbstractDuration *const duration) const
82 {
83  return Integer::fromValue(duration->minutes() * (duration->isPositive() ? 1 : -1));
84 }
85 
86 Item SecondsFromDurationFN::extract(const AbstractDuration *const duration) const
87 {
88  return toItem(Decimal::fromValue((duration->seconds() + duration->mseconds() / 1000.0) *
89  (duration->isPositive() ? 1 : -1)));
90 }
91 
92 template<typename TSubClass>
94 {
95  const Item item(m_operands.first()->evaluateSingleton(context));
96  if(item)
97  {
98  return static_cast<const TSubClass *>(this)->
99  extract(item.as<AbstractDateTime>()->toDateTime());
100  }
101  else
102  return Item();
103 }
104 
105 Item YearFromAbstractDateTimeFN::extract(const QDateTime &dt) const
106 {
107  return Integer::fromValue(dt.date().year());
108 }
109 
110 Item DayFromAbstractDateTimeFN::extract(const QDateTime &dt) const
111 {
112  return Integer::fromValue(dt.date().day());
113 }
114 
115 Item MinutesFromAbstractDateTimeFN::extract(const QDateTime &dt) const
116 {
117  return Integer::fromValue(dt.time().minute());
118 }
119 
120 Item SecondsFromAbstractDateTimeFN::extract(const QDateTime &dt) const
121 {
122  const QTime time(dt.time());
123  return toItem(Decimal::fromValue(time.second() + time.msec() / 1000.0));
124 }
125 
126 Item TimezoneFromAbstractDateTimeFN::extract(const QDateTime &dt) const
127 {
128  if(dt.timeSpec() == Qt::UTC)
129  return toItem(CommonValues::DayTimeDurationZero);
130  else if(dt.timeSpec() == Qt::OffsetFromUTC)
131  return toItem(DayTimeDuration::fromSeconds(dt.utcOffset()));
132  else
133  return Item();
134 }
135 
136 Item MonthFromAbstractDateTimeFN::extract(const QDateTime &dt) const
137 {
138  return Integer::fromValue(dt.date().month());
139 }
140 
141 Item HoursFromAbstractDateTimeFN::extract(const QDateTime &dt) const
142 {
143  return Integer::fromValue(dt.time().hour());
144 }
145 
virtual SecondProperty seconds() const =0
Base class for classes implementing durations.
Base class for classes implementing values related to time, date or both.
virtual MinuteProperty minutes() const =0
int month() const
Returns the number corresponding to the month of this date, using the following convention: ...
Definition: qdatetime.cpp:382
int day() const
Returns the day of the month (1 to 31) of this date.
Definition: qdatetime.cpp:395
Item toItem(const QExplicitlySharedDataPointer< T > atomicValue)
Definition: qitem_p.h:431
int utcOffset() const
Definition: qdatetime.cpp:3449
virtual MonthProperty months() const =0
The QTime class provides clock time functions.
Definition: qdatetime.h:148
virtual DayCountProperty days() const =0
Helper class for implementing functions extracting components from durations.
const QDateTime & toDateTime() const
virtual HourProperty hours() const =0
int minute() const
Returns the minute part (0 to 59) of the time.
Definition: qdatetime.cpp:1589
virtual YearProperty years() const =0
QDate date() const
Returns the date part of the datetime.
Definition: qdatetime.cpp:2357
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
Qt::TimeSpec timeSpec() const
Returns the time specification of the datetime.
Definition: qdatetime.cpp:2379
Helper class for implementing functions extracting components from date/time values.
int year() const
Returns the year of this date.
Definition: qdatetime.cpp:353
QTime time() const
Returns the time part of the datetime.
Definition: qdatetime.cpp:2368
virtual MSecondProperty mseconds() const =0
int hour() const
Returns the hour part (0 to 23) of the time.
Definition: qdatetime.cpp:1578