scrapinghub / scrapinghub/dateparser

Prefer "pm" when the base is after noon

Open
#908 4 comments 0 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

Currently, writing a time without specifying "AM" or "PM" will automatically be parsed as "AM".

If the current time (or the relative base if set) is after noon, for example, 6:00 PM, it would make more sense that "7:00" should be parsed as 7:00 PM and not 7:00 AM.

Either this should be the default behavior or there could be a setting to allow AM/PM to be assumed based on the base.

dateparser.parse("7:00")
# datetime.datetime(2021, 4, 11, 7, 0)

base = datetime.datetime(2021, 4, 12, 18, 0) # 6:00 PM

dateparser.parse("7:00", settings={ "RELATIVE_BASE": base })
# datetime.datetime(2021, 4, 12, 7, 0)

The expected output for the first example should be datetime.datetime(2021, 4, 12, 19, 0) if the current time is after noon.

The second example should always output datetime.datetime(2021, 4, 12, 19, 0).

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 at the dateparser.parse entry point and trace handling of time-only strings and the RELATIVE_BASE setting. Compare the two examples for bases before and after noon; done means an omitted AM/PM follows the relevant base time and the documented expected outputs are covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.