summaryrefslogtreecommitdiffstats
path: root/src/corelib/time/qtimezoneprivate_tz.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2021-01-14 15:36:02 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2021-01-27 15:00:57 +0100
commit3c9013b76a6f4214f469613baf7ae5225b649660 (patch)
tree46ba036598023a8d4ff780f9e1a81ccb38638562 /src/corelib/time/qtimezoneprivate_tz.cpp
parentb08368d99fa41b3f84cf30468c2dc9f5c2c43423 (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. Pick-to: 6.0 5.15 Change-Id: I177db55de1ffbc763def8a0423642f2b3da74fa6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/time/qtimezoneprivate_tz.cpp')
-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 938f8d119a..126e64add5 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();
}
}