Simplify date parsing (#195)

Create common functions parse_date, parse_month_year_date and parse_datetime.

Those functions support trying multiple formats, and come with default formats lists that support most of the date format encountered so far.

Notable change: year-month dates are now set to the end of month (impacted couchbase-server and ibm-aix).
This commit is contained in:
Marc Wrobel
2023-11-26 21:01:35 +01:00
committed by GitHub
parent 1e65a048b0
commit 0d17306872
24 changed files with 133 additions and 168 deletions

View File

@@ -1,6 +1,6 @@
import re
from datetime import datetime
from pathlib import Path
from common import dates
from common import endoflife
from common.git import Git
@@ -18,13 +18,8 @@ REPO_URL = "https://github.com/apache/httpd.git"
def parse(date: str) -> str:
date = date.replace("Feburary", "February")
for format in ["%B %d, %Y", "%B %d, %Y", "%b %d, %Y", "%b. %d, %Y"]:
try:
return datetime.strptime(date, format).strftime("%Y-%m-%d")
except ValueError:
pass
raise ValueError(f"Unknown date format for '{date}'")
date = date.replace(". ", " ")
return dates.parse_date(date).strftime("%Y-%m-%d")
def fetch_versions_from_file(release_notes_file: Path, versions: dict):