diff --git a/src/corelib/time/qtimezoneprivate_android.cpp b/src/corelib/time/qtimezoneprivate_android.cpp index fc3653752a..ba87cf79fe 100644 --- a/src/corelib/time/qtimezoneprivate_android.cpp +++ b/src/corelib/time/qtimezoneprivate_android.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2019 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Copyright (C) 2014 Drew Parsons ** Contact: https://www.qt.io/licensing/ ** @@ -78,6 +78,26 @@ QAndroidTimeZonePrivate::~QAndroidTimeZonePrivate() { } +static QJNIObjectPrivate getDisplayName(QJNIObjectPrivate zone, jint style, jboolean dst, + const QLocale &locale) +{ + QJNIObjectPrivate jlanguage + = QJNIObjectPrivate::fromString(QLocale::languageToString(locale.language())); + QJNIObjectPrivate jcountry + = QJNIObjectPrivate::fromString(QLocale::countryToString(locale.country())); + QJNIObjectPrivate + jvariant = QJNIObjectPrivate::fromString(QLocale::scriptToString(locale.script())); + QJNIObjectPrivate jlocale("java.util.Locale", + "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", + static_cast(jlanguage.object()), + static_cast(jcountry.object()), + static_cast(jvariant.object())); + + return zone.callObjectMethod("getDisplayName", + "(ZILjava/util/Locale;)Ljava/lang/String;", + dst, style, jlocale.object()); +} + void QAndroidTimeZonePrivate::init(const QByteArray &ianaId) { const QString iana = QString::fromUtf8(ianaId); @@ -99,10 +119,13 @@ void QAndroidTimeZonePrivate::init(const QByteArray &ianaId) // the zone object we got and ignore the zone if not. // Try checking ianaId against getID(), getDisplayName(): m_id = match(androidTimeZone.callObjectMethod("getID", "()Ljava/lang/String;")); - for (int style = 1; m_id.isEmpty() && style-- > 0;) { - for (int dst = 1; m_id.isEmpty() && dst-- > 0;) { - m_id = match(androidTimeZone.callObjectMethod( - "getDisplayName", "(ZI)Ljava/lang/String;", bool(dst), style)); + for (int style = 1; m_id.isEmpty() && style >= 0; --style) { + for (int dst = 1; m_id.isEmpty() && dst >= 0; --dst) { + for (int pick = 2; m_id.isEmpty() && pick >= 0; --pick) { + QLocale locale = (pick == 0 ? QLocale::system() + : pick == 1 ? QLocale() : QLocale::c()); + m_id = match(getDisplayName(androidTimeZone, style, jboolean(dst), locale)); + } } } } @@ -124,14 +147,7 @@ QString QAndroidTimeZonePrivate::displayName(QTimeZone::TimeType timeType, QTime // treat all NameTypes as java TimeZone style LONG (value 1), except of course QTimeZone::ShortName which is style SHORT (value 0); jint style = (nameType == QTimeZone::ShortName ? 0 : 1); - QJNIObjectPrivate jlanguage = QJNIObjectPrivate::fromString(QLocale::languageToString(locale.language())); - QJNIObjectPrivate jcountry = QJNIObjectPrivate::fromString(QLocale::countryToString(locale.country())); - QJNIObjectPrivate jvariant = QJNIObjectPrivate::fromString(QLocale::scriptToString(locale.script())); - QJNIObjectPrivate jlocale("java.util.Locale", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", static_cast(jlanguage.object()), static_cast(jcountry.object()), static_cast(jvariant.object())); - - QJNIObjectPrivate jname = androidTimeZone.callObjectMethod("getDisplayName", "(ZILjava/util/Locale;)Ljava/lang/String;", daylightTime, style, jlocale.object()); - - name = jname.toString(); + name = getDisplayName(androidTimeZone, style, daylightTime, locale).toString(); } return name;