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:
14
src/php.py
14
src/php.py
@@ -1,26 +1,16 @@
|
||||
import json
|
||||
from common import dates
|
||||
from common import endoflife
|
||||
from datetime import datetime
|
||||
|
||||
PHP_MAJOR_VERSIONS = [4, 5, 7, 8]
|
||||
|
||||
|
||||
# Date format is 03 Nov 2022
|
||||
# With some versions using 03 November 2022 instead
|
||||
# we return it as YYYY-MM-DD
|
||||
def parse_date(date_str):
|
||||
try:
|
||||
return datetime.strptime(date_str, "%d %b %Y").strftime("%Y-%m-%d")
|
||||
except ValueError:
|
||||
return datetime.strptime(date_str, "%d %B %Y").strftime("%Y-%m-%d")
|
||||
|
||||
|
||||
def fetch_versions(major_version):
|
||||
url = f"https://www.php.net/releases/index.php?json&max=-1&version={major_version}"
|
||||
response = endoflife.fetch_url(url)
|
||||
data = json.loads(response)
|
||||
for v in data:
|
||||
data[v] = parse_date(data[v]["date"])
|
||||
data[v] = dates.parse_date(data[v]["date"]).strftime("%Y-%m-%d")
|
||||
print(f"{v}: {data[v]}")
|
||||
|
||||
return data
|
||||
|
||||
Reference in New Issue
Block a user