Skip to content

Commit 8ddef06

Browse files
committed
Also encode Duration to JSON
1 parent 472c4e1 commit 8ddef06

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

lib/elixir/lib/json.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ defimpl JSON.Encoder, for: Map do
150150
end
151151
end
152152

153-
defimpl JSON.Encoder, for: [Date, Time, NaiveDateTime, DateTime] do
153+
defimpl JSON.Encoder, for: [Date, Time, NaiveDateTime, DateTime, Duration] do
154154
def encode(value, _encoder) do
155155
[?", @for.to_iso8601(value), ?"]
156156
end

lib/elixir/test/elixir/json_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ defmodule JSONTest do
5252
assert JSON.encode!(~T[14:00:00.123]) == "\"14:00:00.123\""
5353
assert JSON.encode!(~N[2010-04-17 14:00:00.123]) == "\"2010-04-17T14:00:00.123\""
5454
assert JSON.encode!(~U[2010-04-17 14:00:00.123Z]) == "\"2010-04-17T14:00:00.123Z\""
55+
assert JSON.encode!(Duration.new!(month: 2, hour: 3)) == "\"P2MT3H\""
5556
end
5657
end
5758

0 commit comments

Comments
 (0)