scrapinghub / scrapinghub/dateparser

CS: Incorrect use of date as time

Open
#1,029 5 comments 3 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

Hi, I have found out that a date expressed as dd.mm. is incorrectly interpreted as a time.

In Czech, we use the dot . to separate days, months and years. We use the double dot : to separate hours, minutes and seconds. I would expect to define the separators somewhere in dateparser/data/date_translation_data/cs.py.

If you confirm that this is an issue, I am eager to dig into the library and prepare a PR.

print(dateparser.parse('23. 12.', languages=['cs']))
# 2021-12-23 00:00:00 -> OK

print(dateparser.parse('23.12.', languages=['cs']))
# 2021-12-21 23:12:00 -> INCORRECT, should be 2021-12-23 00:00:00

print(dateparser.parse('23:12', languages=['cs']))
# 2021-12-21 23:12:00 -> OK

Hotfix: Adding a custom date format solves this issue. However, it does not work for search_dates() as a custom date_formats attribute is not supported there.

print(dateparser.parse('23.12.', languages=['cs'], date_formats=['%d.%m.']))

Hotfix2: Adding a space between day and month using a regex solves the problem even for search_dates().

utterance = re.sub(r'\b([1-3][0-9]|[1-9])\.([1-9]|12)(\.|\b)', r'\1. \2.', utterance) 

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 three dateparser.parse examples and the search_dates case, then inspect dateparser/data/date_translation_data/cs.py and the parsing entry points. Confirm that compact Czech dates such as 23.12. are treated as dates while 23:12 remains a time; done when both parse() and search_dates() handle the intended forms without the reported workaround.

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
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.