Packages

A simple library which converts the values of maps from various string representations of dates and times into native Elixir 1.3 dates. This is useful as a plug for converting user input into something that can reliably be sent to Ecto for saving to a database.

Current section

Files

Jump to
date_params lib plug.ex
Raw

lib/plug.ex

defmodule DateParams.Plug do
@moduledocc"""
A helpful plug that take incoming paramaters and transforms the values into
native `Date` and `NaiveDateTime` structs.
Set it up in a controller like so:
plug DateParams.Plug, [["vacation", "starts_at"], ["vacation", "ends_at"]]
"""
def init(opts), do: opts
def call(conn = %{params: params}, opts) do
%{conn | params: DateParams.to_structs(params, opts)}
end
end