Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions arrow/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 8 additions & 0 deletions tests/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading