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>
This commit is contained in:
Edward Welbourne 2021-01-14 15:36:02 +01:00 committed by Qt Cherry-pick Bot
parent 2a2783e824
commit 7834756da6

View File

@ -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();
}
}