Skip to content

Commit 692b14d

Browse files
tknorrisrazzeee
authored andcommitted
Remove strptime from fallback since it's not needed and can throw an
exception
1 parent 6300f08 commit 692b14d

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

utilities.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -477,30 +477,26 @@ def kodiRpcToTraktMediaObjects(data, mode='collected'):
477477
def convertDateTimeToUTC(toConvert):
478478
if toConvert:
479479
dateFormat = "%Y-%m-%d %H:%M:%S"
480-
try:
481-
naive = datetime.strptime(toConvert, dateFormat)
482-
except TypeError:
483-
naive = datetime(*(time.strptime(toConvert, dateFormat)[0:6]))
484-
if 2038 < naive.year or 1970 > naive.year:
480+
try: naive = datetime.strptime(toConvert, dateFormat)
481+
except TypeError: naive = datetime(*(time.strptime(toConvert, dateFormat)[0:6]))
482+
if naive.year < 1970 or naive.year > 2038:
485483
logger.debug('convertDateTimeToUTC() Movie/show was collected/watched outside of the unix timespan. Fallback to datetime now')
486-
naive = datetime.strptime(str(datetime.now()).split(".")[0], dateFormat)
484+
naive = datetime.now()
487485
local = naive.replace(tzinfo=tzlocal())
488486
utc = local.astimezone(tzutc())
489487
return unicode(utc)
490-
491488
else:
492489
return toConvert
493490

494491
def convertUtcToDateTime(toConvert):
495492
if toConvert:
496493
dateFormat = "%Y-%m-%d %H:%M:%S"
497494
naive = dateutil.parser.parse(toConvert)
498-
if 2038 < naive.year or 1970 > naive.year:
495+
if naive.year < 1970 or naive.year > 2038:
499496
logger.debug('convertUtcToDateTime() Movie/show was collected/watched outside of the unix timespan. Fallback to datetime now')
500-
naive = datetime.strptime(str(datetime.now()).split(".")[0], dateFormat)
497+
naive = datetime.now()
501498
utc = naive.replace(tzinfo=tzutc())
502499
local = utc.astimezone(tzlocal())
503-
504500
return local.strftime(dateFormat)
505501
else:
506502
return toConvert

0 commit comments

Comments
 (0)