mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-12-22 22:35:21 +00:00
[utils] improve to verify date format
This commit is contained in:
parent
a803582717
commit
a58f25bc3b
@ -3081,7 +3081,15 @@ def date_from_str(date_str):
|
||||
unit += 's'
|
||||
delta = datetime.timedelta(**{unit: time})
|
||||
return today + delta
|
||||
|
||||
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):
|
||||
|
Loading…
Reference in New Issue
Block a user