scrapinghub / scrapinghub/dateparser

Using locale gives wrong results

Open
#608 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Type: Bug
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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.