File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -348,18 +348,17 @@ def setDatetimeTimezone(value):
348348 if value is None or value is False :
349349 tzinfo = None
350350 # Use local timezone if value is True or "local"
351- elif value is True or ( isinstance ( value , str ) and value .strip ().lower () == 'local' ) :
351+ elif value is True or str ( value ) .strip ().lower () == 'local' :
352352 tzinfo = datetime .now ().astimezone ().tzinfo
353- # Attempt to resolve value as an IANA timezone string or boolean-like string
353+ # Attempt to resolve value as a boolean-like string or IANA timezone string
354354 else :
355355 setting = str (value ).strip ()
356- lower = setting .lower ()
357- # Handle common boolean-like strings from config/environment
358- if lower in ('true' , '1' ):
359- tzinfo = datetime .now ().astimezone ().tzinfo
360- elif lower in ('false' , '0' ):
361- tzinfo = None
362- else :
356+ # Try to cast as boolean first (normalize to lowercase for case-insensitive matching)
357+ try :
358+ is_enabled = cast (bool , setting .lower ())
359+ tzinfo = datetime .now ().astimezone ().tzinfo if is_enabled else None
360+ except ValueError :
361+ # Not a boolean string, try parsing as IANA timezone
363362 try :
364363 tzinfo = ZoneInfo (setting )
365364 except ZoneInfoNotFoundError :
You can’t perform that action at this time.
0 commit comments