Skip to content

Commit

Permalink
Add more supported date formats
Browse files Browse the repository at this point in the history
See #45
  • Loading branch information
Galarzaa90 committed Jun 27, 2024
1 parent 982be5e commit 14abee7
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions tibiawikisql/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def parse_date(value):
- June 28, 2019
- Aug 21, 2014
- May 14, 2024 17:45
Parameters
----------
Expand All @@ -200,14 +201,22 @@ def parse_date(value):
The date represented by the string.
"""
value = value.strip()
try:
dt = datetime.datetime.strptime(value, "%B %d, %Y")
except ValueError:
date_formats = [
"%B %d, %Y",
"%b %d, %Y",
"%Y",
"%B %d, %Y %H:%M",
"%b %d, %Y %H:%M",
"%Y %H:%M",
]
for date_format in date_formats:
try:
dt = datetime.datetime.strptime(value, "%b %d, %Y")
dt = datetime.datetime.strptime(value, date_format)
return dt.date().isoformat()
except ValueError:
dt = datetime.datetime.strptime(value, "%Y")
return dt.date().isoformat()
continue

raise ValueError(f"Date format for value '{value}' not recognized")


def parse_float(value, default=0.0):
Expand Down

0 comments on commit 14abee7

Please sign in to comment.