1
0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-12-01 02:37:25 +01:00

[utils] improve to verify date format

This commit is contained in:
kikuyan 2021-07-17 18:10:46 +09:00
parent a803582717
commit a58f25bc3b

View File

@ -3081,7 +3081,15 @@ def date_from_str(date_str):
unit += 's' unit += 's'
delta = datetime.timedelta(**{unit: time}) delta = datetime.timedelta(**{unit: time})
return today + delta return today + delta
if re.match(r'^\d{8}$', date_str):
try:
return datetime.datetime.strptime(date_str, '%Y%m%d').date() return datetime.datetime.strptime(date_str, '%Y%m%d').date()
except ValueError as err:
errmsg = 'Invalid date: %s (%s)' % (date_str, err)
else:
errmsg = 'Invalid date format: %s (must be 8 digit number)' % date_str
raise ValueError(errmsg)
def hyphenate_date(date_str): def hyphenate_date(date_str):