diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2020-08-28 15:32:09 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2020-09-28 15:48:17 +0200 |
commit | b12d6c6a8ab5f7b01bdd2cb862a66a409700faa1 (patch) | |
tree | 96e4ad9c549c3c350465c6f706e52a816c4e48ed /src/corelib/time/qtimezoneprivate_tz.cpp | |
parent | 32309fb4462aaf86c6efe9a99a8d41d7d2b24bfd (diff) |
Don't guess UTC when we can't find a system zone name
If we're able to load a system zone without knowing its name, we
shouldn't claim that its name is UTC. Instead, use the system zone
information's name for the zone.
Let the backend return an empty string if it can't determine the
system zone ID, provided it has some way to get system zone info
despite not knowing its name. This can happen on Windows if the system
zone is one of Microsoft's idiosyncratic names that we don't
recognize; or on Linux if /etc/timezone is a copy of a zoneinfo file,
instead of a symlink. In support of that, handle empty ID as a request
for system zone info, so that the backend constructors taking an IANA
ID never get passed an empty ID; that gets routed to the default
constructor instead.
This incidentally restores QTzTimeZonePrivate's behavior, for empty
ID, of reading the content of /etc/timezone if we are unable to
determine the name of its zone any other way.
Fixes: QTBUG-86306
Pick-to: 5.15 5.15.1
Change-Id: Iad57c18199124f651ebc3d32c3deffca6eaab512
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/time/qtimezoneprivate_tz.cpp')
-rw-r--r-- | src/corelib/time/qtimezoneprivate_tz.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/corelib/time/qtimezoneprivate_tz.cpp b/src/corelib/time/qtimezoneprivate_tz.cpp index 0ac419ba5a..4ac4559d36 100644 --- a/src/corelib/time/qtimezoneprivate_tz.cpp +++ b/src/corelib/time/qtimezoneprivate_tz.cpp @@ -641,7 +641,7 @@ QTzTimeZonePrivate::QTzTimeZonePrivate() // Create a named time zone QTzTimeZonePrivate::QTzTimeZonePrivate(const QByteArray &ianaId) { - init(ianaId.isEmpty() ? systemTimeZoneId() : ianaId); + init(ianaId); } QTzTimeZonePrivate::~QTzTimeZonePrivate() @@ -854,9 +854,6 @@ QTzTimeZoneCacheEntry QTzTimeZoneCache::fetchEntry(const QByteArray &ianaId) void QTzTimeZonePrivate::init(const QByteArray &ianaId) { - // System ID defaults to UTC, so is never empty; and our callers default to - // the system ID if what they're given is empty. - Q_ASSERT(!ianaId.isEmpty()); static QTzTimeZoneCache tzCache; const auto &entry = tzCache.fetchEntry(ianaId); if (entry.m_tranTimes.isEmpty() && entry.m_posixRule.isEmpty()) @@ -864,6 +861,15 @@ 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; + } + } + } } QLocale::Country QTzTimeZonePrivate::country() const @@ -1261,10 +1267,6 @@ QByteArray QTzTimeZonePrivate::systemTimeZoneId() const ianaId = reader.name(); } - // Give up for now and return UTC - if (ianaId.isEmpty()) - ianaId = utcQByteArray(); - return ianaId; } |