qtimezone.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qtimezone.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9static QTimeZonePrivate *newBackendTimeZone()-
10{-
11 return new QTzTimeZonePrivate();-
12}-
13-
14-
15static QTimeZonePrivate *newBackendTimeZone(const QByteArray &ianaId)-
16{-
17 return new QTzTimeZonePrivate(ianaId);-
18}-
19-
20class QTimeZoneSingleton-
21{-
22public:-
23 QTimeZoneSingleton() : backend(newBackendTimeZone()) {}-
24-
25-
26-
27-
28-
29 QSharedDataPointer<QTimeZonePrivate> backend;-
30};-
31-
32namespace { namespace Q_QGS_global_tz { typedef QTimeZoneSingleton 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 ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<QTimeZoneSingleton, Q_QGS_global_tz::innerFunction, Q_QGS_global_tz::guard> global_tz;;-
33QTimeZone::QTimeZone() noexcept-
34 : d(0)-
35{-
36}
executed 7098826 times by 128 tests: end of block
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractFileEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDBusMetaType
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • ...
7098826
37QTimeZone::QTimeZone(const QByteArray &ianaId)-
38{-
39-
40 d = new QUtcTimeZonePrivate(ianaId);-
41-
42-
43 if (!d->isValid())-
44 d = newBackendTimeZone(ianaId);-
45}-
46QTimeZone::QTimeZone(int offsetSeconds)-
47{-
48-
49 if (offsetSeconds >= -50400 && offsetSeconds <= 50400)-
50 d = new QUtcTimeZonePrivate(offsetSeconds);-
51 else-
52 d = 0;-
53}-
54QTimeZone::QTimeZone(const QByteArray &ianaId, int offsetSeconds, const QString &name,-
55 const QString &abbreviation, QLocale::Country country, const QString &comment)-
56 : d()-
57{-
58 if (!isTimeZoneIdAvailable(ianaId))-
59 d = new QUtcTimeZonePrivate(ianaId, offsetSeconds, name, abbreviation, country, comment);-
60}-
61-
62-
63-
64-
65-
66-
67-
68QTimeZone::QTimeZone(QTimeZonePrivate &dd)-
69 : d(&dd)-
70{-
71}-
72-
73-
74-
75-
76-
77QTimeZone::QTimeZone(const QTimeZone &other)-
78 : d(other.d)-
79{-
80}-
81-
82-
83-
84-
85-
86QTimeZone::~QTimeZone()-
87{-
88}-
89QTimeZone &QTimeZone::operator=(const QTimeZone &other)-
90{-
91 d = other.d;-
92 return *this;-
93}-
94bool QTimeZone::operator==(const QTimeZone &other) const-
95{-
96 if (d && other.d)-
97 return (*d == *other.d);-
98 else-
99 return (d == other.d);-
100}-
101-
102-
103-
104-
105-
106bool QTimeZone::operator!=(const QTimeZone &other) const-
107{-
108 if (d && other.d)-
109 return (*d != *other.d);-
110 else-
111 return (d != other.d);-
112}-
113-
114-
115-
116-
117-
118bool QTimeZone::isValid() const-
119{-
120 if (d)-
121 return d->isValid();-
122 else-
123 return false;-
124}-
125QByteArray QTimeZone::id() const-
126{-
127 if (d)-
128 return d->id();-
129 else-
130 return QByteArray();-
131}-
132-
133-
134-
135-
136-
137QLocale::Country QTimeZone::country() const-
138{-
139 if (isValid())-
140 return d->country();-
141 else-
142 return QLocale::AnyCountry;-
143}-
144QString QTimeZone::comment() const-
145{-
146 if (isValid())-
147 return d->comment();-
148 else-
149 return QString();-
150}-
151QString QTimeZone::displayName(const QDateTime &atDateTime, NameType nameType,-
152 const QLocale &locale) const-
153{-
154 if (isValid())-
155 return d->displayName(atDateTime.toMSecsSinceEpoch(), nameType, locale);-
156 else-
157 return QString();-
158}-
159QString QTimeZone::displayName(TimeType timeType, NameType nameType,-
160 const QLocale &locale) const-
161{-
162 if (isValid())-
163 return d->displayName(timeType, nameType, locale);-
164 else-
165 return QString();-
166}-
167QString QTimeZone::abbreviation(const QDateTime &atDateTime) const-
168{-
169 if (isValid())-
170 return d->abbreviation(atDateTime.toMSecsSinceEpoch());-
171 else-
172 return QString();-
173}-
174int QTimeZone::offsetFromUtc(const QDateTime &atDateTime) const-
175{-
176 if (isValid())-
177 return d->offsetFromUtc(atDateTime.toMSecsSinceEpoch());-
178 else-
179 return 0;-
180}-
181int QTimeZone::standardTimeOffset(const QDateTime &atDateTime) const-
182{-
183 if (isValid())-
184 return d->standardTimeOffset(atDateTime.toMSecsSinceEpoch());-
185 else-
186 return 0;-
187}-
188int QTimeZone::daylightTimeOffset(const QDateTime &atDateTime) const-
189{-
190 if (hasDaylightTime())-
191 return d->daylightTimeOffset(atDateTime.toMSecsSinceEpoch());-
192 else-
193 return 0;-
194}-
195-
196-
197-
198-
199-
200-
201-
202bool QTimeZone::hasDaylightTime() const-
203{-
204 if (isValid())-
205 return d->hasDaylightTime();-
206 else-
207 return false;-
208}-
209-
210-
211-
212-
213-
214-
215-
216bool QTimeZone::isDaylightTime(const QDateTime &atDateTime) const-
217{-
218 if (hasDaylightTime())-
219 return d->isDaylightTime(atDateTime.toMSecsSinceEpoch());-
220 else-
221 return false;-
222}-
223QTimeZone::OffsetData QTimeZone::offsetData(const QDateTime &forDateTime) const-
224{-
225 if (hasTransitions()
hasTransitions()Description
TRUEevaluated 421 times by 1 test
Evaluated by:
  • tst_QTimeZone
FALSEevaluated 41 times by 1 test
Evaluated by:
  • tst_QTimeZone
)
41-421
226 return
executed 421 times by 1 test: return d->toOffsetData(d->data(forDateTime.toMSecsSinceEpoch()));
Executed by:
  • tst_QTimeZone
QTimeZonePrivate::d->toOffsetData(d->data(forDateTime.toMSecsSinceEpoch()));
executed 421 times by 1 test: return d->toOffsetData(d->data(forDateTime.toMSecsSinceEpoch()));
Executed by:
  • tst_QTimeZone
421
227 else-
228 return
executed 41 times by 1 test: return d->invalidOffsetData();
Executed by:
  • tst_QTimeZone
QTimeZonePrivate::d->invalidOffsetData();
executed 41 times by 1 test: return d->invalidOffsetData();
Executed by:
  • tst_QTimeZone
41
229}-
230bool QTimeZone::hasTransitions() const-
231{-
232 if (isValid())-
233 return d->hasTransitions();-
234 else-
235 return false;-
236}-
237QTimeZone::OffsetData QTimeZone::nextTransition(const QDateTime &afterDateTime) const-
238{-
239 if (hasTransitions()
hasTransitions()Description
TRUEevaluated 2107 times by 1 test
Evaluated by:
  • tst_QTimeZone
FALSEevaluated 201 times by 1 test
Evaluated by:
  • tst_QTimeZone
)
201-2107
240 return
executed 2107 times by 1 test: return d->toOffsetData(d->nextTransition(afterDateTime.toMSecsSinceEpoch()));
Executed by:
  • tst_QTimeZone
QTimeZonePrivate::d->toOffsetData(d->nextTransition(afterDateTime.toMSecsSinceEpoch()));
executed 2107 times by 1 test: return d->toOffsetData(d->nextTransition(afterDateTime.toMSecsSinceEpoch()));
Executed by:
  • tst_QTimeZone
2107
241 else-
242 return
executed 201 times by 1 test: return d->invalidOffsetData();
Executed by:
  • tst_QTimeZone
QTimeZonePrivate::d->invalidOffsetData();
executed 201 times by 1 test: return d->invalidOffsetData();
Executed by:
  • tst_QTimeZone
201
243}-
244QTimeZone::OffsetData QTimeZone::previousTransition(const QDateTime &beforeDateTime) const-
245{-
246 if (hasTransitions()
hasTransitions()Description
TRUEevaluated 2107 times by 1 test
Evaluated by:
  • tst_QTimeZone
FALSEevaluated 201 times by 1 test
Evaluated by:
  • tst_QTimeZone
)
201-2107
247 return
executed 2107 times by 1 test: return d->toOffsetData(d->previousTransition(beforeDateTime.toMSecsSinceEpoch()));
Executed by:
  • tst_QTimeZone
QTimeZonePrivate::d->toOffsetData(d->previousTransition(beforeDateTime.toMSecsSinceEpoch()));
executed 2107 times by 1 test: return d->toOffsetData(d->previousTransition(beforeDateTime.toMSecsSinceEpoch()));
Executed by:
  • tst_QTimeZone
2107
248 else-
249 return
executed 201 times by 1 test: return d->invalidOffsetData();
Executed by:
  • tst_QTimeZone
QTimeZonePrivate::d->invalidOffsetData();
executed 201 times by 1 test: return d->invalidOffsetData();
Executed by:
  • tst_QTimeZone
201
250}-
251QTimeZone::OffsetDataList QTimeZone::transitions(const QDateTime &fromDateTime,-
252 const QDateTime &toDateTime) const-
253{-
254 OffsetDataList list;-
255 if (hasTransitions()
hasTransitions()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QTimeZone
FALSEnever evaluated
) {
0-1
256 const QTimeZonePrivate::DataList plist = d->transitions(fromDateTime.toMSecsSinceEpoch(),-
257 toDateTime.toMSecsSinceEpoch());-
258 list.reserve(plist.count());-
259 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(plist)>::type> _container_((plist)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const QTimeZonePrivate::Data &pdata = *_container_.i; _container_.control; _container_.control = 0: plist)-
260 list.append(QTimeZonePrivate::d->toOffsetData(pdata));
executed 2 times by 1 test: list.append(d->toOffsetData(pdata));
Executed by:
  • tst_QTimeZone
2
261 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QTimeZone
1
262 return
executed 1 time by 1 test: return list;
Executed by:
  • tst_QTimeZone
list;
executed 1 time by 1 test: return list;
Executed by:
  • tst_QTimeZone
1
263}-
264QByteArray QTimeZone::systemTimeZoneId()-
265{-
266 return global_tz->backend->systemTimeZoneId();-
267}-
268QTimeZone QTimeZone::systemTimeZone()-
269{-
270 return QTimeZone(QTimeZone::systemTimeZoneId());-
271}-
272-
273-
274-
275-
276-
277-
278-
279QTimeZone QTimeZone::utc()-
280{-
281 return QTimeZone(QTimeZonePrivate::utcQByteArray());-
282}-
283-
284-
285-
286-
287-
288-
289-
290bool QTimeZone::isTimeZoneIdAvailable(const QByteArray &ianaId)-
291{-
292-
293-
294 if (!QTimeZonePrivate::isValidId(ianaId))-
295 return false;-
296 const QList<QByteArray> tzIds = availableTimeZoneIds();-
297 return std::binary_search(tzIds.begin(), tzIds.end(), ianaId);-
298}-
299-
300static QList<QByteArray> set_union(const QList<QByteArray> &l1, const QList<QByteArray> &l2)-
301{-
302 QList<QByteArray> result;-
303 result.reserve(l1.size() + l2.size());-
304 std::set_union(l1.begin(), l1.end(),-
305 l2.begin(), l2.end(),-
306 std::back_inserter(result));-
307 return result;-
308}-
309-
310-
311-
312-
313-
314-
315-
316QList<QByteArray> QTimeZone::availableTimeZoneIds()-
317{-
318 return set_union(QUtcTimeZonePrivate().availableTimeZoneIds(),-
319 global_tz->backend->availableTimeZoneIds());-
320}-
321QList<QByteArray> QTimeZone::availableTimeZoneIds(QLocale::Country country)-
322{-
323 return set_union(QUtcTimeZonePrivate().availableTimeZoneIds(country),-
324 global_tz->backend->availableTimeZoneIds(country));-
325}-
326QList<QByteArray> QTimeZone::availableTimeZoneIds(int offsetSeconds)-
327{-
328 return set_union(QUtcTimeZonePrivate().availableTimeZoneIds(offsetSeconds),-
329 global_tz->backend->availableTimeZoneIds(offsetSeconds));-
330}-
331-
332-
333-
334-
335-
336-
337-
338QByteArray QTimeZone::ianaIdToWindowsId(const QByteArray &ianaId)-
339{-
340 return QTimeZonePrivate::ianaIdToWindowsId(ianaId);-
341}-
342QByteArray QTimeZone::windowsIdToDefaultIanaId(const QByteArray &windowsId)-
343{-
344 return QTimeZonePrivate::windowsIdToDefaultIanaId(windowsId);-
345}-
346QByteArray QTimeZone::windowsIdToDefaultIanaId(const QByteArray &windowsId,-
347 QLocale::Country country)-
348{-
349 return QTimeZonePrivate::windowsIdToDefaultIanaId(windowsId, country);-
350}-
351QList<QByteArray> QTimeZone::windowsIdToIanaIds(const QByteArray &windowsId)-
352{-
353 return QTimeZonePrivate::windowsIdToIanaIds(windowsId);-
354}-
355QList<QByteArray> QTimeZone::windowsIdToIanaIds(const QByteArray &windowsId,-
356 QLocale::Country country)-
357{-
358 return QTimeZonePrivate::windowsIdToIanaIds(windowsId, country);-
359}-
360-
361-
362QDataStream &operator<<(QDataStream &ds, const QTimeZone &tz)-
363{-
364 tz.d->serialize(ds);-
365 return ds;-
366}-
367-
368QDataStream &operator>>(QDataStream &ds, QTimeZone &tz)-
369{-
370 QString ianaId;-
371 ds >> ianaId;-
372 if (ianaId == QLatin1String("OffsetFromUtc")) {-
373 int utcOffset;-
374 QString name;-
375 QString abbreviation;-
376 int country;-
377 QString comment;-
378 ds >> ianaId >> utcOffset >> name >> abbreviation >> country >> comment;-
379 tz = QTimeZone(ianaId.toUtf8(), utcOffset, name, abbreviation, (QLocale::Country) country, comment);-
380 } else {-
381 tz = QTimeZone(ianaId.toUtf8());-
382 }-
383 return ds;-
384}-
385-
386-
387-
388QDebug operator<<(QDebug dbg, const QTimeZone &tz)-
389{-
390 QDebugStateSaver saver(dbg);-
391-
392 dbg.nospace() << "QTimeZone(" << QString::fromUtf8(tz.id()) << ')';-
393 return dbg;-
394}-
395-
396-
397-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9