Skip to content

Commit 9788cc0

Browse files
committed
Reuse floor division quotient in Calendar.ISO month shift
Compute the shifted month directly from the floor-divided year, avoiding rem/2 and branching for negative remainders. Assisted-by: Antigravity:Gemini-3.8-Flash
1 parent 36351ae commit 9788cc0

1 file changed

Lines changed: 1 addition & 7 deletions

File tree

lib/elixir/lib/calendar/iso.ex

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,13 +1904,7 @@ defmodule Calendar.ISO do
19041904
total_months = year * months_in_year + month + months - 1
19051905

19061906
new_year = floor_div_positive_divisor(total_months, months_in_year)
1907-
1908-
new_month =
1909-
case rem(total_months, months_in_year) + 1 do
1910-
new_month when new_month < 1 -> new_month + months_in_year
1911-
new_month -> new_month
1912-
end
1913-
1907+
new_month = total_months - new_year * months_in_year + 1
19141908
new_day = min(day, days_in_month(new_year, new_month))
19151909

19161910
{new_year, new_month, new_day}

0 commit comments

Comments
 (0)