Skip to content

Commit

Permalink
fix stable/patch release timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
yeoldegrove committed Oct 23, 2024
1 parent 2b204fe commit 8819f2b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion glrd/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 11 additions & 2 deletions glrd/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
import signal
import sys
import pytz
from datetime import datetime

DEFAULTS = {
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit 8819f2b

Please sign in to comment.