Skip to content
Open
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
20 changes: 9 additions & 11 deletions arrow/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1223,10 +1223,8 @@ def humanize(
calendar_diff.years * self._MONTHS_PER_YEAR + calendar_diff.months
)

# Round up partial months when already at least one
# calendar month has elapsed and the remaining days
# are more than halfway through another month.
if calendar_months >= 1 and calendar_diff.days > 14:
# For months, if more than 2 weeks, count as a full month
if calendar_diff.days > 14:
Comment on lines +1226 to +1227
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calendar_months is incremented whenever calendar_diff.days > 14, even when calendar_months is currently 0. That means a pure ~15–29 day difference (e.g., 16 days) will be humanized as "a month" instead of weeks/days, reintroducing the behavior that #1242 tried to fix. If the intent is to avoid reporting months unless at least one calendar month has elapsed, restore the calendar_months >= 1 guard (or otherwise ensure sub-month differences don’t get rounded up into 1 month).

Suggested change
# For months, if more than 2 weeks, count as a full month
if calendar_diff.days > 14:
# For months, if more than 2 weeks, count as a full month,
# but only when at least one full calendar month has elapsed.
if calendar_months >= 1 and calendar_diff.days > 14:

Copilot uses AI. Check for mistakes.
calendar_months += 1
Comment on lines +1226 to 1228
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the auto-granularity boundary between weeks and months (sub-month diffs can now become "a month" due to the calendar_diff.days > 14 rounding). Please add/adjust a regression test covering the ~15–29 day range (including the 16-day case referenced in #1242) so the intended behavior is locked in and won’t flip again in future refactors.

Copilot uses AI. Check for mistakes.

calendar_months = min(calendar_months, self._MONTHS_PER_YEAR)
Expand All @@ -1238,13 +1236,6 @@ def humanize(
days = sign * max(delta_second // self._SECS_PER_DAY, 2)
return locale.describe("days", days, only_distance=only_distance)

elif diff < self._SECS_PER_WEEK * 2 and calendar_months < 1:
return locale.describe("week", sign, only_distance=only_distance)

elif calendar_months < 1 and diff < self._SECS_PER_MONTH:
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_YEAR:
if calendar_months == 1:
return locale.describe(
Expand All @@ -1256,6 +1247,13 @@ def humanize(
"months", months, only_distance=only_distance
)

elif diff < self._SECS_PER_WEEK * 2:
return locale.describe("week", sign, only_distance=only_distance)

elif diff < self._SECS_PER_MONTH:
weeks = sign * max(delta_second // self._SECS_PER_WEEK, 2)
return locale.describe("weeks", weeks, only_distance=only_distance)

elif diff < self._SECS_PER_YEAR * 2:
return locale.describe("year", sign, only_distance=only_distance)

Expand Down
Loading