| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qtimezone.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||
| 2 | - | |||||||
| 3 | - | |||||||
| 4 | - | |||||||
| 5 | - | |||||||
| 6 | - | |||||||
| 7 | - | |||||||
| 8 | - | |||||||
| 9 | static QTimeZonePrivate *newBackendTimeZone() | - | ||||||
| 10 | { | - | ||||||
| 11 | return new QTzTimeZonePrivate(); | - | ||||||
| 12 | } | - | ||||||
| 13 | - | |||||||
| 14 | - | |||||||
| 15 | static QTimeZonePrivate *newBackendTimeZone(const QByteArray &ianaId) | - | ||||||
| 16 | { | - | ||||||
| 17 | return new QTzTimeZonePrivate(ianaId); | - | ||||||
| 18 | } | - | ||||||
| 19 | - | |||||||
| 20 | class QTimeZoneSingleton | - | ||||||
| 21 | { | - | ||||||
| 22 | public: | - | ||||||
| 23 | QTimeZoneSingleton() : backend(newBackendTimeZone()) {} | - | ||||||
| 24 | - | |||||||
| 25 | - | |||||||
| 26 | - | |||||||
| 27 | - | |||||||
| 28 | - | |||||||
| 29 | QSharedDataPointer<QTimeZonePrivate> backend; | - | ||||||
| 30 | }; | - | ||||||
| 31 | - | |||||||
| 32 | namespace { 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;; | - | ||||||
| 33 | QTimeZone::QTimeZone() noexcept | - | ||||||
| 34 | : d(0) | - | ||||||
| 35 | { | - | ||||||
| 36 | } executed 7098826 times by 128 tests: end of blockExecuted by:
| 7098826 | ||||||
| 37 | QTimeZone::QTimeZone(const QByteArray &ianaId) | - | ||||||
| 38 | { | - | ||||||
| 39 | - | |||||||
| 40 | d = new QUtcTimeZonePrivate(ianaId); | - | ||||||
| 41 | - | |||||||
| 42 | - | |||||||
| 43 | if (!d->isValid()) | - | ||||||
| 44 | d = newBackendTimeZone(ianaId); | - | ||||||
| 45 | } | - | ||||||
| 46 | QTimeZone::QTimeZone(int offsetSeconds) | - | ||||||
| 47 | { | - | ||||||
| 48 | - | |||||||
| 49 | if (offsetSeconds >= -50400 && offsetSeconds <= 50400) | - | ||||||
| 50 | d = new QUtcTimeZonePrivate(offsetSeconds); | - | ||||||
| 51 | else | - | ||||||
| 52 | d = 0; | - | ||||||
| 53 | } | - | ||||||
| 54 | QTimeZone::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 | - | |||||||
| 68 | QTimeZone::QTimeZone(QTimeZonePrivate &dd) | - | ||||||
| 69 | : d(&dd) | - | ||||||
| 70 | { | - | ||||||
| 71 | } | - | ||||||
| 72 | - | |||||||
| 73 | - | |||||||
| 74 | - | |||||||
| 75 | - | |||||||
| 76 | - | |||||||
| 77 | QTimeZone::QTimeZone(const QTimeZone &other) | - | ||||||
| 78 | : d(other.d) | - | ||||||
| 79 | { | - | ||||||
| 80 | } | - | ||||||
| 81 | - | |||||||
| 82 | - | |||||||
| 83 | - | |||||||
| 84 | - | |||||||
| 85 | - | |||||||
| 86 | QTimeZone::~QTimeZone() | - | ||||||
| 87 | { | - | ||||||
| 88 | } | - | ||||||
| 89 | QTimeZone &QTimeZone::operator=(const QTimeZone &other) | - | ||||||
| 90 | { | - | ||||||
| 91 | d = other.d; | - | ||||||
| 92 | return *this; | - | ||||||
| 93 | } | - | ||||||
| 94 | bool 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 | - | |||||||
| 106 | bool 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 | - | |||||||
| 118 | bool QTimeZone::isValid() const | - | ||||||
| 119 | { | - | ||||||
| 120 | if (d) | - | ||||||
| 121 | return d->isValid(); | - | ||||||
| 122 | else | - | ||||||
| 123 | return false; | - | ||||||
| 124 | } | - | ||||||
| 125 | QByteArray QTimeZone::id() const | - | ||||||
| 126 | { | - | ||||||
| 127 | if (d) | - | ||||||
| 128 | return d->id(); | - | ||||||
| 129 | else | - | ||||||
| 130 | return QByteArray(); | - | ||||||
| 131 | } | - | ||||||
| 132 | - | |||||||
| 133 | - | |||||||
| 134 | - | |||||||
| 135 | - | |||||||
| 136 | - | |||||||
| 137 | QLocale::Country QTimeZone::country() const | - | ||||||
| 138 | { | - | ||||||
| 139 | if (isValid()) | - | ||||||
| 140 | return d->country(); | - | ||||||
| 141 | else | - | ||||||
| 142 | return QLocale::AnyCountry; | - | ||||||
| 143 | } | - | ||||||
| 144 | QString QTimeZone::comment() const | - | ||||||
| 145 | { | - | ||||||
| 146 | if (isValid()) | - | ||||||
| 147 | return d->comment(); | - | ||||||
| 148 | else | - | ||||||
| 149 | return QString(); | - | ||||||
| 150 | } | - | ||||||
| 151 | QString 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 | } | - | ||||||
| 159 | QString 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 | } | - | ||||||
| 167 | QString QTimeZone::abbreviation(const QDateTime &atDateTime) const | - | ||||||
| 168 | { | - | ||||||
| 169 | if (isValid()) | - | ||||||
| 170 | return d->abbreviation(atDateTime.toMSecsSinceEpoch()); | - | ||||||
| 171 | else | - | ||||||
| 172 | return QString(); | - | ||||||
| 173 | } | - | ||||||
| 174 | int QTimeZone::offsetFromUtc(const QDateTime &atDateTime) const | - | ||||||
| 175 | { | - | ||||||
| 176 | if (isValid()) | - | ||||||
| 177 | return d->offsetFromUtc(atDateTime.toMSecsSinceEpoch()); | - | ||||||
| 178 | else | - | ||||||
| 179 | return 0; | - | ||||||
| 180 | } | - | ||||||
| 181 | int QTimeZone::standardTimeOffset(const QDateTime &atDateTime) const | - | ||||||
| 182 | { | - | ||||||
| 183 | if (isValid()) | - | ||||||
| 184 | return d->standardTimeOffset(atDateTime.toMSecsSinceEpoch()); | - | ||||||
| 185 | else | - | ||||||
| 186 | return 0; | - | ||||||
| 187 | } | - | ||||||
| 188 | int 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 | - | |||||||
| 202 | bool QTimeZone::hasDaylightTime() const | - | ||||||
| 203 | { | - | ||||||
| 204 | if (isValid()) | - | ||||||
| 205 | return d->hasDaylightTime(); | - | ||||||
| 206 | else | - | ||||||
| 207 | return false; | - | ||||||
| 208 | } | - | ||||||
| 209 | - | |||||||
| 210 | - | |||||||
| 211 | - | |||||||
| 212 | - | |||||||
| 213 | - | |||||||
| 214 | - | |||||||
| 215 | - | |||||||
| 216 | bool QTimeZone::isDaylightTime(const QDateTime &atDateTime) const | - | ||||||
| 217 | { | - | ||||||
| 218 | if (hasDaylightTime()) | - | ||||||
| 219 | return d->isDaylightTime(atDateTime.toMSecsSinceEpoch()); | - | ||||||
| 220 | else | - | ||||||
| 221 | return false; | - | ||||||
| 222 | } | - | ||||||
| 223 | QTimeZone::OffsetData QTimeZone::offsetData(const QDateTime &forDateTime) const | - | ||||||
| 224 | { | - | ||||||
| 225 | if (hasTransitions()
| 41-421 | ||||||
| 226 | return executed 421 times by 1 test: QTimeZonePrivate::d->toOffsetData(d->data(forDateTime.toMSecsSinceEpoch()));return d->toOffsetData(d->data(forDateTime.toMSecsSinceEpoch()));Executed by:
executed 421 times by 1 test: return d->toOffsetData(d->data(forDateTime.toMSecsSinceEpoch()));Executed by:
| 421 | ||||||
| 227 | else | - | ||||||
| 228 | return executed 41 times by 1 test: QTimeZonePrivate::d->invalidOffsetData();return d->invalidOffsetData();Executed by:
executed 41 times by 1 test: return d->invalidOffsetData();Executed by:
| 41 | ||||||
| 229 | } | - | ||||||
| 230 | bool QTimeZone::hasTransitions() const | - | ||||||
| 231 | { | - | ||||||
| 232 | if (isValid()) | - | ||||||
| 233 | return d->hasTransitions(); | - | ||||||
| 234 | else | - | ||||||
| 235 | return false; | - | ||||||
| 236 | } | - | ||||||
| 237 | QTimeZone::OffsetData QTimeZone::nextTransition(const QDateTime &afterDateTime) const | - | ||||||
| 238 | { | - | ||||||
| 239 | if (hasTransitions()
| 201-2107 | ||||||
| 240 | return executed 2107 times by 1 test: QTimeZonePrivate::d->toOffsetData(d->nextTransition(afterDateTime.toMSecsSinceEpoch()));return d->toOffsetData(d->nextTransition(afterDateTime.toMSecsSinceEpoch()));Executed by:
executed 2107 times by 1 test: return d->toOffsetData(d->nextTransition(afterDateTime.toMSecsSinceEpoch()));Executed by:
| 2107 | ||||||
| 241 | else | - | ||||||
| 242 | return executed 201 times by 1 test: QTimeZonePrivate::d->invalidOffsetData();return d->invalidOffsetData();Executed by:
executed 201 times by 1 test: return d->invalidOffsetData();Executed by:
| 201 | ||||||
| 243 | } | - | ||||||
| 244 | QTimeZone::OffsetData QTimeZone::previousTransition(const QDateTime &beforeDateTime) const | - | ||||||
| 245 | { | - | ||||||
| 246 | if (hasTransitions()
| 201-2107 | ||||||
| 247 | return executed 2107 times by 1 test: QTimeZonePrivate::d->toOffsetData(d->previousTransition(beforeDateTime.toMSecsSinceEpoch()));return d->toOffsetData(d->previousTransition(beforeDateTime.toMSecsSinceEpoch()));Executed by:
executed 2107 times by 1 test: return d->toOffsetData(d->previousTransition(beforeDateTime.toMSecsSinceEpoch()));Executed by:
| 2107 | ||||||
| 248 | else | - | ||||||
| 249 | return executed 201 times by 1 test: QTimeZonePrivate::d->invalidOffsetData();return d->invalidOffsetData();Executed by:
executed 201 times by 1 test: return d->invalidOffsetData();Executed by:
| 201 | ||||||
| 250 | } | - | ||||||
| 251 | QTimeZone::OffsetDataList QTimeZone::transitions(const QDateTime &fromDateTime, | - | ||||||
| 252 | const QDateTime &toDateTime) const | - | ||||||
| 253 | { | - | ||||||
| 254 | OffsetDataList list; | - | ||||||
| 255 | if (hasTransitions()
| 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:
| 2 | ||||||
| 261 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||
| 262 | return executed 1 time by 1 test: list;return list;Executed by:
executed 1 time by 1 test: return list;Executed by:
| 1 | ||||||
| 263 | } | - | ||||||
| 264 | QByteArray QTimeZone::systemTimeZoneId() | - | ||||||
| 265 | { | - | ||||||
| 266 | return global_tz->backend->systemTimeZoneId(); | - | ||||||
| 267 | } | - | ||||||
| 268 | QTimeZone QTimeZone::systemTimeZone() | - | ||||||
| 269 | { | - | ||||||
| 270 | return QTimeZone(QTimeZone::systemTimeZoneId()); | - | ||||||
| 271 | } | - | ||||||
| 272 | - | |||||||
| 273 | - | |||||||
| 274 | - | |||||||
| 275 | - | |||||||
| 276 | - | |||||||
| 277 | - | |||||||
| 278 | - | |||||||
| 279 | QTimeZone QTimeZone::utc() | - | ||||||
| 280 | { | - | ||||||
| 281 | return QTimeZone(QTimeZonePrivate::utcQByteArray()); | - | ||||||
| 282 | } | - | ||||||
| 283 | - | |||||||
| 284 | - | |||||||
| 285 | - | |||||||
| 286 | - | |||||||
| 287 | - | |||||||
| 288 | - | |||||||
| 289 | - | |||||||
| 290 | bool 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 | - | |||||||
| 300 | static 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 | - | |||||||
| 316 | QList<QByteArray> QTimeZone::availableTimeZoneIds() | - | ||||||
| 317 | { | - | ||||||
| 318 | return set_union(QUtcTimeZonePrivate().availableTimeZoneIds(), | - | ||||||
| 319 | global_tz->backend->availableTimeZoneIds()); | - | ||||||
| 320 | } | - | ||||||
| 321 | QList<QByteArray> QTimeZone::availableTimeZoneIds(QLocale::Country country) | - | ||||||
| 322 | { | - | ||||||
| 323 | return set_union(QUtcTimeZonePrivate().availableTimeZoneIds(country), | - | ||||||
| 324 | global_tz->backend->availableTimeZoneIds(country)); | - | ||||||
| 325 | } | - | ||||||
| 326 | QList<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 | - | |||||||
| 338 | QByteArray QTimeZone::ianaIdToWindowsId(const QByteArray &ianaId) | - | ||||||
| 339 | { | - | ||||||
| 340 | return QTimeZonePrivate::ianaIdToWindowsId(ianaId); | - | ||||||
| 341 | } | - | ||||||
| 342 | QByteArray QTimeZone::windowsIdToDefaultIanaId(const QByteArray &windowsId) | - | ||||||
| 343 | { | - | ||||||
| 344 | return QTimeZonePrivate::windowsIdToDefaultIanaId(windowsId); | - | ||||||
| 345 | } | - | ||||||
| 346 | QByteArray QTimeZone::windowsIdToDefaultIanaId(const QByteArray &windowsId, | - | ||||||
| 347 | QLocale::Country country) | - | ||||||
| 348 | { | - | ||||||
| 349 | return QTimeZonePrivate::windowsIdToDefaultIanaId(windowsId, country); | - | ||||||
| 350 | } | - | ||||||
| 351 | QList<QByteArray> QTimeZone::windowsIdToIanaIds(const QByteArray &windowsId) | - | ||||||
| 352 | { | - | ||||||
| 353 | return QTimeZonePrivate::windowsIdToIanaIds(windowsId); | - | ||||||
| 354 | } | - | ||||||
| 355 | QList<QByteArray> QTimeZone::windowsIdToIanaIds(const QByteArray &windowsId, | - | ||||||
| 356 | QLocale::Country country) | - | ||||||
| 357 | { | - | ||||||
| 358 | return QTimeZonePrivate::windowsIdToIanaIds(windowsId, country); | - | ||||||
| 359 | } | - | ||||||
| 360 | - | |||||||
| 361 | - | |||||||
| 362 | QDataStream &operator<<(QDataStream &ds, const QTimeZone &tz) | - | ||||||
| 363 | { | - | ||||||
| 364 | tz.d->serialize(ds); | - | ||||||
| 365 | return ds; | - | ||||||
| 366 | } | - | ||||||
| 367 | - | |||||||
| 368 | QDataStream &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 | - | |||||||
| 388 | QDebug 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 code | Preprocessed file |