summary refs log tree commit diff
path: root/pkgs/development/libraries/qt-5/5.12/qtbase.patch.d/0009-qtbase-tzdir.patch
blob: 95aefd9df7bd84c4d0c27c856012249bdc1469c3 (plain) (blame)
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
From 18e87f3de05ffbed6f5d9b4f9a3fc20373f4c06b Mon Sep 17 00:00:00 2001
From: Thomas Tuegel <ttuegel@mailbox.org>
Date: Tue, 17 Sep 2019 05:36:25 -0500
Subject: [PATCH 09/11] qtbase-tzdir

---
 src/corelib/tools/qtimezoneprivate_tz.cpp | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/corelib/tools/qtimezoneprivate_tz.cpp b/src/corelib/tools/qtimezoneprivate_tz.cpp
index 7d85bc07..c13d99b8 100644
--- a/src/corelib/tools/qtimezoneprivate_tz.cpp
+++ b/src/corelib/tools/qtimezoneprivate_tz.cpp
@@ -71,7 +71,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");
 
@@ -650,12 +654,16 @@ 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));
-            if (!tzif.open(QIODevice::ReadOnly))
-                return;
+            // Open named tz, try modern path first, if fails try legacy path
+            tzif.setFileName(QLatin1String("/usr/share/zoneinfo/") + QString::fromLocal8Bit(ianaId));
+            if (!tzif.open(QIODevice::ReadOnly)) {
+                tzif.setFileName(QLatin1String("/usr/lib/zoneinfo/") + QString::fromLocal8Bit(ianaId));
+                if (!tzif.open(QIODevice::ReadOnly))
+                    return;
+            }
         }
     }
 
-- 
2.22.1