1
0
Fork 0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-11-21 17:51:51 +00: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'
delta = datetime.timedelta(**{unit: time})
return today + delta
return datetime.datetime.strptime(date_str, '%Y%m%d').date()
if re.match(r'^\d{8}$', date_str):
try:
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):