scrapinghub / dateparser

python parser for human readable dates
BSD 3-Clause "New" or "Revised" License
2.54k stars 464 forks source link

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

Closed amineKammah closed 5 months ago

amineKammah commented 8 months ago

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)
benbuzbee commented 6 months ago

+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