Skip to content

Commit 2b3d954

Browse files
committed
Fix timezone handling in format_date_iso: ensure fallback to UTC for invalid configurations
1 parent 36e606e commit 2b3d954

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

server/utils/datetime_utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,13 @@ def format_date_iso(date_val: str) -> Optional[str]:
209209
# 2. If it has no timezone, assume it's UTC (our DB storage format)
210210
# then CONVERT to user's configured timezone
211211
if dt.tzinfo is None:
212-
# Mark as UTC first
212+
# Mark as UTC first — critical: localize() would label without converting
213213
dt = dt.replace(tzinfo=datetime.UTC)
214-
# Convert to user's timezone
215-
target_tz = conf.tz if isinstance(conf.tz, datetime.tzinfo) else ZoneInfo(conf.tz)
214+
# Resolve target timezone; fall back to UTC if conf.tz is missing/invalid
215+
try:
216+
target_tz = conf.tz if isinstance(conf.tz, datetime.tzinfo) else ZoneInfo(conf.tz)
217+
except Exception:
218+
target_tz = datetime.UTC
216219
dt = dt.astimezone(target_tz)
217220

218221
# 3. Return the string. .isoformat() will now include the +11:00 or +10:00

0 commit comments

Comments
 (0)