diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2021-01-14 15:36:02 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-02-02 11:56:17 +0000 |
commit | 7834756da680da853f0372417c3cdcc276be557d (patch) | |
tree | 0ddf60c4091929731afda90f96592c83319c7883 | |
parent | 2a2783e8248214af5a5c77ec73896e4884a4b1e1 (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>
-rw-r--r-- | src/corelib/time/qtimezoneprivate_tz.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/corelib/time/qtimezoneprivate_tz.cpp b/src/corelib/time/qtimezoneprivate_tz.cpp index 0b97d39091..ace966e15b 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(); } } |