Skip to content

Commit

Permalink
Handle decoding of %Time{} struct
Browse files Browse the repository at this point in the history
  • Loading branch information
gmile committed May 4, 2024
1 parent a9902f3 commit bceff9a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/ecto/adapters/sqlite3/codec.ex
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ defmodule Ecto.Adapters.SQLite3.Codec do

def time_decode(nil), do: {:ok, nil}

def time_decode(%Time{} = value) do
{:ok, value}
end

def time_decode(value) do
case Time.from_iso8601(value) do
{:ok, _time} = result -> result
Expand Down
5 changes: 5 additions & 0 deletions test/ecto/adapters/sqlite3/codec_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ defmodule Ecto.Adapters.SQLite3.CodecTest do
{:ok, time} = Time.from_iso8601("23:50:07.123Z")
assert {:ok, ^time} = Codec.time_decode("23:50:07.123Z")
end

test "struct" do
time = ~T[10:28:14.748721]
assert {:ok, ^time} = Codec.time_decode(time)
end
end

describe ".utc_datetime_decode/1" do
Expand Down

0 comments on commit bceff9a

Please sign in to comment.