Use multiple date formats in DateRange validator
This commit is contained in:
12
atst/domain/date.py
Normal file
12
atst/domain/date.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import pendulum
|
||||
|
||||
|
||||
def parse_date(data):
|
||||
date_formats = ["YYYY-MM-DD", "MM/DD/YYYY"]
|
||||
for _format in date_formats:
|
||||
try:
|
||||
return pendulum.from_format(data, _format).date()
|
||||
except (ValueError, pendulum.parsing.exceptions.ParserError):
|
||||
pass
|
||||
|
||||
raise ValueError("Unable to parse string {}".format(data))
|
Reference in New Issue
Block a user