scrapinghub / scrapinghub/dateparser
Using locale gives wrong results
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.9k
- Forks
- 520
- Avg merge
- 22h 56m
- Merged PRs (30d)
- 6
Description
default_startdate = datetime(year=2, month=1, day=1, hour=0, minute=0, second=0, microsecond=0)
default_enddate = datetime(year=9998, month=12, day=31, hour=0, minute=0, second=0, microsecond=0)
s = dateparser.parse('02/2013', settings={'RELATIVE_BASE': default_startdate})
sl = dateparser.parse('02/2013', locales=['en-001'], settings={'RELATIVE_BASE': default_startdate})
e = dateparser.parse('02/2013', settings={'RELATIVE_BASE': default_enddate})
el = dateparser.parse('02/2013', locales=['en-001'], settings={'RELATIVE_BASE': default_enddate})
s=2013-02-01 00:00:00
sl=2013-01-02 00:00:00
e=2013-02-28 00:00:00
el=2013-12-02 00:00:00
It appears that 02 is taken as the day instead of the month when the locale is used even though locale en-001 is defined as having date order DMY.
Adding settings: 'DATE_ORDER': 'DMY', 'PREFER_LANGUAGE_DATE_ORDER': False makes no difference.
What locale is used by default if locales is not specified (I'm curious as to why not setting locales gives the correct behaviour)?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the reported dateparser.parse calls with the en-001 locale and both RELATIVE_BASE values, then trace the locale date-order handling. Done means the documented DMY order is honored for this input and regression coverage verifies both boundary cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- internationalization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100