Improved timezone handling
This commit is contained in:
parent
090b854f66
commit
0057693f28
|
@ -36,10 +36,16 @@ def parse_response_datetime(response) -> datetime.datetime:
|
||||||
).replace(tzinfo=datetime.UTC)
|
).replace(tzinfo=datetime.UTC)
|
||||||
|
|
||||||
|
|
||||||
|
LOCAL_TIMEZONE = datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo
|
||||||
|
|
||||||
|
|
||||||
def parse_time(text: str) -> datetime.datetime:
|
def parse_time(text: str) -> datetime.datetime:
|
||||||
text = text.replace('\n', ' ')
|
text = text.replace('\n', ' ')
|
||||||
text = text.strip()
|
text = text.strip()
|
||||||
return datetime.datetime.strptime(text, '%d %b %Y %I:%M:%S %p')
|
time = datetime.datetime.strptime(text, '%d %b %Y %I:%M:%S %p')
|
||||||
|
time = time.replace(tzinfo=LOCAL_TIMEZONE)
|
||||||
|
assert time.tzinfo is not None, time
|
||||||
|
return time
|
||||||
|
|
||||||
|
|
||||||
def parse_date(text: str) -> datetime.date:
|
def parse_date(text: str) -> datetime.date:
|
||||||
|
|
|
@ -62,6 +62,8 @@ def csv_str_to_value(
|
||||||
def csv_safe_value(v: object) -> str:
|
def csv_safe_value(v: object) -> str:
|
||||||
if isinstance(v, urllib.parse.ParseResult):
|
if isinstance(v, urllib.parse.ParseResult):
|
||||||
return v.geturl()
|
return v.geturl()
|
||||||
|
if isinstance(v, datetime.datetime):
|
||||||
|
assert v.tzinfo is not None, v
|
||||||
return str(v)
|
return str(v)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user