scrapinghub / scrapinghub/dateparser

Proposal: Have an api to retrieve the relativedelta information

Open
#1,035 3 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

dateparser is a fantastic tool to calculate a date given a literal expression like "3 years and 6 months".

However, it does not seem possible to leverage the syntactic parser to retrieve a relativedelta (https://dateutil.readthedocs.io/en/stable/relativedelta.html) structure filled with the result of the parsing.
For example if the text says:

3 years and 6 months

It would be great to obtain a structured filled with

relativedelta(year=3, month=6)

At least I could not find on the API a way to do so. The only way seems to calculate the resulting date with

dateparser.get_date_data("3 years 6 months")

then get the current date (datetime.now()) and derive the number of months. The drawback is you loose the resolution. In the example above, you will be able to calculate 42 months but won't be able to keep the original sentence meaning: 3 years and 6 months.

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 with the existing get_date_data API and the parser path it uses; the issue does not identify an implementation file or test. Compare the requested structured result with dateutil.relativedelta and define how expressions such as “3 years and 6 months” should preserve their original units, then add coverage for that behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.