Skip to content

Commit

Permalink
Improve robustness of strptime pre-formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
MoojMidge committed Jan 16, 2024
1 parent acd6e53 commit fbae2cd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions resources/lib/youtube_plugin/kodion/utils/datetime_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,15 @@ def datetime_to_since(context, dt, local=True):

def strptime(datetime_str, fmt=None):
if fmt is None:
fmt = '%Y-%m-%dT%H%M%S'
fmt = '%Y-%m-%d%H%M%S'

if ' ' in datetime_str:
date_part, time_part = datetime_str.split(' ')
elif 'T' in datetime_str:
date_part, time_part = datetime_str.split('T')
else:
date_part = None
time_part = datetime_str

if ':' in time_part:
time_part = time_part.replace(':', '')
Expand All @@ -259,7 +262,7 @@ def strptime(datetime_str, fmt=None):

if timezone and timezone_part and offset:
time_part = offset.join((time_part, timezone_part))
datetime_str = 'T'.join((date_part, time_part))
datetime_str = ''.join((date_part, time_part)) if date_part else time_part

try:
return datetime.strptime(datetime_str, fmt)
Expand Down

0 comments on commit fbae2cd

Please sign in to comment.