Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qtimezoneprivate.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2013 John Layt <jlayt@kde.org> | - | ||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
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 The Qt Company. For licensing terms | - | ||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||
15 | ** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free | - | ||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||
25 | ** | - | ||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||
29 | ** | - | ||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||
31 | ** | - | ||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||
33 | - | |||||||||||||
34 | - | |||||||||||||
35 | #include "qtimezone.h" | - | ||||||||||||
36 | #include "qtimezoneprivate_p.h" | - | ||||||||||||
37 | #include "qtimezoneprivate_data_p.h" | - | ||||||||||||
38 | - | |||||||||||||
39 | #include <qdatastream.h> | - | ||||||||||||
40 | #include <qdebug.h> | - | ||||||||||||
41 | - | |||||||||||||
42 | #include <algorithm> | - | ||||||||||||
43 | - | |||||||||||||
44 | QT_BEGIN_NAMESPACE | - | ||||||||||||
45 | - | |||||||||||||
46 | enum { | - | ||||||||||||
47 | MSECS_TRAN_WINDOW = 21600000 // 6 hour window for possible recent transitions | - | ||||||||||||
48 | }; | - | ||||||||||||
49 | - | |||||||||||||
50 | /* | - | ||||||||||||
51 | Static utilities for looking up Windows ID tables | - | ||||||||||||
52 | */ | - | ||||||||||||
53 | - | |||||||||||||
54 | static const int windowsDataTableSize = sizeof(windowsDataTable) / sizeof(QWindowsData) - 1; | - | ||||||||||||
55 | static const int zoneDataTableSize = sizeof(zoneDataTable) / sizeof(QZoneData) - 1; | - | ||||||||||||
56 | static const int utcDataTableSize = sizeof(utcDataTable) / sizeof(QUtcData) - 1; | - | ||||||||||||
57 | - | |||||||||||||
58 | - | |||||||||||||
59 | static const QZoneData *zoneData(quint16 index) | - | ||||||||||||
60 | { | - | ||||||||||||
61 | Q_ASSERT(index < zoneDataTableSize); | - | ||||||||||||
62 | return &zoneDataTable[index]; executed 6186 times by 1 test: return &zoneDataTable[index]; Executed by:
| 6186 | ||||||||||||
63 | } | - | ||||||||||||
64 | - | |||||||||||||
65 | static const QWindowsData *windowsData(quint16 index) | - | ||||||||||||
66 | { | - | ||||||||||||
67 | Q_ASSERT(index < windowsDataTableSize); | - | ||||||||||||
68 | return &windowsDataTable[index]; executed 837 times by 1 test: return &windowsDataTable[index]; Executed by:
| 837 | ||||||||||||
69 | } | - | ||||||||||||
70 | - | |||||||||||||
71 | static const QUtcData *utcData(quint16 index) | - | ||||||||||||
72 | { | - | ||||||||||||
73 | Q_ASSERT(index < utcDataTableSize); | - | ||||||||||||
74 | return &utcDataTable[index]; executed 36620 times by 2 tests: return &utcDataTable[index]; Executed by:
| 36620 | ||||||||||||
75 | } | - | ||||||||||||
76 | - | |||||||||||||
77 | // Return the Windows ID literal for a given QWindowsData | - | ||||||||||||
78 | static QByteArray windowsId(const QWindowsData *windowsData) | - | ||||||||||||
79 | { | - | ||||||||||||
80 | return (windowsIdData + windowsData->windowsIdIndex); executed 551 times by 1 test: return (windowsIdData + windowsData->windowsIdIndex); Executed by:
| 551 | ||||||||||||
81 | } | - | ||||||||||||
82 | - | |||||||||||||
83 | // Return the IANA ID literal for a given QWindowsData | - | ||||||||||||
84 | static QByteArray ianaId(const QWindowsData *windowsData) | - | ||||||||||||
85 | { | - | ||||||||||||
86 | return (ianaIdData + windowsData->ianaIdIndex); executed 1 time by 1 test: return (ianaIdData + windowsData->ianaIdIndex); Executed by:
| 1 | ||||||||||||
87 | } | - | ||||||||||||
88 | - | |||||||||||||
89 | // Return the IANA ID literal for a given QZoneData | - | ||||||||||||
90 | static QByteArray ianaId(const QZoneData *zoneData) | - | ||||||||||||
91 | { | - | ||||||||||||
92 | return (ianaIdData + zoneData->ianaIdIndex); executed 1692 times by 1 test: return (ianaIdData + zoneData->ianaIdIndex); Executed by:
| 1692 | ||||||||||||
93 | } | - | ||||||||||||
94 | - | |||||||||||||
95 | static QByteArray utcId(const QUtcData *utcData) | - | ||||||||||||
96 | { | - | ||||||||||||
97 | return (ianaIdData + utcData->ianaIdIndex); executed 36584 times by 2 tests: return (ianaIdData + utcData->ianaIdIndex); Executed by:
| 36584 | ||||||||||||
98 | } | - | ||||||||||||
99 | - | |||||||||||||
100 | static quint16 toWindowsIdKey(const QByteArray &winId) | - | ||||||||||||
101 | { | - | ||||||||||||
102 | for (quint16 i = 0; i < windowsDataTableSize; ++i) {
| 3-549 | ||||||||||||
103 | const QWindowsData *data = windowsData(i); | - | ||||||||||||
104 | if (windowsId(data) == winId)
| 9-540 | ||||||||||||
105 | return data->windowsIdKey; executed 9 times by 1 test: return data->windowsIdKey; Executed by:
| 9 | ||||||||||||
106 | } executed 540 times by 1 test: end of block Executed by:
| 540 | ||||||||||||
107 | return 0; executed 3 times by 1 test: return 0; Executed by:
| 3 | ||||||||||||
108 | } | - | ||||||||||||
109 | - | |||||||||||||
110 | static QByteArray toWindowsIdLiteral(quint16 windowsIdKey) | - | ||||||||||||
111 | { | - | ||||||||||||
112 | for (quint16 i = 0; i < windowsDataTableSize; ++i) {
| 0-52 | ||||||||||||
113 | const QWindowsData *data = windowsData(i); | - | ||||||||||||
114 | if (data->windowsIdKey == windowsIdKey)
| 2-50 | ||||||||||||
115 | return windowsId(data); executed 2 times by 1 test: return windowsId(data); Executed by:
| 2 | ||||||||||||
116 | } executed 50 times by 1 test: end of block Executed by:
| 50 | ||||||||||||
117 | return QByteArray(); never executed: return QByteArray(); | 0 | ||||||||||||
118 | } | - | ||||||||||||
119 | - | |||||||||||||
120 | /* | - | ||||||||||||
121 | Base class implementing common utility routines, only intantiate for a null tz. | - | ||||||||||||
122 | */ | - | ||||||||||||
123 | - | |||||||||||||
124 | QTimeZonePrivate::QTimeZonePrivate() | - | ||||||||||||
125 | { | - | ||||||||||||
126 | } | - | ||||||||||||
127 | - | |||||||||||||
128 | QTimeZonePrivate::QTimeZonePrivate(const QTimeZonePrivate &other) | - | ||||||||||||
129 | : QSharedData(other), m_id(other.m_id) | - | ||||||||||||
130 | { | - | ||||||||||||
131 | } executed 20 times by 1 test: end of block Executed by:
| 20 | ||||||||||||
132 | - | |||||||||||||
133 | QTimeZonePrivate::~QTimeZonePrivate() | - | ||||||||||||
134 | { | - | ||||||||||||
135 | } | - | ||||||||||||
136 | - | |||||||||||||
137 | QTimeZonePrivate *QTimeZonePrivate::clone() | - | ||||||||||||
138 | { | - | ||||||||||||
139 | return new QTimeZonePrivate(*this); never executed: return new QTimeZonePrivate(*this); | 0 | ||||||||||||
140 | } | - | ||||||||||||
141 | - | |||||||||||||
142 | bool QTimeZonePrivate::operator==(const QTimeZonePrivate &other) const | - | ||||||||||||
143 | { | - | ||||||||||||
144 | // TODO Too simple, but need to solve problem of comparing different derived classes | - | ||||||||||||
145 | // Should work for all System and ICU classes as names guaranteed unique, but not for Simple. | - | ||||||||||||
146 | // Perhaps once all classes have working transitions can compare full list? | - | ||||||||||||
147 | return (m_id == other.m_id); executed 21 times by 2 tests: return (m_id == other.m_id); Executed by:
| 21 | ||||||||||||
148 | } | - | ||||||||||||
149 | - | |||||||||||||
150 | bool QTimeZonePrivate::operator!=(const QTimeZonePrivate &other) const | - | ||||||||||||
151 | { | - | ||||||||||||
152 | return !(*this == other); executed 2 times by 1 test: return !(*this == other); Executed by:
| 2 | ||||||||||||
153 | } | - | ||||||||||||
154 | - | |||||||||||||
155 | bool QTimeZonePrivate::isValid() const | - | ||||||||||||
156 | { | - | ||||||||||||
157 | return !m_id.isEmpty(); executed 13384 times by 2 tests: return !m_id.isEmpty(); Executed by:
| 13384 | ||||||||||||
158 | } | - | ||||||||||||
159 | - | |||||||||||||
160 | QByteArray QTimeZonePrivate::id() const | - | ||||||||||||
161 | { | - | ||||||||||||
162 | return m_id; executed 469 times by 2 tests: return m_id; Executed by:
| 469 | ||||||||||||
163 | } | - | ||||||||||||
164 | - | |||||||||||||
165 | QLocale::Country QTimeZonePrivate::country() const | - | ||||||||||||
166 | { | - | ||||||||||||
167 | // Default fall-back mode, use the zoneTable to find Region of known Zones | - | ||||||||||||
168 | for (int i = 0; i < zoneDataTableSize; ++i) {
| 0 | ||||||||||||
169 | const QZoneData *data = zoneData(i); | - | ||||||||||||
170 | if (ianaId(data).split(' ').contains(m_id))
| 0 | ||||||||||||
171 | return (QLocale::Country)data->country; never executed: return (QLocale::Country)data->country; | 0 | ||||||||||||
172 | } never executed: end of block | 0 | ||||||||||||
173 | return QLocale::AnyCountry; never executed: return QLocale::AnyCountry; | 0 | ||||||||||||
174 | } | - | ||||||||||||
175 | - | |||||||||||||
176 | QString QTimeZonePrivate::comment() const | - | ||||||||||||
177 | { | - | ||||||||||||
178 | return QString(); never executed: return QString(); | 0 | ||||||||||||
179 | } | - | ||||||||||||
180 | - | |||||||||||||
181 | QString QTimeZonePrivate::displayName(qint64 atMSecsSinceEpoch, | - | ||||||||||||
182 | QTimeZone::NameType nameType, | - | ||||||||||||
183 | const QLocale &locale) const | - | ||||||||||||
184 | { | - | ||||||||||||
185 | if (nameType == QTimeZone::OffsetName)
| 0-450 | ||||||||||||
186 | return isoOffsetFormat(offsetFromUtc(atMSecsSinceEpoch)); never executed: return isoOffsetFormat(offsetFromUtc(atMSecsSinceEpoch)); | 0 | ||||||||||||
187 | - | |||||||||||||
188 | if (isDaylightTime(atMSecsSinceEpoch))
| 21-429 | ||||||||||||
189 | return displayName(QTimeZone::DaylightTime, nameType, locale); executed 21 times by 1 test: return displayName(QTimeZone::DaylightTime, nameType, locale); Executed by:
| 21 | ||||||||||||
190 | else | - | ||||||||||||
191 | return displayName(QTimeZone::StandardTime, nameType, locale); executed 429 times by 1 test: return displayName(QTimeZone::StandardTime, nameType, locale); Executed by:
| 429 | ||||||||||||
192 | } | - | ||||||||||||
193 | - | |||||||||||||
194 | QString QTimeZonePrivate::displayName(QTimeZone::TimeType timeType, | - | ||||||||||||
195 | QTimeZone::NameType nameType, | - | ||||||||||||
196 | const QLocale &locale) const | - | ||||||||||||
197 | { | - | ||||||||||||
198 | Q_UNUSED(timeType) | - | ||||||||||||
199 | Q_UNUSED(nameType) | - | ||||||||||||
200 | Q_UNUSED(locale) | - | ||||||||||||
201 | return QString(); never executed: return QString(); | 0 | ||||||||||||
202 | } | - | ||||||||||||
203 | - | |||||||||||||
204 | QString QTimeZonePrivate::abbreviation(qint64 atMSecsSinceEpoch) const | - | ||||||||||||
205 | { | - | ||||||||||||
206 | Q_UNUSED(atMSecsSinceEpoch) | - | ||||||||||||
207 | return QString(); never executed: return QString(); | 0 | ||||||||||||
208 | } | - | ||||||||||||
209 | - | |||||||||||||
210 | int QTimeZonePrivate::offsetFromUtc(qint64 atMSecsSinceEpoch) const | - | ||||||||||||
211 | { | - | ||||||||||||
212 | return standardTimeOffset(atMSecsSinceEpoch) + daylightTimeOffset(atMSecsSinceEpoch); executed 44 times by 1 test: return standardTimeOffset(atMSecsSinceEpoch) + daylightTimeOffset(atMSecsSinceEpoch); Executed by:
| 44 | ||||||||||||
213 | } | - | ||||||||||||
214 | - | |||||||||||||
215 | int QTimeZonePrivate::standardTimeOffset(qint64 atMSecsSinceEpoch) const | - | ||||||||||||
216 | { | - | ||||||||||||
217 | Q_UNUSED(atMSecsSinceEpoch) | - | ||||||||||||
218 | return invalidSeconds(); never executed: return invalidSeconds(); | 0 | ||||||||||||
219 | } | - | ||||||||||||
220 | - | |||||||||||||
221 | int QTimeZonePrivate::daylightTimeOffset(qint64 atMSecsSinceEpoch) const | - | ||||||||||||
222 | { | - | ||||||||||||
223 | Q_UNUSED(atMSecsSinceEpoch) | - | ||||||||||||
224 | return invalidSeconds(); never executed: return invalidSeconds(); | 0 | ||||||||||||
225 | } | - | ||||||||||||
226 | - | |||||||||||||
227 | bool QTimeZonePrivate::hasDaylightTime() const | - | ||||||||||||
228 | { | - | ||||||||||||
229 | return false; executed 202 times by 2 tests: return false; Executed by:
| 202 | ||||||||||||
230 | } | - | ||||||||||||
231 | - | |||||||||||||
232 | bool QTimeZonePrivate::isDaylightTime(qint64 atMSecsSinceEpoch) const | - | ||||||||||||
233 | { | - | ||||||||||||
234 | Q_UNUSED(atMSecsSinceEpoch) | - | ||||||||||||
235 | return false; executed 40 times by 2 tests: return false; Executed by:
| 40 | ||||||||||||
236 | } | - | ||||||||||||
237 | - | |||||||||||||
238 | QTimeZonePrivate::Data QTimeZonePrivate::data(qint64 forMSecsSinceEpoch) const | - | ||||||||||||
239 | { | - | ||||||||||||
240 | Q_UNUSED(forMSecsSinceEpoch) | - | ||||||||||||
241 | return invalidData(); never executed: return invalidData(); | 0 | ||||||||||||
242 | } | - | ||||||||||||
243 | - | |||||||||||||
244 | // Private only method for use by QDateTime to convert local msecs to epoch msecs | - | ||||||||||||
245 | // TODO Could be platform optimised if needed | - | ||||||||||||
246 | QTimeZonePrivate::Data QTimeZonePrivate::dataForLocalTime(qint64 forLocalMSecs) const | - | ||||||||||||
247 | { | - | ||||||||||||
248 | if (!hasDaylightTime() ||!hasTransitions()) {
| 0-646 | ||||||||||||
249 | // No DST means same offset for all local msecs | - | ||||||||||||
250 | // Having DST but no transitions means we can't calculate, so use nearest | - | ||||||||||||
251 | return data(forLocalMSecs - (standardTimeOffset(forLocalMSecs) * 1000)); executed 345 times by 2 tests: return data(forLocalMSecs - (standardTimeOffset(forLocalMSecs) * 1000)); Executed by:
| 345 | ||||||||||||
252 | } | - | ||||||||||||
253 | - | |||||||||||||
254 | // Get the transition for the local msecs which most of the time should be the right one | - | ||||||||||||
255 | // Only around the transition times might it not be the right one | - | ||||||||||||
256 | Data tran = previousTransition(forLocalMSecs); | - | ||||||||||||
257 | Data nextTran; | - | ||||||||||||
258 | - | |||||||||||||
259 | // If the local msecs is less than the real local time of the transition | - | ||||||||||||
260 | // then get the previous transition to use instead | - | ||||||||||||
261 | if (forLocalMSecs < tran.atMSecsSinceEpoch + (tran.offsetFromUtc * 1000)) {
| 5-641 | ||||||||||||
262 | while (tran.atMSecsSinceEpoch != invalidMSecs()
| 0-10 | ||||||||||||
263 | && forLocalMSecs < tran.atMSecsSinceEpoch + (tran.offsetFromUtc * 1000)) {
| 5 | ||||||||||||
264 | nextTran = tran; | - | ||||||||||||
265 | tran = previousTransition(tran.atMSecsSinceEpoch); | - | ||||||||||||
266 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||
267 | } else { executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||
268 | // The zone msecs is after the transition, so check it is before the next tran | - | ||||||||||||
269 | // If not try use the next transition instead | - | ||||||||||||
270 | nextTran = nextTransition(tran.atMSecsSinceEpoch); | - | ||||||||||||
271 | while (nextTran.atMSecsSinceEpoch != invalidMSecs()
| 249-6111 | ||||||||||||
272 | && forLocalMSecs >= nextTran.atMSecsSinceEpoch + (nextTran.offsetFromUtc * 1000)) {
| 392-5719 | ||||||||||||
273 | tran = nextTran; | - | ||||||||||||
274 | nextTran = nextTransition(tran.atMSecsSinceEpoch); | - | ||||||||||||
275 | } executed 5719 times by 2 tests: end of block Executed by:
| 5719 | ||||||||||||
276 | } executed 641 times by 2 tests: end of block Executed by:
| 641 | ||||||||||||
277 | - | |||||||||||||
278 | if (tran.daylightTimeOffset == 0) {
| 59-587 | ||||||||||||
279 | // If tran is in StandardTime, then need to check if falls close to either DST transition. | - | ||||||||||||
280 | // If it does, then it may need adjusting for missing hour or for second occurrence | - | ||||||||||||
281 | qint64 diffPrevTran = forLocalMSecs | - | ||||||||||||
282 | - (tran.atMSecsSinceEpoch + (tran.offsetFromUtc * 1000)); | - | ||||||||||||
283 | qint64 diffNextTran = nextTran.atMSecsSinceEpoch + (nextTran.offsetFromUtc * 1000) | - | ||||||||||||
284 | - forLocalMSecs; | - | ||||||||||||
285 | if (diffPrevTran >= 0 && diffPrevTran < MSECS_TRAN_WINDOW) {
| 0-587 | ||||||||||||
286 | // If tran picked is for standard time check if changed from DST in last 6 hours, | - | ||||||||||||
287 | // as the local msecs may be ambiguous and represent two valid utc msecs. | - | ||||||||||||
288 | // If in last 6 hours then get prev tran and if diff falls within the DST offset | - | ||||||||||||
289 | // then use the prev tran as we default to the FirstOccurrence | - | ||||||||||||
290 | // TODO Check if faster to just always get prev tran, or if faster using 6 hour check. | - | ||||||||||||
291 | Data dstTran = previousTransition(tran.atMSecsSinceEpoch); | - | ||||||||||||
292 | if (dstTran.atMSecsSinceEpoch != invalidMSecs()
| 0-15 | ||||||||||||
293 | && dstTran.daylightTimeOffset > 0 && diffPrevTran < (dstTran.daylightTimeOffset * 1000))
| 0-15 | ||||||||||||
294 | tran = dstTran; executed 12 times by 1 test: tran = dstTran; Executed by:
| 12 | ||||||||||||
295 | } else if (diffNextTran >= 0 && diffNextTran <= (nextTran.daylightTimeOffset * 1000)) { executed 15 times by 1 test: end of block Executed by:
| 0-572 | ||||||||||||
296 | // If time falls within last hour of standard time then is actually the missing hour | - | ||||||||||||
297 | // So return the next tran instead and adjust the local time to be valid | - | ||||||||||||
298 | tran = nextTran; | - | ||||||||||||
299 | forLocalMSecs = forLocalMSecs + (nextTran.daylightTimeOffset * 1000); | - | ||||||||||||
300 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
301 | } executed 587 times by 2 tests: end of block Executed by:
| 587 | ||||||||||||
302 | - | |||||||||||||
303 | // tran should now hold the right transition offset to use | - | ||||||||||||
304 | tran.atMSecsSinceEpoch = forLocalMSecs - (tran.offsetFromUtc * 1000); | - | ||||||||||||
305 | return tran; executed 646 times by 2 tests: return tran; Executed by:
| 646 | ||||||||||||
306 | } | - | ||||||||||||
307 | - | |||||||||||||
308 | bool QTimeZonePrivate::hasTransitions() const | - | ||||||||||||
309 | { | - | ||||||||||||
310 | return false; executed 469 times by 1 test: return false; Executed by:
| 469 | ||||||||||||
311 | } | - | ||||||||||||
312 | - | |||||||||||||
313 | QTimeZonePrivate::Data QTimeZonePrivate::nextTransition(qint64 afterMSecsSinceEpoch) const | - | ||||||||||||
314 | { | - | ||||||||||||
315 | Q_UNUSED(afterMSecsSinceEpoch) | - | ||||||||||||
316 | return invalidData(); never executed: return invalidData(); | 0 | ||||||||||||
317 | } | - | ||||||||||||
318 | - | |||||||||||||
319 | QTimeZonePrivate::Data QTimeZonePrivate::previousTransition(qint64 beforeMSecsSinceEpoch) const | - | ||||||||||||
320 | { | - | ||||||||||||
321 | Q_UNUSED(beforeMSecsSinceEpoch) | - | ||||||||||||
322 | return invalidData(); never executed: return invalidData(); | 0 | ||||||||||||
323 | } | - | ||||||||||||
324 | - | |||||||||||||
325 | QTimeZonePrivate::DataList QTimeZonePrivate::transitions(qint64 fromMSecsSinceEpoch, | - | ||||||||||||
326 | qint64 toMSecsSinceEpoch) const | - | ||||||||||||
327 | { | - | ||||||||||||
328 | DataList list; | - | ||||||||||||
329 | if (toMSecsSinceEpoch >= fromMSecsSinceEpoch) {
| 0-2 | ||||||||||||
330 | // fromMSecsSinceEpoch is inclusive but nextTransitionTime() is exclusive so go back 1 msec | - | ||||||||||||
331 | Data next = nextTransition(fromMSecsSinceEpoch - 1); | - | ||||||||||||
332 | while (next.atMSecsSinceEpoch != invalidMSecs()
| 0-6 | ||||||||||||
333 | && next.atMSecsSinceEpoch <= toMSecsSinceEpoch) {
| 2-4 | ||||||||||||
334 | list.append(next); | - | ||||||||||||
335 | next = nextTransition(next.atMSecsSinceEpoch); | - | ||||||||||||
336 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
337 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
338 | return list; executed 2 times by 1 test: return list; Executed by:
| 2 | ||||||||||||
339 | } | - | ||||||||||||
340 | - | |||||||||||||
341 | QByteArray QTimeZonePrivate::systemTimeZoneId() const | - | ||||||||||||
342 | { | - | ||||||||||||
343 | return QByteArray(); never executed: return QByteArray(); | 0 | ||||||||||||
344 | } | - | ||||||||||||
345 | - | |||||||||||||
346 | QList<QByteArray> QTimeZonePrivate::availableTimeZoneIds() const | - | ||||||||||||
347 | { | - | ||||||||||||
348 | return QList<QByteArray>(); never executed: return QList<QByteArray>(); | 0 | ||||||||||||
349 | } | - | ||||||||||||
350 | - | |||||||||||||
351 | QList<QByteArray> QTimeZonePrivate::availableTimeZoneIds(QLocale::Country country) const | - | ||||||||||||
352 | { | - | ||||||||||||
353 | // Default fall-back mode, use the zoneTable to find Region of know Zones | - | ||||||||||||
354 | QList<QByteArray> regions; | - | ||||||||||||
355 | - | |||||||||||||
356 | // First get all Zones in the Zones table belonging to the Region | - | ||||||||||||
357 | for (int i = 0; i < zoneDataTableSize; ++i) {
| 0 | ||||||||||||
358 | if (zoneData(i)->country == country)
| 0 | ||||||||||||
359 | regions += ianaId(zoneData(i)).split(' '); never executed: regions += ianaId(zoneData(i)).split(' '); | 0 | ||||||||||||
360 | } never executed: end of block | 0 | ||||||||||||
361 | - | |||||||||||||
362 | std::sort(regions.begin(), regions.end()); | - | ||||||||||||
363 | regions.erase(std::unique(regions.begin(), regions.end()), regions.end()); | - | ||||||||||||
364 | - | |||||||||||||
365 | // Then select just those that are available | - | ||||||||||||
366 | const QList<QByteArray> all = availableTimeZoneIds(); | - | ||||||||||||
367 | QList<QByteArray> result; | - | ||||||||||||
368 | result.reserve(qMin(all.size(), regions.size())); | - | ||||||||||||
369 | std::set_intersection(all.begin(), all.end(), regions.cbegin(), regions.cend(), | - | ||||||||||||
370 | std::back_inserter(result)); | - | ||||||||||||
371 | return result; never executed: return result; | 0 | ||||||||||||
372 | } | - | ||||||||||||
373 | - | |||||||||||||
374 | QList<QByteArray> QTimeZonePrivate::availableTimeZoneIds(int offsetFromUtc) const | - | ||||||||||||
375 | { | - | ||||||||||||
376 | // Default fall-back mode, use the zoneTable to find Offset of know Zones | - | ||||||||||||
377 | QList<QByteArray> offsets; | - | ||||||||||||
378 | // First get all Zones in the table using the Offset | - | ||||||||||||
379 | for (int i = 0; i < windowsDataTableSize; ++i) {
| 1-105 | ||||||||||||
380 | const QWindowsData *winData = windowsData(i); | - | ||||||||||||
381 | if (winData->offsetFromUtc == offsetFromUtc) {
| 4-101 | ||||||||||||
382 | for (int j = 0; j < zoneDataTableSize; ++j) {
| 4-1376 | ||||||||||||
383 | const QZoneData *data = zoneData(j); | - | ||||||||||||
384 | if (data->windowsIdKey == winData->windowsIdKey)
| 27-1349 | ||||||||||||
385 | offsets += ianaId(data).split(' '); executed 27 times by 1 test: offsets += ianaId(data).split(' '); Executed by:
| 27 | ||||||||||||
386 | } executed 1376 times by 1 test: end of block Executed by:
| 1376 | ||||||||||||
387 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
388 | } executed 105 times by 1 test: end of block Executed by:
| 105 | ||||||||||||
389 | - | |||||||||||||
390 | std::sort(offsets.begin(), offsets.end()); | - | ||||||||||||
391 | offsets.erase(std::unique(offsets.begin(), offsets.end()), offsets.end()); | - | ||||||||||||
392 | - | |||||||||||||
393 | // Then select just those that are available | - | ||||||||||||
394 | const QList<QByteArray> all = availableTimeZoneIds(); | - | ||||||||||||
395 | QList<QByteArray> result; | - | ||||||||||||
396 | result.reserve(qMin(all.size(), offsets.size())); | - | ||||||||||||
397 | std::set_intersection(all.begin(), all.end(), offsets.cbegin(), offsets.cend(), | - | ||||||||||||
398 | std::back_inserter(result)); | - | ||||||||||||
399 | return result; executed 1 time by 1 test: return result; Executed by:
| 1 | ||||||||||||
400 | } | - | ||||||||||||
401 | - | |||||||||||||
402 | #ifndef QT_NO_DATASTREAM | - | ||||||||||||
403 | void QTimeZonePrivate::serialize(QDataStream &ds) const | - | ||||||||||||
404 | { | - | ||||||||||||
405 | ds << QString::fromUtf8(m_id); | - | ||||||||||||
406 | } executed 2 times by 2 tests: end of block Executed by:
| 2 | ||||||||||||
407 | #endif // QT_NO_DATASTREAM | - | ||||||||||||
408 | - | |||||||||||||
409 | // Static Utility Methods | - | ||||||||||||
410 | - | |||||||||||||
411 | QTimeZonePrivate::Data QTimeZonePrivate::invalidData() | - | ||||||||||||
412 | { | - | ||||||||||||
413 | Data data; | - | ||||||||||||
414 | data.atMSecsSinceEpoch = invalidMSecs(); | - | ||||||||||||
415 | data.offsetFromUtc = invalidSeconds(); | - | ||||||||||||
416 | data.standardTimeOffset = invalidSeconds(); | - | ||||||||||||
417 | data.daylightTimeOffset = invalidSeconds(); | - | ||||||||||||
418 | return data; executed 1890 times by 2 tests: return data; Executed by:
| 1890 | ||||||||||||
419 | } | - | ||||||||||||
420 | - | |||||||||||||
421 | QTimeZone::OffsetData QTimeZonePrivate::invalidOffsetData() | - | ||||||||||||
422 | { | - | ||||||||||||
423 | QTimeZone::OffsetData offsetData; | - | ||||||||||||
424 | offsetData.atUtc = QDateTime(); | - | ||||||||||||
425 | offsetData.offsetFromUtc = invalidSeconds(); | - | ||||||||||||
426 | offsetData.standardTimeOffset = invalidSeconds(); | - | ||||||||||||
427 | offsetData.daylightTimeOffset = invalidSeconds(); | - | ||||||||||||
428 | return offsetData; executed 5069 times by 1 test: return offsetData; Executed by:
| 5069 | ||||||||||||
429 | } | - | ||||||||||||
430 | - | |||||||||||||
431 | QTimeZone::OffsetData QTimeZonePrivate::toOffsetData(const QTimeZonePrivate::Data &data) | - | ||||||||||||
432 | { | - | ||||||||||||
433 | QTimeZone::OffsetData offsetData = invalidOffsetData(); | - | ||||||||||||
434 | if (data.atMSecsSinceEpoch != invalidMSecs()) {
| 1626-3011 | ||||||||||||
435 | offsetData.atUtc = QDateTime::fromMSecsSinceEpoch(data.atMSecsSinceEpoch, Qt::UTC); | - | ||||||||||||
436 | offsetData.offsetFromUtc = data.offsetFromUtc; | - | ||||||||||||
437 | offsetData.standardTimeOffset = data.standardTimeOffset; | - | ||||||||||||
438 | offsetData.daylightTimeOffset = data.daylightTimeOffset; | - | ||||||||||||
439 | offsetData.abbreviation = data.abbreviation; | - | ||||||||||||
440 | } executed 3011 times by 1 test: end of block Executed by:
| 3011 | ||||||||||||
441 | return offsetData; executed 4637 times by 1 test: return offsetData; Executed by:
| 4637 | ||||||||||||
442 | } | - | ||||||||||||
443 | - | |||||||||||||
444 | // Is the format of the ID valid ? | - | ||||||||||||
445 | bool QTimeZonePrivate::isValidId(const QByteArray &ianaId) | - | ||||||||||||
446 | { | - | ||||||||||||
447 | /* | - | ||||||||||||
448 | Main rules for defining TZ/IANA names as per ftp://ftp.iana.org/tz/code/Theory | - | ||||||||||||
449 | 1. Use only valid POSIX file name components | - | ||||||||||||
450 | 2. Within a file name component, use only ASCII letters, `.', `-' and `_'. | - | ||||||||||||
451 | 3. Do not use digits (except in a [+-]\d+ suffix, when used). | - | ||||||||||||
452 | 4. A file name component must not exceed 14 characters or start with `-' | - | ||||||||||||
453 | However, the rules are really guidelines - a later one says | - | ||||||||||||
454 | - Do not change established names if they only marginally violate the | - | ||||||||||||
455 | above rules. | - | ||||||||||||
456 | We may, therefore, need to be a bit slack in our check here, if we hit | - | ||||||||||||
457 | legitimate exceptions in real time-zone databases. | - | ||||||||||||
458 | - | |||||||||||||
459 | In particular, aliases such as "Etc/GMT+7" and "SystemV/EST5EDT" are valid | - | ||||||||||||
460 | so we need to accept digits, ':', and '+'; aliases typically have the form | - | ||||||||||||
461 | of POSIX TZ strings, which allow a suffix to a proper IANA name. A POSIX | - | ||||||||||||
462 | suffix starts with an offset (as in GMT+7) and may continue with another | - | ||||||||||||
463 | name (as in EST5EDT, giving the DST name of the zone); a further offset is | - | ||||||||||||
464 | allowed (for DST). The ("hard to describe and [...] error-prone in | - | ||||||||||||
465 | practice") POSIX form even allows a suffix giving the dates (and | - | ||||||||||||
466 | optionally times) of the annual DST transitions. Hopefully, no TZ aliases | - | ||||||||||||
467 | go that far, but we at least need to accept an offset and (single | - | ||||||||||||
468 | fragment) DST-name. | - | ||||||||||||
469 | - | |||||||||||||
470 | But for the legacy complications, the following would be preferable if | - | ||||||||||||
471 | QRegExp would work on QByteArrays directly: | - | ||||||||||||
472 | const QRegExp rx(QStringLiteral("[a-z+._][a-z+._-]{,13}" | - | ||||||||||||
473 | "(?:/[a-z+._][a-z+._-]{,13})*" | - | ||||||||||||
474 | // Optional suffix: | - | ||||||||||||
475 | "(?:[+-]?\d{1,2}(?::\d{1,2}){,2}" // offset | - | ||||||||||||
476 | // one name fragment (DST): | - | ||||||||||||
477 | "(?:[a-z+._][a-z+._-]{,13})?)"), | - | ||||||||||||
478 | Qt::CaseInsensitive); | - | ||||||||||||
479 | return rx.exactMatch(ianaId); | - | ||||||||||||
480 | */ | - | ||||||||||||
481 | - | |||||||||||||
482 | // Somewhat slack hand-rolled version: | - | ||||||||||||
483 | const int MinSectionLength = 1; | - | ||||||||||||
484 | const int MaxSectionLength = 14; | - | ||||||||||||
485 | int sectionLength = 0; | - | ||||||||||||
486 | for (const char *it = ianaId.begin(), * const end = ianaId.end(); it != end; ++it, ++sectionLength) {
| 517-7700 | ||||||||||||
487 | const char ch = *it; | - | ||||||||||||
488 | if (ch == '/') {
| 578-7122 | ||||||||||||
489 | if (sectionLength < MinSectionLength || sectionLength > MaxSectionLength)
| 3-575 | ||||||||||||
490 | return false; // violates (4) executed 6 times by 1 test: return false; Executed by:
| 6 | ||||||||||||
491 | sectionLength = -1; | - | ||||||||||||
492 | } else if (ch == '-') { executed 572 times by 1 test: end of block Executed by:
| 30-7092 | ||||||||||||
493 | if (sectionLength == 0)
| 4-26 | ||||||||||||
494 | return false; // violates (4) executed 4 times by 1 test: return false; Executed by:
| 4 | ||||||||||||
495 | } else if (!(ch >= 'a' && ch <= 'z') executed 26 times by 1 test: end of block Executed by:
| 0-5499 | ||||||||||||
496 | && !(ch >= 'A' && ch <= 'Z')
| 72-1140 | ||||||||||||
497 | && !(ch == '_')
| 68-457 | ||||||||||||
498 | && !(ch == '.')
| 5-452 | ||||||||||||
499 | // Should ideally check these only happen as an offset: | - | ||||||||||||
500 | && !(ch >= '0' && ch <= '9')
| 51-399 | ||||||||||||
501 | && !(ch == '+')
| 24-80 | ||||||||||||
502 | && !(ch == ':')) {
| 39-41 | ||||||||||||
503 | return false; // violates (2) executed 39 times by 1 test: return false; Executed by:
| 39 | ||||||||||||
504 | } | - | ||||||||||||
505 | } executed 7651 times by 1 test: end of block Executed by:
| 7651 | ||||||||||||
506 | if (sectionLength < MinSectionLength || sectionLength > MaxSectionLength)
| 1-516 | ||||||||||||
507 | return false; // violates (4) executed 4 times by 1 test: return false; Executed by:
| 4 | ||||||||||||
508 | return true; executed 513 times by 1 test: return true; Executed by:
| 513 | ||||||||||||
509 | } | - | ||||||||||||
510 | - | |||||||||||||
511 | QString QTimeZonePrivate::isoOffsetFormat(int offsetFromUtc) | - | ||||||||||||
512 | { | - | ||||||||||||
513 | const int mins = offsetFromUtc / 60; | - | ||||||||||||
514 | return QString::fromUtf8("UTC%1%2:%3").arg(mins >= 0 ? QLatin1Char('+') : QLatin1Char('-')) executed 7 times by 2 tests: return QString::fromUtf8("UTC%1%2:%3").arg(mins >= 0 ? QLatin1Char('+') : QLatin1Char('-')) .arg(qAbs(mins) / 60, 2, 10, QLatin1Char('0')) .arg(qAbs(mins) % 60, 2, 10, QLatin1Char('0')); Executed by:
| 7 | ||||||||||||
515 | .arg(qAbs(mins) / 60, 2, 10, QLatin1Char('0')) executed 7 times by 2 tests: return QString::fromUtf8("UTC%1%2:%3").arg(mins >= 0 ? QLatin1Char('+') : QLatin1Char('-')) .arg(qAbs(mins) / 60, 2, 10, QLatin1Char('0')) .arg(qAbs(mins) % 60, 2, 10, QLatin1Char('0')); Executed by:
| 7 | ||||||||||||
516 | .arg(qAbs(mins) % 60, 2, 10, QLatin1Char('0')); executed 7 times by 2 tests: return QString::fromUtf8("UTC%1%2:%3").arg(mins >= 0 ? QLatin1Char('+') : QLatin1Char('-')) .arg(qAbs(mins) / 60, 2, 10, QLatin1Char('0')) .arg(qAbs(mins) % 60, 2, 10, QLatin1Char('0')); Executed by:
| 7 | ||||||||||||
517 | } | - | ||||||||||||
518 | - | |||||||||||||
519 | QByteArray QTimeZonePrivate::ianaIdToWindowsId(const QByteArray &id) | - | ||||||||||||
520 | { | - | ||||||||||||
521 | for (int i = 0; i < zoneDataTableSize; ++i) {
| 3-1655 | ||||||||||||
522 | const QZoneData *data = zoneData(i); | - | ||||||||||||
523 | if (ianaId(data).split(' ').contains(id))
| 2-1653 | ||||||||||||
524 | return toWindowsIdLiteral(data->windowsIdKey); executed 2 times by 1 test: return toWindowsIdLiteral(data->windowsIdKey); Executed by:
| 2 | ||||||||||||
525 | } executed 1653 times by 1 test: end of block Executed by:
| 1653 | ||||||||||||
526 | return QByteArray(); executed 3 times by 1 test: return QByteArray(); Executed by:
| 3 | ||||||||||||
527 | } | - | ||||||||||||
528 | - | |||||||||||||
529 | QByteArray QTimeZonePrivate::windowsIdToDefaultIanaId(const QByteArray &windowsId) | - | ||||||||||||
530 | { | - | ||||||||||||
531 | const quint16 windowsIdKey = toWindowsIdKey(windowsId); | - | ||||||||||||
532 | for (int i = 0; i < windowsDataTableSize; ++i) {
| 1-131 | ||||||||||||
533 | const QWindowsData *data = windowsData(i); | - | ||||||||||||
534 | if (data->windowsIdKey == windowsIdKey)
| 1-130 | ||||||||||||
535 | return ianaId(data); executed 1 time by 1 test: return ianaId(data); Executed by:
| 1 | ||||||||||||
536 | } executed 130 times by 1 test: end of block Executed by:
| 130 | ||||||||||||
537 | return QByteArray(); executed 1 time by 1 test: return QByteArray(); Executed by:
| 1 | ||||||||||||
538 | } | - | ||||||||||||
539 | - | |||||||||||||
540 | QByteArray QTimeZonePrivate::windowsIdToDefaultIanaId(const QByteArray &windowsId, | - | ||||||||||||
541 | QLocale::Country country) | - | ||||||||||||
542 | { | - | ||||||||||||
543 | const QList<QByteArray> list = windowsIdToIanaIds(windowsId, country); | - | ||||||||||||
544 | if (list.count() > 0)
| 0-2 | ||||||||||||
545 | return list.first(); executed 2 times by 1 test: return list.first(); Executed by:
| 2 | ||||||||||||
546 | else | - | ||||||||||||
547 | return QByteArray(); never executed: return QByteArray(); | 0 | ||||||||||||
548 | } | - | ||||||||||||
549 | - | |||||||||||||
550 | QList<QByteArray> QTimeZonePrivate::windowsIdToIanaIds(const QByteArray &windowsId) | - | ||||||||||||
551 | { | - | ||||||||||||
552 | const quint16 windowsIdKey = toWindowsIdKey(windowsId); | - | ||||||||||||
553 | QList<QByteArray> list; | - | ||||||||||||
554 | - | |||||||||||||
555 | for (int i = 0; i < zoneDataTableSize; ++i) {
| 2-688 | ||||||||||||
556 | const QZoneData *data = zoneData(i); | - | ||||||||||||
557 | if (data->windowsIdKey == windowsIdKey)
| 4-684 | ||||||||||||
558 | list << ianaId(data).split(' '); executed 4 times by 1 test: list << ianaId(data).split(' '); Executed by:
| 4 | ||||||||||||
559 | } executed 688 times by 1 test: end of block Executed by:
| 688 | ||||||||||||
560 | - | |||||||||||||
561 | // Return the full list in alpha order | - | ||||||||||||
562 | std::sort(list.begin(), list.end()); | - | ||||||||||||
563 | return list; executed 2 times by 1 test: return list; Executed by:
| 2 | ||||||||||||
564 | } | - | ||||||||||||
565 | - | |||||||||||||
566 | QList<QByteArray> QTimeZonePrivate::windowsIdToIanaIds(const QByteArray &windowsId, | - | ||||||||||||
567 | QLocale::Country country) | - | ||||||||||||
568 | { | - | ||||||||||||
569 | const quint16 windowsIdKey = toWindowsIdKey(windowsId); | - | ||||||||||||
570 | for (int i = 0; i < zoneDataTableSize; ++i) {
| 2-2467 | ||||||||||||
571 | const QZoneData *data = zoneData(i); | - | ||||||||||||
572 | // Return the region matches in preference order | - | ||||||||||||
573 | if (data->windowsIdKey == windowsIdKey && data->country == (quint16) country)
| 6-2450 | ||||||||||||
574 | return ianaId(data).split(' '); executed 6 times by 1 test: return ianaId(data).split(' '); Executed by:
| 6 | ||||||||||||
575 | } executed 2461 times by 1 test: end of block Executed by:
| 2461 | ||||||||||||
576 | - | |||||||||||||
577 | return QList<QByteArray>(); executed 2 times by 1 test: return QList<QByteArray>(); Executed by:
| 2 | ||||||||||||
578 | } | - | ||||||||||||
579 | - | |||||||||||||
580 | // Define template for derived classes to reimplement so QSharedDataPointer clone() works correctly | - | ||||||||||||
581 | template<> QTimeZonePrivate *QSharedDataPointer<QTimeZonePrivate>::clone() | - | ||||||||||||
582 | { | - | ||||||||||||
583 | return d->clone(); executed 20 times by 1 test: return d->clone(); Executed by:
| 20 | ||||||||||||
584 | } | - | ||||||||||||
585 | - | |||||||||||||
586 | /* | - | ||||||||||||
587 | UTC Offset implementation, used when QT_NO_SYSTEMLOCALE set and QT_USE_ICU not set, | - | ||||||||||||
588 | or for QDateTimes with a Qt:Spec of Qt::OffsetFromUtc. | - | ||||||||||||
589 | */ | - | ||||||||||||
590 | - | |||||||||||||
591 | // Create default UTC time zone | - | ||||||||||||
592 | QUtcTimeZonePrivate::QUtcTimeZonePrivate() | - | ||||||||||||
593 | { | - | ||||||||||||
594 | const QString name = utcQString(); | - | ||||||||||||
595 | init(utcQByteArray(), 0, name, name, QLocale::AnyCountry, name); | - | ||||||||||||
596 | } executed 469 times by 1 test: end of block Executed by:
| 469 | ||||||||||||
597 | - | |||||||||||||
598 | // Create a named UTC time zone | - | ||||||||||||
599 | QUtcTimeZonePrivate::QUtcTimeZonePrivate(const QByteArray &id) | - | ||||||||||||
600 | { | - | ||||||||||||
601 | // Look for the name in the UTC list, if found set the values | - | ||||||||||||
602 | for (int i = 0; i < utcDataTableSize; ++i) {
| 450-18407 | ||||||||||||
603 | const QUtcData *data = utcData(i); | - | ||||||||||||
604 | const QByteArray uid = utcId(data); | - | ||||||||||||
605 | if (uid == id) {
| 45-18362 | ||||||||||||
606 | QString name = QString::fromUtf8(id); | - | ||||||||||||
607 | init(id, data->offsetFromUtc, name, name, QLocale::AnyCountry, name); | - | ||||||||||||
608 | break; executed 45 times by 1 test: break; Executed by:
| 45 | ||||||||||||
609 | } | - | ||||||||||||
610 | } executed 18362 times by 2 tests: end of block Executed by:
| 18362 | ||||||||||||
611 | } executed 495 times by 2 tests: end of block Executed by:
| 495 | ||||||||||||
612 | - | |||||||||||||
613 | // Create offset from UTC | - | ||||||||||||
614 | QUtcTimeZonePrivate::QUtcTimeZonePrivate(qint32 offsetSeconds) | - | ||||||||||||
615 | { | - | ||||||||||||
616 | QString utcId; | - | ||||||||||||
617 | - | |||||||||||||
618 | if (offsetSeconds == 0)
| 0-7 | ||||||||||||
619 | utcId = utcQString(); never executed: utcId = utcQString(); | 0 | ||||||||||||
620 | else | - | ||||||||||||
621 | utcId = isoOffsetFormat(offsetSeconds); executed 7 times by 2 tests: utcId = isoOffsetFormat(offsetSeconds); Executed by:
| 7 | ||||||||||||
622 | - | |||||||||||||
623 | init(utcId.toUtf8(), offsetSeconds, utcId, utcId, QLocale::AnyCountry, utcId); | - | ||||||||||||
624 | } executed 7 times by 2 tests: end of block Executed by:
| 7 | ||||||||||||
625 | - | |||||||||||||
626 | QUtcTimeZonePrivate::QUtcTimeZonePrivate(const QByteArray &zoneId, int offsetSeconds, | - | ||||||||||||
627 | const QString &name, const QString &abbreviation, | - | ||||||||||||
628 | QLocale::Country country, const QString &comment) | - | ||||||||||||
629 | { | - | ||||||||||||
630 | init(zoneId, offsetSeconds, name, abbreviation, country, comment); | - | ||||||||||||
631 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||
632 | - | |||||||||||||
633 | QUtcTimeZonePrivate::QUtcTimeZonePrivate(const QUtcTimeZonePrivate &other) | - | ||||||||||||
634 | : QTimeZonePrivate(other), m_name(other.m_name), | - | ||||||||||||
635 | m_abbreviation(other.m_abbreviation), | - | ||||||||||||
636 | m_comment(other.m_comment), | - | ||||||||||||
637 | m_country(other.m_country), | - | ||||||||||||
638 | m_offsetFromUtc(other.m_offsetFromUtc) | - | ||||||||||||
639 | { | - | ||||||||||||
640 | } never executed: end of block | 0 | ||||||||||||
641 | - | |||||||||||||
642 | QUtcTimeZonePrivate::~QUtcTimeZonePrivate() | - | ||||||||||||
643 | { | - | ||||||||||||
644 | } | - | ||||||||||||
645 | - | |||||||||||||
646 | QTimeZonePrivate *QUtcTimeZonePrivate::clone() | - | ||||||||||||
647 | { | - | ||||||||||||
648 | return new QUtcTimeZonePrivate(*this); never executed: return new QUtcTimeZonePrivate(*this); | 0 | ||||||||||||
649 | } | - | ||||||||||||
650 | - | |||||||||||||
651 | QTimeZonePrivate::Data QUtcTimeZonePrivate::data(qint64 forMSecsSinceEpoch) const | - | ||||||||||||
652 | { | - | ||||||||||||
653 | Data d; | - | ||||||||||||
654 | d.abbreviation = m_abbreviation; | - | ||||||||||||
655 | d.atMSecsSinceEpoch = forMSecsSinceEpoch; | - | ||||||||||||
656 | d.standardTimeOffset = d.offsetFromUtc = m_offsetFromUtc; | - | ||||||||||||
657 | d.daylightTimeOffset = 0; | - | ||||||||||||
658 | return d; executed 83 times by 2 tests: return d; Executed by:
| 83 | ||||||||||||
659 | } | - | ||||||||||||
660 | - | |||||||||||||
661 | void QUtcTimeZonePrivate::init(const QByteArray &zoneId) | - | ||||||||||||
662 | { | - | ||||||||||||
663 | m_id = zoneId; | - | ||||||||||||
664 | } never executed: end of block | 0 | ||||||||||||
665 | - | |||||||||||||
666 | void QUtcTimeZonePrivate::init(const QByteArray &zoneId, int offsetSeconds, const QString &name, | - | ||||||||||||
667 | const QString &abbreviation, QLocale::Country country, | - | ||||||||||||
668 | const QString &comment) | - | ||||||||||||
669 | { | - | ||||||||||||
670 | m_id = zoneId; | - | ||||||||||||
671 | m_offsetFromUtc = offsetSeconds; | - | ||||||||||||
672 | m_name = name; | - | ||||||||||||
673 | m_abbreviation = abbreviation; | - | ||||||||||||
674 | m_country = country; | - | ||||||||||||
675 | m_comment = comment; | - | ||||||||||||
676 | } executed 524 times by 2 tests: end of block Executed by:
| 524 | ||||||||||||
677 | - | |||||||||||||
678 | QLocale::Country QUtcTimeZonePrivate::country() const | - | ||||||||||||
679 | { | - | ||||||||||||
680 | return m_country; executed 42 times by 1 test: return m_country; Executed by:
| 42 | ||||||||||||
681 | } | - | ||||||||||||
682 | - | |||||||||||||
683 | QString QUtcTimeZonePrivate::comment() const | - | ||||||||||||
684 | { | - | ||||||||||||
685 | return m_comment; executed 41 times by 1 test: return m_comment; Executed by:
| 41 | ||||||||||||
686 | } | - | ||||||||||||
687 | - | |||||||||||||
688 | QString QUtcTimeZonePrivate::displayName(QTimeZone::TimeType timeType, | - | ||||||||||||
689 | QTimeZone::NameType nameType, | - | ||||||||||||
690 | const QLocale &locale) const | - | ||||||||||||
691 | { | - | ||||||||||||
692 | Q_UNUSED(timeType) | - | ||||||||||||
693 | Q_UNUSED(locale) | - | ||||||||||||
694 | if (nameType == QTimeZone::ShortName)
| 0-121 | ||||||||||||
695 | return m_abbreviation; never executed: return m_abbreviation; | 0 | ||||||||||||
696 | else if (nameType == QTimeZone::OffsetName)
| 0-121 | ||||||||||||
697 | return isoOffsetFormat(m_offsetFromUtc); never executed: return isoOffsetFormat(m_offsetFromUtc); | 0 | ||||||||||||
698 | return m_name; executed 121 times by 1 test: return m_name; Executed by:
| 121 | ||||||||||||
699 | } | - | ||||||||||||
700 | - | |||||||||||||
701 | QString QUtcTimeZonePrivate::abbreviation(qint64 atMSecsSinceEpoch) const | - | ||||||||||||
702 | { | - | ||||||||||||
703 | Q_UNUSED(atMSecsSinceEpoch) | - | ||||||||||||
704 | return m_abbreviation; executed 81 times by 1 test: return m_abbreviation; Executed by:
| 81 | ||||||||||||
705 | } | - | ||||||||||||
706 | - | |||||||||||||
707 | qint32 QUtcTimeZonePrivate::standardTimeOffset(qint64 atMSecsSinceEpoch) const | - | ||||||||||||
708 | { | - | ||||||||||||
709 | Q_UNUSED(atMSecsSinceEpoch) | - | ||||||||||||
710 | return m_offsetFromUtc; executed 168 times by 2 tests: return m_offsetFromUtc; Executed by:
| 168 | ||||||||||||
711 | } | - | ||||||||||||
712 | - | |||||||||||||
713 | qint32 QUtcTimeZonePrivate::daylightTimeOffset(qint64 atMSecsSinceEpoch) const | - | ||||||||||||
714 | { | - | ||||||||||||
715 | Q_UNUSED(atMSecsSinceEpoch) | - | ||||||||||||
716 | return 0; executed 45 times by 1 test: return 0; Executed by:
| 45 | ||||||||||||
717 | } | - | ||||||||||||
718 | - | |||||||||||||
719 | QByteArray QUtcTimeZonePrivate::systemTimeZoneId() const | - | ||||||||||||
720 | { | - | ||||||||||||
721 | return utcQByteArray(); never executed: return utcQByteArray(); | 0 | ||||||||||||
722 | } | - | ||||||||||||
723 | - | |||||||||||||
724 | QList<QByteArray> QUtcTimeZonePrivate::availableTimeZoneIds() const | - | ||||||||||||
725 | { | - | ||||||||||||
726 | QList<QByteArray> result; | - | ||||||||||||
727 | result.reserve(utcDataTableSize); | - | ||||||||||||
728 | for (int i = 0; i < utcDataTableSize; ++i)
| 466-18174 | ||||||||||||
729 | result << utcId(utcData(i)); executed 18174 times by 1 test: result << utcId(utcData(i)); Executed by:
| 18174 | ||||||||||||
730 | std::sort(result.begin(), result.end()); // ### or already sorted?? | - | ||||||||||||
731 | // ### assuming no duplicates | - | ||||||||||||
732 | return result; executed 466 times by 1 test: return result; Executed by:
| 466 | ||||||||||||
733 | } | - | ||||||||||||
734 | - | |||||||||||||
735 | QList<QByteArray> QUtcTimeZonePrivate::availableTimeZoneIds(QLocale::Country country) const | - | ||||||||||||
736 | { | - | ||||||||||||
737 | // If AnyCountry then is request for all non-region offset codes | - | ||||||||||||
738 | if (country == QLocale::AnyCountry)
| 0-1 | ||||||||||||
739 | return availableTimeZoneIds(); never executed: return availableTimeZoneIds(); | 0 | ||||||||||||
740 | return QList<QByteArray>(); executed 1 time by 1 test: return QList<QByteArray>(); Executed by:
| 1 | ||||||||||||
741 | } | - | ||||||||||||
742 | - | |||||||||||||
743 | QList<QByteArray> QUtcTimeZonePrivate::availableTimeZoneIds(qint32 offsetSeconds) const | - | ||||||||||||
744 | { | - | ||||||||||||
745 | QList<QByteArray> result; | - | ||||||||||||
746 | for (int i = 0; i < utcDataTableSize; ++i) {
| 1-39 | ||||||||||||
747 | const QUtcData *data = utcData(i); | - | ||||||||||||
748 | if (data->offsetFromUtc == offsetSeconds)
| 3-36 | ||||||||||||
749 | result << utcId(data); executed 3 times by 1 test: result << utcId(data); Executed by:
| 3 | ||||||||||||
750 | } executed 39 times by 1 test: end of block Executed by:
| 39 | ||||||||||||
751 | std::sort(result.begin(), result.end()); // ### or already sorted?? | - | ||||||||||||
752 | // ### assuming no duplicates | - | ||||||||||||
753 | return result; executed 1 time by 1 test: return result; Executed by:
| 1 | ||||||||||||
754 | } | - | ||||||||||||
755 | - | |||||||||||||
756 | #ifndef QT_NO_DATASTREAM | - | ||||||||||||
757 | void QUtcTimeZonePrivate::serialize(QDataStream &ds) const | - | ||||||||||||
758 | { | - | ||||||||||||
759 | ds << QStringLiteral("OffsetFromUtc") << QString::fromUtf8(m_id) << m_offsetFromUtc << m_name executed 1 time by 1 test: return qstring_literal_temp; Executed by:
| 1 | ||||||||||||
760 | << m_abbreviation << (qint32) m_country << m_comment; | - | ||||||||||||
761 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
762 | #endif // QT_NO_DATASTREAM | - | ||||||||||||
763 | - | |||||||||||||
764 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |