1
0

Improved timezone handling

This commit is contained in:
Jon Michael Aanes 2024-08-27 00:31:44 +02:00
parent 090b854f66
commit 0057693f28
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
2 changed files with 9 additions and 1 deletions

View File

@ -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:

View File

@ -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)