[discourse] Add auto method (#515)

Closes #505.
This commit is contained in:
Marc Wrobel
2025-09-11 12:21:20 +02:00
committed by GitHub
parent add9ee5bed
commit d190da8073
2 changed files with 31 additions and 0 deletions

View File

@@ -58,6 +58,7 @@ def parse_datetime(text: str, formats: list[str] = frozenset([
"%a %d %b %Y %H:%M:%S %z", # Wed 01 Jan 2020 00:00:00 -0400
"%a %b %d %H:%M:%S %Z %Y", # Wed Jan 01 00:00:00 UTC 2020
"%a %b %d %H:%M:%S %z %Y", # Wed Jan 01 00:00:00 -0400 2020
"%b %d %Y %I:%M %p", # Jan 1 2020 0:00 pm
"%Y%m%d%H%M%S", # 20230501083234
]), to_utc: bool = True) -> datetime:
"""Parse a given text representing a datetime using a list of formats,