mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-16 06:15:46 +00:00
[utils] improve to verify date format
This commit is contained in:
parent
a803582717
commit
a58f25bc3b
1 changed files with 9 additions and 1 deletions
|
@ -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
|
||||||
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):
|
def hyphenate_date(date_str):
|
||||||
|
|
Loading…
Reference in a new issue