From 905fb43594026a459339f9bdf59efb14f7132fdc Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 27 Oct 2023 18:57:00 +0200 Subject: [PATCH] Include offset-zone's ID in the available IDs for an offset While it would be perverse for availableTimeZoneIds() to list all supported UTC-offset zone IDs, it makes reasonably good sense for its offset-specific overload to include the ID QTimeZone would use for the relevant UTC-offset, since passing this ID to the ID-based constructor will indeed get a zone with this offset. In particular, it already does include the offset-zone's ID if there is an IANA UTC-offset zone with the given offset; and its list is apt to be empty otherwise. Only applies to IDs we would in fact accept, checked with offsetFromUtcString() to match the QTZ constructor's check. Change-Id: I77bb60b166c3d3af5824d84952e1e10a5d32a5ad Reviewed-by: Paul Wicking Reviewed-by: Thiago Macieira --- src/corelib/time/qtimezone.cpp | 6 +++++- src/corelib/time/qtimezoneprivate.cpp | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/corelib/time/qtimezone.cpp b/src/corelib/time/qtimezone.cpp index c593af544f..9839107e80 100644 --- a/src/corelib/time/qtimezone.cpp +++ b/src/corelib/time/qtimezone.cpp @@ -1504,9 +1504,13 @@ QList QTimeZone::availableTimeZoneIds(QLocale::Territory territory) Returns a list of all available IANA time zone IDs with a given standard time offset of \a offsetSeconds. + Where the given offset is supported, \c{QTimeZone(offsetSeconds).id()} is + included in the list, even if it is not an IANA ID. This only arises when + there is no IANA UTC-offset ID with the given offset. + This method is only available when feature \c timezone is enabled. - \sa isTimeZoneIdAvailable() + \sa isTimeZoneIdAvailable(), QTimeZone(int) */ QList QTimeZone::availableTimeZoneIds(int offsetSeconds) diff --git a/src/corelib/time/qtimezoneprivate.cpp b/src/corelib/time/qtimezoneprivate.cpp index 97f2f85e52..71b1674b84 100644 --- a/src/corelib/time/qtimezoneprivate.cpp +++ b/src/corelib/time/qtimezoneprivate.cpp @@ -989,6 +989,12 @@ QList QUtcTimeZonePrivate::availableTimeZoneIds(qint32 offsetSeconds } result << id.toByteArray(); } + // CLDR only has round multiples of a quarter hour, and only some of + // those. For anything else, throw in the ID we would use for this offset + // (if we'd accept that ID). + QByteArray isoName = isoOffsetFormat(offsetSeconds, QTimeZone::ShortName).toUtf8(); + if (offsetFromUtcString(isoName) == qint64(offsetSeconds) && !result.contains(isoName)) + result << isoName; // Not guaranteed to be sorted, so sort: std::sort(result.begin(), result.end()); // ### assuming no duplicates