dateparser icon indicating copy to clipboard operation
dateparser copied to clipboard

fix: allow 'N {interval} from now' (#502)

Open jakeogh opened this issue 7 months ago • 5 comments

This is a copy of PR https://github.com/scrapinghub/dateparser/pull/642 which fixes https://github.com/scrapinghub/dateparser/issues/502. I'm not sure why it was closed, or if this is the right way to re-submit it. Afaict it's a general fix that works in all cases.

Before:

$ python -c "from dateparser import parse; from datetime import datetime ; print(parse('in 2 days', settings={'RELATIVE_BASE': datetime.now()}))"
2025-05-19 00:34:29.964320

$ python -c "from dateparser import parse; from datetime import datetime ; print(parse('2 days fron now', settings={'RELATIVE_BASE': datetime.now()}))"
None

After:

$ python -c "from dateparser import parse; from datetime import datetime ; print(parse('in 2 days', settings={'RELATIVE_BASE': datetime.now()}))"
2025-05-19 00:34:29.964320

$ python -c "from dateparser import parse; from datetime import datetime ; print(parse('2 days fron now', settings={'RELATIVE_BASE': datetime.now()}))"
2025-05-19 00:34:29.964320

jakeogh avatar May 17 '25 07:05 jakeogh

Can we get this merged? Would like to have support for "* from now" format

deepthi-mck avatar Sep 09 '25 07:09 deepthi-mck

Closing and reopening to see if CI triggers.

Gallaecio avatar Oct 06 '25 12:10 Gallaecio

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 96.58%. Comparing base (bdc57d3) to head (a795ec0).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1271   +/-   ##
=======================================
  Coverage   96.58%   96.58%           
=======================================
  Files         235      235           
  Lines        2866     2866           
=======================================
  Hits         2768     2768           
  Misses         98       98           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Oct 06 '25 12:10 codecov[bot]

It seems tests do not pass.

a = (<tests.test_freshness_date_parser.TestFreshnessDateDataParser testMethod=test_relative_past_dates_038_7_years_from_now>,)
kw = {}

    @wraps(func)
    def standalone_func(*a, **kw):
>       return func(*(a + p.args), **p.kwargs, **kw)
E       TypeError: test_relative_past_dates() got an unexpected keyword argument 'in_future'

.tox/min-all/lib/python3.9/site-packages/parameterized/parameterized.py:620: TypeError

Gallaecio avatar Oct 06 '25 12:10 Gallaecio

The test cases were decorating the wrong function, they should pass now.

jakeogh avatar Oct 18 '25 20:10 jakeogh