Skip to content

Commit 9832039

Browse files
committed
handle the situation when updated_at is a string
1 parent 6fc6a76 commit 9832039

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

lib/arc_ecto/definition.ex

+13-7
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ defmodule Arc.Ecto.Definition do
1818
url
1919
else
2020
case updated_at do
21-
%NaiveDateTime{} ->
22-
stamp = :calendar.datetime_to_gregorian_seconds(NaiveDateTime.to_erl(updated_at))
23-
case URI.parse(url).query do
24-
nil -> url <> "?v=#{stamp}"
25-
_ -> url <> "&v=#{stamp}"
26-
end
27-
_ -> url
21+
%NaiveDateTime{} -> version_url(updated_at, url)
22+
string when is_bitstring(updated_at) ->
23+
version_url(NaiveDateTime.from_iso8601!(string), url)
24+
_ ->
25+
url
2826
end
2927
end
3028
end
@@ -34,6 +32,14 @@ defmodule Arc.Ecto.Definition do
3432
def delete({%{file_name: file_name, updated_at: _updated_at}, scope}), do: super({file_name, scope})
3533

3634
def delete(args), do: super(args)
35+
36+
defp version_url(updated_at, url) do
37+
stamp = :calendar.datetime_to_gregorian_seconds(NaiveDateTime.to_erl(updated_at))
38+
case URI.parse(url).query do
39+
nil -> url <> "?v=#{stamp}"
40+
_ -> url <> "&v=#{stamp}"
41+
end
42+
end
3743
end
3844
end
3945
end

0 commit comments

Comments
 (0)