aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2015-10-28 21:40:22 +0600
committerSergey M․ <dstftw@gmail.com>2015-10-28 21:40:22 +0600
commit52c3a6e49d2cbc1932992d816d28bbed629daadc (patch)
treea30e8575f221be621f8cd628b901c23055c8c9cf /youtube_dl
parent4e16c1f80b009001aaea6f8baca5dfbfa9b58c11 (diff)
[utils] Improve parse_iso8601
Diffstat (limited to 'youtube_dl')
-rw-r--r--youtube_dl/utils.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index a61e47646..558c9c7d5 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -814,9 +814,11 @@ def parse_iso8601(date_str, delimiter='T', timezone=None):
if date_str is None:
return None
+ date_str = re.sub(r'\.[0-9]+', '', date_str)
+
if timezone is None:
m = re.search(
- r'(\.[0-9]+)?(?:Z$| ?(?P<sign>\+|-)(?P<hours>[0-9]{2}):?(?P<minutes>[0-9]{2})$)',
+ r'(?:Z$| ?(?P<sign>\+|-)(?P<hours>[0-9]{2}):?(?P<minutes>[0-9]{2})$)',
date_str)
if not m:
timezone = datetime.timedelta()
@@ -829,9 +831,12 @@ def parse_iso8601(date_str, delimiter='T', timezone=None):
timezone = datetime.timedelta(
hours=sign * int(m.group('hours')),
minutes=sign * int(m.group('minutes')))
- date_format = '%Y-%m-%d{0}%H:%M:%S'.format(delimiter)
- dt = datetime.datetime.strptime(date_str, date_format) - timezone
- return calendar.timegm(dt.timetuple())
+ try:
+ date_format = '%Y-%m-%d{0}%H:%M:%S'.format(delimiter)
+ dt = datetime.datetime.strptime(date_str, date_format) - timezone
+ return calendar.timegm(dt.timetuple())
+ except ValueError:
+ pass
def unified_strdate(date_str, day_first=True):