From 023a8d48e28f27da9fab097ecbe9acfbb8323544 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 11 Apr 2025 17:19:23 +0200 Subject: [PATCH] Isolate an "enough like C locale" test and use consistently Various checks for whether a locale was suitable for use of ASCII offset formats were expressed in terms of QLocale::C. One was wrongly expressed in terms of isDataLocale(), which is meant to be true for the locale the backend thinks its data is suitable for. Write a new method of QTimeZonePrivate to check for this, accepting en-Latn-* as a good enough match, and deploy where it's the right test. Pick-to: 6.9 6.8 Change-Id: Ieab129eb5c252732b8916fce017ec0a22684eba8 Reviewed-by: Ivan Solovev Reviewed-by: Thiago Macieira --- src/corelib/time/qtimezoneprivate.cpp | 8 ++++---- src/corelib/time/qtimezoneprivate_p.h | 7 +++++++ src/corelib/time/qtimezoneprivate_tz.cpp | 6 +++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/corelib/time/qtimezoneprivate.cpp b/src/corelib/time/qtimezoneprivate.cpp index e3a12dc341a..13a24db870e 100644 --- a/src/corelib/time/qtimezoneprivate.cpp +++ b/src/corelib/time/qtimezoneprivate.cpp @@ -172,7 +172,7 @@ QString QTimeZonePrivate::displayName(qint64 atMSecsSinceEpoch, { const Data tran = data(atMSecsSinceEpoch); if (tran.atMSecsSinceEpoch != invalidMSecs()) { - if (nameType == QTimeZone::OffsetName && locale.language() == QLocale::C) + if (nameType == QTimeZone::OffsetName && isAnglicLocale(locale)) return isoOffsetFormat(tran.offsetFromUtc); if (nameType == QTimeZone::ShortName && isDataLocale(locale)) return tran.abbreviation; @@ -194,7 +194,7 @@ QString QTimeZonePrivate::displayName(QTimeZone::TimeType timeType, { const Data tran = data(timeType); if (tran.atMSecsSinceEpoch != invalidMSecs()) { - if (nameType == QTimeZone::OffsetName && isDataLocale(locale)) + if (nameType == QTimeZone::OffsetName && isAnglicLocale(locale)) return isoOffsetFormat(tran.offsetFromUtc); #if QT_CONFIG(timezone_locale) @@ -1041,8 +1041,8 @@ QTimeZonePrivate::Data QUtcTimeZonePrivate::data(QTimeZone::TimeType timeType) c bool QUtcTimeZonePrivate::isDataLocale(const QLocale &locale) const { - // Officially only supports C locale names; these are surely also viable for English. - return locale.language() == QLocale::C || locale.language() == QLocale::English; + // Officially only supports C locale names; these are surely also viable for en-Latn-*. + return isAnglicLocale(locale); } void QUtcTimeZonePrivate::init(const QByteArray &zoneId, int offsetSeconds, const QString &name, diff --git a/src/corelib/time/qtimezoneprivate_p.h b/src/corelib/time/qtimezoneprivate_p.h index b2c03e49f0a..67b4f724281 100644 --- a/src/corelib/time/qtimezoneprivate_p.h +++ b/src/corelib/time/qtimezoneprivate_p.h @@ -109,6 +109,13 @@ public: virtual Data data(qint64 forMSecsSinceEpoch) const; virtual Data data(QTimeZone::TimeType timeType) const; virtual bool isDataLocale(const QLocale &locale) const; + static bool isAnglicLocale(const QLocale &locale) + { + // Sufficiently like the C locale for displayName()-related purposes: + const QLocale::Language lang = locale.language(); + return lang == QLocale::C + || (lang == QLocale::English && locale.script() == QLocale::LatinScript); + } QDateTimePrivate::ZoneState stateAtZoneTime(qint64 forLocalMSecs, QDateTimePrivate::TransitionOptions resolve) const; diff --git a/src/corelib/time/qtimezoneprivate_tz.cpp b/src/corelib/time/qtimezoneprivate_tz.cpp index c9d4d551832..42246c3d084 100644 --- a/src/corelib/time/qtimezoneprivate_tz.cpp +++ b/src/corelib/time/qtimezoneprivate_tz.cpp @@ -1030,7 +1030,7 @@ QString QTzTimeZonePrivate::displayName(QTimeZone::TimeType timeType, if (nameType == QTimeZone::ShortName) return tran.abbreviation; // Save base class repeating the data(timeType) query: - if (locale.language() == QLocale::C) + if (isAnglicLocale(locale)) return isoOffsetFormat(tran.offsetFromUtc); } } @@ -1176,8 +1176,8 @@ QTimeZonePrivate::Data QTzTimeZonePrivate::data(QTimeZone::TimeType timeType) co bool QTzTimeZonePrivate::isDataLocale(const QLocale &locale) const { - // TZ data uses English / C locale names: - return locale.language() == QLocale::C || locale.language() == QLocale::English; + // TZ data uses en-Latn-* / C locale names: + return isAnglicLocale(locale); } bool QTzTimeZonePrivate::hasTransitions() const