Skip to content

Commit b93d9e1

Browse files
authored
Fix OverflowError for far-future dates
1 parent a2006ea commit b93d9e1

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/humanize/time.py renamed to src/humanize/ (dt.timedelta(days=365 + 35), "1 year, 1 month ago"),

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ def _abs_timedelta(delta: dt.timedelta) -> dt.timedelta:
6161
Returns:
6262
datetime.timedelta: Absolute timedelta.
6363
"""
64-
if delta.days < 0:
65-
now = _now()
66-
return now - (now + delta)
67-
return delta
64+
# Use abs() rather than round-tripping through the current datetime:
65+
# `now + delta` overflows (OverflowError) when a negative delta reaches back
66+
# past year 1, e.g. for naturaltime(dt.datetime(9999, 12, 31)).
67+
return abs(delta)
6868

6969

7070
def _date_and_delta(

0 commit comments

Comments
 (0)