Skip to content

Commit 4e61690

Browse files
authored
Remove redundant abs calls from Calendar.ISO (#15675)
The BCE guards establish the sign of both calculations, so compute their positive magnitudes directly. Assisted-by: Codex:GPT-5
1 parent 44ea7a6 commit 4e61690

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

lib/elixir/lib/calendar/iso.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ defmodule Calendar.ISO do
11761176
@doc since: "1.8.0"
11771177
@spec year_of_era(year) :: {1..10_000, era}
11781178
def year_of_era(year) when is_year_CE(year), do: {year, 1}
1179-
def year_of_era(year) when is_year_BCE(year), do: {abs(year) + 1, 0}
1179+
def year_of_era(year) when is_year_BCE(year), do: {1 - year, 0}
11801180

11811181
@doc """
11821182
Calendar callback to compute the year and era from the
@@ -1229,7 +1229,7 @@ defmodule Calendar.ISO do
12291229
end
12301230

12311231
def day_of_era(year, month, day) when is_year_BCE(year) do
1232-
day = abs(date_to_iso_days(year, month, day) - @iso_epoch)
1232+
day = @iso_epoch - date_to_iso_days(year, month, day)
12331233
{day, 0}
12341234
end
12351235

0 commit comments

Comments
 (0)