path: root/src/corelib/tools/qtimezoneprivate_p.h
diff options
authorDrew Parsons <>2014-06-23 15:37:05 +1000
committerDrew Parsons <>2014-11-26 01:43:10 +0100
commit9a565f8fe47f09b3275d7cb425b62117e26be4e9 (patch)
treec1ad95f0074e085accc4aa59cd9e4ce7375e3a23 /src/corelib/tools/qtimezoneprivate_p.h
parent1611adc17eda0f4a85aea8d9cb4c5d01be0eda41 (diff)
provide Android timezones in QTimeZone
QTimeZone on a unix-based system expects IANA (Olson) timezones to be provided in /usr/share/zoneinfo or /usr/lib/zoneinfo. But on an Android system the timezone datafiles at this location are incomplete (Android instead uses the java class java.util.TimeZone). QTimeZone on Android therefore would only return the default UTC timezones, not the full set of IANA timezones. This patch invokes JNI on an Android system to make the full set of java timezones known to QTimeZone. The implementation adds a new QAndroidTimeZonePrivate class, invoked by the private implementation of QTimeZone in place of QTzTimeZonePrivate. QAndroidTimeZonePrivate contains adds a new QJNIObjectPrivate [java.util.TimeZone] androidTimeZone property which is used to access the java timezone API. Android limitations: 1) the java class java.util.TimeZone does not provide transitions (see 2) abbreviation( ) is provided using Java TimeZone::getDisplayName( ) with the java SHORT style. This sometimes generates a GMT reference instead of a three-letter code, e.g. America/Sao_Paulo returns "GMT-03:00" instead of "BRT" 3) hasDaylightTime() is handled using Java TimeZone::useDaylightTime(), which according to java (Android) documentation only tests for future transitions, not past transitions. This might conflict with the Qt documentation for this function (which is intended to test also for past transitions). [ChangeLog][Platform Specific Changes][Android][QtCore][QTimeZone] Android timezones are now available in QTimeZone. Change-Id: I165a39b7d4cb30b68f2da8556d85fc5b4480da4b Task-number: QTBUG-35908 Reviewed-by: Thiago Macieira <>
Diffstat (limited to 'src/corelib/tools/qtimezoneprivate_p.h')
1 files changed, 47 insertions, 1 deletions
diff --git a/src/corelib/tools/qtimezoneprivate_p.h b/src/corelib/tools/qtimezoneprivate_p.h
index 5ba42de560..486f9c1ffa 100644
--- a/src/corelib/tools/qtimezoneprivate_p.h
+++ b/src/corelib/tools/qtimezoneprivate_p.h
@@ -65,6 +65,10 @@ class NSTimeZone;
#include <qt_windows.h>
#endif // Q_OS_WIN
+#ifdef Q_OS_ANDROID
+#include <QtCore/private/qjni_p.h>
class Q_CORE_EXPORT QTimeZonePrivate : public QSharedData
@@ -256,7 +260,7 @@ private:
#endif // QT_USE_ICU
-#if defined Q_OS_UNIX && !defined Q_OS_MAC
+#if defined Q_OS_UNIX && !defined Q_OS_MAC && !defined Q_OS_ANDROID
class Q_AUTOTEST_EXPORT QTzTimeZonePrivate Q_DECL_FINAL : public QTimeZonePrivate
@@ -424,6 +428,48 @@ private:
#endif // Q_OS_WIN
+#ifdef Q_OS_ANDROID
+class QAndroidTimeZonePrivate Q_DECL_FINAL : public QTimeZonePrivate
+ // Create default time zone
+ QAndroidTimeZonePrivate();
+ // Create named time zone
+ QAndroidTimeZonePrivate(const QByteArray &ianaId);
+ QAndroidTimeZonePrivate(const QAndroidTimeZonePrivate &other);
+ ~QAndroidTimeZonePrivate();
+ QTimeZonePrivate *clone();
+ QString displayName(QTimeZone::TimeType timeType, QTimeZone::NameType nameType,
+ const QLocale &locale) const Q_DECL_OVERRIDE;
+ QString abbreviation(qint64 atMSecsSinceEpoch) const Q_DECL_OVERRIDE;
+ int offsetFromUtc(qint64 atMSecsSinceEpoch) const Q_DECL_OVERRIDE;
+ int standardTimeOffset(qint64 atMSecsSinceEpoch) const Q_DECL_OVERRIDE;
+ int daylightTimeOffset(qint64 atMSecsSinceEpoch) const Q_DECL_OVERRIDE;
+ bool hasDaylightTime() const Q_DECL_OVERRIDE;
+ bool isDaylightTime(qint64 atMSecsSinceEpoch) const Q_DECL_OVERRIDE;
+ Data data(qint64 forMSecsSinceEpoch) const Q_DECL_OVERRIDE;
+ bool hasTransitions() const Q_DECL_OVERRIDE;
+ Data nextTransition(qint64 afterMSecsSinceEpoch) const Q_DECL_OVERRIDE;
+ Data previousTransition(qint64 beforeMSecsSinceEpoch) const Q_DECL_OVERRIDE;
+ QByteArray systemTimeZoneId() const Q_DECL_OVERRIDE;
+ QSet<QByteArray> availableTimeZoneIds() const Q_DECL_OVERRIDE;
+ void init(const QByteArray &zoneId);
+ QJNIObjectPrivate androidTimeZone;
+#endif // Q_OS_ANDROID