Skip to content

Commit 1d84530

Browse files
committed
add Code.ensure_loaded to Duration to ensure pre 1.17 compatibility
1 parent febb5c9 commit 1d84530

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lib/phoenix_html/safe.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ defimpl Phoenix.HTML.Safe, for: DateTime do
4444
end
4545
end
4646

47-
defimpl Phoenix.HTML.Safe, for: Duration do
48-
defdelegate to_iodata(data), to: Duration, as: :to_iso8601
47+
if Code.ensure_loaded?(Duration) do
48+
defimpl Phoenix.HTML.Safe, for: Duration do
49+
defdelegate to_iodata(data), to: Duration, as: :to_iso8601
50+
end
4951
end
5052

5153
defimpl Phoenix.HTML.Safe, for: List do

test/phoenix_html/safe_test.exs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ defmodule Phoenix.HTML.SafeTest do
6262
assert Safe.to_iodata(datetime) == "2000-01-01T12:13:14+00:30"
6363
end
6464

65-
test "impl for Duration" do
66-
duration = Duration.new!(month: 1)
67-
assert Safe.to_iodata(duration) == "P1M"
65+
if Code.ensure_loaded?(Duration) do
66+
test "impl for Duration" do
67+
duration = Duration.new!(month: 1)
68+
assert Safe.to_iodata(duration) == "P1M"
69+
end
6870
end
6971

7072
test "impl for URI" do

0 commit comments

Comments
 (0)