Ecto, Phoenix and utc datetime

I will provide my solution here. So i created custom Ecto.Type which will receive local datetime and timezone. And that will convert it to utc.

  @behaviour Ecto.Type
  def type(), do: :utc_datetime
..
  def cast(%{"datetimelocal" => datetimelocal, "tz" => tz}) do
    case Timex.parse(datetimelocal, "{ISO:Extended}") do
      {:error, _error} ->
        Ecto.Type.cast(type(), nil)
      {:ok, value} ->
        Ecto.Type.cast(type(), Timex.to_datetime(value, tz))
    end
  end
  ..
  def cast(data), do: Ecto.Type.cast(type(), data)