From 8819f2b1516e964dfa2a82b70dc03805cc5fb932 Mon Sep 17 00:00:00 2001 From: Eike Waldt Date: Wed, 23 Oct 2024 16:04:49 +0200 Subject: [PATCH] fix stable/patch release timestamps --- glrd/manage.py | 2 +- glrd/util.py | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/glrd/manage.py b/glrd/manage.py index abf9a20..e8cba72 100755 --- a/glrd/manage.py +++ b/glrd/manage.py @@ -379,7 +379,7 @@ def create_initial_releases(releases): "lifecycle": { "released": { "isodate": release['published_at'][:10], - "timestamp": isodate_to_timestamp(release['published_at'][:10]) + "timestamp": isodate_to_timestamp(release['published_at']) }, "eol": { "isodate": None, diff --git a/glrd/util.py b/glrd/util.py index fb01b54..d1d711a 100644 --- a/glrd/util.py +++ b/glrd/util.py @@ -2,6 +2,7 @@ import re import signal import sys +import pytz from datetime import datetime DEFAULTS = { @@ -50,8 +51,16 @@ def timestamp_to_isotime(timestamp): return dt.strftime("%H:%M:%S") def isodate_to_timestamp(isodate): - """Convert ISO date to timestamp.""" - return int(datetime.strptime(isodate, "%Y-%m-%d").timestamp()) + """ + Convert an ISO 8601 formatted date (with or without time) to a Unix timestamp. + If only a date is provided, assume the time is 00:00:00 UTC. + """ + try: + # Try parsing with full ISO format (date and time with 'Z' timezone) + return int(datetime.strptime(isodate, "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=pytz.UTC).timestamp()) + except ValueError: + # If the time part is missing, assume time is 00:00:00 UTC + return int(datetime.strptime(isodate, "%Y-%m-%d").replace(tzinfo=pytz.UTC).timestamp()) def timestamp_to_isodate(timestamp): """Convert timestamp to ISO date."""