File: Determine-IANA-nee-Olson-database-version-dynamically.patch

package info (click to toggle)
python-tz 2025.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,396 kB
  • sloc: ansic: 7,826; python: 2,414; awk: 1,067; makefile: 921; sh: 693
file content (189 lines) | stat: -rw-r--r-- 7,818 bytes parent folder | download
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
From: Benjamin Drung <benjamin.drung@canonical.com>
Date: Thu, 22 Feb 2024 16:12:57 +0100
Subject: Determine IANA (nee Olson) database version dynamically

Forwarded: not-needed
Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
---
 pytz/__init__.py          | 13 ++++++++++++-
 pytz/tests/test_tzinfo.py |  8 --------
 2 files changed, 12 insertions(+), 9 deletions(-)

Index: python-tz-2025.2/src/pytz/__init__.py
===================================================================
--- python-tz-2025.2.orig/src/pytz/__init__.py
+++ python-tz-2025.2/src/pytz/__init__.py
@@ -13,6 +13,7 @@ import datetime
 import os.path
 import pathlib
 import zoneinfo
+import re
 
 from pytz.exceptions import AmbiguousTimeError
 from pytz.exceptions import InvalidTimeError
@@ -22,9 +23,18 @@ from pytz.lazy import LazyDict, LazyList
 from pytz.tzinfo import unpickler, BaseTzInfo
 from pytz.tzfile import build_tzinfo
 
+def _read_olson_version() -> str:
+    tzdata_zi = pathlib.Path("/usr/share/zoneinfo/tzdata.zi")
+    with tzdata_zi.open(encoding="utf-8") as tzdata_zi_file:
+        line = tzdata_zi_file.readline()
+    match = re.match(r"^#\s*version\s*([0-9a-z]*)\s*$", line)
+    if not match:
+        return "unknown"
+    return match.group(1)
+
 
 # The IANA (nee Olson) database is updated several times a year.
-OLSON_VERSION = '2025b'
+OLSON_VERSION = _read_olson_version()
 VERSION = '2025.2'  # pip compatible version number.
 __version__ = VERSION
 
Index: python-tz-2025.2/src/pytz/tests/test_tzinfo.py
===================================================================
--- python-tz-2025.2.orig/src/pytz/tests/test_tzinfo.py
+++ python-tz-2025.2/src/pytz/tests/test_tzinfo.py
@@ -65,21 +65,21 @@ if sys.version_info[0] > 2:
 
 class BasicTest(unittest.TestCase):
 
-    def testVersion(self):
-        # Ensuring the correct version of pytz has been loaded
-        self.assertEqual(
-            EXPECTED_VERSION, pytz.__version__,
-            'Incorrect pytz version loaded. Import path is stuffed '
-            'or this test needs updating. (Wanted %s, got %s)'
-            % (EXPECTED_VERSION, pytz.__version__)
-        )
-
-        self.assertEqual(
-            EXPECTED_OLSON_VERSION, pytz.OLSON_VERSION,
-            'Incorrect pytz version loaded. Import path is stuffed '
-            'or this test needs updating. (Wanted %s, got %s)'
-            % (EXPECTED_OLSON_VERSION, pytz.OLSON_VERSION)
-        )
+    # def testVersion(self):
+    #     # Ensuring the correct version of pytz has been loaded
+    #     self.assertEqual(
+    #         EXPECTED_VERSION, pytz.__version__,
+    #         'Incorrect pytz version loaded. Import path is stuffed '
+    #         'or this test needs updating. (Wanted %s, got %s)'
+    #         % (EXPECTED_VERSION, pytz.__version__)
+    #     )
+
+    #     self.assertEqual(
+    #         EXPECTED_OLSON_VERSION, pytz.OLSON_VERSION,
+    #         'Incorrect pytz version loaded. Import path is stuffed '
+    #         'or this test needs updating. (Wanted %s, got %s)'
+    #         % (EXPECTED_OLSON_VERSION, pytz.OLSON_VERSION)
+    #     )
 
     def testGMT(self):
         now = datetime.now(tz=GMT)
@@ -98,7 +98,7 @@ class BasicTest(unittest.TestCase):
         # This tzinfo behavior is required to make
         # datetime.time.{utcoffset, dst, tzname} work as documented.
 
-        dst_tz = pytz.timezone('US/Eastern')
+        dst_tz = pytz.timezone('America/New_York')
 
         # This information is not known when we don't have a date,
         # so return None per API.
@@ -106,7 +106,7 @@ class BasicTest(unittest.TestCase):
         self.assertIsNone(dst_tz.dst(None))
         # We don't know the abbreviation, but this is still a valid
         # tzname per the Python documentation.
-        self.assertEqual(dst_tz.tzname(None), 'US/Eastern')
+        self.assertEqual(dst_tz.tzname(None), 'America/New_York')
 
     def clearCache(self):
         pytz._tzinfo_cache.clear()
@@ -116,12 +116,12 @@ class BasicTest(unittest.TestCase):
         # and traditional strings, and that the desired singleton is
         # returned.
         self.clearCache()
-        eastern = pytz.timezone(unicode('US/Eastern'))
-        self.assertIs(eastern, pytz.timezone('US/Eastern'))
+        eastern = pytz.timezone(unicode('America/New_York'))
+        self.assertIs(eastern, pytz.timezone('America/New_York'))
 
         self.clearCache()
-        eastern = pytz.timezone('US/Eastern')
-        self.assertIs(eastern, pytz.timezone(unicode('US/Eastern')))
+        eastern = pytz.timezone('America/New_York')
+        self.assertIs(eastern, pytz.timezone(unicode('America/New_York')))
 
     def testStaticTzInfo(self):
         # Ensure that static timezones are correctly detected,
@@ -204,11 +204,11 @@ class PicklingTest(unittest.TestCase):
         # where created with pytz2006j
         east1 = pickle.loads(
             _byte_string(
-                "cpytz\n_p\np1\n(S'US/Eastern'\np2\nI-18000\n"
+                "cpytz\n_p\np1\n(S'America/New_York'\np2\nI-18000\n"
                 "I0\nS'EST'\np3\ntRp4\n."
             )
         )
-        east2 = pytz.timezone('US/Eastern').localize(
+        east2 = pytz.timezone('America/New_York').localize(
             datetime(2006, 1, 1)).tzinfo
         self.assertIs(east1, east2)
 
@@ -228,7 +228,7 @@ class PicklingTest(unittest.TestCase):
 
 
 class USEasternDSTStartTestCase(unittest.TestCase):
-    tzinfo = pytz.timezone('US/Eastern')
+    tzinfo = pytz.timezone('America/New_York')
 
     # 24 hours before DST changeover
     transition_time = datetime(2002, 4, 7, 7, 0, 0, tzinfo=UTC)
@@ -354,7 +354,7 @@ class USEasternDSTStartTestCase(unittest
 
 
 class USEasternDSTEndTestCase(USEasternDSTStartTestCase):
-    tzinfo = pytz.timezone('US/Eastern')
+    tzinfo = pytz.timezone('America/New_York')
     transition_time = datetime(2002, 10, 27, 6, 0, 0, tzinfo=UTC)
     before = {
         'tzname': 'EDT',
@@ -594,7 +594,7 @@ class ReferenceUSEasternDSTEndTestCase(U
     def testHourBefore(self):
         # Python's datetime library has a bug, where the hour before
         # a daylight saving transition is one hour out. For example,
-        # at the end of US/Eastern daylight saving time, 01:00 EST
+        # at the end of America/New_York daylight saving time, 01:00 EST
         # occurs twice (once at 05:00 UTC and once at 06:00 UTC),
         # whereas the first should actually be 01:00 EDT.
         # Note that this bug is by design - by accepting this ambiguity
@@ -612,7 +612,7 @@ class ReferenceUSEasternDSTEndTestCase(U
 
 class LocalTestCase(unittest.TestCase):
     def testLocalize(self):
-        loc_tz = pytz.timezone('US/Eastern')
+        loc_tz = pytz.timezone('America/New_York')
 
         # End of DST ambiguity check
         loc_time = loc_tz.localize(datetime(1918, 10, 27, 1, 59, 59), is_dst=1)
@@ -671,7 +671,7 @@ class LocalTestCase(unittest.TestCase):
                 self.assertEqual(loc_time.strftime(fmt), expected[not dst])
 
     def testNormalize(self):
-        tz = pytz.timezone('US/Eastern')
+        tz = pytz.timezone('America/New_York')
         dt = datetime(2004, 4, 4, 7, 0, 0, tzinfo=UTC).astimezone(tz)
         dt2 = dt - timedelta(minutes=10)
         self.assertEqual(
@@ -707,8 +707,8 @@ class CommonTimezonesTestCase(unittest.T
         self.assertIn('Europe/Bratislava', pytz.common_timezones_set)
 
     def test_us_eastern(self):
-        self.assertIn('US/Eastern', pytz.common_timezones)
-        self.assertIn('US/Eastern', pytz.common_timezones_set)
+        self.assertIn('America/New_York', pytz.common_timezones)
+        self.assertIn('America/New_York', pytz.common_timezones_set)
 
     def test_belfast(self):
         self.assertIn('Europe/Belfast', pytz.all_timezones_set)