Update datetime parse helper

Allow non T in isotime format, add non T normal datetime parsing
This commit is contained in:
Clemens Schwaighofer
2025-11-06 13:24:27 +09:00
parent 0981c74da9
commit c98c5df63c
5 changed files with 60 additions and 8 deletions

View File

@@ -159,10 +159,14 @@ def parse_flexible_date(
# Try different parsing methods
parsers: list[Callable[[str], datetime]] = [
# ISO 8601 format
# ISO 8601 format, also with missing "T"
lambda x: datetime.fromisoformat(x), # pylint: disable=W0108
lambda x: datetime.fromisoformat(x.replace(' ', 'T')), # pylint: disable=W0108
# Simple date format
lambda x: datetime.strptime(x, "%Y-%m-%d"),
# datetime without T
lambda x: datetime.strptime(x, "%Y-%m-%d %H:%M:%S"),
lambda x: datetime.strptime(x, "%Y-%m-%d %H:%M:%S.%f"),
# Alternative ISO formats (fallback)
lambda x: datetime.strptime(x, "%Y-%m-%dT%H:%M:%S"),
lambda x: datetime.strptime(x, "%Y-%m-%dT%H:%M:%S.%f"),