scrapinghub / scrapinghub/dateparser

dateparser.parse() prefers current year also when 'STRICT_PARSING' is True

Open
#1,034 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.9k
Forks
520
Avg merge
22h 56m
Merged PRs (30d)
6

Description

When I use the dateparser.parse() functionality I expect it to behave the same way for two different input dates that are off by one year. However, based on the current implementation it seems to prefer the current year and detect that in a string. This can be seen in the following comparison:

>>> dateparser.parse('03/06/2020a', settings={'STRICT_PARSING':True})
datetime.datetime(2, 1, 4, 9, 31, 4, 821531)
>>> dateparser.parse('03/06/2022a', settings={'STRICT_PARSING':True})
datetime.datetime(2022, 6, 3, 0, 0)

The same input string, with the only difference of the year 2022a instead of 2020a or 2021a will be parsed correctly if it is the current year. However, this is not deterministic and IMO not expected behavior, as the result will change depending on the current year of the localization.

This applies to the default settings as well as the {'STRICT_PARSING':True} settings.

Could you please advise with which settings I could achieve a deterministic result here? Or ideally improve the implementation here / guide me towards where I could contribute and fix this issue?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two dateparser.parse() examples from the issue with and without STRICT_PARSING, then trace the parsing path that handles dates containing a trailing letter. Done should mean equivalent inputs are handled deterministically regardless of the current year, with regression coverage for the reported examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.