scrapinghub / scrapinghub/dateparser

ISO 8601 YYYY-MM-DD parsing depends on locale

Open
#1,125 0 comments 5 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

An ISO 8601 with dashes YYYY-MM-DD is quite common and I would think that there isn't much chance to confuse with other formats. However, the parsing depends on the locale leading to incorrectly parsed dates. Examples:

>>> dateparser.parse('1991-05-11')
datetime.datetime(1991, 5, 11, 0, 0)  # correct
>>> dateparser.parse('1991-05-11', locales=["en"])
datetime.datetime(1991, 5, 11, 0, 0)  # correct
>>> dateparser.parse('1991-05-11', locales=["de"])
datetime.datetime(1991, 11, 5, 0, 0)  # wrong!
>>> dateparser.parse('1991-05-11', locales=["es"])
datetime.datetime(1991, 11, 5, 0, 0)  # wrong!
>>> print(dateparser.parse('1991-05-17', locales=["de"]))
None  # wrong!

Is this the expected behavior, or is it just a bug?

Note that the input can be in many formats including ISO, which is why I want to give locales. But I do need ISO to work correctly.

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 dateparser.parse examples with locales=["de"] and locales=["es"], including both valid and invalid day values. Done means dashed ISO dates parse as YYYY-MM-DD regardless of the selected locale, while the issue's other locale-sensitive formats remain supported.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
localization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.