Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix more timezone issues #301

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions custom_components/opnsense/pyopnsense/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

import aiohttp
import awesomeversion
from dateutil.parser import parse
from dateutil.parser import UnknownTimezoneWarning, parse

from .const import AMBIGUOUS_TZINFOS

# value to set as the socket timeout
DEFAULT_TIMEOUT = 60
Expand Down Expand Up @@ -463,15 +465,17 @@ async def get_firmware_update_info(self):
# "last_check": "Sun Jan 15 22:05:55 UTC 2023"
# format = "%a %b %d %H:%M:%S %Z %Y"
try:
last_check: datetime = parse(status.get("last_check"))
last_check: datetime = parse(
status.get("last_check"), tzinfos=AMBIGUOUS_TZINFOS
)
if last_check.tzinfo is None:
last_check = last_check.replace(
tzinfo=timezone(datetime.now().astimezone().utcoffset())
)

last_check_timestamp: float = last_check.timestamp()

except (ValueError, TypeError):
except (ValueError, TypeError, UnknownTimezoneWarning):
last_check_timestamp: float = 0

stale: bool = (
Expand Down
22 changes: 22 additions & 0 deletions custom_components/opnsense/pyopnsense/const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from collections.abc import Mapping
from typing import Any

from dateutil.tz import gettz

AMBIGUOUS_TZINFOS: Mapping[str, Any] = {
"ACST": gettz("Australia/Darwin"), # Australian Central Standard Time
"ACT": gettz("America/Rio_Branco"), # Acre Time (Brazil)
"AEST": gettz("Australia/Sydney"), # Australian Eastern Standard Time
"AST": gettz("America/Halifax"), # Atlantic Standard Time (Caribbean/Canada)
"AWST": gettz("Australia/Perth"), # Australian Western Standard Time
"BST": gettz("Europe/London"), # British Summer Time
"CET": gettz("Europe/Paris"), # Central European Time
"CST": gettz("America/Chicago"), # Central Standard Time (North America)
"EET": gettz("Europe/Bucharest"), # Eastern European Time
"EST": gettz("America/New_York"), # Eastern Standard Time (North America)
"HST": gettz("Pacific/Honolulu"), # Hawaii-Aleutian Standard Time
"IST": gettz("Asia/Kolkata"), # Indian Standard Time
"MST": gettz("America/Denver"), # Mountain Standard Time (North America)
"NZST": gettz("Pacific/Auckland"), # New Zealand Standard Time
"PST": gettz("America/Los_Angeles"), # Pacific Standard Time (North America)
}
Loading