--- a/src/corelib/time/qtimezoneprivate_tz.cpp +++ b/src/corelib/time/qtimezoneprivate_tz.cpp @@ -1192,6 +1192,12 @@ public: return m_name; } + m_name = etcSysconfigClock(); + if (!m_name.isEmpty()) { + m_last = local; + return m_name; + } + // Some systems (e.g. uClibc) have a default value for $TZ in /etc/TZ: m_name = etcContent(QStringLiteral("/etc/TZ")); if (!m_name.isEmpty()) { @@ -1225,6 +1231,28 @@ private: return QT_STAT(path, &data) == -1 ? StatIdent() : StatIdent(data); } + static QByteArray etcSysconfigClock() + { + // On some Red Hat distros /etc/localtime is real file with name held in /etc/sysconfig/clock + // in a line like ZONE="Europe/Oslo" or TIMEZONE="Europe/Oslo" or ZONE=Europe/Oslo + QByteArray tz_id; + QFile tzif(QStringLiteral("/etc/sysconfig/clock")); + if (tzif.open(QIODevice::ReadOnly)) { + while (tz_id.isEmpty() && !tzif.atEnd()) { + const QByteArray line(tzif.readLine().trimmed()); + if (line.startsWith("ZONE=\"")) + tz_id = line.mid(6, line.length() - 7); + else if (line.startsWith("TIMEZONE=\"")) + tz_id = line.mid(10, line.length() - 11); + else if (line.startsWith("ZONE=")) + tz_id = line.mid(5); + else if (line.startsWith("TIMEZONE=")) + tz_id = line.mid(9); + } + } + return tz_id; + } + static QByteArray etcLocalTime() { // On most distros /etc/localtime is a symlink to a real file so extract