customize dateparser to use YMD order

This commit is contained in:
Sean Breckenridge 2023-04-17 14:17:49 -07:00
parent 87627cef46
commit d84be4ee41

View file

@ -84,15 +84,15 @@ def parse_datetime_float(date_str: str) -> float:
try: try:
import dateparser # type: ignore[import] import dateparser # type: ignore[import]
except ImportError:
pass
else:
# dateparser is a bit more lenient than the above, lets you type # dateparser is a bit more lenient than the above, lets you type
# all sorts of dates as inputs # all sorts of dates as inputs
# https://github.com/scrapinghub/dateparser#how-to-use # https://github.com/scrapinghub/dateparser#how-to-use
res: Optional[datetime] = dateparser.parse(ds, settings={"DATE_ORDER": "YMD"})
res: Optional[datetime] = dateparser.parse(ds)
if res is not None: if res is not None:
return res.timestamp() return res.timestamp()
except ImportError:
pass
raise QueryException(f"Was not able to parse {ds} into a datetime") raise QueryException(f"Was not able to parse {ds} into a datetime")