scrapinghub / scrapinghub/dateparser
Timezone not handled properly when parsing incomplete dates
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.9k
- Forks
- 520
- Avg merge
- 22h 56m
- Merged PRs (30d)
- 6
Description
Version: dateparser 0.6.0
The parse function seems to use the UTC time when checking future/past dates. The function should have returned future/past dates based on the actual/local time.
The behavior is shown on the third line (I'm currently in UTC+2). Expected result is on the 20th.
>>> datetime.now()
datetime.datetime(2017, 4, 19, 14, 23, 15, 131445)
>>> datetime.utcnow()
datetime.datetime(2017, 4, 19, 12, 23, 15, 131445)
>>> dateparser.parse('13:00', settings={'PREFER_DATES_FROM': 'future'})
datetime.datetime(2017, 4, 19, 13, 0)
>>> dateparser.parse('11:00', settings={'PREFER_DATES_FROM': 'future'})
datetime.datetime(2017, 4, 20, 11, 0)
I believe this is an error due to the fact that relative dates are relative to the actual/local time:
>>> dateparser.parse("in 5 min")
datetime.datetime(2017, 4, 19, 14, 28, 15, 131445)
This seems to be a workaround:
>>> dateparser.parse('13:00', settings={'PREFER_DATES_FROM': 'future', 'RELATIVE_BASE': datetime.now()})
datetime.datetime(2017, 4, 20, 13, 0)
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
Start by reproducing the parse('13:00' and parse('11:00') examples with PREFER_DATES_FROM='future' in the dateparser parse path, comparing the default base time with datetime.now(). Check how incomplete dates and relative dates obtain their reference time. Done means future/past decisions use the actual local reference time while preserving the documented RELATIVE_BASE workaround behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100