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( 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)