From 187bc63d23ef3aca9089f106daa7252d61a7d084 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Tue, 10 May 2022 00:18:31 +0200 Subject: Fix date handling in feeds Cf. comment in new zoned_datetime function. Also fix a concert pubDate. --- admin/feeds/build-feed.py | 34 +++++++++++++++------------------- admin/feeds/concerts-pubdates.json | 2 +- 2 files changed, 16 insertions(+), 20 deletions(-) (limited to 'admin') 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" } -- cgit v1.2.3