Skip to content

Leave out a time span that does not fit in the years 1 to 9999 - #1580

Merged
AdrianAtZyte merged 1 commit into
scrapinghub:masterfrom
serhii73:fix-time-span-out-of-range
Nov 13, 2026
Merged

AdrianAtZyte merged 1 commit into
scrapinghub:masterfrom
serhii73:fix-time-span-out-of-range

Conversation

@serhii73

Copy link
Copy Markdown
Collaborator

search_dates() with RETURN_TIME_SPAN raises ValueError when the text holds a span that starts before the year 1 or ends after the year 9999, and the other dates of the text are lost with it:

>>> import datetime
>>> from dateparser.search import search_dates
>>> search_dates(
...     "Meeting on 12 January 2020. Totals for the last 120000 months.",
...     languages=["en"],
...     settings={"RETURN_TIME_SPAN": True, "RELATIVE_BASE": datetime.datetime(2020, 6, 15, 12)},
... )
Traceback (most recent call last):
  ...
ValueError: year -7980 is out of range

A span whose arithmetic overflows (e.g. "the next 99999999999 days") is already left out; this treats a span that ends outside the range of datetime the same way, with either strategy. With the change the call above returns [('on 12 January 2020', datetime.datetime(2020, 1, 12, 0, 0))], and "the next 120000 months" alone returns None.

Only inputs that raised before are affected: the new except clause runs only when the span cannot be computed. A span that still fits ("the past 24233 months" from 2020-06-15 starts on 0001-01-15) is returned as before; a test pins it.

An earlier attempt at this, #1568, was closed automatically.

🤖 Generated with Claude Code

search_dates() with RETURN_TIME_SPAN raised ValueError for a text such as
"the last 120000 months", whose span starts before the year 1, or "the next
120000 months", which ends after the year 9999, and the other dates of the
text were lost with it. A span whose arithmetic overflows was already left
out; leave these out as well, with either strategy.
@codecov

codecov Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.23%. Comparing base (90544c0) to head (428510c).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1580   +/-   ##
=======================================
  Coverage   99.23%   99.23%           
=======================================
  Files         239      239           
  Lines        4203     4203           
=======================================
  Hits         4171     4171           
  Misses         32       32           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

@codspeed

codspeed Bot commented Nov 13, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 11 untouched benchmarks


Comparing serhii73:fix-time-span-out-of-range (428510c) with master (90544c0)

Open in CodSpeed

@AdrianAtZyte
AdrianAtZyte merged commit 1fdf5da into scrapinghub:master Nov 13, 2026
32 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants