File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66import re
77import pytz
88from typing import Union , Optional
9- from zoneinfo import ZoneInfo
9+ from zoneinfo import ZoneInfo , ZoneInfoNotFoundError
1010import email .utils
1111import conf
1212# from const import *
@@ -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 (ZoneInfoNotFoundError , ValueError , TypeError ):
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
You can’t perform that action at this time.
0 commit comments