1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-11-23 00:54:31 +01:00

handle wrong formatted date argument

The provided date argument (--date, --datebefore or --dateafter) is parsed by
datetimp.strptime(). This function throws as ValueError exception at failure.

This patch implements exception handling by catching the ValueError exception,
printing an error message and exiting with a non-zero exit code.
This commit is contained in:
Franz König 2018-05-21 01:20:05 +02:00
parent 504f20dd30
commit 4d64bc5251

View File

@ -1270,7 +1270,10 @@ 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() try:
return datetime.datetime.strptime(date_str, '%Y%m%d').date()
except ValueError:
sys.exit('ERROR: cannot parse datestring ' + date_str)
def hyphenate_date(date_str): def hyphenate_date(date_str):