summaryrefslogtreecommitdiffstats
path: root/src/corelib/time
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2024-02-06 14:14:11 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2024-02-12 17:52:58 +0100
commit7c502391cf73e3fa5bc02ea0b46261f0b5be0b84 (patch)
treeb3a42323e69c397901391f654d20a1eafe807b60 /src/corelib/time
parent721641d38cd8df8399d9a473bf35c69a41f02d70 (diff)
Implement QTZP::isTimeZoneIdAvailable() on Android
The QTZP base implementation of the availability check was to construct the list of all available IDs, then see whether the given ID appears in it. This can be very inefficient. The ICU backend has recently grown a more efficient solution than that, matching the TZ and Darwin backends. For Android this was still very inefficient, but its instantiation is cheaper, so simply instantiate and see if the result is valid. For MS, the backend caches the list of available zones, so searching the list is a reasonable solution, given the complexity of its constructor. Add an implementation for Android and document, in the base-class, that the fall-back is only suitable for use if the list is cached. Pick-to: 6.7 6.6 6.5 Change-Id: I9dc2ba4be1492ec811c8db6cff9490ac0303115d Reviewed-by: Volker Krause <vkrause@kde.org> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/corelib/time')
-rw-r--r--src/corelib/time/qtimezoneprivate.cpp3
-rw-r--r--src/corelib/time/qtimezoneprivate_android.cpp6
-rw-r--r--src/corelib/time/qtimezoneprivate_p.h2
3 files changed, 9 insertions, 2 deletions
diff --git a/src/corelib/time/qtimezoneprivate.cpp b/src/corelib/time/qtimezoneprivate.cpp
index 9f439513db..cf81324346 100644
--- a/src/corelib/time/qtimezoneprivate.cpp
+++ b/src/corelib/time/qtimezoneprivate.cpp
@@ -519,7 +519,8 @@ QByteArray QTimeZonePrivate::systemTimeZoneId() const
bool QTimeZonePrivate::isTimeZoneIdAvailable(const QByteArray& ianaId) const
{
- // Fall-back implementation, can be made faster in subclasses
+ // Fall-back implementation, can be made faster in subclasses.
+ // Backends that don't cache the available list SHOULD override this.
const QList<QByteArray> tzIds = availableTimeZoneIds();
return std::binary_search(tzIds.begin(), tzIds.end(), ianaId);
}
diff --git a/src/corelib/time/qtimezoneprivate_android.cpp b/src/corelib/time/qtimezoneprivate_android.cpp
index 05b4bd8cbc..0194352f5e 100644
--- a/src/corelib/time/qtimezoneprivate_android.cpp
+++ b/src/corelib/time/qtimezoneprivate_android.cpp
@@ -206,6 +206,12 @@ QByteArray QAndroidTimeZonePrivate::systemTimeZoneId() const
return id.toString().toUtf8();
}
+bool QAndroidTimeZonePrivate::isTimeZoneIdAvailable(const QByteArray &ianaId) const
+{
+ QAndroidTimeZonePrivate probe(ianaId);
+ return probe.isValid();
+}
+
QList<QByteArray> QAndroidTimeZonePrivate::availableTimeZoneIds() const
{
QList<QByteArray> availableTimeZoneIdList;
diff --git a/src/corelib/time/qtimezoneprivate_p.h b/src/corelib/time/qtimezoneprivate_p.h
index bef9c11d43..3bb12019b5 100644
--- a/src/corelib/time/qtimezoneprivate_p.h
+++ b/src/corelib/time/qtimezoneprivate_p.h
@@ -463,7 +463,7 @@ public:
Data data(qint64 forMSecsSinceEpoch) const override;
QByteArray systemTimeZoneId() const override;
-
+ bool isTimeZoneIdAvailable(const QByteArray &ianaId) const override;
QList<QByteArray> availableTimeZoneIds() const override;
private: