Make expiry parsing backward compatible to 3.9
authorJeremy Stanley <fungi@yuggoth.org>
Sat, 11 May 2024 02:41:03 +0000 (02:41 +0000)
committerJeremy Stanley <fungi@yuggoth.org>
Sat, 11 May 2024 02:43:57 +0000 (02:43 +0000)
The expiration timestamp parser inadvertently relied on patterns
which weren't supported by earlier versions of the datetime module.
Solve it with a slightly uglier one.

weather.py

index cf9bc23..322e83d 100644 (file)
@@ -328,7 +328,13 @@ def get_alert(
                 # hours ago
                 import datetime, zoneinfo
                 expiration = datetime.datetime.fromisoformat(
-                    "%sT%sZ" % (expirycheck[1][:8], expirycheck[1][-4:]))
+                    "%s-%s-%sT%s:%s" % (
+                        expirycheck[1][:4],
+                        expirycheck[1][4:6],
+                        expirycheck[1][6:8],
+                        expirycheck[1][8:10],
+                        expirycheck[1][-2:],
+                    )).replace(tzinfo=zoneinfo.ZoneInfo("UTC"))
                 now = datetime.datetime.now(tz=zoneinfo.ZoneInfo("UTC"))
                 if now - expiration > datetime.timedelta(hours=delay):
                     return ""