Current section
Files
Jump to
Current section
Files
lib/hugs/cast.ex
defmodule Hugs.Cast do
def string_to_existing_atom(string) when is_binary(string) do
{:ok, String.to_existing_atom(string)}
catch
:error, :badarg -> {:error, {:unexisting_atom, string}}
end
def string_to_existing_atom(atom) when is_atom(atom) do
{:ok, atom}
end
def datetime_from_iso8601(string) when is_binary(string) do
case DateTime.from_iso8601(string) do
{:ok, value, _calendar_offset} -> {:ok, value}
{:error, _} = err -> err
end
end
def datetime_from_iso8601(%DateTime{} = dt) do
{:ok, dt}
end
def datetime_from_iso8601(_string) do
{:error, "not a string"}
end
def in_out(cast_in, cast_out) when is_function(cast_in, 1) and is_function(cast_out, 1) do
end
end