Allow for multiple date formats
This commit is contained in:
@@ -7,7 +7,17 @@ import pendulum
|
||||
class DateField(DateField):
|
||||
def _value(self):
|
||||
if self.data:
|
||||
return pendulum.parse(self.data).date()
|
||||
date_formats = [
|
||||
"YYYY-MM-DD",
|
||||
"MM/DD/YYYY"
|
||||
]
|
||||
for _format in date_formats:
|
||||
try:
|
||||
return pendulum.from_format(self.data, _format).date()
|
||||
except (ValueError, pendulum.parsing.exceptions.ParserError):
|
||||
pass
|
||||
|
||||
raise ValueError("Unable to parse string {}".format(self.data))
|
||||
else:
|
||||
return None
|
||||
|
||||
|
Reference in New Issue
Block a user