mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-10 06:04:15 +00:00
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>
This commit is contained in:
parent
d5cad1fe1c
commit
dcedde1947
1 changed files with 9 additions and 4 deletions
|
@ -323,13 +323,18 @@ def toDatetime(value, format=None):
|
|||
return None
|
||||
else:
|
||||
try:
|
||||
return datetime.utcfromtimestamp(0) + timedelta(seconds=int(value))
|
||||
value = int(value)
|
||||
except ValueError:
|
||||
log.info('Failed to parse "%s" to datetime as timestamp, defaulting to None', value)
|
||||
return None
|
||||
except OverflowError:
|
||||
log.info('Failed to parse "%s" to datetime as timestamp (out-of-bounds), defaulting to None', value)
|
||||
return None
|
||||
try:
|
||||
return datetime.fromtimestamp(value)
|
||||
except (OSError, OverflowError):
|
||||
try:
|
||||
return datetime.fromtimestamp(0) + timedelta(seconds=value)
|
||||
except OverflowError:
|
||||
log.info('Failed to parse "%s" to datetime as timestamp (out-of-bounds), defaulting to None', value)
|
||||
return None
|
||||
return value
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue