From 092563a3d06026a0e64d2f0f1d926e6aa34955fd Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 17 Mar 2023 16:45:27 +0100 Subject: [PATCH] Skip QTimeZone::isTimeZoneIdAvailable()'s validity check on Unix [ChangeLog][Corelib][QTimeZone] On Unix (other than macOS and Android), the TZ-DB backend has long accepted any well-formed POSIX zone description as a time-zone ID. This is now reflected in QTimeZone::isTimeZoneIdAvailable(), which previously claimed not to accept these IDs. However, avaliableTimeZoneIds() still does not attempt to construct all possible POSIX descriptors to include in its return. Change-Id: I1df8df0a4acaca9e70d72f13200b4c31305732f3 Reviewed-by: Thiago Macieira --- src/corelib/time/qtimezone.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/corelib/time/qtimezone.cpp b/src/corelib/time/qtimezone.cpp index 58f0de3047..c5fc6e20a5 100644 --- a/src/corelib/time/qtimezone.cpp +++ b/src/corelib/time/qtimezone.cpp @@ -1347,12 +1347,18 @@ QTimeZone QTimeZone::utc() bool QTimeZone::isTimeZoneIdAvailable(const QByteArray &ianaId) { +#if defined(Q_OS_UNIX) && !(defined(Q_OS_ANDROID) || defined(Q_OS_DARWIN)) + // Keep #if-ery consistent with selection of QTzTimeZonePrivate in + // newBackendTimeZone(). Skip the pre-check, as the TZ backend accepts POSIX + // zone IDs, which need not be valid IANA IDs. +#else // isValidId is not strictly required, but faster to weed out invalid // IDs as availableTimeZoneIds() may be slow if (!QTimeZonePrivate::isValidId(ianaId)) return false; - return QUtcTimeZonePrivate().isTimeZoneIdAvailable(ianaId) || - global_tz->backend->isTimeZoneIdAvailable(ianaId); +#endif + return QUtcTimeZonePrivate().isTimeZoneIdAvailable(ianaId) + || global_tz->backend->isTimeZoneIdAvailable(ianaId); } static QList set_union(const QList &l1, const QList &l2)