Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qtimezoneprivate_tz.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | - | |||||||||||||
6 | - | |||||||||||||
7 | - | |||||||||||||
8 | - | |||||||||||||
9 | - | |||||||||||||
10 | - | |||||||||||||
11 | - | |||||||||||||
12 | - | |||||||||||||
13 | - | |||||||||||||
14 | - | |||||||||||||
15 | struct QTzTimeZone { | - | ||||||||||||
16 | QLocale::Country country; | - | ||||||||||||
17 | QByteArray comment; | - | ||||||||||||
18 | }; | - | ||||||||||||
19 | - | |||||||||||||
20 | - | |||||||||||||
21 | typedef QHash<QByteArray, QTzTimeZone> QTzTimeZoneHash; | - | ||||||||||||
22 | - | |||||||||||||
23 | - | |||||||||||||
24 | static QTzTimeZoneHash loadTzTimeZones() | - | ||||||||||||
25 | { | - | ||||||||||||
26 | QString path = ([]() -> QString { enum { Size = sizeof(u"" "/usr/share/zoneinfo/zone.tab")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "/usr/share/zoneinfo/zone.tab" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()); | - | ||||||||||||
27 | if (!QFile::exists(path)
| 0-1 | ||||||||||||
28 | 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 never executed: qstring_literal_temp;return qstring_literal_temp; never executed: }());return qstring_literal_temp; 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; }()); | 0 | ||||||||||||
29 | - | |||||||||||||
30 | QFile tzif(path); | - | ||||||||||||
31 | if (!tzif.open(QIODevice::ReadOnly)
| 0-1 | ||||||||||||
32 | return never executed: QTzTimeZoneHash();return QTzTimeZoneHash(); never executed: return QTzTimeZoneHash(); | 0 | ||||||||||||
33 | - | |||||||||||||
34 | QTzTimeZoneHash zonesHash; | - | ||||||||||||
35 | - | |||||||||||||
36 | QTextStream ts(&tzif); | - | ||||||||||||
37 | while (!ts.atEnd()
| 1-445 | ||||||||||||
38 | const QString line = ts.readLine(); | - | ||||||||||||
39 | - | |||||||||||||
40 | if (!line.isEmpty()
| 0-445 | ||||||||||||
41 | - | |||||||||||||
42 | const QStringListauto parts = line.splitsplitRef(QLatin1Char('\t');)); | - | ||||||||||||
43 | QTzTimeZone zone; | - | ||||||||||||
44 | zone.country = QLocalePrivate::codeToCountry(parts.at(0)); | - | ||||||||||||
45 | if (parts.size() > 3
| 204-217 | ||||||||||||
46 | zone.comment = parts.at(3).toUtf8(); executed 204 times by 1 test: zone.comment = parts.at(3).toUtf8(); Executed by:
| 204 | ||||||||||||
47 | zonesHash.insert(parts.at(2).toUtf8(), zone); | - | ||||||||||||
48 | } executed 421 times by 1 test: end of block Executed by:
| 421 | ||||||||||||
49 | } executed 445 times by 1 test: end of block Executed by:
| 445 | ||||||||||||
50 | return executed 1 time by 1 test: zonesHash;return zonesHash; Executed by:
executed 1 time by 1 test: return zonesHash; Executed by:
| 1 | ||||||||||||
51 | } | - | ||||||||||||
52 | - | |||||||||||||
53 | - | |||||||||||||
54 | namespace { namespace Q_QGS_tzZones { typedef const QTzTimeZoneHash Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type (loadTzTimeZones()))) : value (loadTzTimeZones()) { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<const QTzTimeZoneHash, Q_QGS_tzZones::innerFunction, Q_QGS_tzZones::guard> tzZones;; | - | ||||||||||||
55 | struct QTzHeader { | - | ||||||||||||
56 | char tzh_magic[4]; | - | ||||||||||||
57 | char tzh_version; | - | ||||||||||||
58 | char tzh_reserved[15]; | - | ||||||||||||
59 | quint32 tzh_ttisgmtcnt; | - | ||||||||||||
60 | quint32 tzh_ttisstdcnt; | - | ||||||||||||
61 | quint32 tzh_leapcnt; | - | ||||||||||||
62 | quint32 tzh_timecnt; | - | ||||||||||||
63 | quint32 tzh_typecnt; | - | ||||||||||||
64 | quint32 tzh_charcnt; | - | ||||||||||||
65 | }; | - | ||||||||||||
66 | - | |||||||||||||
67 | struct QTzTransition { | - | ||||||||||||
68 | qint64 tz_time; | - | ||||||||||||
69 | quint8 tz_typeind; | - | ||||||||||||
70 | }; | - | ||||||||||||
71 | template<> class QTypeInfo<QTzTransition > { public: enum { isComplex = (((Q_PRIMITIVE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_PRIMITIVE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_PRIMITIVE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(QTzTransition)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< QTzTransition >::value, isDummy = (((Q_PRIMITIVE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(QTzTransition) }; static inline const char *name() { return "QTzTransition"; } }; | - | ||||||||||||
72 | - | |||||||||||||
73 | struct QTzType { | - | ||||||||||||
74 | int tz_gmtoff; | - | ||||||||||||
75 | bool tz_isdst; | - | ||||||||||||
76 | quint8 tz_abbrind; | - | ||||||||||||
77 | bool tz_ttisgmt; | - | ||||||||||||
78 | bool tz_ttisstd; | - | ||||||||||||
79 | }; | - | ||||||||||||
80 | template<> class QTypeInfo<QTzType > { public: enum { isComplex = (((Q_PRIMITIVE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_PRIMITIVE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_PRIMITIVE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(QTzType)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< QTzType >::value, isDummy = (((Q_PRIMITIVE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(QTzType) }; static inline const char *name() { return "QTzType"; } }; | - | ||||||||||||
81 | - | |||||||||||||
82 | - | |||||||||||||
83 | - | |||||||||||||
84 | - | |||||||||||||
85 | static QTzHeader parseTzHeader(QDataStream &ds, bool *ok) | - | ||||||||||||
86 | { | - | ||||||||||||
87 | QTzHeader hdr; | - | ||||||||||||
88 | quint8 ch; | - | ||||||||||||
89 | *ok = false; | - | ||||||||||||
90 | - | |||||||||||||
91 | - | |||||||||||||
92 | ds.readRawData(hdr.tzh_magic, 4); | - | ||||||||||||
93 | - | |||||||||||||
94 | if (memcmp(hdr.tzh_magic, "TZif", 4) != 0 || ds.status() != QDataStream::Ok) | - | ||||||||||||
95 | return hdr; | - | ||||||||||||
96 | - | |||||||||||||
97 | - | |||||||||||||
98 | ds >> ch; | - | ||||||||||||
99 | hdr.tzh_version = ch; | - | ||||||||||||
100 | if (ds.status() != QDataStream::Ok | - | ||||||||||||
101 | || (hdr.tzh_version != '2' && hdr.tzh_version != '\0' && hdr.tzh_version != '3')) { | - | ||||||||||||
102 | return hdr; | - | ||||||||||||
103 | } | - | ||||||||||||
104 | - | |||||||||||||
105 | - | |||||||||||||
106 | ds.readRawData(hdr.tzh_reserved, 15); | - | ||||||||||||
107 | if (ds.status() != QDataStream::Ok) | - | ||||||||||||
108 | return hdr; | - | ||||||||||||
109 | - | |||||||||||||
110 | - | |||||||||||||
111 | ds >> hdr.tzh_ttisgmtcnt >> hdr.tzh_ttisstdcnt >> hdr.tzh_leapcnt >> hdr.tzh_timecnt | - | ||||||||||||
112 | >> hdr.tzh_typecnt >> hdr.tzh_charcnt; | - | ||||||||||||
113 | - | |||||||||||||
114 | - | |||||||||||||
115 | if (ds.status() != QDataStream::Ok | - | ||||||||||||
116 | || hdr.tzh_timecnt > 1200 | - | ||||||||||||
117 | || hdr.tzh_typecnt > 256 | - | ||||||||||||
118 | || hdr.tzh_charcnt > 50 | - | ||||||||||||
119 | || hdr.tzh_leapcnt > 50 | - | ||||||||||||
120 | || hdr.tzh_ttisgmtcnt > hdr.tzh_typecnt | - | ||||||||||||
121 | || hdr.tzh_ttisstdcnt > hdr.tzh_typecnt) { | - | ||||||||||||
122 | return hdr; | - | ||||||||||||
123 | } | - | ||||||||||||
124 | - | |||||||||||||
125 | *ok = true; | - | ||||||||||||
126 | return hdr; | - | ||||||||||||
127 | } | - | ||||||||||||
128 | - | |||||||||||||
129 | static QVector<QTzTransition> parseTzTransitions(QDataStream &ds, int tzh_timecnt, bool longTran) | - | ||||||||||||
130 | { | - | ||||||||||||
131 | QVector<QTzTransition> transitions(tzh_timecnt); | - | ||||||||||||
132 | - | |||||||||||||
133 | if (longTran) { | - | ||||||||||||
134 | - | |||||||||||||
135 | for (int i = 0; i < tzh_timecnt && ds.status() == QDataStream::Ok; ++i) { | - | ||||||||||||
136 | ds >> transitions[i].tz_time; | - | ||||||||||||
137 | if (ds.status() != QDataStream::Ok) | - | ||||||||||||
138 | transitions.resize(i); | - | ||||||||||||
139 | } | - | ||||||||||||
140 | } else { | - | ||||||||||||
141 | - | |||||||||||||
142 | int val; | - | ||||||||||||
143 | for (int i = 0; i < tzh_timecnt && ds.status() == QDataStream::Ok; ++i) { | - | ||||||||||||
144 | ds >> val; | - | ||||||||||||
145 | transitions[i].tz_time = val; | - | ||||||||||||
146 | if (ds.status() != QDataStream::Ok) | - | ||||||||||||
147 | transitions.resize(i); | - | ||||||||||||
148 | } | - | ||||||||||||
149 | } | - | ||||||||||||
150 | - | |||||||||||||
151 | - | |||||||||||||
152 | for (int i = 0; i < tzh_timecnt && ds.status() == QDataStream::Ok; ++i) { | - | ||||||||||||
153 | quint8 typeind; | - | ||||||||||||
154 | ds >> typeind; | - | ||||||||||||
155 | if (ds.status() == QDataStream::Ok) | - | ||||||||||||
156 | transitions[i].tz_typeind = typeind; | - | ||||||||||||
157 | } | - | ||||||||||||
158 | - | |||||||||||||
159 | return transitions; | - | ||||||||||||
160 | } | - | ||||||||||||
161 | - | |||||||||||||
162 | static QVector<QTzType> parseTzTypes(QDataStream &ds, int tzh_typecnt) | - | ||||||||||||
163 | { | - | ||||||||||||
164 | QVector<QTzType> types(tzh_typecnt); | - | ||||||||||||
165 | - | |||||||||||||
166 | - | |||||||||||||
167 | for (int i = 0; i < tzh_typecnt && ds.status() == QDataStream::Ok; ++i) { | - | ||||||||||||
168 | QTzType &type = types[i]; | - | ||||||||||||
169 | - | |||||||||||||
170 | ds >> type.tz_gmtoff; | - | ||||||||||||
171 | - | |||||||||||||
172 | if (ds.status() == QDataStream::Ok) | - | ||||||||||||
173 | ds >> type.tz_isdst; | - | ||||||||||||
174 | - | |||||||||||||
175 | if (ds.status() == QDataStream::Ok) | - | ||||||||||||
176 | ds >> type.tz_abbrind; | - | ||||||||||||
177 | - | |||||||||||||
178 | type.tz_ttisgmt = false; | - | ||||||||||||
179 | type.tz_ttisstd = false; | - | ||||||||||||
180 | if (ds.status() != QDataStream::Ok) | - | ||||||||||||
181 | types.resize(i); | - | ||||||||||||
182 | } | - | ||||||||||||
183 | - | |||||||||||||
184 | return types; | - | ||||||||||||
185 | } | - | ||||||||||||
186 | - | |||||||||||||
187 | static QMap<int, QByteArray> parseTzAbbreviations(QDataStream &ds, int tzh_charcnt, const QVector<QTzType> &types) | - | ||||||||||||
188 | { | - | ||||||||||||
189 | - | |||||||||||||
190 | - | |||||||||||||
191 | - | |||||||||||||
192 | - | |||||||||||||
193 | - | |||||||||||||
194 | QMap<int, QByteArray> map; | - | ||||||||||||
195 | quint8 ch; | - | ||||||||||||
196 | QByteArray input; | - | ||||||||||||
197 | - | |||||||||||||
198 | for (int i = 0; i < tzh_charcnt
| 0-14643 | ||||||||||||
199 | ds >> ch; | - | ||||||||||||
200 | if (ds.status() == QDataStream::Ok
| 0-14643 | ||||||||||||
201 | input.append(char(ch)); executed 14643 times by 2 tests: input.append(char(ch)); Executed by:
| 14643 | ||||||||||||
202 | else | - | ||||||||||||
203 | return never executed: map;return map; never executed: return map; | 0 | ||||||||||||
204 | } | - | ||||||||||||
205 | - | |||||||||||||
206 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(types)>::type> _container_((types)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const QTzType &type = *_container_.i; _container_.control; _container_.control = 0: types) { | - | ||||||||||||
207 | QByteArray abbrev; | - | ||||||||||||
208 | for (int i = type.tz_abbrind; input.at(i) != '\0'
| 5130-17454 | ||||||||||||
209 | abbrev.append(input.at(i)); executed 17454 times by 2 tests: abbrev.append(input.at(i)); Executed by:
| 17454 | ||||||||||||
210 | - | |||||||||||||
211 | map[type.tz_abbrind] = abbrev; | - | ||||||||||||
212 | } executed 5130 times by 2 tests: end of block Executed by:
| 5130 | ||||||||||||
213 | return executed 908 times by 2 tests: map;return map; Executed by:
executed 908 times by 2 tests: return map; Executed by:
| 908 | ||||||||||||
214 | } | - | ||||||||||||
215 | - | |||||||||||||
216 | static void parseTzLeapSeconds(QDataStream &ds, int tzh_leapcnt, bool longTran) | - | ||||||||||||
217 | { | - | ||||||||||||
218 | - | |||||||||||||
219 | - | |||||||||||||
220 | qint64 val; | - | ||||||||||||
221 | if (longTran) { | - | ||||||||||||
222 | qint64 time; | - | ||||||||||||
223 | for (int i = 0; i < tzh_leapcnt && ds.status() == QDataStream::Ok; ++i) { | - | ||||||||||||
224 | - | |||||||||||||
225 | ds >> time; | - | ||||||||||||
226 | - | |||||||||||||
227 | if (ds.status() == QDataStream::Ok) | - | ||||||||||||
228 | ds >> val; | - | ||||||||||||
229 | } | - | ||||||||||||
230 | } else { | - | ||||||||||||
231 | for (int i = 0; i < tzh_leapcnt && ds.status() == QDataStream::Ok; ++i) { | - | ||||||||||||
232 | - | |||||||||||||
233 | ds >> val; | - | ||||||||||||
234 | - | |||||||||||||
235 | if (ds.status() == QDataStream::Ok) | - | ||||||||||||
236 | ds >> val; | - | ||||||||||||
237 | } | - | ||||||||||||
238 | } | - | ||||||||||||
239 | } | - | ||||||||||||
240 | - | |||||||||||||
241 | static QVector<QTzType> parseTzIndicators(QDataStream &ds, const QVector<QTzType> &types, int tzh_ttisstdcnt, int tzh_ttisgmtcnt) | - | ||||||||||||
242 | { | - | ||||||||||||
243 | QVector<QTzType> result = types; | - | ||||||||||||
244 | bool temp; | - | ||||||||||||
245 | - | |||||||||||||
246 | - | |||||||||||||
247 | for (int i = 0; i < tzh_ttisstdcnt && ds.status() == QDataStream::Ok; ++i) { | - | ||||||||||||
248 | ds >> temp; | - | ||||||||||||
249 | if (ds.status() == QDataStream::Ok) | - | ||||||||||||
250 | result[i].tz_ttisstd = temp; | - | ||||||||||||
251 | } | - | ||||||||||||
252 | - | |||||||||||||
253 | - | |||||||||||||
254 | for (int i = 0; i < tzh_ttisgmtcnt && ds.status() == QDataStream::Ok; ++i) { | - | ||||||||||||
255 | ds >> temp; | - | ||||||||||||
256 | if (ds.status() == QDataStream::Ok) | - | ||||||||||||
257 | result[i].tz_ttisgmt = temp; | - | ||||||||||||
258 | } | - | ||||||||||||
259 | - | |||||||||||||
260 | return result; | - | ||||||||||||
261 | } | - | ||||||||||||
262 | - | |||||||||||||
263 | static QByteArray parseTzPosixRule(QDataStream &ds) | - | ||||||||||||
264 | { | - | ||||||||||||
265 | - | |||||||||||||
266 | QByteArray rule; | - | ||||||||||||
267 | - | |||||||||||||
268 | quint8 ch; | - | ||||||||||||
269 | ds >> ch; | - | ||||||||||||
270 | if (ch != '\n' || ds.status() != QDataStream::Ok) | - | ||||||||||||
271 | return rule; | - | ||||||||||||
272 | ds >> ch; | - | ||||||||||||
273 | while (ch != '\n' && ds.status() == QDataStream::Ok) { | - | ||||||||||||
274 | rule.append((char)ch); | - | ||||||||||||
275 | ds >> ch; | - | ||||||||||||
276 | } | - | ||||||||||||
277 | - | |||||||||||||
278 | return rule; | - | ||||||||||||
279 | } | - | ||||||||||||
280 | - | |||||||||||||
281 | static QDate calculateDowDate(int year, int month, int dayOfWeek, int week) | - | ||||||||||||
282 | { | - | ||||||||||||
283 | QDate date(year, month, 1); | - | ||||||||||||
284 | int startDow = date.dayOfWeek(); | - | ||||||||||||
285 | if (startDow <= dayOfWeek) | - | ||||||||||||
286 | date = date.addDays(dayOfWeek - startDow - 7); | - | ||||||||||||
287 | else | - | ||||||||||||
288 | date = date.addDays(dayOfWeek - startDow); | - | ||||||||||||
289 | date = date.addDays(week * 7); | - | ||||||||||||
290 | while (date.month() != month) | - | ||||||||||||
291 | date = date.addDays(-7); | - | ||||||||||||
292 | return date; | - | ||||||||||||
293 | } | - | ||||||||||||
294 | - | |||||||||||||
295 | static QDate calculatePosixDate(const QByteArray &dateRule, int year) | - | ||||||||||||
296 | { | - | ||||||||||||
297 | - | |||||||||||||
298 | if (dateRule.at(0) == 'M') { | - | ||||||||||||
299 | - | |||||||||||||
300 | QList<QByteArray> dateParts = dateRule.split('.'); | - | ||||||||||||
301 | int month = dateParts.at(0).mid(1).toInt(); | - | ||||||||||||
302 | int week = dateParts.at(1).toInt(); | - | ||||||||||||
303 | int dow = dateParts.at(2).toInt(); | - | ||||||||||||
304 | if (dow == 0) | - | ||||||||||||
305 | ++dow; | - | ||||||||||||
306 | return calculateDowDate(year, month, dow, week); | - | ||||||||||||
307 | } else if (dateRule.at(0) == 'J') { | - | ||||||||||||
308 | - | |||||||||||||
309 | int doy = dateRule.mid(1).toInt(); | - | ||||||||||||
310 | QDate date = QDate(year, 1, 1).addDays(doy - 1); | - | ||||||||||||
311 | if (QDate::isLeapYear(date.year())) | - | ||||||||||||
312 | date = date.addDays(-1); | - | ||||||||||||
313 | return date; | - | ||||||||||||
314 | } else { | - | ||||||||||||
315 | - | |||||||||||||
316 | int doy = dateRule.toInt(); | - | ||||||||||||
317 | return QDate(year, 1, 1).addDays(doy - 1); | - | ||||||||||||
318 | } | - | ||||||||||||
319 | } | - | ||||||||||||
320 | - | |||||||||||||
321 | - | |||||||||||||
322 | static int parsePosixTime(const char *begin, const char *end) | - | ||||||||||||
323 | { | - | ||||||||||||
324 | - | |||||||||||||
325 | int hour, min = 0, sec = 0; | - | ||||||||||||
326 | - | |||||||||||||
327 | - | |||||||||||||
328 | - | |||||||||||||
329 | - | |||||||||||||
330 | - | |||||||||||||
331 | - | |||||||||||||
332 | - | |||||||||||||
333 | bool ok = false; | - | ||||||||||||
334 | hour = qstrtoll(begin, &begin, 10, &ok); | - | ||||||||||||
335 | if (!ok || hour < 0) | - | ||||||||||||
336 | return (-2147483647 - 1); | - | ||||||||||||
337 | if (begin < end && *begin == ':') { | - | ||||||||||||
338 | - | |||||||||||||
339 | ++begin; | - | ||||||||||||
340 | min = qstrtoll(begin, &begin, 10, &ok); | - | ||||||||||||
341 | if (!ok || min < 0) | - | ||||||||||||
342 | return (-2147483647 - 1); | - | ||||||||||||
343 | - | |||||||||||||
344 | if (begin < end && *begin == ':') { | - | ||||||||||||
345 | - | |||||||||||||
346 | ++begin; | - | ||||||||||||
347 | sec = qstrtoll(begin, &begin, 10, &ok); | - | ||||||||||||
348 | if (!ok || sec < 0) | - | ||||||||||||
349 | return (-2147483647 - 1); | - | ||||||||||||
350 | } | - | ||||||||||||
351 | } | - | ||||||||||||
352 | - | |||||||||||||
353 | - | |||||||||||||
354 | if (begin != end) | - | ||||||||||||
355 | return (-2147483647 - 1); | - | ||||||||||||
356 | - | |||||||||||||
357 | return (hour * 60 + min) * 60 + sec; | - | ||||||||||||
358 | } | - | ||||||||||||
359 | - | |||||||||||||
360 | static QTime parsePosixTransitionTime(const QByteArray &timeRule) | - | ||||||||||||
361 | { | - | ||||||||||||
362 | - | |||||||||||||
363 | int value = parsePosixTime(timeRule.constBegin(), timeRule.constEnd()); | - | ||||||||||||
364 | if (value == (-2147483647 - 1)) { | - | ||||||||||||
365 | - | |||||||||||||
366 | return QTime(2, 0, 0); | - | ||||||||||||
367 | } | - | ||||||||||||
368 | return QTime::fromMSecsSinceStartOfDay(value * 1000); | - | ||||||||||||
369 | } | - | ||||||||||||
370 | - | |||||||||||||
371 | static int parsePosixOffset(const char *begin, const char *end) | - | ||||||||||||
372 | { | - | ||||||||||||
373 | - | |||||||||||||
374 | - | |||||||||||||
375 | bool negate = true; | - | ||||||||||||
376 | if (*begin == '+') { | - | ||||||||||||
377 | ++begin; | - | ||||||||||||
378 | } else if (*begin == '-') { | - | ||||||||||||
379 | negate = false; | - | ||||||||||||
380 | ++begin; | - | ||||||||||||
381 | } | - | ||||||||||||
382 | - | |||||||||||||
383 | int value = parsePosixTime(begin, end); | - | ||||||||||||
384 | if (value == (-2147483647 - 1)) | - | ||||||||||||
385 | return value; | - | ||||||||||||
386 | return negate ? -value : value; | - | ||||||||||||
387 | } | - | ||||||||||||
388 | - | |||||||||||||
389 | static inline bool asciiIsLetter(char ch) | - | ||||||||||||
390 | { | - | ||||||||||||
391 | ch |= 0x20; | - | ||||||||||||
392 | return ch >= 'a' && ch <= 'z'; | - | ||||||||||||
393 | } | - | ||||||||||||
394 | - | |||||||||||||
395 | - | |||||||||||||
396 | - | |||||||||||||
397 | - | |||||||||||||
398 | static QPair<QString, int> parsePosixZoneNameAndOffset(const char *&pos, const char *end) | - | ||||||||||||
399 | { | - | ||||||||||||
400 | static const char offsetChars[] = "0123456789:"; | - | ||||||||||||
401 | QPair<QString, int> result = qMakePair(QString(), (-2147483647 - 1)); | - | ||||||||||||
402 | - | |||||||||||||
403 | const char *nameBegin = pos; | - | ||||||||||||
404 | const char *nameEnd; | - | ||||||||||||
405 | ((!(pos < end)) ? qt_assert("pos < end",__FILE__,459465) : qt_noop()); | - | ||||||||||||
406 | - | |||||||||||||
407 | if (*pos == '<') { | - | ||||||||||||
408 | nameBegin = pos + 1; | - | ||||||||||||
409 | nameEnd = nameBegin; | - | ||||||||||||
410 | while (nameEnd < end && *nameEnd != '>') { | - | ||||||||||||
411 | - | |||||||||||||
412 | ++nameEnd; | - | ||||||||||||
413 | } | - | ||||||||||||
414 | pos = nameEnd + 1; | - | ||||||||||||
415 | } else { | - | ||||||||||||
416 | nameBegin = pos; | - | ||||||||||||
417 | nameEnd = nameBegin; | - | ||||||||||||
418 | while (nameEnd < end && asciiIsLetter(*nameEnd)) | - | ||||||||||||
419 | ++nameEnd; | - | ||||||||||||
420 | pos = nameEnd; | - | ||||||||||||
421 | } | - | ||||||||||||
422 | if (nameEnd - nameBegin < 3) | - | ||||||||||||
423 | return result; | - | ||||||||||||
424 | - | |||||||||||||
425 | - | |||||||||||||
426 | const char *zoneBegin = pos; | - | ||||||||||||
427 | const char *zoneEnd = pos; | - | ||||||||||||
428 | if (zoneEnd < end && (zoneEnd[0] == '+' || zoneEnd[0] == '-')) | - | ||||||||||||
429 | ++zoneEnd; | - | ||||||||||||
430 | while (zoneEnd < end) { | - | ||||||||||||
431 | if (strchr(offsetChars, char(*zoneEnd)) == __null) | - | ||||||||||||
432 | break; | - | ||||||||||||
433 | ++zoneEnd; | - | ||||||||||||
434 | } | - | ||||||||||||
435 | - | |||||||||||||
436 | result.first = QString::fromUtf8(nameBegin, nameEnd - nameBegin); | - | ||||||||||||
437 | if (zoneEnd > zoneBegin) | - | ||||||||||||
438 | result.second = parsePosixOffset(zoneBegin, zoneEnd); | - | ||||||||||||
439 | pos = zoneEnd; | - | ||||||||||||
440 | return result; | - | ||||||||||||
441 | } | - | ||||||||||||
442 | - | |||||||||||||
443 | static QVector<QTimeZonePrivate::Data> calculatePosixTransitions(const QByteArray &posixRule, | - | ||||||||||||
444 | int startYear, int endYear, | - | ||||||||||||
445 | int lastTranMSecs) | - | ||||||||||||
446 | { | - | ||||||||||||
447 | QVector<QTimeZonePrivate::Data> result; | - | ||||||||||||
448 | - | |||||||||||||
449 | - | |||||||||||||
450 | if (startYear > 292278994) | - | ||||||||||||
451 | startYear = 292278994; | - | ||||||||||||
452 | if (endYear > 292278994) | - | ||||||||||||
453 | endYear = 292278994; | - | ||||||||||||
454 | - | |||||||||||||
455 | - | |||||||||||||
456 | - | |||||||||||||
457 | - | |||||||||||||
458 | QList<QByteArray> parts = posixRule.split(','); | - | ||||||||||||
459 | - | |||||||||||||
460 | QPair<QString, int> stdZone, dstZone; | - | ||||||||||||
461 | { | - | ||||||||||||
462 | const QByteArray &zoneinfo = parts.at(0); | - | ||||||||||||
463 | const char *begin = zoneinfo.constBegin(); | - | ||||||||||||
464 | - | |||||||||||||
465 | stdZone = parsePosixZoneNameAndOffset(begin, zoneinfo.constEnd()); | - | ||||||||||||
466 | if (stdZone.second == (-2147483647 - 1)) { | - | ||||||||||||
467 | stdZone.second = 0; | - | ||||||||||||
468 | } else if (begin < zoneinfo.constEnd()) { | - | ||||||||||||
469 | dstZone = parsePosixZoneNameAndOffset(begin, zoneinfo.constEnd()); | - | ||||||||||||
470 | if (dstZone.second == (-2147483647 - 1)) { | - | ||||||||||||
471 | - | |||||||||||||
472 | dstZone.second = stdZone.second + (60 * 60); | - | ||||||||||||
473 | } | - | ||||||||||||
474 | } | - | ||||||||||||
475 | } | - | ||||||||||||
476 | - | |||||||||||||
477 | - | |||||||||||||
478 | if (parts.count() == 1) { | - | ||||||||||||
479 | QTimeZonePrivate::Data data; | - | ||||||||||||
480 | data.atMSecsSinceEpoch = lastTranMSecs; | - | ||||||||||||
481 | data.offsetFromUtc = stdZone.second; | - | ||||||||||||
482 | data.standardTimeOffset = stdZone.second; | - | ||||||||||||
483 | data.daylightTimeOffset = 0; | - | ||||||||||||
484 | data.abbreviation = stdZone.first; | - | ||||||||||||
485 | result << data; | - | ||||||||||||
486 | return result; | - | ||||||||||||
487 | } | - | ||||||||||||
488 | - | |||||||||||||
489 | - | |||||||||||||
490 | - | |||||||||||||
491 | QList<QByteArray> dstParts = parts.at(1).split('/'); | - | ||||||||||||
492 | QByteArray dstDateRule = dstParts.at(0); | - | ||||||||||||
493 | QTime dstTime; | - | ||||||||||||
494 | if (dstParts.count() > 1) | - | ||||||||||||
495 | dstTime = parsePosixTransitionTime(dstParts.at(1)); | - | ||||||||||||
496 | else | - | ||||||||||||
497 | dstTime = QTime(2, 0, 0); | - | ||||||||||||
498 | - | |||||||||||||
499 | - | |||||||||||||
500 | QList<QByteArray> stdParts = parts.at(2).split('/'); | - | ||||||||||||
501 | QByteArray stdDateRule = stdParts.at(0); | - | ||||||||||||
502 | QTime stdTime; | - | ||||||||||||
503 | if (stdParts.count() > 1) | - | ||||||||||||
504 | stdTime = parsePosixTransitionTime(stdParts.at(1)); | - | ||||||||||||
505 | else | - | ||||||||||||
506 | stdTime = QTime(2, 0, 0); | - | ||||||||||||
507 | - | |||||||||||||
508 | for (int year = startYear; year <= endYear; ++year) { | - | ||||||||||||
509 | QTimeZonePrivate::Data dstData; | - | ||||||||||||
510 | QDateTime dst(calculatePosixDate(dstDateRule, year), dstTime, Qt::UTC); | - | ||||||||||||
511 | dstData.atMSecsSinceEpoch = dst.toMSecsSinceEpoch() - (stdZone.second * 1000); | - | ||||||||||||
512 | dstData.offsetFromUtc = dstZone.second; | - | ||||||||||||
513 | dstData.standardTimeOffset = stdZone.second; | - | ||||||||||||
514 | dstData.daylightTimeOffset = dstZone.second - stdZone.second; | - | ||||||||||||
515 | dstData.abbreviation = dstZone.first; | - | ||||||||||||
516 | QTimeZonePrivate::Data stdData; | - | ||||||||||||
517 | QDateTime std(calculatePosixDate(stdDateRule, year), stdTime, Qt::UTC); | - | ||||||||||||
518 | stdData.atMSecsSinceEpoch = std.toMSecsSinceEpoch() - (dstZone.second * 1000); | - | ||||||||||||
519 | stdData.offsetFromUtc = stdZone.second; | - | ||||||||||||
520 | stdData.standardTimeOffset = stdZone.second; | - | ||||||||||||
521 | stdData.daylightTimeOffset = 0; | - | ||||||||||||
522 | stdData.abbreviation = stdZone.first; | - | ||||||||||||
523 | - | |||||||||||||
524 | if (year == 292278994 && (dstData.atMSecsSinceEpoch < 0 || stdData.atMSecsSinceEpoch < 0)) { | - | ||||||||||||
525 | if (dstData.atMSecsSinceEpoch > 0) { | - | ||||||||||||
526 | result << dstData; | - | ||||||||||||
527 | } else if (stdData.atMSecsSinceEpoch > 0) { | - | ||||||||||||
528 | result << stdData; | - | ||||||||||||
529 | } | - | ||||||||||||
530 | } else if (dst < std) { | - | ||||||||||||
531 | result << dstData << stdData; | - | ||||||||||||
532 | } else { | - | ||||||||||||
533 | result << stdData << dstData; | - | ||||||||||||
534 | } | - | ||||||||||||
535 | } | - | ||||||||||||
536 | return result; | - | ||||||||||||
537 | } | - | ||||||||||||
538 | - | |||||||||||||
539 | - | |||||||||||||
540 | QTzTimeZonePrivate::QTzTimeZonePrivate() | - | ||||||||||||
541 | - | |||||||||||||
542 | : m_icu(0) | - | ||||||||||||
543 | - | |||||||||||||
544 | { | - | ||||||||||||
545 | init(systemTimeZoneId()); | - | ||||||||||||
546 | } | - | ||||||||||||
547 | - | |||||||||||||
548 | - | |||||||||||||
549 | QTzTimeZonePrivate::QTzTimeZonePrivate(const QByteArray &ianaId) | - | ||||||||||||
550 | - | |||||||||||||
551 | : m_icu(0) | - | ||||||||||||
552 | - | |||||||||||||
553 | { | - | ||||||||||||
554 | init(ianaId); | - | ||||||||||||
555 | } | - | ||||||||||||
556 | - | |||||||||||||
557 | QTzTimeZonePrivate::QTzTimeZonePrivate(const QTzTimeZonePrivate &other) | - | ||||||||||||
558 | : QTimeZonePrivate(other), m_tranTimes(other.m_tranTimes), | - | ||||||||||||
559 | m_tranRules(other.m_tranRules), m_abbreviations(other.m_abbreviations), | - | ||||||||||||
560 | - | |||||||||||||
561 | m_icu(other.m_icu), | - | ||||||||||||
562 | - | |||||||||||||
563 | m_posixRule(other.m_posixRule) | - | ||||||||||||
564 | { | - | ||||||||||||
565 | } | - | ||||||||||||
566 | - | |||||||||||||
567 | QTzTimeZonePrivate::~QTzTimeZonePrivate() | - | ||||||||||||
568 | { | - | ||||||||||||
569 | } | - | ||||||||||||
570 | - | |||||||||||||
571 | QTimeZonePrivate *QTzTimeZonePrivate::clone() | - | ||||||||||||
572 | { | - | ||||||||||||
573 | return new QTzTimeZonePrivate(*this); | - | ||||||||||||
574 | } | - | ||||||||||||
575 | - | |||||||||||||
576 | void QTzTimeZonePrivate::init(const QByteArray &ianaId) | - | ||||||||||||
577 | { | - | ||||||||||||
578 | QFile tzif; | - | ||||||||||||
579 | if (ianaId.isEmpty()
| 0-457 | ||||||||||||
580 | - | |||||||||||||
581 | tzif.setFileName(([]() -> QString { enum { Size = sizeof(u"" "/etc/localtime")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "/etc/localtime" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())); | - | ||||||||||||
582 | if (!tzif.open(QIODevice::ReadOnly)
| 0 | ||||||||||||
583 | return; never executed: return; | 0 | ||||||||||||
584 | } never executed: else {end of block | 0 | ||||||||||||
585 | - | |||||||||||||
586 | tzif.setFileName(QLatin1String("/usr/share/zoneinfo/") + QString::fromLocal8Bit(ianaId)); | - | ||||||||||||
587 | if (!tzif.open(QIODevice::ReadOnly)
| 3-454 | ||||||||||||
588 | tzif.setFileName(QLatin1String("/usr/lib/zoneinfo/") + QString::fromLocal8Bit(ianaId)); | - | ||||||||||||
589 | if (!tzif.open(QIODevice::ReadOnly)
| 0-3 | ||||||||||||
590 | return; executed 3 times by 2 tests: return; Executed by:
| 3 | ||||||||||||
591 | } never executed: end of block | 0 | ||||||||||||
592 | } executed 454 times by 2 tests: end of block Executed by:
| 454 | ||||||||||||
593 | - | |||||||||||||
594 | QDataStream ds(&tzif); | - | ||||||||||||
595 | - | |||||||||||||
596 | - | |||||||||||||
597 | bool ok = false; | - | ||||||||||||
598 | QTzHeader hdr = parseTzHeader(ds, &ok); | - | ||||||||||||
599 | if (!ok
| 0-454 | ||||||||||||
600 | return; never executed: return; | 0 | ||||||||||||
601 | QVector<QTzTransition> tranList = parseTzTransitions(ds, hdr.tzh_timecnt, false); | - | ||||||||||||
602 | if (ds.status() != QDataStream::Ok
| 0-454 | ||||||||||||
603 | return; never executed: return; | 0 | ||||||||||||
604 | QVector<QTzType> typeList = parseTzTypes(ds, hdr.tzh_typecnt); | - | ||||||||||||
605 | if (ds.status() != QDataStream::Ok
| 0-454 | ||||||||||||
606 | return; never executed: return; | 0 | ||||||||||||
607 | QMap<int, QByteArray> abbrevMap = parseTzAbbreviations(ds, hdr.tzh_charcnt, typeList); | - | ||||||||||||
608 | if (ds.status() != QDataStream::Ok
| 0-454 | ||||||||||||
609 | return; never executed: return; | 0 | ||||||||||||
610 | parseTzLeapSeconds(ds, hdr.tzh_leapcnt, false); | - | ||||||||||||
611 | if (ds.status() != QDataStream::Ok
| 0-454 | ||||||||||||
612 | return; never executed: return; | 0 | ||||||||||||
613 | typeList = parseTzIndicators(ds, typeList, hdr.tzh_ttisstdcnt, hdr.tzh_ttisgmtcnt); | - | ||||||||||||
614 | if (ds.status() != QDataStream::Ok
| 0-454 | ||||||||||||
615 | return; never executed: return; | 0 | ||||||||||||
616 | - | |||||||||||||
617 | - | |||||||||||||
618 | if (hdr.tzh_version == '2'
| 0-447 | ||||||||||||
619 | ok = false; | - | ||||||||||||
620 | QTzHeader hdr2 = parseTzHeader(ds, &ok); | - | ||||||||||||
621 | if (!ok
| 0-454 | ||||||||||||
622 | return; never executed: return; | 0 | ||||||||||||
623 | tranList = parseTzTransitions(ds, hdr2.tzh_timecnt, true); | - | ||||||||||||
624 | if (ds.status() != QDataStream::Ok
| 0-454 | ||||||||||||
625 | return; never executed: return; | 0 | ||||||||||||
626 | typeList = parseTzTypes(ds, hdr2.tzh_typecnt); | - | ||||||||||||
627 | if (ds.status() != QDataStream::Ok
| 0-454 | ||||||||||||
628 | return; never executed: return; | 0 | ||||||||||||
629 | abbrevMap = parseTzAbbreviations(ds, hdr2.tzh_charcnt, typeList); | - | ||||||||||||
630 | if (ds.status() != QDataStream::Ok
| 0-454 | ||||||||||||
631 | return; never executed: return; | 0 | ||||||||||||
632 | parseTzLeapSeconds(ds, hdr2.tzh_leapcnt, true); | - | ||||||||||||
633 | if (ds.status() != QDataStream::Ok
| 0-454 | ||||||||||||
634 | return; never executed: return; | 0 | ||||||||||||
635 | typeList = parseTzIndicators(ds, typeList, hdr2.tzh_ttisstdcnt, hdr2.tzh_ttisgmtcnt); | - | ||||||||||||
636 | if (ds.status() != QDataStream::Ok
| 0-454 | ||||||||||||
637 | return; never executed: return; | 0 | ||||||||||||
638 | m_posixRule = parseTzPosixRule(ds); | - | ||||||||||||
639 | if (ds.status() != QDataStream::Ok
| 0-454 | ||||||||||||
640 | return; never executed: return; | 0 | ||||||||||||
641 | } executed 454 times by 2 tests: end of block Executed by:
| 454 | ||||||||||||
642 | - | |||||||||||||
643 | - | |||||||||||||
644 | - | |||||||||||||
645 | - | |||||||||||||
646 | m_abbreviationsconst int size = abbrevMap.valuessize(); | - | ||||||||||||
647 | QListm_abbreviations.clear(); | - | ||||||||||||
648 | m_abbreviations.reserve(size); | - | ||||||||||||
649 | QVector<int> abbrindList; | - | ||||||||||||
650 | abbrindList.reserve(size); | - | ||||||||||||
651 | for (auto it = abbrevMap.keyscbegin(), end = abbrevMap.cend(); it != end
| 454-1827 | ||||||||||||
652 | m_abbreviations.append(it.value()); | - | ||||||||||||
653 | abbrindList.append(it.key()); | - | ||||||||||||
654 | } executed 1827 times by 2 tests: end of block Executed by:
| 1827 | ||||||||||||
655 | for (int i = 0; i < typeList.size()
| 454-2700 | ||||||||||||
656 | 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 | ||||||||||||
657 | - | |||||||||||||
658 | - | |||||||||||||
659 | - | |||||||||||||
660 | int utcOffset = 0; | - | ||||||||||||
for (QForeachContainer<typename QtPrivate::remove_reference<decltype(tranList)>::type> _container_((tranList)); _container_.control && _container_.i != _container_.e; | ||||||||||||||
661 | ++_container_.i, _container_.control ^= 1)for (const QTzTransition &tran = *_container_.i; _container_.control; _container_.control = 0): qAsConst(tranList)) { | - | ||||||||||||
662 | if (!typeList.at(tran.tz_typeind).tz_isdst
| 3-454 | ||||||||||||
663 | utcOffset = typeList.at(tran.tz_typeind).tz_gmtoff; | - | ||||||||||||
664 | break; executed 454 times by 2 tests: break; Executed by:
| 454 | ||||||||||||
665 | } | - | ||||||||||||
666 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||
667 | - | |||||||||||||
668 | - | |||||||||||||
669 | m_tranTimes.reserve(tranList.count()); | - | ||||||||||||
670 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(tranList)>::type> _container_((tranList)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const QTzTransition &tz_tran = *_container_.i; _container_.control; _container_.control = 0): qAsConst(tranList)) { | - | ||||||||||||
671 | QTzTransitionTime tran; | - | ||||||||||||
672 | QTzTransitionRule rule; | - | ||||||||||||
673 | const QTzType tz_type = typeList.at(tz_tran.tz_typeind); | - | ||||||||||||
674 | - | |||||||||||||
675 | - | |||||||||||||
676 | if (!tz_type.tz_isdst
| 15309-16244 | ||||||||||||
677 | utcOffset = tz_type.tz_gmtoff; executed 16244 times by 2 tests: utcOffset = tz_type.tz_gmtoff; Executed by:
| 16244 | ||||||||||||
678 | rule.stdOffset = utcOffset; | - | ||||||||||||
679 | rule.dstOffset = tz_type.tz_gmtoff - utcOffset; | - | ||||||||||||
680 | rule.abbreviationIndex = tz_type.tz_abbrind; | - | ||||||||||||
681 | - | |||||||||||||
682 | int ruleIndex = m_tranRules.indexOf(rule); | - | ||||||||||||
683 | if (ruleIndex == -1
| 1704-29849 | ||||||||||||
684 | m_tranRules.append(rule); | - | ||||||||||||
685 | tran.ruleIndex = m_tranRules.size() - 1; | - | ||||||||||||
686 | } executed 1704 times by 2 tests: else {end of block Executed by:
| 1704 | ||||||||||||
687 | tran.ruleIndex = ruleIndex; | - | ||||||||||||
688 | } executed 29849 times by 2 tests: end of block Executed by:
| 29849 | ||||||||||||
689 | - | |||||||||||||
690 | - | |||||||||||||
691 | if (tz_type.tz_ttisgmt
| 8759-22794 | ||||||||||||
692 | tran.atMSecsSinceEpoch = tz_tran.tz_time * 1000; executed 8759 times by 2 tests: tran.atMSecsSinceEpoch = tz_tran.tz_time * 1000; Executed by:
| 8759 | ||||||||||||
693 | else if (tz_type.tz_ttisstd
| 7286-15508 | ||||||||||||
694 | tran.atMSecsSinceEpoch = tz_tran.tz_time * 1000; executed 7286 times by 2 tests: tran.atMSecsSinceEpoch = tz_tran.tz_time * 1000; Executed by:
| 7286 | ||||||||||||
695 | else | - | ||||||||||||
696 | tran.atMSecsSinceEpoch = tz_tran.tz_time * 1000; executed 15508 times by 2 tests: tran.atMSecsSinceEpoch = tz_tran.tz_time * 1000; Executed by:
| 15508 | ||||||||||||
697 | - | |||||||||||||
698 | m_tranTimes.append(tran); | - | ||||||||||||
699 | } executed 31553 times by 2 tests: end of block Executed by:
| 31553 | ||||||||||||
700 | - | |||||||||||||
701 | if (ianaId.isEmpty()
| 0-454 | ||||||||||||
702 | m_id = systemTimeZoneId(); never executed: m_id = systemTimeZoneId(); | 0 | ||||||||||||
703 | else | - | ||||||||||||
704 | m_id = ianaId; executed 454 times by 2 tests: m_id = ianaId; Executed by:
| 454 | ||||||||||||
705 | } | - | ||||||||||||
706 | - | |||||||||||||
707 | QLocale::Country QTzTimeZonePrivate::country() const | - | ||||||||||||
708 | { | - | ||||||||||||
709 | return tzZones->value(m_id).country; | - | ||||||||||||
710 | } | - | ||||||||||||
711 | - | |||||||||||||
712 | QString QTzTimeZonePrivate::comment() const | - | ||||||||||||
713 | { | - | ||||||||||||
714 | return QString::fromUtf8(tzZones->value(m_id).comment); | - | ||||||||||||
715 | } | - | ||||||||||||
716 | - | |||||||||||||
717 | QString QTzTimeZonePrivate::displayName(qint64 atMSecsSinceEpoch, | - | ||||||||||||
718 | QTimeZone::NameType nameType, | - | ||||||||||||
719 | const QLocale &locale) const | - | ||||||||||||
720 | { | - | ||||||||||||
721 | - | |||||||||||||
722 | if (!m_icu) | - | ||||||||||||
723 | m_icu = new QIcuTimeZonePrivate(m_id); | - | ||||||||||||
724 | - | |||||||||||||
725 | - | |||||||||||||
726 | if (m_icu->isValid()) | - | ||||||||||||
727 | return m_icu->displayName(atMSecsSinceEpoch, nameType, locale); | - | ||||||||||||
728 | - | |||||||||||||
729 | - | |||||||||||||
730 | - | |||||||||||||
731 | - | |||||||||||||
732 | return abbreviation(atMSecsSinceEpoch); | - | ||||||||||||
733 | } | - | ||||||||||||
734 | - | |||||||||||||
735 | QString QTzTimeZonePrivate::displayName(QTimeZone::TimeType timeType, | - | ||||||||||||
736 | QTimeZone::NameType nameType, | - | ||||||||||||
737 | const QLocale &locale) const | - | ||||||||||||
738 | { | - | ||||||||||||
739 | - | |||||||||||||
740 | if (!m_icu) | - | ||||||||||||
741 | m_icu = new QIcuTimeZonePrivate(m_id); | - | ||||||||||||
742 | - | |||||||||||||
743 | - | |||||||||||||
744 | if (m_icu->isValid()) | - | ||||||||||||
745 | return m_icu->displayName(timeType, nameType, locale); | - | ||||||||||||
746 | - | |||||||||||||
747 | - | |||||||||||||
748 | - | |||||||||||||
749 | - | |||||||||||||
750 | - | |||||||||||||
751 | - | |||||||||||||
752 | - | |||||||||||||
753 | if (timeType == QTimeZone::GenericTime) | - | ||||||||||||
754 | timeType = QTimeZone::StandardTime; | - | ||||||||||||
755 | - | |||||||||||||
756 | - | |||||||||||||
757 | const qint64 currentMSecs = QDateTime::currentMSecsSinceEpoch(); | - | ||||||||||||
758 | QTimeZonePrivate::Data tran = data(currentMSecs); | - | ||||||||||||
759 | if (tran.atMSecsSinceEpoch != invalidMSecs() | - | ||||||||||||
760 | && ((timeType == QTimeZone::DaylightTime && tran.daylightTimeOffset != 0) | - | ||||||||||||
761 | || (timeType == QTimeZone::StandardTime && tran.daylightTimeOffset == 0))) { | - | ||||||||||||
762 | return tran.abbreviation; | - | ||||||||||||
763 | } | - | ||||||||||||
764 | - | |||||||||||||
765 | - | |||||||||||||
766 | tran = nextTransition(currentMSecs); | - | ||||||||||||
767 | if (tran.atMSecsSinceEpoch != invalidMSecs() | - | ||||||||||||
768 | && ((timeType == QTimeZone::DaylightTime && tran.daylightTimeOffset != 0) | - | ||||||||||||
769 | || (timeType == QTimeZone::StandardTime && tran.daylightTimeOffset == 0))) { | - | ||||||||||||
770 | return tran.abbreviation; | - | ||||||||||||
771 | } | - | ||||||||||||
772 | - | |||||||||||||
773 | - | |||||||||||||
774 | tran = previousTransition(currentMSecs); | - | ||||||||||||
775 | if (tran.atMSecsSinceEpoch != invalidMSecs()) | - | ||||||||||||
776 | tran = previousTransition(tran.atMSecsSinceEpoch); | - | ||||||||||||
777 | if (tran.atMSecsSinceEpoch != invalidMSecs() | - | ||||||||||||
778 | && ((timeType == QTimeZone::DaylightTime && tran.daylightTimeOffset != 0) | - | ||||||||||||
779 | || (timeType == QTimeZone::StandardTime && tran.daylightTimeOffset == 0))) { | - | ||||||||||||
780 | return tran.abbreviation; | - | ||||||||||||
781 | } | - | ||||||||||||
782 | - | |||||||||||||
783 | - | |||||||||||||
784 | for (int i = m_tranTimes.size() - 1; i >= 0; --i) { | - | ||||||||||||
785 | if (m_tranTimes.at(i).atMSecsSinceEpoch <= currentMSecs) { | - | ||||||||||||
786 | tran = dataForTzTransition(m_tranTimes.at(i)); | - | ||||||||||||
787 | if ((timeType == QTimeZone::DaylightTime && tran.daylightTimeOffset != 0) | - | ||||||||||||
788 | || (timeType == QTimeZone::StandardTime && tran.daylightTimeOffset == 0)) { | - | ||||||||||||
789 | return tran.abbreviation; | - | ||||||||||||
790 | } | - | ||||||||||||
791 | } | - | ||||||||||||
792 | } | - | ||||||||||||
793 | - | |||||||||||||
794 | - | |||||||||||||
795 | return data(currentMSecs).abbreviation; | - | ||||||||||||
796 | } | - | ||||||||||||
797 | - | |||||||||||||
798 | QString QTzTimeZonePrivate::abbreviation(qint64 atMSecsSinceEpoch) const | - | ||||||||||||
799 | { | - | ||||||||||||
800 | return data(atMSecsSinceEpoch).abbreviation; | - | ||||||||||||
801 | } | - | ||||||||||||
802 | - | |||||||||||||
803 | int QTzTimeZonePrivate::offsetFromUtc(qint64 atMSecsSinceEpoch) const | - | ||||||||||||
804 | { | - | ||||||||||||
805 | const QTimeZonePrivate::Data tran = data(atMSecsSinceEpoch); | - | ||||||||||||
806 | return tran.standardTimeOffset + tran.daylightTimeOffset; | - | ||||||||||||
807 | } | - | ||||||||||||
808 | - | |||||||||||||
809 | int QTzTimeZonePrivate::standardTimeOffset(qint64 atMSecsSinceEpoch) const | - | ||||||||||||
810 | { | - | ||||||||||||
811 | return data(atMSecsSinceEpoch).standardTimeOffset; | - | ||||||||||||
812 | } | - | ||||||||||||
813 | - | |||||||||||||
814 | int QTzTimeZonePrivate::daylightTimeOffset(qint64 atMSecsSinceEpoch) const | - | ||||||||||||
815 | { | - | ||||||||||||
816 | return data(atMSecsSinceEpoch).daylightTimeOffset; | - | ||||||||||||
817 | } | - | ||||||||||||
818 | - | |||||||||||||
819 | bool QTzTimeZonePrivate::hasDaylightTime() const | - | ||||||||||||
820 | { | - | ||||||||||||
821 | - | |||||||||||||
822 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(m_tranRules)>::type> _container_((m_tranRules)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const QTzTransitionRule &rule = *_container_.i; _container_.control; _container_.control = 0: m_tranRules) { | - | ||||||||||||
823 | if (rule.dstOffset != 0
| 1519-3635 | ||||||||||||
824 | return executed 1519 times by 2 tests: true;return true; Executed by:
executed 1519 times by 2 tests: return true; Executed by:
| 1519 | ||||||||||||
825 | } executed 3635 times by 2 tests: end of block Executed by:
| 3635 | ||||||||||||
826 | return executed 660 times by 1 test: false;return false; Executed by:
executed 660 times by 1 test: return false; Executed by:
| 660 | ||||||||||||
827 | } | - | ||||||||||||
828 | - | |||||||||||||
829 | bool QTzTimeZonePrivate::isDaylightTime(qint64 atMSecsSinceEpoch) const | - | ||||||||||||
830 | { | - | ||||||||||||
831 | return (daylightTimeOffset(atMSecsSinceEpoch) != 0); | - | ||||||||||||
832 | } | - | ||||||||||||
833 | - | |||||||||||||
834 | QTimeZonePrivate::Data QTzTimeZonePrivate::dataForTzTransition(QTzTransitionTime tran) const | - | ||||||||||||
835 | { | - | ||||||||||||
836 | QTimeZonePrivate::Data data; | - | ||||||||||||
837 | data.atMSecsSinceEpoch = tran.atMSecsSinceEpoch; | - | ||||||||||||
838 | QTzTransitionRule rule = m_tranRules.at(tran.ruleIndex); | - | ||||||||||||
839 | data.standardTimeOffset = rule.stdOffset; | - | ||||||||||||
840 | data.daylightTimeOffset = rule.dstOffset; | - | ||||||||||||
841 | data.offsetFromUtc = rule.stdOffset + rule.dstOffset; | - | ||||||||||||
842 | data.abbreviation = QString::fromUtf8(m_abbreviations.at(rule.abbreviationIndex)); | - | ||||||||||||
843 | return data; | - | ||||||||||||
844 | } | - | ||||||||||||
845 | - | |||||||||||||
846 | QTimeZonePrivate::Data QTzTimeZonePrivate::data(qint64 forMSecsSinceEpoch) const | - | ||||||||||||
847 | { | - | ||||||||||||
848 | - | |||||||||||||
849 | if (m_tranTimes.size() > 0 && m_tranTimes.last().atMSecsSinceEpoch < forMSecsSinceEpoch | - | ||||||||||||
850 | && !m_posixRule.isEmpty() && forMSecsSinceEpoch >= 0) { | - | ||||||||||||
851 | const int year = QDateTime::fromMSecsSinceEpoch(forMSecsSinceEpoch, Qt::UTC).date().year(); | - | ||||||||||||
852 | QVector<QTimeZonePrivate::Data> posixTrans = | - | ||||||||||||
853 | calculatePosixTransitions(m_posixRule, year - 1, year + 1, | - | ||||||||||||
854 | m_tranTimes.last().atMSecsSinceEpoch); | - | ||||||||||||
855 | for (int i = posixTrans.size() - 1; i >= 0; --i) { | - | ||||||||||||
856 | if (posixTrans.at(i).atMSecsSinceEpoch <= forMSecsSinceEpoch) { | - | ||||||||||||
857 | QTimeZonePrivate::Data data = posixTrans.at(i); | - | ||||||||||||
858 | data.atMSecsSinceEpoch = forMSecsSinceEpoch; | - | ||||||||||||
859 | return data; | - | ||||||||||||
860 | } | - | ||||||||||||
861 | } | - | ||||||||||||
862 | } | - | ||||||||||||
863 | - | |||||||||||||
864 | - | |||||||||||||
865 | for (int i = m_tranTimes.size() - 1; i >= 0; --i) { | - | ||||||||||||
866 | if (m_tranTimes.at(i).atMSecsSinceEpoch <= forMSecsSinceEpoch) { | - | ||||||||||||
867 | Data data = dataForTzTransition(m_tranTimes.at(i)); | - | ||||||||||||
868 | data.atMSecsSinceEpoch = forMSecsSinceEpoch; | - | ||||||||||||
869 | return data; | - | ||||||||||||
870 | } | - | ||||||||||||
871 | } | - | ||||||||||||
872 | - | |||||||||||||
873 | - | |||||||||||||
874 | if (m_tranTimes.size() > 0) { | - | ||||||||||||
875 | Data data = dataForTzTransition(m_tranTimes.at(0)); | - | ||||||||||||
876 | data.atMSecsSinceEpoch = forMSecsSinceEpoch; | - | ||||||||||||
877 | return data; | - | ||||||||||||
878 | } | - | ||||||||||||
879 | - | |||||||||||||
880 | - | |||||||||||||
881 | return invalidData(); | - | ||||||||||||
882 | } | - | ||||||||||||
883 | - | |||||||||||||
884 | bool QTzTimeZonePrivate::hasTransitions() const | - | ||||||||||||
885 | { | - | ||||||||||||
886 | return true; | - | ||||||||||||
887 | } | - | ||||||||||||
888 | - | |||||||||||||
889 | QTimeZonePrivate::Data QTzTimeZonePrivate::nextTransition(qint64 afterMSecsSinceEpoch) const | - | ||||||||||||
890 | { | - | ||||||||||||
891 | - | |||||||||||||
892 | if (m_tranTimes.size() > 0 && m_tranTimes.last().atMSecsSinceEpoch < afterMSecsSinceEpoch | - | ||||||||||||
893 | && !m_posixRule.isEmpty() && afterMSecsSinceEpoch >= 0) { | - | ||||||||||||
894 | const int year = QDateTime::fromMSecsSinceEpoch(afterMSecsSinceEpoch, Qt::UTC).date().year(); | - | ||||||||||||
895 | QVector<QTimeZonePrivate::Data> posixTrans = | - | ||||||||||||
896 | calculatePosixTransitions(m_posixRule, year - 1, year + 1, | - | ||||||||||||
897 | m_tranTimes.last().atMSecsSinceEpoch); | - | ||||||||||||
898 | for (int i = 0; i < posixTrans.size(); ++i) { | - | ||||||||||||
899 | if (posixTrans.at(i).atMSecsSinceEpoch > afterMSecsSinceEpoch) | - | ||||||||||||
900 | return posixTrans.at(i); | - | ||||||||||||
901 | } | - | ||||||||||||
902 | } | - | ||||||||||||
903 | - | |||||||||||||
904 | - | |||||||||||||
905 | for (int i = 0; i < m_tranTimes.size(); ++i) { | - | ||||||||||||
906 | if (m_tranTimes.at(i).atMSecsSinceEpoch > afterMSecsSinceEpoch) { | - | ||||||||||||
907 | return dataForTzTransition(m_tranTimes.at(i)); | - | ||||||||||||
908 | } | - | ||||||||||||
909 | } | - | ||||||||||||
910 | - | |||||||||||||
911 | - | |||||||||||||
912 | return invalidData(); | - | ||||||||||||
913 | } | - | ||||||||||||
914 | - | |||||||||||||
915 | QTimeZonePrivate::Data QTzTimeZonePrivate::previousTransition(qint64 beforeMSecsSinceEpoch) const | - | ||||||||||||
916 | { | - | ||||||||||||
917 | - | |||||||||||||
918 | if (m_tranTimes.size() > 0 && m_tranTimes.last().atMSecsSinceEpoch < beforeMSecsSinceEpoch | - | ||||||||||||
919 | && !m_posixRule.isEmpty() && beforeMSecsSinceEpoch > 0) { | - | ||||||||||||
920 | const int year = QDateTime::fromMSecsSinceEpoch(beforeMSecsSinceEpoch, Qt::UTC).date().year(); | - | ||||||||||||
921 | QVector<QTimeZonePrivate::Data> posixTrans = | - | ||||||||||||
922 | calculatePosixTransitions(m_posixRule, year - 1, year + 1, | - | ||||||||||||
923 | m_tranTimes.last().atMSecsSinceEpoch); | - | ||||||||||||
924 | for (int i = posixTrans.size() - 1; i >= 0; --i) { | - | ||||||||||||
925 | if (posixTrans.at(i).atMSecsSinceEpoch < beforeMSecsSinceEpoch) | - | ||||||||||||
926 | return posixTrans.at(i); | - | ||||||||||||
927 | } | - | ||||||||||||
928 | } | - | ||||||||||||
929 | - | |||||||||||||
930 | - | |||||||||||||
931 | for (int i = m_tranTimes.size() - 1; i >= 0; --i) { | - | ||||||||||||
932 | if (m_tranTimes.at(i).atMSecsSinceEpoch < beforeMSecsSinceEpoch) { | - | ||||||||||||
933 | return dataForTzTransition(m_tranTimes.at(i)); | - | ||||||||||||
934 | } | - | ||||||||||||
935 | } | - | ||||||||||||
936 | - | |||||||||||||
937 | - | |||||||||||||
938 | return invalidData(); | - | ||||||||||||
939 | } | - | ||||||||||||
940 | - | |||||||||||||
941 | - | |||||||||||||
942 | QByteArray QTzTimeZonePrivate::systemTimeZoneId() const | - | ||||||||||||
943 | { | - | ||||||||||||
944 | - | |||||||||||||
945 | QByteArray ianaId = qgetenv("TZ"); | - | ||||||||||||
946 | if (!ianaId.isEmpty() && ianaId.at(0) == ':') | - | ||||||||||||
947 | ianaId = ianaId.mid(1); | - | ||||||||||||
948 | - | |||||||||||||
949 | - | |||||||||||||
950 | - | |||||||||||||
951 | - | |||||||||||||
952 | - | |||||||||||||
953 | if (ianaId == "/etc/localtime") | - | ||||||||||||
954 | ianaId.clear(); | - | ||||||||||||
955 | - | |||||||||||||
956 | - | |||||||||||||
957 | if (ianaId.isEmpty()) { | - | ||||||||||||
958 | QFile tzif(([]() -> QString { enum { Size = sizeof(u"" "/etc/timezone")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "/etc/timezone" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())); | - | ||||||||||||
959 | if (tzif.open(QIODevice::ReadOnly)) { | - | ||||||||||||
960 | - | |||||||||||||
961 | QTextStream ts(&tzif); | - | ||||||||||||
962 | if (!ts.atEnd()) | - | ||||||||||||
963 | ianaId = ts.readLine().toUtf8(); | - | ||||||||||||
964 | } | - | ||||||||||||
965 | } | - | ||||||||||||
966 | - | |||||||||||||
967 | - | |||||||||||||
968 | if (ianaId.isEmpty()) { | - | ||||||||||||
969 | const QString path = QFile::symLinkTarget(([]() -> QString { enum { Size = sizeof(u"" "/etc/localtime")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "/etc/localtime" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())); | - | ||||||||||||
970 | if (!path.isEmpty()) { | - | ||||||||||||
971 | - | |||||||||||||
972 | int index = path.indexOf(QLatin1String("/zoneinfo/")) + 10; | - | ||||||||||||
973 | ianaId = path.mid(index).toUtf8(); | - | ||||||||||||
974 | } | - | ||||||||||||
975 | } | - | ||||||||||||
976 | - | |||||||||||||
977 | - | |||||||||||||
978 | - | |||||||||||||
979 | if (ianaId.isEmpty()) { | - | ||||||||||||
980 | QFile tzif(([]() -> QString { enum { Size = sizeof(u"" "/etc/sysconfig/clock")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "/etc/sysconfig/clock" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())); | - | ||||||||||||
981 | if (tzif.open(QIODevice::ReadOnly)) { | - | ||||||||||||
982 | - | |||||||||||||
983 | QTextStream ts(&tzif); | - | ||||||||||||
984 | QString line; | - | ||||||||||||
985 | while (ianaId.isEmpty() && !ts.atEnd() && ts.status() == QTextStream::Ok) { | - | ||||||||||||
986 | line = ts.readLine(); | - | ||||||||||||
987 | if (line.startsWith(QLatin1String("ZONE="))) { | - | ||||||||||||
988 | ianaId = line.mid(6, line.size() - 7).toUtf8(); | - | ||||||||||||
989 | } else if (line.startsWith(QLatin1String("TIMEZONE="))) { | - | ||||||||||||
990 | ianaId = line.mid(10, line.size() - 11).toUtf8(); | - | ||||||||||||
991 | } | - | ||||||||||||
992 | } | - | ||||||||||||
993 | } | - | ||||||||||||
994 | } | - | ||||||||||||
995 | - | |||||||||||||
996 | - | |||||||||||||
997 | if (ianaId.isEmpty()) | - | ||||||||||||
998 | ianaId = utcQByteArray(); | - | ||||||||||||
999 | - | |||||||||||||
1000 | return ianaId; | - | ||||||||||||
1001 | } | - | ||||||||||||
1002 | - | |||||||||||||
1003 | QList<QByteArray> QTzTimeZonePrivate::availableTimeZoneIds() const | - | ||||||||||||
1004 | { | - | ||||||||||||
1005 | QList<QByteArray> result = tzZones->keys(); | - | ||||||||||||
1006 | std::sort(result.begin(), result.end()); | - | ||||||||||||
1007 | return result; | - | ||||||||||||
1008 | } | - | ||||||||||||
1009 | - | |||||||||||||
1010 | QList<QByteArray> QTzTimeZonePrivate::availableTimeZoneIds(QLocale::Country country) const | - | ||||||||||||
1011 | { | - | ||||||||||||
1012 | - | |||||||||||||
1013 | QList<QByteArray> result; | - | ||||||||||||
1014 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(auto it = tzZones->keys())>::type> _container_((cbegin(), end = tzZones->keys())); _container_.control && _container_.icend(); it
| 1-421 | ||||||||||||
1015 | if (tzZones->it.
| 29-392 | ||||||||||||
1016 | result << it.key;(); executed 29 times by 1 test: result << it.key(); Executed by:
| 29 | ||||||||||||
1017 | } executed 421 times by 1 test: end of block Executed by:
| 421 | ||||||||||||
1018 | std::sort(result.begin(), result.end()); | - | ||||||||||||
1019 | return executed 1 time by 1 test: result;return result; Executed by:
executed 1 time by 1 test: return result; Executed by:
| 1 | ||||||||||||
1020 | } | - | ||||||||||||
1021 | - | |||||||||||||
1022 | - | |||||||||||||
Switch to Source code | Preprocessed file |