scrapinghub / scrapinghub/dateparser

Comparing output for `current_period` and `past` values of `PREFER_DATES_FROM` setting

Open
#1,031 0 comments 1 reaction 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

I observed one interesting behavior where for some cases the current_period and past values of PREFER_DATES_FROM return the same result but it's different for others. For example, suppose today is Thursday 23th, then

text = "Thursday"
print(dateparser.parse(text, settings={'PREFER_DATES_FROM': 'current_period'}))
>>> 2021-12-23 00:00:00
print(dateparser.parse(text, settings={'PREFER_DATES_FROM': 'past'}))
>>> 2021-12-16 00:00:00

This is the expected behavior, where for current_period we get today's date (at the time of writing) i.e. 23rd, and for past its last Thursday 16th.

Now for another case,

text = "Friday"
print(dateparser.parse(text, settings={'PREFER_DATES_FROM': 'current_period'}))
>>> 2021-12-17 00:00:00
print(dateparser.parse(text, settings={'PREFER_DATES_FROM': 'past'}))
>>> 2021-12-17 00:00:00

Here, the output is the same for both cases. But shouldn't the current_period return the nearest Friday or at least the Friday of the ongoing week which will be 24th and not last Friday that is 17th?

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 Thursday and Friday examples through dateparser.parse with the PREFER_DATES_FROM setting. Trace the relative-weekday parsing entry point to determine why current_period and past converge, then check existing tests for related preference behavior. Done means the intended semantics are established and the differing cases are covered by regression tests.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.