scrapinghub / scrapinghub/dateparser
CS: Incorrect use of date as time
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
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 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