Skip to content

Commit 3957df4

Browse files
refactor: Use utils.cast() for partial config parsing
Co-authored-by: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com>
1 parent c5addc0 commit 3957df4

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

plexapi/utils.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff 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:

0 commit comments

Comments
 (0)