summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2021-01-14 15:36:02 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-02-03 11:28:50 +0000
commit5f91ed149379e8259212c21c87992c3b04120cf7 (patch)
tree5de620327d7b39db579c06482acfb097297fafc5 /src/corelib
parentd70fe37b8142e7ee69d695a1e2611a55a785db2f (diff)
QTzTimeZonePrivate::init(): fix handling of empty ID
We were using the first abbreviation in the list, where the current time's one is probably more apt. We look up displayName() using ICU, when in use, but that abbreviatio may be unknown to it. So ensure, when using abbreviation in place of empty id, that we get the system zone for ICU, for use if we're asked for the display name. This is a follow up to b12d6c6a8ab5f7b01bdd2cb862a66a409700faa1. Change-Id: I177db55de1ffbc763def8a0423642f2b3da74fa6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 3c9013b76a6f4214f469613baf7ae5225b649660) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/time/qtimezoneprivate_tz.cpp20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/corelib/time/qtimezoneprivate_tz.cpp b/src/corelib/time/qtimezoneprivate_tz.cpp
index 68cd0fcc7e..c40f228e48 100644
--- a/src/corelib/time/qtimezoneprivate_tz.cpp
+++ b/src/corelib/time/qtimezoneprivate_tz.cpp
@@ -867,13 +867,19 @@ void QTzTimeZonePrivate::init(const QByteArray &ianaId)
cached_data = std::move(entry);
m_id = ianaId;
// Avoid empty ID, if we have an abbreviation to use instead
- if (m_id.isEmpty()) { // We've read /etc/localtime's contents
- for (const auto &abbr : cached_data.m_abbreviations) {
- if (!abbr.isEmpty()) {
- m_id = abbr;
- break;
- }
- }
+ if (m_id.isEmpty()) {
+ // This can only happen for the system zone, when we've read the
+ // contents of /etc/localtime because it wasn't a symlink.
+#if QT_CONFIG(icu)
+ // Use ICU's system zone, if only to avoid using the abbreviation as ID
+ // (ICU might mis-recognize it) in displayName().
+ m_icu = new QIcuTimeZonePrivate();
+ // Use its ID, as an alternate source of data:
+ m_id = m_icu->id();
+ if (!m_id.isEmpty())
+ return;
+#endif
+ m_id = abbreviation(QDateTime::currentMSecsSinceEpoch()).toUtf8();
}
}