Skip to content
Merged
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
2 changes: 1 addition & 1 deletion lib/elixir/lib/calendar/date.ex
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ defmodule Date do
@doc since: "1.11.0"
@spec from_gregorian_days(integer(), Calendar.calendar()) :: t
def from_gregorian_days(days, calendar \\ Calendar.ISO) when is_integer(days) do
from_iso_days({days, 0}, calendar)
from_iso_days({days, {0, 86_400}}, calendar)
end

@doc """
Expand Down
13 changes: 13 additions & 0 deletions lib/elixir/test/elixir/calendar/date_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,19 @@ defmodule DateTest do
fn -> Date.convert!(~D[2016-02-03], FakeCalendar) end
end

test "from_gregorian_days/2" do
assert Date.from_gregorian_days(730_485, Calendar.Holocene) ==
Calendar.Holocene.date(12000, 01, 01)

assert Date.from_gregorian_days(-1, Calendar.Holocene) ==
Calendar.Holocene.date(9999, 12, 31)

for days <- [-1_000_000, 0, 1, 1_000_000] do
date = Date.from_gregorian_days(days, Calendar.Holocene)
assert Date.to_gregorian_days(date) == days
end
end

test "add/2" do
assert Date.add(~D[0000-01-01], 3_652_424) == ~D[9999-12-31]
assert Date.add(~D[0000-01-01], 3_652_425) == Date.new!(10000, 1, 1)
Expand Down
Loading