[coldfusion] Add automation (#172)

Co-authored-by: Marc Wrobel <marc.wrobel@gmail.com>
This commit is contained in:
Nemo
2023-11-27 02:08:23 +05:30
committed by GitHub
parent 9dfd8f4f6e
commit d7b0de3e17
2 changed files with 35 additions and 3 deletions

View File

@@ -3,8 +3,6 @@ import calendar
def parse_date(text, formats=frozenset([
"%B %d, %Y", # January 1, 2020
"%b %d, %Y", # Jan 1, 2020
"%B %d %Y", # January 1 2020
"%b %d %Y", # Jan 1 2020
"%d %B %Y", # 1 January 2020
@@ -33,13 +31,14 @@ def parse_datetime(text, formats=frozenset([
"%Y-%m-%d %H:%M:%S", # 2023-05-01 08:32:34
"%Y-%m-%dT%H:%M:%S", # 2023-05-01T08:32:34
"%Y-%m-%d %H:%M:%S %z", # 2023-05-01 08:32:34 +0900
"%a, %d %b %Y %H:%M:%S %Z", # Wed, 01 Jan 2020 00:00:00 GMT
"%a %d %b %Y %H:%M:%S %Z", # Wed, 01 Jan 2020 00:00:00 GMT
"%Y-%m-%dT%H:%M:%S%z", # 2023-05-01T08:32:34+0900
]), to_utc=True) -> datetime:
"""Parse a given text representing a datetime using a list of formats,
optionally converting it to UTC.
"""
text = text.strip()
text = text.replace(", ", " ") # so that we don't have to deal with commas in formats
for fmt in formats:
try:
date = datetime.strptime(text, fmt)