[version_table] Improve date parsing (#527)

So far the script only allowed datetimes. Now full/partial dates are allowed too.
This commit is contained in:
Marc Wrobel
2025-11-08 13:18:14 +01:00
committed by GitHub
parent 03905bcf79
commit 1fb86114be
3 changed files with 13 additions and 7 deletions

View File

@@ -93,6 +93,15 @@ def parse_datetime(text: str, formats: list[str] = frozenset([
raise ValueError(msg)
def parse__datetime_or_date_or_month_year_date(text: str) -> datetime.datetime:
"""Parse a given text representing a datetime, date or a partial date using the default list of formats.
"""
try:
return parse_datetime(text)
except ValueError:
return parse_date_or_month_year_date(text)
def date(year: int, month: int, day: int) -> datetime.datetime:
"""Create a datetime object with the given year, month and day, at midnight."""
return datetime.datetime(year, month, day, tzinfo=datetime.timezone.utc)