diff options
Diffstat (limited to 'src/corelib/time/qtimezoneprivate_mac.mm')
-rw-r--r-- | src/corelib/time/qtimezoneprivate_mac.mm | 71 |
1 files changed, 20 insertions, 51 deletions
diff --git a/src/corelib/time/qtimezoneprivate_mac.mm b/src/corelib/time/qtimezoneprivate_mac.mm index 1fb48a31d3..da7e24d614 100644 --- a/src/corelib/time/qtimezoneprivate_mac.mm +++ b/src/corelib/time/qtimezoneprivate_mac.mm @@ -1,42 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Copyright (C) 2013 John Layt <jlayt@kde.org> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2019 The Qt Company Ltd. +// Copyright (C) 2013 John Layt <jlayt@kde.org> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qtimezone.h" #include "qtimezoneprivate_p.h" @@ -55,7 +19,8 @@ QT_BEGIN_NAMESPACE /* Private - OS X system implementation + Darwin system implementation + https://developer.apple.com/documentation/foundation/nstimezone */ // Create the system default time zone @@ -92,12 +57,10 @@ QMacTimeZonePrivate *QMacTimeZonePrivate::clone() const void QMacTimeZonePrivate::init(const QByteArray &ianaId) { - if (availableTimeZoneIds().contains(ianaId)) { - m_nstz = [[NSTimeZone timeZoneWithName:QString::fromUtf8(ianaId).toNSString()] retain]; - if (m_nstz) - m_id = ianaId; - } - if (!m_nstz) { + m_nstz = [[NSTimeZone timeZoneWithName:QString::fromUtf8(ianaId).toNSString()] retain]; + if (m_nstz) { + m_id = ianaId; + } else { // macOS has been seen returning a systemTimeZone which reports its name // as Asia/Kolkata, which doesn't appear in knownTimeZoneNames (which // calls the zone Asia/Calcutta). So explicitly check for the name @@ -149,7 +112,7 @@ QString QMacTimeZonePrivate::displayName(QTimeZone::TimeType timeType, style = NSTimeZoneNameStyleStandard; break; case QTimeZone::OffsetName : - // Unreachable + Q_UNREACHABLE(); break; } @@ -185,7 +148,7 @@ int QMacTimeZonePrivate::daylightTimeOffset(qint64 atMSecsSinceEpoch) const bool QMacTimeZonePrivate::hasDaylightTime() const { - // TODO No Mac API, assume if has transitions + // TODO Scan transitions for one after which isDaylightSavingTimeForDate is true. return hasTransitions(); } @@ -227,7 +190,7 @@ QTimeZonePrivate::Data QMacTimeZonePrivate::nextTransition(qint64 afterMSecsSinc const NSTimeInterval nextSecs = nextDate.timeIntervalSince1970; if (nextDate == nil || nextSecs <= seconds) { [nextDate release]; - return invalidData(); + return {}; } tran.atMSecsSinceEpoch = nextSecs * 1000; tran.offsetFromUtc = [m_nstz secondsFromGMTForDate:nextDate]; @@ -240,7 +203,7 @@ QTimeZonePrivate::Data QMacTimeZonePrivate::nextTransition(qint64 afterMSecsSinc QTimeZonePrivate::Data QMacTimeZonePrivate::previousTransition(qint64 beforeMSecsSinceEpoch) const { // The native API only lets us search forward, so we need to find an early-enough start: - const NSTimeInterval lowerBound = std::numeric_limits<NSTimeInterval>::lowest(); + constexpr NSTimeInterval lowerBound = std::numeric_limits<NSTimeInterval>::lowest(); const qint64 endSecs = beforeMSecsSinceEpoch / 1000; const int year = 366 * 24 * 3600; // a (long) year, in seconds NSTimeInterval prevSecs = endSecs; // sentinel for later check @@ -310,7 +273,7 @@ QTimeZonePrivate::Data QMacTimeZonePrivate::previousTransition(qint64 beforeMSec return data(qint64(prevSecs * 1e3)); // No transition data; or first transition later than requested time. - return invalidData(); + return {}; } QByteArray QMacTimeZonePrivate::systemTimeZoneId() const @@ -321,6 +284,12 @@ QByteArray QMacTimeZonePrivate::systemTimeZoneId() const return QString::fromNSString(NSTimeZone.systemTimeZone.name).toUtf8(); } +bool QMacTimeZonePrivate::isTimeZoneIdAvailable(const QByteArray& ianaId) const +{ + QMacAutoReleasePool pool; + return [NSTimeZone timeZoneWithName:QString::fromUtf8(ianaId).toNSString()] != nil; +} + QList<QByteArray> QMacTimeZonePrivate::availableTimeZoneIds() const { NSEnumerator *enumerator = NSTimeZone.knownTimeZoneNames.objectEnumerator; |