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