Skip to content

Commit dcedde1

Browse files
cdce8pJonnyWong16
andauthored
Fix datetime returning UTC (#1262)
* Replace datetime.utcfromtimestamp * Update plexapi/utils.py Co-authored-by: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> * Default using `fromtimestamp` and fallback to using `timedelta` from 0 --------- Co-authored-by: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com>
1 parent d5cad1f commit dcedde1

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

plexapi/utils.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,18 @@ def toDatetime(value, format=None):
323323
return None
324324
else:
325325
try:
326-
return datetime.utcfromtimestamp(0) + timedelta(seconds=int(value))
326+
value = int(value)
327327
except ValueError:
328328
log.info('Failed to parse "%s" to datetime as timestamp, defaulting to None', value)
329329
return None
330-
except OverflowError:
331-
log.info('Failed to parse "%s" to datetime as timestamp (out-of-bounds), defaulting to None', value)
332-
return None
330+
try:
331+
return datetime.fromtimestamp(value)
332+
except (OSError, OverflowError):
333+
try:
334+
return datetime.fromtimestamp(0) + timedelta(seconds=value)
335+
except OverflowError:
336+
log.info('Failed to parse "%s" to datetime as timestamp (out-of-bounds), defaulting to None', value)
337+
return None
333338
return value
334339

335340

0 commit comments

Comments
 (0)