1 From da003b582ee8823b29b1ff5c0aca8e06e7741b94 Mon Sep 17 00:00:00 2001
2 From: Thomas Tuegel <ttuegel@mailbox.org>
3 Date: Tue, 17 Sep 2019 05:36:25 -0500
4 Subject: [PATCH 08/11] qtbase-tzdir
7 src/corelib/time/qtimezoneprivate_tz.cpp | 31 +++++++++++++++---------
8 1 file changed, 19 insertions(+), 12 deletions(-)
10 diff --git a/src/corelib/time/qtimezoneprivate_tz.cpp b/src/corelib/time/qtimezoneprivate_tz.cpp
11 index 01f9a6cce0..910338205a 100644
12 --- a/src/corelib/time/qtimezoneprivate_tz.cpp
13 +++ b/src/corelib/time/qtimezoneprivate_tz.cpp
14 @@ -77,7 +77,11 @@ typedef QHash<QByteArray, QTzTimeZone> QTzTimeZoneHash;
15 // Parse zone.tab table, assume lists all installed zones, if not will need to read directories
16 static QTzTimeZoneHash loadTzTimeZones()
18 - QString path = QStringLiteral("/usr/share/zoneinfo/zone.tab");
19 + // Try TZDIR first, in case we're running on NixOS.
20 + QString path = QFile::decodeName(qgetenv("TZDIR")) + QStringLiteral("/zone.tab");
21 + // Fallback to traditional paths in case we are not on NixOS.
22 + if (!QFile::exists(path))
23 + path = QStringLiteral("/usr/share/zoneinfo/zone.tab");
24 if (!QFile::exists(path))
25 path = QStringLiteral("/usr/lib/zoneinfo/zone.tab");
27 @@ -672,20 +676,23 @@ QTzTimeZoneCacheEntry QTzTimeZoneCache::findEntry(const QByteArray &ianaId)
28 if (!tzif.open(QIODevice::ReadOnly))
31 - // Open named tz, try modern path first, if fails try legacy path
32 - tzif.setFileName(QLatin1String("/usr/share/zoneinfo/") + QString::fromLocal8Bit(ianaId));
33 + // Try TZDIR first, in case we're running on NixOS
34 + tzif.setFileName(QFile::decodeName(qgetenv("TZDIR")) + QStringLiteral("/") + QString::fromLocal8Bit(ianaId));
35 if (!tzif.open(QIODevice::ReadOnly)) {
36 - tzif.setFileName(QLatin1String("/usr/lib/zoneinfo/") + QString::fromLocal8Bit(ianaId));
37 + tzif.setFileName(QLatin1String("/usr/share/zoneinfo/") + QString::fromLocal8Bit(ianaId));
38 if (!tzif.open(QIODevice::ReadOnly)) {
39 - // ianaId may be a POSIX rule, taken from $TZ or /etc/TZ
40 - const QByteArray zoneInfo = ianaId.split(',').at(0);
41 - const char *begin = zoneInfo.constBegin();
42 - if (PosixZone::parse(begin, zoneInfo.constEnd()).hasValidOffset()
43 - && (begin == zoneInfo.constEnd()
44 - || PosixZone::parse(begin, zoneInfo.constEnd()).hasValidOffset())) {
45 - ret.m_posixRule = ianaId;
46 + tzif.setFileName(QLatin1String("/usr/lib/zoneinfo/") + QString::fromLocal8Bit(ianaId));
47 + if (!tzif.open(QIODevice::ReadOnly)) {
48 + // ianaId may be a POSIX rule, taken from $TZ or /etc/TZ
49 + const QByteArray zoneInfo = ianaId.split(',').at(0);
50 + const char *begin = zoneInfo.constBegin();
51 + if (PosixZone::parse(begin, zoneInfo.constEnd()).hasValidOffset()
52 + && (begin == zoneInfo.constEnd()
53 + || PosixZone::parse(begin, zoneInfo.constEnd()).hasValidOffset())) {
54 + ret.m_posixRule = ianaId;