summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2025-11-11 19:30:49 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2025-11-18 15:07:47 +0100
commit729d08d5222f580fd5ff3768f0a3d226103c5623 (patch)
treed6cc7977986b51639338ef5d1d2f90b1e44507fb /src
parenta9b87f644d983188abb361c834f44010a5c683d3 (diff)
Tweak QTZLocale's parsing of offsets to pretend "GMT" == "UTC"
This is needed to match kludges already present in QUtcTZP::displayName(), which needs to do this to respect locale zone offset forms. Task-number: QTBUG-139223 Change-Id: I367413817e4824e3e5dbe0c73d8d6b36dfc1bf64 Reviewed-by: Mate Barany <mate.barany@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/time/qtimezonelocale.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/corelib/time/qtimezonelocale.cpp b/src/corelib/time/qtimezonelocale.cpp
index f296f682c96..3c0371ef0e2 100644
--- a/src/corelib/time/qtimezonelocale.cpp
+++ b/src/corelib/time/qtimezonelocale.cpp
@@ -491,9 +491,22 @@ OffsetFormatMatch matchOffsetFormat(QStringView text, const QLocale &locale, qsi
const QStringView gmtPrefix = offsetFormat.first(cut);
const QStringView gmtSuffix = offsetFormat.sliced(cut + 2); // After %0
const qsizetype gmtSize = cut + gmtSuffix.size();
+ const auto crossMatch = [gmtPrefix, text]
+ (QLatin1StringView lhs, QLatin1StringView rhs) {
+ const qsizetype len = lhs.size();
+ Q_ASSERT(len == rhs.size());
+ if (!gmtPrefix.startsWith(lhs) || !text.startsWith(rhs))
+ return false;
+ if (gmtPrefix.size() == len)
+ return true;
+ return text.sliced(len).startsWith(gmtPrefix.sliced(len));
+ };
// Cheap pre-test: check suffix does appear after prefix, albeit we must
// later check it actually appears right after the offset text:
- if ((gmtPrefix.isEmpty() || text.startsWith(gmtPrefix))
+ if ((gmtPrefix.isEmpty() || text.startsWith(gmtPrefix)
+ // Treat GMT and UTC as matches for one another to match
+ // QUtcTimeZonePrivate::displayName()'s kludges:
+ || crossMatch("GMT"_L1, "UTC"_L1) || crossMatch("UTC"_L1, "GMT"_L1))
&& (gmtSuffix.isEmpty() || text.sliced(cut).indexOf(gmtSuffix) >= 0)) {
if (auto match = matchOffsetText(text.sliced(cut), posHourForm, locale, scale)) {
if (text.sliced(cut + match.size).startsWith(gmtSuffix)) // too sliced ?