urlinfo:generic: support more datetime formats
This commit is contained in:
parent
c118016700
commit
59b59fddd3
1 changed files with 11 additions and 3 deletions
|
|
@ -150,11 +150,19 @@ def aslist(o: Any):
|
||||||
|
|
||||||
def fromisoformat(s) -> datetime:
|
def fromisoformat(s) -> datetime:
|
||||||
try:
|
try:
|
||||||
datetime.fromisoformat(s)
|
return datetime.fromisoformat(s)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
# '2003-08-15T13:18:27Z'
|
formats = (
|
||||||
return datetime.strptime(s, r"%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=timezone.utc)
|
r"%Y-%m-%dT%H:%M:%SZ", # '2003-08-15T13:18:27Z', found at ???
|
||||||
|
r"%Y-%m-%dT%H:%M:%S.000Z", # '2020-12-03T18:42:00.000Z', found at wsj
|
||||||
|
)
|
||||||
|
for fmt in formats:
|
||||||
|
try:
|
||||||
|
return datetime.strptime(s, fmt).replace(tzinfo=timezone.utc)
|
||||||
|
except ValueError as e:
|
||||||
|
pass
|
||||||
|
raise e
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue