aboutsummaryrefslogtreecommitdiff
path: root/nixpkgs/pkgs/development/libraries/qt-5/5.14/qtbase.patch.d/0008-qtbase-tzdir.patch
blob: 71653a0e36e0fbf20b2b7a2c1821a0f6db0b776c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
From 882343ea200fe28810bf217a820816affe885a39 Mon Sep 17 00:00:00 2001
From: Thomas Tuegel <ttuegel@mailbox.org>
Date: Tue, 17 Sep 2019 05:36:25 -0500
Subject: [PATCH 08/10] qtbase-tzdir

---
 src/corelib/time/qtimezoneprivate_tz.cpp | 31 +++++++++++++++---------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/src/corelib/time/qtimezoneprivate_tz.cpp b/src/corelib/time/qtimezoneprivate_tz.cpp
index 3c2695a789..e75735f88f 100644
--- a/src/corelib/time/qtimezoneprivate_tz.cpp
+++ b/src/corelib/time/qtimezoneprivate_tz.cpp
@@ -75,7 +75,11 @@ typedef QHash<QByteArray, QTzTimeZone> QTzTimeZoneHash;
 // Parse zone.tab table, assume lists all installed zones, if not will need to read directories
 static QTzTimeZoneHash loadTzTimeZones()
 {
-    QString path = QStringLiteral("/usr/share/zoneinfo/zone.tab");
+    // Try TZDIR first, in case we're running on NixOS.
+    QString path = QFile::decodeName(qgetenv("TZDIR")) + QStringLiteral("/zone.tab");
+    // Fallback to traditional paths in case we are not on NixOS.
+    if (!QFile::exists(path))
+        path = QStringLiteral("/usr/share/zoneinfo/zone.tab");
     if (!QFile::exists(path))
         path = QStringLiteral("/usr/lib/zoneinfo/zone.tab");
 
@@ -658,20 +662,23 @@ void QTzTimeZonePrivate::init(const QByteArray &ianaId)
         if (!tzif.open(QIODevice::ReadOnly))
             return;
     } else {
-        // Open named tz, try modern path first, if fails try legacy path
-        tzif.setFileName(QLatin1String("/usr/share/zoneinfo/") + QString::fromLocal8Bit(ianaId));
+        // Try TZDIR first, in case we're running on NixOS
+        tzif.setFileName(QFile::decodeName(qgetenv("TZDIR")) + QStringLiteral("/") + QString::fromLocal8Bit(ianaId));
         if (!tzif.open(QIODevice::ReadOnly)) {
-            tzif.setFileName(QLatin1String("/usr/lib/zoneinfo/") + QString::fromLocal8Bit(ianaId));
+            tzif.setFileName(QLatin1String("/usr/share/zoneinfo/") + QString::fromLocal8Bit(ianaId));
             if (!tzif.open(QIODevice::ReadOnly)) {
-                // ianaId may be a POSIX rule, taken from $TZ or /etc/TZ
-                const QByteArray zoneInfo = ianaId.split(',').at(0);
-                const char *begin = zoneInfo.constBegin();
-                if (PosixZone::parse(begin, zoneInfo.constEnd()).hasValidOffset()
-                    && (begin == zoneInfo.constEnd()
-                        || PosixZone::parse(begin, zoneInfo.constEnd()).hasValidOffset())) {
-                    m_id = m_posixRule = ianaId;
+                tzif.setFileName(QLatin1String("/usr/lib/zoneinfo/") + QString::fromLocal8Bit(ianaId));
+                if (!tzif.open(QIODevice::ReadOnly)) {
+                    // ianaId may be a POSIX rule, taken from $TZ or /etc/TZ
+                    const QByteArray zoneInfo = ianaId.split(',').at(0);
+                    const char *begin = zoneInfo.constBegin();
+                    if (PosixZone::parse(begin, zoneInfo.constEnd()).hasValidOffset()
+                        && (begin == zoneInfo.constEnd()
+                            || PosixZone::parse(begin, zoneInfo.constEnd()).hasValidOffset())) {
+                        m_id = m_posixRule = ianaId;
+                    }
+                    return;
                 }
-                return;
             }
         }
     }
-- 
2.25.1