|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtXmlPatterns module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
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 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 /** |
|
43 * @file |
|
44 * @short This file is included by qdatetimefns_p.h. |
|
45 * If you need includes in this file, put them in qdatetimefns_p.h, outside of the namespace. |
|
46 */ |
|
47 |
|
48 template<typename TSubClass> |
|
49 Item ExtractFromDurationFN<TSubClass>::evaluateSingleton(const DynamicContext::Ptr &context) const |
|
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> |
|
93 Item ExtractFromDateTimeFN<TSubClass>::evaluateSingleton(const DynamicContext::Ptr &context) const |
|
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 |