From a44782a58b4a17d654464e0f651b7bbd58d04d6d Mon Sep 17 00:00:00 2001 From: Kadir Can Ozden <101993364+bysiber@users.noreply.github.com> Date: Fri, 20 Feb 2026 08:27:08 +0300 Subject: [PATCH 1/2] Fix humanize gap between weeks and months for same-month deltas When the time difference exceeds _SECS_PER_MONTH (30.5 days) but calendar_months is still 0 (both dates in the same calendar month), no branch in the if/elif chain matched: - "weeks" requires diff < _SECS_PER_MONTH -> False - "months" requires calendar_months >= 1 -> False Execution fell through to the "year" branch, so a ~31-day difference within the same month reported "a year ago". This affects all 7 months with 31 days (Jan, Mar, May, Jul, Aug, Oct, Dec) when comparing dates near the start and end of the same month. Add an explicit branch for this case that reports "a month" when diff >= _SECS_PER_MONTH but calendar_months < 1. --- arrow/arrow.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arrow/arrow.py b/arrow/arrow.py index f0a57f04..3f8ab751 100644 --- a/arrow/arrow.py +++ b/arrow/arrow.py @@ -1245,6 +1245,9 @@ def humanize( weeks = sign * max(delta_second // self._SECS_PER_WEEK, 2) return locale.describe("weeks", weeks, only_distance=only_distance) + elif calendar_months < 1 and diff >= self._SECS_PER_MONTH: + return locale.describe("month", sign, only_distance=only_distance) + elif calendar_months >= 1 and diff < self._SECS_PER_YEAR: if calendar_months == 1: return locale.describe( From 9551f978949df932e87542eba27bdbcbc00e4531 Mon Sep 17 00:00:00 2001 From: Kadir Can Ozden <101993364+bysiber@users.noreply.github.com> Date: Fri, 20 Feb 2026 10:34:12 +0300 Subject: [PATCH 2/2] Add test for month boundary with large delta in humanize --- tests/test_arrow.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_arrow.py b/tests/test_arrow.py index b595e4e2..69ba1db6 100644 --- a/tests/test_arrow.py +++ b/tests/test_arrow.py @@ -2223,6 +2223,14 @@ def test_month(self): assert self.now.humanize(later, only_distance=True) == "a month" assert later.humanize(self.now, only_distance=True) == "a month" + def test_month_boundary_with_large_delta(self): + """~31 days where calendar_months is 0 but elapsed exceeds _SECS_PER_MONTH.""" + # Jan 15 -> Feb 15: calendar_months may round to 0, but 31 days > 30.5 + arw = arrow.Arrow(2013, 1, 15) + later = arrow.Arrow(2013, 2, 15) + assert arw.humanize(later) == "a month ago" + assert later.humanize(arw) == "in a month" + def test_months(self): later = self.now.shift(months=2) earlier = self.now.shift(months=-2)