Merge branch 'main' of github.com:netalertx/NetAlertX
Some checks failed
✅ Code checks / check-url-paths (push) Has been cancelled
✅ Code checks / lint (push) Has been cancelled
✅ Code checks / docker-tests (push) Has been cancelled
🐳 👩‍💻 docker dev / docker_dev (push) Has been cancelled
📘 Deploy MkDocs / deploy (push) Has been cancelled

This commit is contained in:
jokob-sk
2026-04-06 12:27:59 +10:00

View File

@@ -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 *
@@ -209,10 +209,13 @@ def format_date_iso(date_val: str) -> Optional[str]:
# 2. If it has no timezone, assume it's UTC (our DB storage format) # 2. If it has no timezone, assume it's UTC (our DB storage format)
# then CONVERT to user's configured timezone # then CONVERT to user's configured timezone
if dt.tzinfo is None: if dt.tzinfo is None:
# Mark as UTC first # Mark as UTC first — critical: localize() would label without converting
dt = dt.replace(tzinfo=datetime.UTC) dt = dt.replace(tzinfo=datetime.UTC)
# Convert to user's timezone # Resolve target timezone; fall back to UTC if conf.tz is missing/invalid
target_tz = conf.tz if isinstance(conf.tz, datetime.tzinfo) else ZoneInfo(conf.tz) try:
target_tz = conf.tz if isinstance(conf.tz, datetime.tzinfo) else ZoneInfo(conf.tz)
except (ZoneInfoNotFoundError, ValueError, TypeError):
target_tz = datetime.UTC
dt = dt.astimezone(target_tz) dt = dt.astimezone(target_tz)
# 3. Return the string. .isoformat() will now include the +11:00 or +10:00 # 3. Return the string. .isoformat() will now include the +11:00 or +10:00