Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qtimezoneprivate_tz.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 | #include "qtimezone.h" | - | ||||||||||||||||||
35 | #include "qtimezoneprivate_p.h" | - | ||||||||||||||||||
36 | - | |||||||||||||||||||
37 | #include <QtCore/QFile> | - | ||||||||||||||||||
38 | #include <QtCore/QHash> | - | ||||||||||||||||||
39 | #include <QtCore/QDataStream> | - | ||||||||||||||||||
40 | #include <QtCore/QDateTime> | - | ||||||||||||||||||
41 | - | |||||||||||||||||||
42 | #include <qdebug.h> | - | ||||||||||||||||||
43 | - | |||||||||||||||||||
44 | #include "qlocale_tools_p.h" | - | ||||||||||||||||||
45 | - | |||||||||||||||||||
46 | #include <algorithm> | - | ||||||||||||||||||
47 | - | |||||||||||||||||||
48 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
49 | - | |||||||||||||||||||
50 | /* | - | ||||||||||||||||||
51 | Private | - | ||||||||||||||||||
52 | - | |||||||||||||||||||
53 | tz file implementation | - | ||||||||||||||||||
54 | */ | - | ||||||||||||||||||
55 | - | |||||||||||||||||||
56 | struct QTzTimeZone { | - | ||||||||||||||||||
57 | QLocale::Country country; | - | ||||||||||||||||||
58 | QByteArray comment; | - | ||||||||||||||||||
59 | }; | - | ||||||||||||||||||
60 | - | |||||||||||||||||||
61 | // Define as a type as Q_GLOBAL_STATIC doesn't like it | - | ||||||||||||||||||
62 | typedef QHash<QByteArray, QTzTimeZone> QTzTimeZoneHash; | - | ||||||||||||||||||
63 | - | |||||||||||||||||||
64 | // Parse zone.tab table, assume lists all installed zones, if not will need to read directories | - | ||||||||||||||||||
65 | static QTzTimeZoneHash loadTzTimeZones() | - | ||||||||||||||||||
66 | { | - | ||||||||||||||||||
67 | QString path = QStringLiteral("/usr/share/zoneinfo/zone.tab"); executed 1 time by 1 test: return qstring_literal_temp; Executed by:
| 1 | ||||||||||||||||||
68 | if (!QFile::exists(path))
| 0-1 | ||||||||||||||||||
69 | path = QStringLiteral("/usr/lib/zoneinfo/zone.tab"); never executed: path = ([]() -> QString { enum { Size = sizeof(u"" "/usr/lib/zoneinfo/zone.tab")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "/usr/lib/zoneinfo/zone.tab" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()); never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
70 | - | |||||||||||||||||||
71 | QFile tzif(path); | - | ||||||||||||||||||
72 | if (!tzif.open(QIODevice::ReadOnly))
| 0-1 | ||||||||||||||||||
73 | return QTzTimeZoneHash(); never executed: return QTzTimeZoneHash(); | 0 | ||||||||||||||||||
74 | - | |||||||||||||||||||
75 | QTzTimeZoneHash zonesHash; | - | ||||||||||||||||||
76 | // TODO QTextStream inefficient, replace later | - | ||||||||||||||||||
77 | QTextStream ts(&tzif); | - | ||||||||||||||||||
78 | while (!ts.atEnd()) {
| 1-445 | ||||||||||||||||||
79 | const QString line = ts.readLine(); | - | ||||||||||||||||||
80 | // Comment lines are prefixed with a # | - | ||||||||||||||||||
81 | if (!line.isEmpty() && line.at(0) != '#') {
| 0-445 | ||||||||||||||||||
82 | // Data rows are tab-separated columns Region, Coordinates, ID, Optional Comments | - | ||||||||||||||||||
83 | const QStringList parts = line.split('\t'); | - | ||||||||||||||||||
84 | QTzTimeZone zone; | - | ||||||||||||||||||
85 | zone.country = QLocalePrivate::codeToCountry(parts.at(0)); | - | ||||||||||||||||||
86 | if (parts.size() > 3)
| 204-217 | ||||||||||||||||||
87 | zone.comment = parts.at(3).toUtf8(); executed 204 times by 1 test: zone.comment = parts.at(3).toUtf8(); Executed by:
| 204 | ||||||||||||||||||
88 | zonesHash.insert(parts.at(2).toUtf8(), zone); | - | ||||||||||||||||||
89 | } executed 421 times by 1 test: end of block Executed by:
| 421 | ||||||||||||||||||
90 | } executed 445 times by 1 test: end of block Executed by:
| 445 | ||||||||||||||||||
91 | return zonesHash; executed 1 time by 1 test: return zonesHash; Executed by:
| 1 | ||||||||||||||||||
92 | } | - | ||||||||||||||||||
93 | - | |||||||||||||||||||
94 | // Hash of available system tz files as loaded by loadTzTimeZones() | - | ||||||||||||||||||
95 | Q_GLOBAL_STATIC_WITH_ARGS(const QTzTimeZoneHash, tzZones, (loadTzTimeZones())); executed 1 time by 1 test: end of block Executed by:
executed 1 time by 1 test: guard.store(QtGlobalStatic::Destroyed); Executed by:
executed 1732 times by 1 test: return &holder.value; Executed by:
| 0-1732 | ||||||||||||||||||
96 | - | |||||||||||||||||||
97 | /* | - | ||||||||||||||||||
98 | The following is copied and modified from tzfile.h which is in the public domain. | - | ||||||||||||||||||
99 | Copied as no compatibility guarantee and is never system installed. | - | ||||||||||||||||||
100 | See https://github.com/eggert/tz/blob/master/tzfile.h | - | ||||||||||||||||||
101 | */ | - | ||||||||||||||||||
102 | - | |||||||||||||||||||
103 | #define TZ_MAGIC "TZif" | - | ||||||||||||||||||
104 | #define TZ_MAX_TIMES 1200 | - | ||||||||||||||||||
105 | #define TZ_MAX_TYPES 256 // Limited by what (unsigned char)'s can hold | - | ||||||||||||||||||
106 | #define TZ_MAX_CHARS 50 // Maximum number of abbreviation characters | - | ||||||||||||||||||
107 | #define TZ_MAX_LEAPS 50 // Maximum number of leap second corrections | - | ||||||||||||||||||
108 | - | |||||||||||||||||||
109 | struct QTzHeader { | - | ||||||||||||||||||
110 | char tzh_magic[4]; // TZ_MAGIC | - | ||||||||||||||||||
111 | char tzh_version; // '\0' or '2' as of 2005 | - | ||||||||||||||||||
112 | char tzh_reserved[15]; // reserved--must be zero | - | ||||||||||||||||||
113 | quint32 tzh_ttisgmtcnt; // number of trans. time flags | - | ||||||||||||||||||
114 | quint32 tzh_ttisstdcnt; // number of trans. time flags | - | ||||||||||||||||||
115 | quint32 tzh_leapcnt; // number of leap seconds | - | ||||||||||||||||||
116 | quint32 tzh_timecnt; // number of transition times | - | ||||||||||||||||||
117 | quint32 tzh_typecnt; // number of local time types | - | ||||||||||||||||||
118 | quint32 tzh_charcnt; // number of abbr. chars | - | ||||||||||||||||||
119 | }; | - | ||||||||||||||||||
120 | - | |||||||||||||||||||
121 | struct QTzTransition { | - | ||||||||||||||||||
122 | qint64 tz_time; // Transition time | - | ||||||||||||||||||
123 | quint8 tz_typeind; // Type Index | - | ||||||||||||||||||
124 | }; | - | ||||||||||||||||||
125 | Q_DECLARE_TYPEINFO(QTzTransition, Q_PRIMITIVE_TYPE); | - | ||||||||||||||||||
126 | - | |||||||||||||||||||
127 | struct QTzType { | - | ||||||||||||||||||
128 | int tz_gmtoff; // UTC offset in seconds | - | ||||||||||||||||||
129 | bool tz_isdst; // Is DST | - | ||||||||||||||||||
130 | quint8 tz_abbrind; // abbreviation list index | - | ||||||||||||||||||
131 | bool tz_ttisgmt; // Is in UTC time | - | ||||||||||||||||||
132 | bool tz_ttisstd; // Is in Standard time | - | ||||||||||||||||||
133 | }; | - | ||||||||||||||||||
134 | Q_DECLARE_TYPEINFO(QTzType, Q_PRIMITIVE_TYPE); | - | ||||||||||||||||||
135 | - | |||||||||||||||||||
136 | - | |||||||||||||||||||
137 | // TZ File parsing | - | ||||||||||||||||||
138 | - | |||||||||||||||||||
139 | static QTzHeader parseTzHeader(QDataStream &ds, bool *ok) | - | ||||||||||||||||||
140 | { | - | ||||||||||||||||||
141 | QTzHeader hdr; | - | ||||||||||||||||||
142 | quint8 ch; | - | ||||||||||||||||||
143 | *ok = false; | - | ||||||||||||||||||
144 | - | |||||||||||||||||||
145 | // Parse Magic, 4 bytes | - | ||||||||||||||||||
146 | ds.readRawData(hdr.tzh_magic, 4); | - | ||||||||||||||||||
147 | - | |||||||||||||||||||
148 | if (memcmp(hdr.tzh_magic, TZ_MAGIC, 4) != 0 || ds.status() != QDataStream::Ok)
| 0-908 | ||||||||||||||||||
149 | return hdr; never executed: return hdr; | 0 | ||||||||||||||||||
150 | - | |||||||||||||||||||
151 | // Parse Version, 1 byte, before 2005 was '\0', since 2005 a '2', since 2013 a '3' | - | ||||||||||||||||||
152 | ds >> ch; | - | ||||||||||||||||||
153 | hdr.tzh_version = ch; | - | ||||||||||||||||||
154 | if (ds.status() != QDataStream::Ok
| 0-908 | ||||||||||||||||||
155 | || (hdr.tzh_version != '2' && hdr.tzh_version != '\0' && hdr.tzh_version != '3')) {
| 0-894 | ||||||||||||||||||
156 | return hdr; never executed: return hdr; | 0 | ||||||||||||||||||
157 | } | - | ||||||||||||||||||
158 | - | |||||||||||||||||||
159 | // Parse reserved space, 15 bytes | - | ||||||||||||||||||
160 | ds.readRawData(hdr.tzh_reserved, 15); | - | ||||||||||||||||||
161 | if (ds.status() != QDataStream::Ok)
| 0-908 | ||||||||||||||||||
162 | return hdr; never executed: return hdr; | 0 | ||||||||||||||||||
163 | - | |||||||||||||||||||
164 | // Parse rest of header, 6 x 4-byte transition counts | - | ||||||||||||||||||
165 | ds >> hdr.tzh_ttisgmtcnt >> hdr.tzh_ttisstdcnt >> hdr.tzh_leapcnt >> hdr.tzh_timecnt | - | ||||||||||||||||||
166 | >> hdr.tzh_typecnt >> hdr.tzh_charcnt; | - | ||||||||||||||||||
167 | - | |||||||||||||||||||
168 | // Check defined maximums | - | ||||||||||||||||||
169 | if (ds.status() != QDataStream::Ok
| 0-908 | ||||||||||||||||||
170 | || hdr.tzh_timecnt > TZ_MAX_TIMES
| 0-908 | ||||||||||||||||||
171 | || hdr.tzh_typecnt > TZ_MAX_TYPES
| 0-908 | ||||||||||||||||||
172 | || hdr.tzh_charcnt > TZ_MAX_CHARS
| 0-908 | ||||||||||||||||||
173 | || hdr.tzh_leapcnt > TZ_MAX_LEAPS
| 0-908 | ||||||||||||||||||
174 | || hdr.tzh_ttisgmtcnt > hdr.tzh_typecnt
| 0-908 | ||||||||||||||||||
175 | || hdr.tzh_ttisstdcnt > hdr.tzh_typecnt) {
| 0-908 | ||||||||||||||||||
176 | return hdr; never executed: return hdr; | 0 | ||||||||||||||||||
177 | } | - | ||||||||||||||||||
178 | - | |||||||||||||||||||
179 | *ok = true; | - | ||||||||||||||||||
180 | return hdr; executed 908 times by 2 tests: return hdr; Executed by:
| 908 | ||||||||||||||||||
181 | } | - | ||||||||||||||||||
182 | - | |||||||||||||||||||
183 | static QVector<QTzTransition> parseTzTransitions(QDataStream &ds, int tzh_timecnt, bool longTran) | - | ||||||||||||||||||
184 | { | - | ||||||||||||||||||
185 | QVector<QTzTransition> transitions(tzh_timecnt); | - | ||||||||||||||||||
186 | - | |||||||||||||||||||
187 | if (longTran) {
| 454 | ||||||||||||||||||
188 | // Parse tzh_timecnt x 8-byte transition times | - | ||||||||||||||||||
189 | for (int i = 0; i < tzh_timecnt && ds.status() == QDataStream::Ok; ++i) {
| 0-31553 | ||||||||||||||||||
190 | ds >> transitions[i].tz_time; | - | ||||||||||||||||||
191 | if (ds.status() != QDataStream::Ok)
| 0-31553 | ||||||||||||||||||
192 | transitions.resize(i); never executed: transitions.resize(i); | 0 | ||||||||||||||||||
193 | } executed 31553 times by 2 tests: end of block Executed by:
| 31553 | ||||||||||||||||||
194 | } else { executed 454 times by 2 tests: end of block Executed by:
| 454 | ||||||||||||||||||
195 | // Parse tzh_timecnt x 4-byte transition times | - | ||||||||||||||||||
196 | int val; | - | ||||||||||||||||||
197 | for (int i = 0; i < tzh_timecnt && ds.status() == QDataStream::Ok; ++i) {
| 0-31278 | ||||||||||||||||||
198 | ds >> val; | - | ||||||||||||||||||
199 | transitions[i].tz_time = val; | - | ||||||||||||||||||
200 | if (ds.status() != QDataStream::Ok)
| 0-31278 | ||||||||||||||||||
201 | transitions.resize(i); never executed: transitions.resize(i); | 0 | ||||||||||||||||||
202 | } executed 31278 times by 2 tests: end of block Executed by:
| 31278 | ||||||||||||||||||
203 | } executed 454 times by 2 tests: end of block Executed by:
| 454 | ||||||||||||||||||
204 | - | |||||||||||||||||||
205 | // Parse tzh_timecnt x 1-byte transition type index | - | ||||||||||||||||||
206 | for (int i = 0; i < tzh_timecnt && ds.status() == QDataStream::Ok; ++i) {
| 0-62831 | ||||||||||||||||||
207 | quint8 typeind; | - | ||||||||||||||||||
208 | ds >> typeind; | - | ||||||||||||||||||
209 | if (ds.status() == QDataStream::Ok)
| 0-62831 | ||||||||||||||||||
210 | transitions[i].tz_typeind = typeind; executed 62831 times by 2 tests: transitions[i].tz_typeind = typeind; Executed by:
| 62831 | ||||||||||||||||||
211 | } executed 62831 times by 2 tests: end of block Executed by:
| 62831 | ||||||||||||||||||
212 | - | |||||||||||||||||||
213 | return transitions; executed 908 times by 2 tests: return transitions; Executed by:
| 908 | ||||||||||||||||||
214 | } | - | ||||||||||||||||||
215 | - | |||||||||||||||||||
216 | static QVector<QTzType> parseTzTypes(QDataStream &ds, int tzh_typecnt) | - | ||||||||||||||||||
217 | { | - | ||||||||||||||||||
218 | QVector<QTzType> types(tzh_typecnt); | - | ||||||||||||||||||
219 | - | |||||||||||||||||||
220 | // Parse tzh_typecnt x transition types | - | ||||||||||||||||||
221 | for (int i = 0; i < tzh_typecnt && ds.status() == QDataStream::Ok; ++i) {
| 0-5130 | ||||||||||||||||||
222 | QTzType &type = types[i]; | - | ||||||||||||||||||
223 | // Parse UTC Offset, 4 bytes | - | ||||||||||||||||||
224 | ds >> type.tz_gmtoff; | - | ||||||||||||||||||
225 | // Parse Is DST flag, 1 byte | - | ||||||||||||||||||
226 | if (ds.status() == QDataStream::Ok)
| 0-5130 | ||||||||||||||||||
227 | ds >> type.tz_isdst; executed 5130 times by 2 tests: ds >> type.tz_isdst; Executed by:
| 5130 | ||||||||||||||||||
228 | // Parse Abbreviation Array Index, 1 byte | - | ||||||||||||||||||
229 | if (ds.status() == QDataStream::Ok)
| 0-5130 | ||||||||||||||||||
230 | ds >> type.tz_abbrind; executed 5130 times by 2 tests: ds >> type.tz_abbrind; Executed by:
| 5130 | ||||||||||||||||||
231 | // Set defaults in case not populated later | - | ||||||||||||||||||
232 | type.tz_ttisgmt = false; | - | ||||||||||||||||||
233 | type.tz_ttisstd = false; | - | ||||||||||||||||||
234 | if (ds.status() != QDataStream::Ok)
| 0-5130 | ||||||||||||||||||
235 | types.resize(i); never executed: types.resize(i); | 0 | ||||||||||||||||||
236 | } executed 5130 times by 2 tests: end of block Executed by:
| 5130 | ||||||||||||||||||
237 | - | |||||||||||||||||||
238 | return types; executed 908 times by 2 tests: return types; Executed by:
| 908 | ||||||||||||||||||
239 | } | - | ||||||||||||||||||
240 | - | |||||||||||||||||||
241 | static QMap<int, QByteArray> parseTzAbbreviations(QDataStream &ds, int tzh_charcnt, const QVector<QTzType> &types) | - | ||||||||||||||||||
242 | { | - | ||||||||||||||||||
243 | // Parse the abbreviation list which is tzh_charcnt long with '\0' separated strings. The | - | ||||||||||||||||||
244 | // QTzType.tz_abbrind index points to the first char of the abbreviation in the array, not the | - | ||||||||||||||||||
245 | // occurrence in the list. It can also point to a partial string so we need to use the actual typeList | - | ||||||||||||||||||
246 | // index values when parsing. By using a map with tz_abbrind as ordered key we get both index | - | ||||||||||||||||||
247 | // methods in one data structure and can convert the types afterwards. | - | ||||||||||||||||||
248 | QMap<int, QByteArray> map; | - | ||||||||||||||||||
249 | quint8 ch; | - | ||||||||||||||||||
250 | QByteArray input; | - | ||||||||||||||||||
251 | // First parse the full abbrev string | - | ||||||||||||||||||
252 | for (int i = 0; i < tzh_charcnt && ds.status() == QDataStream::Ok; ++i) {
| 0-14643 | ||||||||||||||||||
253 | ds >> ch; | - | ||||||||||||||||||
254 | if (ds.status() == QDataStream::Ok)
| 0-14643 | ||||||||||||||||||
255 | input.append(char(ch)); executed 14643 times by 2 tests: input.append(char(ch)); Executed by:
| 14643 | ||||||||||||||||||
256 | else | - | ||||||||||||||||||
257 | return map; never executed: return map; | 0 | ||||||||||||||||||
258 | } | - | ||||||||||||||||||
259 | // Then extract all the substrings pointed to by types | - | ||||||||||||||||||
260 | foreach (const QTzType &type, types) { | - | ||||||||||||||||||
261 | QByteArray abbrev; | - | ||||||||||||||||||
262 | for (int i = type.tz_abbrind; input.at(i) != '\0'; ++i)
| 5130-17454 | ||||||||||||||||||
263 | abbrev.append(input.at(i)); executed 17454 times by 2 tests: abbrev.append(input.at(i)); Executed by:
| 17454 | ||||||||||||||||||
264 | // Have reached end of an abbreviation, so add to map | - | ||||||||||||||||||
265 | map[type.tz_abbrind] = abbrev; | - | ||||||||||||||||||
266 | } executed 5130 times by 2 tests: end of block Executed by:
| 5130 | ||||||||||||||||||
267 | return map; executed 908 times by 2 tests: return map; Executed by:
| 908 | ||||||||||||||||||
268 | } | - | ||||||||||||||||||
269 | - | |||||||||||||||||||
270 | static void parseTzLeapSeconds(QDataStream &ds, int tzh_leapcnt, bool longTran) | - | ||||||||||||||||||
271 | { | - | ||||||||||||||||||
272 | // Parse tzh_leapcnt x pairs of leap seconds | - | ||||||||||||||||||
273 | // We don't use leap seconds, so only read and don't store | - | ||||||||||||||||||
274 | qint64 val; | - | ||||||||||||||||||
275 | if (longTran) {
| 454 | ||||||||||||||||||
276 | qint64 time; | - | ||||||||||||||||||
277 | for (int i = 0; i < tzh_leapcnt && ds.status() == QDataStream::Ok; ++i) {
| 0-454 | ||||||||||||||||||
278 | // Parse Leap Occurrence Time, 8 bytes | - | ||||||||||||||||||
279 | ds >> time; | - | ||||||||||||||||||
280 | // Parse Leap Seconds To Apply, 4 bytes | - | ||||||||||||||||||
281 | if (ds.status() == QDataStream::Ok)
| 0 | ||||||||||||||||||
282 | ds >> val; never executed: ds >> val; | 0 | ||||||||||||||||||
283 | } never executed: end of block | 0 | ||||||||||||||||||
284 | } else { executed 454 times by 2 tests: end of block Executed by:
| 454 | ||||||||||||||||||
285 | for (int i = 0; i < tzh_leapcnt && ds.status() == QDataStream::Ok; ++i) {
| 0-454 | ||||||||||||||||||
286 | // Parse Leap Occurrence Time, 4 bytes | - | ||||||||||||||||||
287 | ds >> val; | - | ||||||||||||||||||
288 | // Parse Leap Seconds To Apply, 4 bytes | - | ||||||||||||||||||
289 | if (ds.status() == QDataStream::Ok)
| 0 | ||||||||||||||||||
290 | ds >> val; never executed: ds >> val; | 0 | ||||||||||||||||||
291 | } never executed: end of block | 0 | ||||||||||||||||||
292 | } executed 454 times by 2 tests: end of block Executed by:
| 454 | ||||||||||||||||||
293 | } | - | ||||||||||||||||||
294 | - | |||||||||||||||||||
295 | static QVector<QTzType> parseTzIndicators(QDataStream &ds, const QVector<QTzType> &types, int tzh_ttisstdcnt, int tzh_ttisgmtcnt) | - | ||||||||||||||||||
296 | { | - | ||||||||||||||||||
297 | QVector<QTzType> result = types; | - | ||||||||||||||||||
298 | bool temp; | - | ||||||||||||||||||
299 | - | |||||||||||||||||||
300 | // Parse tzh_ttisstdcnt x 1-byte standard/wall indicators | - | ||||||||||||||||||
301 | for (int i = 0; i < tzh_ttisstdcnt && ds.status() == QDataStream::Ok; ++i) {
| 0-5130 | ||||||||||||||||||
302 | ds >> temp; | - | ||||||||||||||||||
303 | if (ds.status() == QDataStream::Ok)
| 0-5130 | ||||||||||||||||||
304 | result[i].tz_ttisstd = temp; executed 5130 times by 2 tests: result[i].tz_ttisstd = temp; Executed by:
| 5130 | ||||||||||||||||||
305 | } executed 5130 times by 2 tests: end of block Executed by:
| 5130 | ||||||||||||||||||
306 | - | |||||||||||||||||||
307 | // Parse tzh_ttisgmtcnt x 1-byte UTC/local indicators | - | ||||||||||||||||||
308 | for (int i = 0; i < tzh_ttisgmtcnt && ds.status() == QDataStream::Ok; ++i) {
| 0-5130 | ||||||||||||||||||
309 | ds >> temp; | - | ||||||||||||||||||
310 | if (ds.status() == QDataStream::Ok)
| 0-5130 | ||||||||||||||||||
311 | result[i].tz_ttisgmt = temp; executed 5130 times by 2 tests: result[i].tz_ttisgmt = temp; Executed by:
| 5130 | ||||||||||||||||||
312 | } executed 5130 times by 2 tests: end of block Executed by:
| 5130 | ||||||||||||||||||
313 | - | |||||||||||||||||||
314 | return result; executed 908 times by 2 tests: return result; Executed by:
| 908 | ||||||||||||||||||
315 | } | - | ||||||||||||||||||
316 | - | |||||||||||||||||||
317 | static QByteArray parseTzPosixRule(QDataStream &ds) | - | ||||||||||||||||||
318 | { | - | ||||||||||||||||||
319 | // Parse POSIX rule, variable length '\n' enclosed | - | ||||||||||||||||||
320 | QByteArray rule; | - | ||||||||||||||||||
321 | - | |||||||||||||||||||
322 | quint8 ch; | - | ||||||||||||||||||
323 | ds >> ch; | - | ||||||||||||||||||
324 | if (ch != '\n' || ds.status() != QDataStream::Ok)
| 0-454 | ||||||||||||||||||
325 | return rule; never executed: return rule; | 0 | ||||||||||||||||||
326 | ds >> ch; | - | ||||||||||||||||||
327 | while (ch != '\n' && ds.status() == QDataStream::Ok) {
| 0-5987 | ||||||||||||||||||
328 | rule.append((char)ch); | - | ||||||||||||||||||
329 | ds >> ch; | - | ||||||||||||||||||
330 | } executed 5987 times by 2 tests: end of block Executed by:
| 5987 | ||||||||||||||||||
331 | - | |||||||||||||||||||
332 | return rule; executed 454 times by 2 tests: return rule; Executed by:
| 454 | ||||||||||||||||||
333 | } | - | ||||||||||||||||||
334 | - | |||||||||||||||||||
335 | static QDate calculateDowDate(int year, int month, int dayOfWeek, int week) | - | ||||||||||||||||||
336 | { | - | ||||||||||||||||||
337 | QDate date(year, month, 1); | - | ||||||||||||||||||
338 | int startDow = date.dayOfWeek(); | - | ||||||||||||||||||
339 | if (startDow <= dayOfWeek)
| 295-3471 | ||||||||||||||||||
340 | date = date.addDays(dayOfWeek - startDow - 7); executed 295 times by 2 tests: date = date.addDays(dayOfWeek - startDow - 7); Executed by:
| 295 | ||||||||||||||||||
341 | else | - | ||||||||||||||||||
342 | date = date.addDays(dayOfWeek - startDow); executed 3471 times by 2 tests: date = date.addDays(dayOfWeek - startDow); Executed by:
| 3471 | ||||||||||||||||||
343 | date = date.addDays(week * 7); | - | ||||||||||||||||||
344 | while (date.month() != month)
| 1243-3766 | ||||||||||||||||||
345 | date = date.addDays(-7); executed 1243 times by 2 tests: date = date.addDays(-7); Executed by:
| 1243 | ||||||||||||||||||
346 | return date; executed 3766 times by 2 tests: return date; Executed by:
| 3766 | ||||||||||||||||||
347 | } | - | ||||||||||||||||||
348 | - | |||||||||||||||||||
349 | static QDate calculatePosixDate(const QByteArray &dateRule, int year) | - | ||||||||||||||||||
350 | { | - | ||||||||||||||||||
351 | // Can start with M, J, or a digit | - | ||||||||||||||||||
352 | if (dateRule.at(0) == 'M') {
| 24-3766 | ||||||||||||||||||
353 | // nth week in month format "Mmonth.week.dow" | - | ||||||||||||||||||
354 | QList<QByteArray> dateParts = dateRule.split('.'); | - | ||||||||||||||||||
355 | int month = dateParts.at(0).mid(1).toInt(); | - | ||||||||||||||||||
356 | int week = dateParts.at(1).toInt(); | - | ||||||||||||||||||
357 | int dow = dateParts.at(2).toInt(); | - | ||||||||||||||||||
358 | if (dow == 0)
| 252-3514 | ||||||||||||||||||
359 | ++dow; executed 3514 times by 2 tests: ++dow; Executed by:
| 3514 | ||||||||||||||||||
360 | return calculateDowDate(year, month, dow, week); executed 3766 times by 2 tests: return calculateDowDate(year, month, dow, week); Executed by:
| 3766 | ||||||||||||||||||
361 | } else if (dateRule.at(0) == 'J') {
| 0-24 | ||||||||||||||||||
362 | // Day of Year ignores Feb 29 | - | ||||||||||||||||||
363 | int doy = dateRule.mid(1).toInt(); | - | ||||||||||||||||||
364 | QDate date = QDate(year, 1, 1).addDays(doy - 1); | - | ||||||||||||||||||
365 | if (QDate::isLeapYear(date.year()))
| 0-24 | ||||||||||||||||||
366 | date = date.addDays(-1); never executed: date = date.addDays(-1); | 0 | ||||||||||||||||||
367 | return date; executed 24 times by 1 test: return date; Executed by:
| 24 | ||||||||||||||||||
368 | } else { | - | ||||||||||||||||||
369 | // Day of Year includes Feb 29 | - | ||||||||||||||||||
370 | int doy = dateRule.toInt(); | - | ||||||||||||||||||
371 | return QDate(year, 1, 1).addDays(doy - 1); never executed: return QDate(year, 1, 1).addDays(doy - 1); | 0 | ||||||||||||||||||
372 | } | - | ||||||||||||||||||
373 | } | - | ||||||||||||||||||
374 | - | |||||||||||||||||||
375 | // returns the time in seconds, INT_MIN if we failed to parse | - | ||||||||||||||||||
376 | static int parsePosixTime(const char *begin, const char *end) | - | ||||||||||||||||||
377 | { | - | ||||||||||||||||||
378 | // Format "hh[:mm[:ss]]" | - | ||||||||||||||||||
379 | int hour, min = 0, sec = 0; | - | ||||||||||||||||||
380 | - | |||||||||||||||||||
381 | // Note that the calls to qstrtoll do *not* check the end pointer, which | - | ||||||||||||||||||
382 | // means they proceed until they find a non-digit. We check that we're | - | ||||||||||||||||||
383 | // still in range at the end, but we may have read from past end. It's the | - | ||||||||||||||||||
384 | // caller's responsibility to ensure that begin is part of a | - | ||||||||||||||||||
385 | // null-terminated string. | - | ||||||||||||||||||
386 | - | |||||||||||||||||||
387 | bool ok = false; | - | ||||||||||||||||||
388 | hour = qstrtoll(begin, &begin, 10, &ok); | - | ||||||||||||||||||
389 | if (!ok || hour < 0)
| 0-5037 | ||||||||||||||||||
390 | return INT_MIN; executed 8 times by 1 test: return (-2147483647 - 1); Executed by:
| 8 | ||||||||||||||||||
391 | if (begin < end && *begin == ':') {
| 0-4855 | ||||||||||||||||||
392 | // minutes | - | ||||||||||||||||||
393 | ++begin; | - | ||||||||||||||||||
394 | min = qstrtoll(begin, &begin, 10, &ok); | - | ||||||||||||||||||
395 | if (!ok || min < 0)
| 0-174 | ||||||||||||||||||
396 | return INT_MIN; never executed: return (-2147483647 - 1); | 0 | ||||||||||||||||||
397 | - | |||||||||||||||||||
398 | if (begin < end && *begin == ':') {
| 0-174 | ||||||||||||||||||
399 | // seconds | - | ||||||||||||||||||
400 | ++begin; | - | ||||||||||||||||||
401 | sec = qstrtoll(begin, &begin, 10, &ok); | - | ||||||||||||||||||
402 | if (!ok || sec < 0)
| 0 | ||||||||||||||||||
403 | return INT_MIN; never executed: return (-2147483647 - 1); | 0 | ||||||||||||||||||
404 | } never executed: end of block | 0 | ||||||||||||||||||
405 | } executed 174 times by 1 test: end of block Executed by:
| 174 | ||||||||||||||||||
406 | - | |||||||||||||||||||
407 | // we must have consumed everything | - | ||||||||||||||||||
408 | if (begin != end)
| 0-5029 | ||||||||||||||||||
409 | return INT_MIN; never executed: return (-2147483647 - 1); | 0 | ||||||||||||||||||
410 | - | |||||||||||||||||||
411 | return (hour * 60 + min) * 60 + sec; executed 5029 times by 2 tests: return (hour * 60 + min) * 60 + sec; Executed by:
| 5029 | ||||||||||||||||||
412 | } | - | ||||||||||||||||||
413 | - | |||||||||||||||||||
414 | static QTime parsePosixTransitionTime(const QByteArray &timeRule) | - | ||||||||||||||||||
415 | { | - | ||||||||||||||||||
416 | // Format "hh[:mm[:ss]]" | - | ||||||||||||||||||
417 | int value = parsePosixTime(timeRule.constBegin(), timeRule.constEnd()); | - | ||||||||||||||||||
418 | if (value == INT_MIN) {
| 8-504 | ||||||||||||||||||
419 | // if we failed to parse, return 02:00 | - | ||||||||||||||||||
420 | return QTime(2, 0, 0); executed 8 times by 1 test: return QTime(2, 0, 0); Executed by:
| 8 | ||||||||||||||||||
421 | } | - | ||||||||||||||||||
422 | return QTime::fromMSecsSinceStartOfDay(value * 1000); executed 504 times by 2 tests: return QTime::fromMSecsSinceStartOfDay(value * 1000); Executed by:
| 504 | ||||||||||||||||||
423 | } | - | ||||||||||||||||||
424 | - | |||||||||||||||||||
425 | static int parsePosixOffset(const char *begin, const char *end) | - | ||||||||||||||||||
426 | { | - | ||||||||||||||||||
427 | // Format "[+|-]hh[:mm[:ss]]" | - | ||||||||||||||||||
428 | // note that the sign is inverted because POSIX counts in hours West of GMT | - | ||||||||||||||||||
429 | bool negate = true; | - | ||||||||||||||||||
430 | if (*begin == '+') {
| 0-4525 | ||||||||||||||||||
431 | ++begin; | - | ||||||||||||||||||
432 | } else if (*begin == '-') { never executed: end of block
| 0-2621 | ||||||||||||||||||
433 | negate = false; | - | ||||||||||||||||||
434 | ++begin; | - | ||||||||||||||||||
435 | } executed 2621 times by 2 tests: end of block Executed by:
| 2621 | ||||||||||||||||||
436 | - | |||||||||||||||||||
437 | int value = parsePosixTime(begin, end); | - | ||||||||||||||||||
438 | if (value == INT_MIN)
| 0-4525 | ||||||||||||||||||
439 | return value; never executed: return value; | 0 | ||||||||||||||||||
440 | return negate ? -value : value; executed 4525 times by 2 tests: return negate ? -value : value; Executed by:
| 1904-4525 | ||||||||||||||||||
441 | } | - | ||||||||||||||||||
442 | - | |||||||||||||||||||
443 | static inline bool asciiIsLetter(char ch) | - | ||||||||||||||||||
444 | { | - | ||||||||||||||||||
445 | ch |= 0x20; // lowercases if it is a letter, otherwise just corrupts ch | - | ||||||||||||||||||
446 | return ch >= 'a' && ch <= 'z'; executed 20587 times by 2 tests: return ch >= 'a' && ch <= 'z'; Executed by:
| 0-20587 | ||||||||||||||||||
447 | } | - | ||||||||||||||||||
448 | - | |||||||||||||||||||
449 | // Returns the zone name, the offset (in seconds) and advances \a begin to | - | ||||||||||||||||||
450 | // where the parsing ended. Returns a zone of INT_MIN in case an offset | - | ||||||||||||||||||
451 | // couldn't be read. | - | ||||||||||||||||||
452 | static QPair<QString, int> parsePosixZoneNameAndOffset(const char *&pos, const char *end) | - | ||||||||||||||||||
453 | { | - | ||||||||||||||||||
454 | static const char offsetChars[] = "0123456789:"; | - | ||||||||||||||||||
455 | QPair<QString, int> result = qMakePair(QString(), INT_MIN); | - | ||||||||||||||||||
456 | - | |||||||||||||||||||
457 | const char *nameBegin = pos; | - | ||||||||||||||||||
458 | const char *nameEnd; | - | ||||||||||||||||||
459 | Q_ASSERT(pos < end); | - | ||||||||||||||||||
460 | - | |||||||||||||||||||
461 | if (*pos == '<') {
| 147-5002 | ||||||||||||||||||
462 | nameBegin = pos + 1; // skip the '<' | - | ||||||||||||||||||
463 | nameEnd = nameBegin; | - | ||||||||||||||||||
464 | while (nameEnd < end && *nameEnd != '>') {
| 0-588 | ||||||||||||||||||
465 | // POSIX says only alphanumeric, but we allow anything | - | ||||||||||||||||||
466 | ++nameEnd; | - | ||||||||||||||||||
467 | } executed 441 times by 1 test: end of block Executed by:
| 441 | ||||||||||||||||||
468 | pos = nameEnd + 1; // skip the '>' | - | ||||||||||||||||||
469 | } else { executed 147 times by 1 test: end of block Executed by:
| 147 | ||||||||||||||||||
470 | nameBegin = pos; | - | ||||||||||||||||||
471 | nameEnd = nameBegin; | - | ||||||||||||||||||
472 | while (nameEnd < end && asciiIsLetter(*nameEnd))
| 624-20587 | ||||||||||||||||||
473 | ++nameEnd; executed 16209 times by 2 tests: ++nameEnd; Executed by:
| 16209 | ||||||||||||||||||
474 | pos = nameEnd; | - | ||||||||||||||||||
475 | } executed 5002 times by 2 tests: end of block Executed by:
| 5002 | ||||||||||||||||||
476 | if (nameEnd - nameBegin < 3)
| 0-5149 | ||||||||||||||||||
477 | return result; // name must be at least 3 characters long never executed: return result; | 0 | ||||||||||||||||||
478 | - | |||||||||||||||||||
479 | // zone offset, form [+-]hh:mm:ss | - | ||||||||||||||||||
480 | const char *zoneBegin = pos; | - | ||||||||||||||||||
481 | const char *zoneEnd = pos; | - | ||||||||||||||||||
482 | if (zoneEnd < end && (zoneEnd[0] == '+' || zoneEnd[0] == '-'))
| 0-4525 | ||||||||||||||||||
483 | ++zoneEnd; executed 2621 times by 2 tests: ++zoneEnd; Executed by:
| 2621 | ||||||||||||||||||
484 | while (zoneEnd < end) {
| 4517-6295 | ||||||||||||||||||
485 | if (strchr(offsetChars, char(*zoneEnd)) == NULL)
| 632-5663 | ||||||||||||||||||
486 | break; executed 632 times by 2 tests: break; Executed by:
| 632 | ||||||||||||||||||
487 | ++zoneEnd; | - | ||||||||||||||||||
488 | } executed 5663 times by 2 tests: end of block Executed by:
| 5663 | ||||||||||||||||||
489 | - | |||||||||||||||||||
490 | result.first = QString::fromUtf8(nameBegin, nameEnd - nameBegin); | - | ||||||||||||||||||
491 | if (zoneEnd > zoneBegin)
| 624-4525 | ||||||||||||||||||
492 | result.second = parsePosixOffset(zoneBegin, zoneEnd); executed 4525 times by 2 tests: result.second = parsePosixOffset(zoneBegin, zoneEnd); Executed by:
| 4525 | ||||||||||||||||||
493 | pos = zoneEnd; | - | ||||||||||||||||||
494 | return result; executed 5149 times by 2 tests: return result; Executed by:
| 5149 | ||||||||||||||||||
495 | } | - | ||||||||||||||||||
496 | - | |||||||||||||||||||
497 | static QVector<QTimeZonePrivate::Data> calculatePosixTransitions(const QByteArray &posixRule, | - | ||||||||||||||||||
498 | int startYear, int endYear, | - | ||||||||||||||||||
499 | int lastTranMSecs) | - | ||||||||||||||||||
500 | { | - | ||||||||||||||||||
501 | QVector<QTimeZonePrivate::Data> result; | - | ||||||||||||||||||
502 | - | |||||||||||||||||||
503 | // Limit year by qint64 max size for msecs | - | ||||||||||||||||||
504 | if (startYear > 292278994)
| 0-4517 | ||||||||||||||||||
505 | startYear = 292278994; never executed: startYear = 292278994; | 0 | ||||||||||||||||||
506 | if (endYear > 292278994)
| 1-4516 | ||||||||||||||||||
507 | endYear = 292278994; executed 1 time by 1 test: endYear = 292278994; Executed by:
| 1 | ||||||||||||||||||
508 | - | |||||||||||||||||||
509 | // POSIX Format is like "TZ=CST6CDT,M3.2.0/2:00:00,M11.1.0/2:00:00" | - | ||||||||||||||||||
510 | // i.e. "std offset dst [offset],start[/time],end[/time]" | - | ||||||||||||||||||
511 | // See the section about TZ at http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html | - | ||||||||||||||||||
512 | QList<QByteArray> parts = posixRule.split(','); | - | ||||||||||||||||||
513 | - | |||||||||||||||||||
514 | QPair<QString, int> stdZone, dstZone; | - | ||||||||||||||||||
515 | { | - | ||||||||||||||||||
516 | const QByteArray &zoneinfo = parts.at(0); | - | ||||||||||||||||||
517 | const char *begin = zoneinfo.constBegin(); | - | ||||||||||||||||||
518 | - | |||||||||||||||||||
519 | stdZone = parsePosixZoneNameAndOffset(begin, zoneinfo.constEnd()); | - | ||||||||||||||||||
520 | if (stdZone.second == INT_MIN) {
| 0-4517 | ||||||||||||||||||
521 | stdZone.second = 0; // reset to UTC if we failed to parse | - | ||||||||||||||||||
522 | } else if (begin < zoneinfo.constEnd()) { never executed: end of block
| 0-3885 | ||||||||||||||||||
523 | dstZone = parsePosixZoneNameAndOffset(begin, zoneinfo.constEnd()); | - | ||||||||||||||||||
524 | if (dstZone.second == INT_MIN) {
| 8-624 | ||||||||||||||||||
525 | // if the dst offset isn't provided, it is 1 hour ahead of the standard offset | - | ||||||||||||||||||
526 | dstZone.second = stdZone.second + (60 * 60); | - | ||||||||||||||||||
527 | } executed 624 times by 2 tests: end of block Executed by:
| 624 | ||||||||||||||||||
528 | } executed 632 times by 2 tests: end of block Executed by:
| 632 | ||||||||||||||||||
529 | } | - | ||||||||||||||||||
530 | - | |||||||||||||||||||
531 | // If only the name part then no transitions | - | ||||||||||||||||||
532 | if (parts.count() == 1) {
| 632-3885 | ||||||||||||||||||
533 | QTimeZonePrivate::Data data; | - | ||||||||||||||||||
534 | data.atMSecsSinceEpoch = lastTranMSecs; | - | ||||||||||||||||||
535 | data.offsetFromUtc = stdZone.second; | - | ||||||||||||||||||
536 | data.standardTimeOffset = stdZone.second; | - | ||||||||||||||||||
537 | data.daylightTimeOffset = 0; | - | ||||||||||||||||||
538 | data.abbreviation = stdZone.first; | - | ||||||||||||||||||
539 | result << data; | - | ||||||||||||||||||
540 | return result; executed 3885 times by 2 tests: return result; Executed by:
| 3885 | ||||||||||||||||||
541 | } | - | ||||||||||||||||||
542 | - | |||||||||||||||||||
543 | - | |||||||||||||||||||
544 | // Get the std to dst transtion details | - | ||||||||||||||||||
545 | QList<QByteArray> dstParts = parts.at(1).split('/'); | - | ||||||||||||||||||
546 | QByteArray dstDateRule = dstParts.at(0); | - | ||||||||||||||||||
547 | QTime dstTime; | - | ||||||||||||||||||
548 | if (dstParts.count() > 1)
| 172-460 | ||||||||||||||||||
549 | dstTime = parsePosixTransitionTime(dstParts.at(1)); executed 172 times by 1 test: dstTime = parsePosixTransitionTime(dstParts.at(1)); Executed by:
| 172 | ||||||||||||||||||
550 | else | - | ||||||||||||||||||
551 | dstTime = QTime(2, 0, 0); executed 460 times by 2 tests: dstTime = QTime(2, 0, 0); Executed by:
| 460 | ||||||||||||||||||
552 | - | |||||||||||||||||||
553 | // Get the dst to std transtion details | - | ||||||||||||||||||
554 | QList<QByteArray> stdParts = parts.at(2).split('/'); | - | ||||||||||||||||||
555 | QByteArray stdDateRule = stdParts.at(0); | - | ||||||||||||||||||
556 | QTime stdTime; | - | ||||||||||||||||||
557 | if (stdParts.count() > 1)
| 292-340 | ||||||||||||||||||
558 | stdTime = parsePosixTransitionTime(stdParts.at(1)); executed 340 times by 2 tests: stdTime = parsePosixTransitionTime(stdParts.at(1)); Executed by:
| 340 | ||||||||||||||||||
559 | else | - | ||||||||||||||||||
560 | stdTime = QTime(2, 0, 0); executed 292 times by 1 test: stdTime = QTime(2, 0, 0); Executed by:
| 292 | ||||||||||||||||||
561 | - | |||||||||||||||||||
562 | for (int year = startYear; year <= endYear; ++year) {
| 632-1895 | ||||||||||||||||||
563 | QTimeZonePrivate::Data dstData; | - | ||||||||||||||||||
564 | QDateTime dst(calculatePosixDate(dstDateRule, year), dstTime, Qt::UTC); | - | ||||||||||||||||||
565 | dstData.atMSecsSinceEpoch = dst.toMSecsSinceEpoch() - (stdZone.second * 1000); | - | ||||||||||||||||||
566 | dstData.offsetFromUtc = dstZone.second; | - | ||||||||||||||||||
567 | dstData.standardTimeOffset = stdZone.second; | - | ||||||||||||||||||
568 | dstData.daylightTimeOffset = dstZone.second - stdZone.second; | - | ||||||||||||||||||
569 | dstData.abbreviation = dstZone.first; | - | ||||||||||||||||||
570 | QTimeZonePrivate::Data stdData; | - | ||||||||||||||||||
571 | QDateTime std(calculatePosixDate(stdDateRule, year), stdTime, Qt::UTC); | - | ||||||||||||||||||
572 | stdData.atMSecsSinceEpoch = std.toMSecsSinceEpoch() - (dstZone.second * 1000); | - | ||||||||||||||||||
573 | stdData.offsetFromUtc = stdZone.second; | - | ||||||||||||||||||
574 | stdData.standardTimeOffset = stdZone.second; | - | ||||||||||||||||||
575 | stdData.daylightTimeOffset = 0; | - | ||||||||||||||||||
576 | stdData.abbreviation = stdZone.first; | - | ||||||||||||||||||
577 | // Part of the high year will overflow | - | ||||||||||||||||||
578 | if (year == 292278994 && (dstData.atMSecsSinceEpoch < 0 || stdData.atMSecsSinceEpoch < 0)) {
| 0-1894 | ||||||||||||||||||
579 | if (dstData.atMSecsSinceEpoch > 0) {
| 0-1 | ||||||||||||||||||
580 | result << dstData; | - | ||||||||||||||||||
581 | } else if (stdData.atMSecsSinceEpoch > 0) { executed 1 time by 1 test: end of block Executed by:
| 0-1 | ||||||||||||||||||
582 | result << stdData; | - | ||||||||||||||||||
583 | } never executed: end of block | 0 | ||||||||||||||||||
584 | } else if (dst < std) { executed 1 time by 1 test: end of block Executed by:
| 1-1654 | ||||||||||||||||||
585 | result << dstData << stdData; | - | ||||||||||||||||||
586 | } else { executed 1654 times by 2 tests: end of block Executed by:
| 1654 | ||||||||||||||||||
587 | result << stdData << dstData; | - | ||||||||||||||||||
588 | } executed 240 times by 1 test: end of block Executed by:
| 240 | ||||||||||||||||||
589 | } | - | ||||||||||||||||||
590 | return result; executed 632 times by 2 tests: return result; Executed by:
| 632 | ||||||||||||||||||
591 | } | - | ||||||||||||||||||
592 | - | |||||||||||||||||||
593 | // Create the system default time zone | - | ||||||||||||||||||
594 | QTzTimeZonePrivate::QTzTimeZonePrivate() | - | ||||||||||||||||||
595 | #ifdef QT_USE_ICU | - | ||||||||||||||||||
596 | : m_icu(0) | - | ||||||||||||||||||
597 | #endif // QT_USE_ICU | - | ||||||||||||||||||
598 | { | - | ||||||||||||||||||
599 | init(systemTimeZoneId()); | - | ||||||||||||||||||
600 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
601 | - | |||||||||||||||||||
602 | // Create a named time zone | - | ||||||||||||||||||
603 | QTzTimeZonePrivate::QTzTimeZonePrivate(const QByteArray &ianaId) | - | ||||||||||||||||||
604 | #ifdef QT_USE_ICU | - | ||||||||||||||||||
605 | : m_icu(0) | - | ||||||||||||||||||
606 | #endif // QT_USE_ICU | - | ||||||||||||||||||
607 | { | - | ||||||||||||||||||
608 | init(ianaId); | - | ||||||||||||||||||
609 | } executed 455 times by 2 tests: end of block Executed by:
| 455 | ||||||||||||||||||
610 | - | |||||||||||||||||||
611 | QTzTimeZonePrivate::QTzTimeZonePrivate(const QTzTimeZonePrivate &other) | - | ||||||||||||||||||
612 | : QTimeZonePrivate(other), m_tranTimes(other.m_tranTimes), | - | ||||||||||||||||||
613 | m_tranRules(other.m_tranRules), m_abbreviations(other.m_abbreviations), | - | ||||||||||||||||||
614 | #ifdef QT_USE_ICU | - | ||||||||||||||||||
615 | m_icu(other.m_icu), | - | ||||||||||||||||||
616 | #endif // QT_USE_ICU | - | ||||||||||||||||||
617 | m_posixRule(other.m_posixRule) | - | ||||||||||||||||||
618 | { | - | ||||||||||||||||||
619 | } executed 20 times by 1 test: end of block Executed by:
| 20 | ||||||||||||||||||
620 | - | |||||||||||||||||||
621 | QTzTimeZonePrivate::~QTzTimeZonePrivate() | - | ||||||||||||||||||
622 | { | - | ||||||||||||||||||
623 | } | - | ||||||||||||||||||
624 | - | |||||||||||||||||||
625 | QTimeZonePrivate *QTzTimeZonePrivate::clone() | - | ||||||||||||||||||
626 | { | - | ||||||||||||||||||
627 | return new QTzTimeZonePrivate(*this); executed 20 times by 1 test: return new QTzTimeZonePrivate(*this); Executed by:
| 20 | ||||||||||||||||||
628 | } | - | ||||||||||||||||||
629 | - | |||||||||||||||||||
630 | void QTzTimeZonePrivate::init(const QByteArray &ianaId) | - | ||||||||||||||||||
631 | { | - | ||||||||||||||||||
632 | QFile tzif; | - | ||||||||||||||||||
633 | if (ianaId.isEmpty()) {
| 0-457 | ||||||||||||||||||
634 | // Open system tz | - | ||||||||||||||||||
635 | tzif.setFileName(QStringLiteral("/etc/localtime")); never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
636 | if (!tzif.open(QIODevice::ReadOnly))
| 0 | ||||||||||||||||||
637 | return; never executed: return; | 0 | ||||||||||||||||||
638 | } else { never executed: end of block | 0 | ||||||||||||||||||
639 | // Open named tz, try modern path first, if fails try legacy path | - | ||||||||||||||||||
640 | tzif.setFileName(QLatin1String("/usr/share/zoneinfo/") + QString::fromLocal8Bit(ianaId)); | - | ||||||||||||||||||
641 | if (!tzif.open(QIODevice::ReadOnly)) {
| 3-454 | ||||||||||||||||||
642 | tzif.setFileName(QLatin1String("/usr/lib/zoneinfo/") + QString::fromLocal8Bit(ianaId)); | - | ||||||||||||||||||
643 | if (!tzif.open(QIODevice::ReadOnly))
| 0-3 | ||||||||||||||||||
644 | return; executed 3 times by 2 tests: return; Executed by:
| 3 | ||||||||||||||||||
645 | } never executed: end of block | 0 | ||||||||||||||||||
646 | } executed 454 times by 2 tests: end of block Executed by:
| 454 | ||||||||||||||||||
647 | - | |||||||||||||||||||
648 | QDataStream ds(&tzif); | - | ||||||||||||||||||
649 | - | |||||||||||||||||||
650 | // Parse the old version block of data | - | ||||||||||||||||||
651 | bool ok = false; | - | ||||||||||||||||||
652 | QTzHeader hdr = parseTzHeader(ds, &ok); | - | ||||||||||||||||||
653 | if (!ok || ds.status() != QDataStream::Ok)
| 0-454 | ||||||||||||||||||
654 | return; never executed: return; | 0 | ||||||||||||||||||
655 | QVector<QTzTransition> tranList = parseTzTransitions(ds, hdr.tzh_timecnt, false); | - | ||||||||||||||||||
656 | if (ds.status() != QDataStream::Ok)
| 0-454 | ||||||||||||||||||
657 | return; never executed: return; | 0 | ||||||||||||||||||
658 | QVector<QTzType> typeList = parseTzTypes(ds, hdr.tzh_typecnt); | - | ||||||||||||||||||
659 | if (ds.status() != QDataStream::Ok)
| 0-454 | ||||||||||||||||||
660 | return; never executed: return; | 0 | ||||||||||||||||||
661 | QMap<int, QByteArray> abbrevMap = parseTzAbbreviations(ds, hdr.tzh_charcnt, typeList); | - | ||||||||||||||||||
662 | if (ds.status() != QDataStream::Ok)
| 0-454 | ||||||||||||||||||
663 | return; never executed: return; | 0 | ||||||||||||||||||
664 | parseTzLeapSeconds(ds, hdr.tzh_leapcnt, false); | - | ||||||||||||||||||
665 | if (ds.status() != QDataStream::Ok)
| 0-454 | ||||||||||||||||||
666 | return; never executed: return; | 0 | ||||||||||||||||||
667 | typeList = parseTzIndicators(ds, typeList, hdr.tzh_ttisstdcnt, hdr.tzh_ttisgmtcnt); | - | ||||||||||||||||||
668 | if (ds.status() != QDataStream::Ok)
| 0-454 | ||||||||||||||||||
669 | return; never executed: return; | 0 | ||||||||||||||||||
670 | - | |||||||||||||||||||
671 | // If version 2 then parse the second block of data | - | ||||||||||||||||||
672 | if (hdr.tzh_version == '2' || hdr.tzh_version == '3') {
| 0-447 | ||||||||||||||||||
673 | ok = false; | - | ||||||||||||||||||
674 | QTzHeader hdr2 = parseTzHeader(ds, &ok); | - | ||||||||||||||||||
675 | if (!ok || ds.status() != QDataStream::Ok)
| 0-454 | ||||||||||||||||||
676 | return; never executed: return; | 0 | ||||||||||||||||||
677 | tranList = parseTzTransitions(ds, hdr2.tzh_timecnt, true); | - | ||||||||||||||||||
678 | if (ds.status() != QDataStream::Ok)
| 0-454 | ||||||||||||||||||
679 | return; never executed: return; | 0 | ||||||||||||||||||
680 | typeList = parseTzTypes(ds, hdr2.tzh_typecnt); | - | ||||||||||||||||||
681 | if (ds.status() != QDataStream::Ok)
| 0-454 | ||||||||||||||||||
682 | return; never executed: return; | 0 | ||||||||||||||||||
683 | abbrevMap = parseTzAbbreviations(ds, hdr2.tzh_charcnt, typeList); | - | ||||||||||||||||||
684 | if (ds.status() != QDataStream::Ok)
| 0-454 | ||||||||||||||||||
685 | return; never executed: return; | 0 | ||||||||||||||||||
686 | parseTzLeapSeconds(ds, hdr2.tzh_leapcnt, true); | - | ||||||||||||||||||
687 | if (ds.status() != QDataStream::Ok)
| 0-454 | ||||||||||||||||||
688 | return; never executed: return; | 0 | ||||||||||||||||||
689 | typeList = parseTzIndicators(ds, typeList, hdr2.tzh_ttisstdcnt, hdr2.tzh_ttisgmtcnt); | - | ||||||||||||||||||
690 | if (ds.status() != QDataStream::Ok)
| 0-454 | ||||||||||||||||||
691 | return; never executed: return; | 0 | ||||||||||||||||||
692 | m_posixRule = parseTzPosixRule(ds); | - | ||||||||||||||||||
693 | if (ds.status() != QDataStream::Ok)
| 0-454 | ||||||||||||||||||
694 | return; never executed: return; | 0 | ||||||||||||||||||
695 | } executed 454 times by 2 tests: end of block Executed by:
| 454 | ||||||||||||||||||
696 | - | |||||||||||||||||||
697 | // Translate the TZ file into internal format | - | ||||||||||||||||||
698 | - | |||||||||||||||||||
699 | // Translate the array index based tz_abbrind into list index | - | ||||||||||||||||||
700 | m_abbreviations = abbrevMap.values(); | - | ||||||||||||||||||
701 | QList<int> abbrindList = abbrevMap.keys(); | - | ||||||||||||||||||
702 | for (int i = 0; i < typeList.size(); ++i)
| 454-2700 | ||||||||||||||||||
703 | typeList[i].tz_abbrind = abbrindList.indexOf(typeList.at(i).tz_abbrind); executed 2700 times by 2 tests: typeList[i].tz_abbrind = abbrindList.indexOf(typeList.at(i).tz_abbrind); Executed by:
| 2700 | ||||||||||||||||||
704 | - | |||||||||||||||||||
705 | // Offsets are stored as total offset, want to know separate UTC and DST offsets | - | ||||||||||||||||||
706 | // so find the first non-dst transition to use as base UTC Offset | - | ||||||||||||||||||
707 | int utcOffset = 0; | - | ||||||||||||||||||
708 | foreach (const QTzTransition &tran, tranList) { | - | ||||||||||||||||||
709 | if (!typeList.at(tran.tz_typeind).tz_isdst) {
| 3-454 | ||||||||||||||||||
710 | utcOffset = typeList.at(tran.tz_typeind).tz_gmtoff; | - | ||||||||||||||||||
711 | break; executed 454 times by 2 tests: break; Executed by:
| 454 | ||||||||||||||||||
712 | } | - | ||||||||||||||||||
713 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
714 | - | |||||||||||||||||||
715 | // Now for each transition time calculate our rule and save them | - | ||||||||||||||||||
716 | m_tranTimes.reserve(tranList.count()); | - | ||||||||||||||||||
717 | foreach (const QTzTransition &tz_tran, tranList) { | - | ||||||||||||||||||
718 | QTzTransitionTime tran; | - | ||||||||||||||||||
719 | QTzTransitionRule rule; | - | ||||||||||||||||||
720 | const QTzType tz_type = typeList.at(tz_tran.tz_typeind); | - | ||||||||||||||||||
721 | - | |||||||||||||||||||
722 | // Calculate the associated Rule | - | ||||||||||||||||||
723 | if (!tz_type.tz_isdst)
| 15309-16244 | ||||||||||||||||||
724 | utcOffset = tz_type.tz_gmtoff; executed 16244 times by 2 tests: utcOffset = tz_type.tz_gmtoff; Executed by:
| 16244 | ||||||||||||||||||
725 | rule.stdOffset = utcOffset; | - | ||||||||||||||||||
726 | rule.dstOffset = tz_type.tz_gmtoff - utcOffset; | - | ||||||||||||||||||
727 | rule.abbreviationIndex = tz_type.tz_abbrind; | - | ||||||||||||||||||
728 | // If the rule already exist then use that, otherwise add it | - | ||||||||||||||||||
729 | int ruleIndex = m_tranRules.indexOf(rule); | - | ||||||||||||||||||
730 | if (ruleIndex == -1) {
| 1704-29849 | ||||||||||||||||||
731 | m_tranRules.append(rule); | - | ||||||||||||||||||
732 | tran.ruleIndex = m_tranRules.size() - 1; | - | ||||||||||||||||||
733 | } else { executed 1704 times by 2 tests: end of block Executed by:
| 1704 | ||||||||||||||||||
734 | tran.ruleIndex = ruleIndex; | - | ||||||||||||||||||
735 | } executed 29849 times by 2 tests: end of block Executed by:
| 29849 | ||||||||||||||||||
736 | - | |||||||||||||||||||
737 | // TODO convert to UTC if not in UTC | - | ||||||||||||||||||
738 | if (tz_type.tz_ttisgmt)
| 8759-22794 | ||||||||||||||||||
739 | tran.atMSecsSinceEpoch = tz_tran.tz_time * 1000; executed 8759 times by 2 tests: tran.atMSecsSinceEpoch = tz_tran.tz_time * 1000; Executed by:
| 8759 | ||||||||||||||||||
740 | else if (tz_type.tz_ttisstd)
| 7286-15508 | ||||||||||||||||||
741 | tran.atMSecsSinceEpoch = tz_tran.tz_time * 1000; executed 7286 times by 2 tests: tran.atMSecsSinceEpoch = tz_tran.tz_time * 1000; Executed by:
| 7286 | ||||||||||||||||||
742 | else | - | ||||||||||||||||||
743 | tran.atMSecsSinceEpoch = tz_tran.tz_time * 1000; executed 15508 times by 2 tests: tran.atMSecsSinceEpoch = tz_tran.tz_time * 1000; Executed by:
| 15508 | ||||||||||||||||||
744 | - | |||||||||||||||||||
745 | m_tranTimes.append(tran); | - | ||||||||||||||||||
746 | } executed 31553 times by 2 tests: end of block Executed by:
| 31553 | ||||||||||||||||||
747 | - | |||||||||||||||||||
748 | if (ianaId.isEmpty())
| 0-454 | ||||||||||||||||||
749 | m_id = systemTimeZoneId(); never executed: m_id = systemTimeZoneId(); | 0 | ||||||||||||||||||
750 | else | - | ||||||||||||||||||
751 | m_id = ianaId; executed 454 times by 2 tests: m_id = ianaId; Executed by:
| 454 | ||||||||||||||||||
752 | } | - | ||||||||||||||||||
753 | - | |||||||||||||||||||
754 | QLocale::Country QTzTimeZonePrivate::country() const | - | ||||||||||||||||||
755 | { | - | ||||||||||||||||||
756 | return tzZones->value(m_id).country; executed 422 times by 1 test: return tzZones->value(m_id).country; Executed by:
| 422 | ||||||||||||||||||
757 | } | - | ||||||||||||||||||
758 | - | |||||||||||||||||||
759 | QString QTzTimeZonePrivate::comment() const | - | ||||||||||||||||||
760 | { | - | ||||||||||||||||||
761 | return QString::fromUtf8(tzZones->value(m_id).comment); executed 421 times by 1 test: return QString::fromUtf8(tzZones->value(m_id).comment); Executed by:
| 421 | ||||||||||||||||||
762 | } | - | ||||||||||||||||||
763 | - | |||||||||||||||||||
764 | QString QTzTimeZonePrivate::displayName(qint64 atMSecsSinceEpoch, | - | ||||||||||||||||||
765 | QTimeZone::NameType nameType, | - | ||||||||||||||||||
766 | const QLocale &locale) const | - | ||||||||||||||||||
767 | { | - | ||||||||||||||||||
768 | #ifdef QT_USE_ICU | - | ||||||||||||||||||
769 | if (!m_icu)
| 0-421 | ||||||||||||||||||
770 | m_icu = new QIcuTimeZonePrivate(m_id); executed 421 times by 1 test: m_icu = new QIcuTimeZonePrivate(m_id); Executed by:
| 421 | ||||||||||||||||||
771 | // TODO small risk may not match if tran times differ due to outdated files | - | ||||||||||||||||||
772 | // TODO Some valid TZ names are not valid ICU names, use translation table? | - | ||||||||||||||||||
773 | if (m_icu->isValid())
| 10-411 | ||||||||||||||||||
774 | return m_icu->displayName(atMSecsSinceEpoch, nameType, locale); executed 411 times by 1 test: return m_icu->displayName(atMSecsSinceEpoch, nameType, locale); Executed by:
| 411 | ||||||||||||||||||
775 | #else | - | ||||||||||||||||||
776 | Q_UNUSED(nameType) | - | ||||||||||||||||||
777 | Q_UNUSED(locale) | - | ||||||||||||||||||
778 | #endif // QT_USE_ICU | - | ||||||||||||||||||
779 | return abbreviation(atMSecsSinceEpoch); executed 10 times by 1 test: return abbreviation(atMSecsSinceEpoch); Executed by:
| 10 | ||||||||||||||||||
780 | } | - | ||||||||||||||||||
781 | - | |||||||||||||||||||
782 | QString QTzTimeZonePrivate::displayName(QTimeZone::TimeType timeType, | - | ||||||||||||||||||
783 | QTimeZone::NameType nameType, | - | ||||||||||||||||||
784 | const QLocale &locale) const | - | ||||||||||||||||||
785 | { | - | ||||||||||||||||||
786 | #ifdef QT_USE_ICU | - | ||||||||||||||||||
787 | if (!m_icu)
| 0-842 | ||||||||||||||||||
788 | m_icu = new QIcuTimeZonePrivate(m_id); never executed: m_icu = new QIcuTimeZonePrivate(m_id); | 0 | ||||||||||||||||||
789 | // TODO small risk may not match if tran times differ due to outdated files | - | ||||||||||||||||||
790 | // TODO Some valid TZ names are not valid ICU names, use translation table? | - | ||||||||||||||||||
791 | if (m_icu->isValid())
| 20-822 | ||||||||||||||||||
792 | return m_icu->displayName(timeType, nameType, locale); executed 822 times by 1 test: return m_icu->displayName(timeType, nameType, locale); Executed by:
| 822 | ||||||||||||||||||
793 | #else | - | ||||||||||||||||||
794 | Q_UNUSED(timeType) | - | ||||||||||||||||||
795 | Q_UNUSED(nameType) | - | ||||||||||||||||||
796 | Q_UNUSED(locale) | - | ||||||||||||||||||
797 | #endif // QT_USE_ICU | - | ||||||||||||||||||
798 | // If no ICU available then have to use abbreviations instead | - | ||||||||||||||||||
799 | // Abbreviations don't have GenericTime | - | ||||||||||||||||||
800 | if (timeType == QTimeZone::GenericTime)
| 0-20 | ||||||||||||||||||
801 | timeType = QTimeZone::StandardTime; never executed: timeType = QTimeZone::StandardTime; | 0 | ||||||||||||||||||
802 | - | |||||||||||||||||||
803 | // Get current tran, if valid and is what we want, then use it | - | ||||||||||||||||||
804 | const qint64 currentMSecs = QDateTime::currentMSecsSinceEpoch(); | - | ||||||||||||||||||
805 | QTimeZonePrivate::Data tran = data(currentMSecs); | - | ||||||||||||||||||
806 | if (tran.atMSecsSinceEpoch != invalidMSecs()
| 0-20 | ||||||||||||||||||
807 | && ((timeType == QTimeZone::DaylightTime && tran.daylightTimeOffset != 0)
| 1-10 | ||||||||||||||||||
808 | || (timeType == QTimeZone::StandardTime && tran.daylightTimeOffset == 0))) {
| 1-10 | ||||||||||||||||||
809 | return tran.abbreviation; executed 10 times by 1 test: return tran.abbreviation; Executed by:
| 10 | ||||||||||||||||||
810 | } | - | ||||||||||||||||||
811 | - | |||||||||||||||||||
812 | // Otherwise get next tran and if valid and is what we want, then use it | - | ||||||||||||||||||
813 | tran = nextTransition(currentMSecs); | - | ||||||||||||||||||
814 | if (tran.atMSecsSinceEpoch != invalidMSecs()
| 1-9 | ||||||||||||||||||
815 | && ((timeType == QTimeZone::DaylightTime && tran.daylightTimeOffset != 0)
| 0-1 | ||||||||||||||||||
816 | || (timeType == QTimeZone::StandardTime && tran.daylightTimeOffset == 0))) {
| 0-1 | ||||||||||||||||||
817 | return tran.abbreviation; executed 1 time by 1 test: return tran.abbreviation; Executed by:
| 1 | ||||||||||||||||||
818 | } | - | ||||||||||||||||||
819 | - | |||||||||||||||||||
820 | // Otherwise get prev tran and if valid and is what we want, then use it | - | ||||||||||||||||||
821 | tran = previousTransition(currentMSecs); | - | ||||||||||||||||||
822 | if (tran.atMSecsSinceEpoch != invalidMSecs())
| 0-9 | ||||||||||||||||||
823 | tran = previousTransition(tran.atMSecsSinceEpoch); executed 9 times by 1 test: tran = previousTransition(tran.atMSecsSinceEpoch); Executed by:
| 9 | ||||||||||||||||||
824 | if (tran.atMSecsSinceEpoch != invalidMSecs()
| 0-9 | ||||||||||||||||||
825 | && ((timeType == QTimeZone::DaylightTime && tran.daylightTimeOffset != 0)
| 0-9 | ||||||||||||||||||
826 | || (timeType == QTimeZone::StandardTime && tran.daylightTimeOffset == 0))) {
| 0-9 | ||||||||||||||||||
827 | return tran.abbreviation; never executed: return tran.abbreviation; | 0 | ||||||||||||||||||
828 | } | - | ||||||||||||||||||
829 | - | |||||||||||||||||||
830 | // Otherwise is strange sequence, so work backwards through trans looking for first match, if any | - | ||||||||||||||||||
831 | for (int i = m_tranTimes.size() - 1; i >= 0; --i) {
| 1-41 | ||||||||||||||||||
832 | if (m_tranTimes.at(i).atMSecsSinceEpoch <= currentMSecs) {
| 0-41 | ||||||||||||||||||
833 | tran = dataForTzTransition(m_tranTimes.at(i)); | - | ||||||||||||||||||
834 | if ((timeType == QTimeZone::DaylightTime && tran.daylightTimeOffset != 0)
| 0-41 | ||||||||||||||||||
835 | || (timeType == QTimeZone::StandardTime && tran.daylightTimeOffset == 0)) {
| 0-33 | ||||||||||||||||||
836 | return tran.abbreviation; executed 8 times by 1 test: return tran.abbreviation; Executed by:
| 8 | ||||||||||||||||||
837 | } | - | ||||||||||||||||||
838 | } executed 33 times by 1 test: end of block Executed by:
| 33 | ||||||||||||||||||
839 | } executed 33 times by 1 test: end of block Executed by:
| 33 | ||||||||||||||||||
840 | - | |||||||||||||||||||
841 | // Otherwise if no match use current data | - | ||||||||||||||||||
842 | return data(currentMSecs).abbreviation; executed 1 time by 1 test: return data(currentMSecs).abbreviation; Executed by:
| 1 | ||||||||||||||||||
843 | } | - | ||||||||||||||||||
844 | - | |||||||||||||||||||
845 | QString QTzTimeZonePrivate::abbreviation(qint64 atMSecsSinceEpoch) const | - | ||||||||||||||||||
846 | { | - | ||||||||||||||||||
847 | return data(atMSecsSinceEpoch).abbreviation; executed 860 times by 2 tests: return data(atMSecsSinceEpoch).abbreviation; Executed by:
| 860 | ||||||||||||||||||
848 | } | - | ||||||||||||||||||
849 | - | |||||||||||||||||||
850 | int QTzTimeZonePrivate::offsetFromUtc(qint64 atMSecsSinceEpoch) const | - | ||||||||||||||||||
851 | { | - | ||||||||||||||||||
852 | const QTimeZonePrivate::Data tran = data(atMSecsSinceEpoch); | - | ||||||||||||||||||
853 | return tran.standardTimeOffset + tran.daylightTimeOffset; executed 441 times by 2 tests: return tran.standardTimeOffset + tran.daylightTimeOffset; Executed by:
| 441 | ||||||||||||||||||
854 | } | - | ||||||||||||||||||
855 | - | |||||||||||||||||||
856 | int QTzTimeZonePrivate::standardTimeOffset(qint64 atMSecsSinceEpoch) const | - | ||||||||||||||||||
857 | { | - | ||||||||||||||||||
858 | return data(atMSecsSinceEpoch).standardTimeOffset; executed 693 times by 2 tests: return data(atMSecsSinceEpoch).standardTimeOffset; Executed by:
| 693 | ||||||||||||||||||
859 | } | - | ||||||||||||||||||
860 | - | |||||||||||||||||||
861 | int QTzTimeZonePrivate::daylightTimeOffset(qint64 atMSecsSinceEpoch) const | - | ||||||||||||||||||
862 | { | - | ||||||||||||||||||
863 | return data(atMSecsSinceEpoch).daylightTimeOffset; executed 588 times by 2 tests: return data(atMSecsSinceEpoch).daylightTimeOffset; Executed by:
| 588 | ||||||||||||||||||
864 | } | - | ||||||||||||||||||
865 | - | |||||||||||||||||||
866 | bool QTzTimeZonePrivate::hasDaylightTime() const | - | ||||||||||||||||||
867 | { | - | ||||||||||||||||||
868 | // TODO Perhaps cache as frequently accessed? | - | ||||||||||||||||||
869 | foreach (const QTzTransitionRule &rule, m_tranRules) { | - | ||||||||||||||||||
870 | if (rule.dstOffset != 0)
| 1519-3635 | ||||||||||||||||||
871 | return true; executed 1519 times by 2 tests: return true; Executed by:
| 1519 | ||||||||||||||||||
872 | } executed 3635 times by 2 tests: end of block Executed by:
| 3635 | ||||||||||||||||||
873 | return false; executed 660 times by 1 test: return false; Executed by:
| 660 | ||||||||||||||||||
874 | } | - | ||||||||||||||||||
875 | - | |||||||||||||||||||
876 | bool QTzTimeZonePrivate::isDaylightTime(qint64 atMSecsSinceEpoch) const | - | ||||||||||||||||||
877 | { | - | ||||||||||||||||||
878 | return (daylightTimeOffset(atMSecsSinceEpoch) != 0); executed 295 times by 2 tests: return (daylightTimeOffset(atMSecsSinceEpoch) != 0); Executed by:
| 295 | ||||||||||||||||||
879 | } | - | ||||||||||||||||||
880 | - | |||||||||||||||||||
881 | QTimeZonePrivate::Data QTzTimeZonePrivate::dataForTzTransition(QTzTransitionTime tran) const | - | ||||||||||||||||||
882 | { | - | ||||||||||||||||||
883 | QTimeZonePrivate::Data data; | - | ||||||||||||||||||
884 | data.atMSecsSinceEpoch = tran.atMSecsSinceEpoch; | - | ||||||||||||||||||
885 | QTzTransitionRule rule = m_tranRules.at(tran.ruleIndex); | - | ||||||||||||||||||
886 | data.standardTimeOffset = rule.stdOffset; | - | ||||||||||||||||||
887 | data.daylightTimeOffset = rule.dstOffset; | - | ||||||||||||||||||
888 | data.offsetFromUtc = rule.stdOffset + rule.dstOffset; | - | ||||||||||||||||||
889 | data.abbreviation = QString::fromUtf8(m_abbreviations.at(rule.abbreviationIndex)); | - | ||||||||||||||||||
890 | return data; executed 9024 times by 2 tests: return data; Executed by:
| 9024 | ||||||||||||||||||
891 | } | - | ||||||||||||||||||
892 | - | |||||||||||||||||||
893 | QTimeZonePrivate::Data QTzTimeZonePrivate::data(qint64 forMSecsSinceEpoch) const | - | ||||||||||||||||||
894 | { | - | ||||||||||||||||||
895 | // If the required time is after the last transition and we have a POSIX rule then use it | - | ||||||||||||||||||
896 | if (m_tranTimes.size() > 0 && m_tranTimes.last().atMSecsSinceEpoch < forMSecsSinceEpoch
| 0-3297 | ||||||||||||||||||
897 | && !m_posixRule.isEmpty() && forMSecsSinceEpoch >= 0) {
| 0-2042 | ||||||||||||||||||
898 | const int year = QDateTime::fromMSecsSinceEpoch(forMSecsSinceEpoch, Qt::UTC).date().year(); | - | ||||||||||||||||||
899 | QVector<QTimeZonePrivate::Data> posixTrans = | - | ||||||||||||||||||
900 | calculatePosixTransitions(m_posixRule, year - 1, year + 1, | - | ||||||||||||||||||
901 | m_tranTimes.last().atMSecsSinceEpoch); | - | ||||||||||||||||||
902 | for (int i = posixTrans.size() - 1; i >= 0; --i) {
| 0-2059 | ||||||||||||||||||
903 | if (posixTrans.at(i).atMSecsSinceEpoch <= forMSecsSinceEpoch) {
| 17-2042 | ||||||||||||||||||
904 | QTimeZonePrivate::Data data = posixTrans.at(i); | - | ||||||||||||||||||
905 | data.atMSecsSinceEpoch = forMSecsSinceEpoch; | - | ||||||||||||||||||
906 | return data; executed 2042 times by 2 tests: return data; Executed by:
| 2042 | ||||||||||||||||||
907 | } | - | ||||||||||||||||||
908 | } executed 17 times by 2 tests: end of block Executed by:
| 17 | ||||||||||||||||||
909 | } never executed: end of block | 0 | ||||||||||||||||||
910 | - | |||||||||||||||||||
911 | // Otherwise if we can find a valid tran then use its rule | - | ||||||||||||||||||
912 | for (int i = m_tranTimes.size() - 1; i >= 0; --i) {
| 3-54031 | ||||||||||||||||||
913 | if (m_tranTimes.at(i).atMSecsSinceEpoch <= forMSecsSinceEpoch) {
| 1252-52779 | ||||||||||||||||||
914 | Data data = dataForTzTransition(m_tranTimes.at(i)); | - | ||||||||||||||||||
915 | data.atMSecsSinceEpoch = forMSecsSinceEpoch; | - | ||||||||||||||||||
916 | return data; executed 1252 times by 2 tests: return data; Executed by:
| 1252 | ||||||||||||||||||
917 | } | - | ||||||||||||||||||
918 | } executed 52779 times by 2 tests: end of block Executed by:
| 52779 | ||||||||||||||||||
919 | - | |||||||||||||||||||
920 | // Otherwise use the earliest transition we have | - | ||||||||||||||||||
921 | if (m_tranTimes.size() > 0) {
| 0-3 | ||||||||||||||||||
922 | Data data = dataForTzTransition(m_tranTimes.at(0)); | - | ||||||||||||||||||
923 | data.atMSecsSinceEpoch = forMSecsSinceEpoch; | - | ||||||||||||||||||
924 | return data; executed 3 times by 2 tests: return data; Executed by:
| 3 | ||||||||||||||||||
925 | } | - | ||||||||||||||||||
926 | - | |||||||||||||||||||
927 | // Otherwise we have no rules, so probably an invalid tz, so return invalid data | - | ||||||||||||||||||
928 | return invalidData(); never executed: return invalidData(); | 0 | ||||||||||||||||||
929 | } | - | ||||||||||||||||||
930 | - | |||||||||||||||||||
931 | bool QTzTimeZonePrivate::hasTransitions() const | - | ||||||||||||||||||
932 | { | - | ||||||||||||||||||
933 | return true; executed 5705 times by 2 tests: return true; Executed by:
| 5705 | ||||||||||||||||||
934 | } | - | ||||||||||||||||||
935 | - | |||||||||||||||||||
936 | QTimeZonePrivate::Data QTzTimeZonePrivate::nextTransition(qint64 afterMSecsSinceEpoch) const | - | ||||||||||||||||||
937 | { | - | ||||||||||||||||||
938 | // If the required time is after the last transition and we have a POSIX rule then use it | - | ||||||||||||||||||
939 | if (m_tranTimes.size() > 0 && m_tranTimes.last().atMSecsSinceEpoch < afterMSecsSinceEpoch
| 0-8488 | ||||||||||||||||||
940 | && !m_posixRule.isEmpty() && afterMSecsSinceEpoch >= 0) {
| 0-1138 | ||||||||||||||||||
941 | const int year = QDateTime::fromMSecsSinceEpoch(afterMSecsSinceEpoch, Qt::UTC).date().year(); | - | ||||||||||||||||||
942 | QVector<QTimeZonePrivate::Data> posixTrans = | - | ||||||||||||||||||
943 | calculatePosixTransitions(m_posixRule, year - 1, year + 1, | - | ||||||||||||||||||
944 | m_tranTimes.last().atMSecsSinceEpoch); | - | ||||||||||||||||||
945 | for (int i = 0; i < posixTrans.size(); ++i) {
| 807-1905 | ||||||||||||||||||
946 | if (posixTrans.at(i).atMSecsSinceEpoch > afterMSecsSinceEpoch)
| 313-1592 | ||||||||||||||||||
947 | return posixTrans.at(i); executed 313 times by 2 tests: return posixTrans.at(i); Executed by:
| 313 | ||||||||||||||||||
948 | } executed 1592 times by 2 tests: end of block Executed by:
| 1592 | ||||||||||||||||||
949 | } executed 807 times by 1 test: end of block Executed by:
| 807 | ||||||||||||||||||
950 | - | |||||||||||||||||||
951 | // Otherwise if we can find a valid tran then use its rule | - | ||||||||||||||||||
952 | for (int i = 0; i < m_tranTimes.size(); ++i) {
| 1042-275638 | ||||||||||||||||||
953 | if (m_tranTimes.at(i).atMSecsSinceEpoch > afterMSecsSinceEpoch) {
| 7133-268505 | ||||||||||||||||||
954 | return dataForTzTransition(m_tranTimes.at(i)); executed 7133 times by 2 tests: return dataForTzTransition(m_tranTimes.at(i)); Executed by:
| 7133 | ||||||||||||||||||
955 | } | - | ||||||||||||||||||
956 | } executed 268505 times by 2 tests: end of block Executed by:
| 268505 | ||||||||||||||||||
957 | - | |||||||||||||||||||
958 | // Otherwise we have no rule, or there is no next transition, so return invalid data | - | ||||||||||||||||||
959 | return invalidData(); executed 1042 times by 2 tests: return invalidData(); Executed by:
| 1042 | ||||||||||||||||||
960 | } | - | ||||||||||||||||||
961 | - | |||||||||||||||||||
962 | QTimeZonePrivate::Data QTzTimeZonePrivate::previousTransition(qint64 beforeMSecsSinceEpoch) const | - | ||||||||||||||||||
963 | { | - | ||||||||||||||||||
964 | // If the required time is after the last transition and we have a POSIX rule then use it | - | ||||||||||||||||||
965 | if (m_tranTimes.size() > 0 && m_tranTimes.last().atMSecsSinceEpoch < beforeMSecsSinceEpoch
| 0-2796 | ||||||||||||||||||
966 | && !m_posixRule.isEmpty() && beforeMSecsSinceEpoch > 0) {
| 0-1355 | ||||||||||||||||||
967 | const int year = QDateTime::fromMSecsSinceEpoch(beforeMSecsSinceEpoch, Qt::UTC).date().year(); | - | ||||||||||||||||||
968 | QVector<QTimeZonePrivate::Data> posixTrans = | - | ||||||||||||||||||
969 | calculatePosixTransitions(m_posixRule, year - 1, year + 1, | - | ||||||||||||||||||
970 | m_tranTimes.last().atMSecsSinceEpoch); | - | ||||||||||||||||||
971 | for (int i = posixTrans.size() - 1; i >= 0; --i) {
| 0-2450 | ||||||||||||||||||
972 | if (posixTrans.at(i).atMSecsSinceEpoch < beforeMSecsSinceEpoch)
| 1095-1355 | ||||||||||||||||||
973 | return posixTrans.at(i); executed 1355 times by 2 tests: return posixTrans.at(i); Executed by:
| 1355 | ||||||||||||||||||
974 | } executed 1095 times by 2 tests: end of block Executed by:
| 1095 | ||||||||||||||||||
975 | } never executed: end of block | 0 | ||||||||||||||||||
976 | - | |||||||||||||||||||
977 | // Otherwise if we can find a valid tran then use its rule | - | ||||||||||||||||||
978 | for (int i = m_tranTimes.size() - 1; i >= 0; --i) {
| 846-82123 | ||||||||||||||||||
979 | if (m_tranTimes.at(i).atMSecsSinceEpoch < beforeMSecsSinceEpoch) {
| 595-81528 | ||||||||||||||||||
980 | return dataForTzTransition(m_tranTimes.at(i)); executed 595 times by 2 tests: return dataForTzTransition(m_tranTimes.at(i)); Executed by:
| 595 | ||||||||||||||||||
981 | } | - | ||||||||||||||||||
982 | } executed 81528 times by 2 tests: end of block Executed by:
| 81528 | ||||||||||||||||||
983 | - | |||||||||||||||||||
984 | // Otherwise we have no rule, so return invalid data | - | ||||||||||||||||||
985 | return invalidData(); executed 846 times by 2 tests: return invalidData(); Executed by:
| 846 | ||||||||||||||||||
986 | } | - | ||||||||||||||||||
987 | - | |||||||||||||||||||
988 | // TODO Could cache the value and monitor the required files for any changes | - | ||||||||||||||||||
989 | QByteArray QTzTimeZonePrivate::systemTimeZoneId() const | - | ||||||||||||||||||
990 | { | - | ||||||||||||||||||
991 | // Check TZ env var first, if not populated try find it | - | ||||||||||||||||||
992 | QByteArray ianaId = qgetenv("TZ"); | - | ||||||||||||||||||
993 | if (!ianaId.isEmpty() && ianaId.at(0) == ':')
| 0-2 | ||||||||||||||||||
994 | ianaId = ianaId.mid(1); never executed: ianaId = ianaId.mid(1); | 0 | ||||||||||||||||||
995 | - | |||||||||||||||||||
996 | // The TZ value can be ":/etc/localtime" which libc considers | - | ||||||||||||||||||
997 | // to be a "default timezone", in which case it will be read | - | ||||||||||||||||||
998 | // by one of the blocks below, so unset it here so it is not | - | ||||||||||||||||||
999 | // considered as a valid/found ianaId | - | ||||||||||||||||||
1000 | if (ianaId == "/etc/localtime")
| 0-2 | ||||||||||||||||||
1001 | ianaId.clear(); never executed: ianaId.clear(); | 0 | ||||||||||||||||||
1002 | - | |||||||||||||||||||
1003 | // On Debian Etch and later /etc/localtime is real file with name held in /etc/timezone | - | ||||||||||||||||||
1004 | if (ianaId.isEmpty()) {
| 0-2 | ||||||||||||||||||
1005 | QFile tzif(QStringLiteral("/etc/timezone")); executed 2 times by 1 test: return qstring_literal_temp; Executed by:
| 2 | ||||||||||||||||||
1006 | if (tzif.open(QIODevice::ReadOnly)) {
| 0-2 | ||||||||||||||||||
1007 | // TODO QTextStream inefficient, replace later | - | ||||||||||||||||||
1008 | QTextStream ts(&tzif); | - | ||||||||||||||||||
1009 | if (!ts.atEnd())
| 0-2 | ||||||||||||||||||
1010 | ianaId = ts.readLine().toUtf8(); executed 2 times by 1 test: ianaId = ts.readLine().toUtf8(); Executed by:
| 2 | ||||||||||||||||||
1011 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
1012 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
1013 | - | |||||||||||||||||||
1014 | // On other distros /etc/localtime is symlink to real file so can extract name from the path | - | ||||||||||||||||||
1015 | if (ianaId.isEmpty()) {
| 0-2 | ||||||||||||||||||
1016 | const QString path = QFile::symLinkTarget(QStringLiteral("/etc/localtime")); never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
1017 | if (!path.isEmpty()) {
| 0 | ||||||||||||||||||
1018 | // /etc/localtime is a symlink to the current TZ file, so extract from path | - | ||||||||||||||||||
1019 | int index = path.indexOf(QLatin1String("/zoneinfo/")) + 10; | - | ||||||||||||||||||
1020 | ianaId = path.mid(index).toUtf8(); | - | ||||||||||||||||||
1021 | } never executed: end of block | 0 | ||||||||||||||||||
1022 | } never executed: end of block | 0 | ||||||||||||||||||
1023 | - | |||||||||||||||||||
1024 | // On some Red Hat distros /etc/localtime is real file with name held in /etc/sysconfig/clock | - | ||||||||||||||||||
1025 | // in a line like ZONE="Europe/Oslo" or TIMEZONE="Europe/Oslo" | - | ||||||||||||||||||
1026 | if (ianaId.isEmpty()) {
| 0-2 | ||||||||||||||||||
1027 | QFile tzif(QStringLiteral("/etc/sysconfig/clock")); never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
1028 | if (tzif.open(QIODevice::ReadOnly)) {
| 0 | ||||||||||||||||||
1029 | // TODO QTextStream inefficient, replace later | - | ||||||||||||||||||
1030 | QTextStream ts(&tzif); | - | ||||||||||||||||||
1031 | QString line; | - | ||||||||||||||||||
1032 | while (ianaId.isEmpty() && !ts.atEnd() && ts.status() == QTextStream::Ok) {
| 0 | ||||||||||||||||||
1033 | line = ts.readLine(); | - | ||||||||||||||||||
1034 | if (line.startsWith(QLatin1String("ZONE="))) {
| 0 | ||||||||||||||||||
1035 | ianaId = line.mid(6, line.size() - 7).toUtf8(); | - | ||||||||||||||||||
1036 | } else if (line.startsWith(QLatin1String("TIMEZONE="))) { never executed: end of block
| 0 | ||||||||||||||||||
1037 | ianaId = line.mid(10, line.size() - 11).toUtf8(); | - | ||||||||||||||||||
1038 | } never executed: end of block | 0 | ||||||||||||||||||
1039 | } never executed: end of block | 0 | ||||||||||||||||||
1040 | } never executed: end of block | 0 | ||||||||||||||||||
1041 | } never executed: end of block | 0 | ||||||||||||||||||
1042 | - | |||||||||||||||||||
1043 | // Give up for now and return UTC | - | ||||||||||||||||||
1044 | if (ianaId.isEmpty())
| 0-2 | ||||||||||||||||||
1045 | ianaId = utcQByteArray(); never executed: ianaId = utcQByteArray(); | 0 | ||||||||||||||||||
1046 | - | |||||||||||||||||||
1047 | return ianaId; executed 2 times by 1 test: return ianaId; Executed by:
| 2 | ||||||||||||||||||
1048 | } | - | ||||||||||||||||||
1049 | - | |||||||||||||||||||
1050 | QList<QByteArray> QTzTimeZonePrivate::availableTimeZoneIds() const | - | ||||||||||||||||||
1051 | { | - | ||||||||||||||||||
1052 | QList<QByteArray> result = tzZones->keys(); | - | ||||||||||||||||||
1053 | std::sort(result.begin(), result.end()); | - | ||||||||||||||||||
1054 | return result; executed 467 times by 1 test: return result; Executed by:
| 467 | ||||||||||||||||||
1055 | } | - | ||||||||||||||||||
1056 | - | |||||||||||||||||||
1057 | QList<QByteArray> QTzTimeZonePrivate::availableTimeZoneIds(QLocale::Country country) const | - | ||||||||||||||||||
1058 | { | - | ||||||||||||||||||
1059 | // TODO AnyCountry | - | ||||||||||||||||||
1060 | QList<QByteArray> result; | - | ||||||||||||||||||
1061 | foreach (const QByteArray &key, tzZones->keys()) { | - | ||||||||||||||||||
1062 | if (tzZones->value(key).country == country)
| 29-392 | ||||||||||||||||||
1063 | result << key; executed 29 times by 1 test: result << key; Executed by:
| 29 | ||||||||||||||||||
1064 | } executed 421 times by 1 test: end of block Executed by:
| 421 | ||||||||||||||||||
1065 | std::sort(result.begin(), result.end()); | - | ||||||||||||||||||
1066 | return result; executed 1 time by 1 test: return result; Executed by:
| 1 | ||||||||||||||||||
1067 | } | - | ||||||||||||||||||
1068 | - | |||||||||||||||||||
1069 | QT_END_NAMESPACE | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |