mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-04-06 02:01:37 -07:00
Fix timezone resolution in format_date_iso: handle specific exceptions for invalid configurations
Some checks are pending
🐳 ⚠ docker-unsafe from next_release branch / docker_dev_unsafe (push) Waiting to run
Some checks are pending
🐳 ⚠ docker-unsafe from next_release branch / docker_dev_unsafe (push) Waiting to run
This commit is contained in:
@@ -6,7 +6,7 @@ import datetime
|
|||||||
import re
|
import re
|
||||||
import pytz
|
import pytz
|
||||||
from typing import Union, Optional
|
from typing import Union, Optional
|
||||||
from zoneinfo import ZoneInfo
|
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
|
||||||
import email.utils
|
import email.utils
|
||||||
import conf
|
import conf
|
||||||
# from const import *
|
# from const import *
|
||||||
@@ -214,7 +214,7 @@ def format_date_iso(date_val: str) -> Optional[str]:
|
|||||||
# Resolve target timezone; fall back to UTC if conf.tz is missing/invalid
|
# Resolve target timezone; fall back to UTC if conf.tz is missing/invalid
|
||||||
try:
|
try:
|
||||||
target_tz = conf.tz if isinstance(conf.tz, datetime.tzinfo) else ZoneInfo(conf.tz)
|
target_tz = conf.tz if isinstance(conf.tz, datetime.tzinfo) else ZoneInfo(conf.tz)
|
||||||
except Exception:
|
except (ZoneInfoNotFoundError, ValueError, TypeError):
|
||||||
target_tz = datetime.UTC
|
target_tz = datetime.UTC
|
||||||
dt = dt.astimezone(target_tz)
|
dt = dt.astimezone(target_tz)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user