summaryrefslogtreecommitdiff
path: root/admin
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@gmail.com>2022-05-10 00:18:31 +0200
committerKévin Le Gouguec <kevin.legouguec@gmail.com>2022-05-10 00:18:31 +0200
commit187bc63d23ef3aca9089f106daa7252d61a7d084 (patch)
treefa84b5b8f88c80278e2957f26f99516a8f8340ee /admin
parent8e99adefe88de9caf51ad13a847149da5eedb1d8 (diff)
downloadquatuorbellefeuille.com-187bc63d23ef3aca9089f106daa7252d61a7d084.tar.xz
Fix date handling in feeds
Cf. comment in new zoned_datetime function. Also fix a concert pubDate.
Diffstat (limited to 'admin')
-rwxr-xr-xadmin/feeds/build-feed.py34
-rw-r--r--admin/feeds/concerts-pubdates.json2
2 files changed, 16 insertions, 20 deletions
diff --git a/admin/feeds/build-feed.py b/admin/feeds/build-feed.py
index e010b63..6c95161 100755
--- a/admin/feeds/build-feed.py
+++ b/admin/feeds/build-feed.py
@@ -18,25 +18,21 @@ from helpers import (
)
-# TODO: handle timezones correctly.
-# Places to disambiguate:
-#
-# - concerts.in:
-# either add the zone explicitly, or deduce it from the place,
-# assuming all times in concerts.in are local times.
-#
-# - concerts-pubdates.json:
-# just add the zone explicitly.
-#
-# Until then, assume all these "naive times" describe the same timezone
-# (CET/CEST).
-
-
-TIMEZONE = datetime.now().astimezone().tzinfo
-NOW = datetime.now(tz=TIMEZONE)
-DATE_FORMAT = '%-d %b %Y %H:%M %z'
+def zoned_datetime(dt):
+ # Assume that whoever wrote the naive timestamp that this datetime
+ # was generated from had the same local time we do.
+
+ # Note: even if we assume that all timestamps in concerts.in and
+ # concerts-pubdates.json come from the same "zone" (Europe/Paris),
+ # the *time offset* can differ (CET vs CEST), so we can't just
+ # define a global TIMEZONE = datetime.now().tzinfo and slap that
+ # on every datetime.
+
+ return dt.replace(tzinfo=dt.astimezone().tzinfo)
-# TODO: add item pubDate
+
+NOW = zoned_datetime(datetime.now())
+DATE_FORMAT = '%-d %b %Y %H:%M %z'
LOCALIZED_TEXT = {
@@ -132,7 +128,7 @@ def generate_concert(concert, concerts_url, pubdates, lang):
pubdate_str = pubdates[concert.time.isoformat(timespec='minutes')]
if pubdate_str is not None:
- pubdate = datetime.fromisoformat(pubdate_str).replace(tzinfo=TIMEZONE)
+ pubdate = zoned_datetime(datetime.fromisoformat(pubdate_str))
item.append(E.pubDate(pubdate.strftime(DATE_FORMAT)))
return item
diff --git a/admin/feeds/concerts-pubdates.json b/admin/feeds/concerts-pubdates.json
index 4232ed7..b3dafd9 100644
--- a/admin/feeds/concerts-pubdates.json
+++ b/admin/feeds/concerts-pubdates.json
@@ -11,5 +11,5 @@
"2021-10-28T18:00": null,
"2021-12-12T16:00": "2021-11-23T23:28",
"2021-12-31T20:00": null,
- "2022-05-07T17:00": null
+ "2022-05-07T20:30": "2022-04-03T20:04"
}