scrapinghub / dateparser

python parser for human readable dates

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parsing using `{"PREFER_DAY_OF_MONTH": "last", "PREFER_MONTH_OF_YEAR": "last"}` doesn't use last day of the last month

amineKammah opened this issue · comments

Hi, I noticed that when parsing a date with missing month and day of month with {"PREFER_DAY_OF_MONTH": "last", "PREFER_MONTH_OF_YEAR": "last"} settings, we default to the last day of the current month instead of the last day of the last month.

For example, when running this code in February, it will return 2022/12/28 instead of 2022/12/31, as the last day of feb is 28.

>>> import dateparser
>>> dateparser.parse("2022", settings={"PREFER_DAY_OF_MONTH": "last", "PREFER_MONTH_OF_YEAR": "last"})
datetime.datetime(2022, 12, 28, 0, 0)

+1; this bit me because it correctly returned the 31st when I wrote my tests in March, then started failing in April :(

I would guess it should resolve the month before the day