diff options
| author | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2022-05-10 00:18:31 +0200 |
|---|---|---|
| committer | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2022-05-10 00:18:31 +0200 |
| commit | 187bc63d23ef3aca9089f106daa7252d61a7d084 (patch) | |
| tree | fa84b5b8f88c80278e2957f26f99516a8f8340ee /admin/feeds/build-feed.py | |
| parent | 8e99adefe88de9caf51ad13a847149da5eedb1d8 (diff) | |
| download | quatuorbellefeuille.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/feeds/build-feed.py')
| -rwxr-xr-x | admin/feeds/build-feed.py | 34 |
1 files changed, 15 insertions, 19 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 |
