DateParams
A simple Elixir library that use the Calendar library to convert values of a map into Elixir 1.3's native date types. This is especially useful when used as a plug to deal with user-inputted dates.
Example
map = %{"date" => "2015-03-12"}
DateParams.to_structs(map, [["date"]])
#=> %{"date" => ~D[2015-03-12]}Using it as a plug
defmodule Project.PageController do
use Project.Web, :controller
plug DateParams.Plug, [["vacation"], ["starts_at"], ["vacation"] ["ends_at"]]
endInstallation
If available in Hex, the package can be installed as:
-
Add
date_paramsto your list of dependencies inmix.exs:
```elixir
def deps do
[{:date_params, "~> 0.1.0"}]
end
```-
Ensure
date_paramsis started before your application:
```elixir
def application do
[applications: [:date_params]]
end
```TODO
-
Add
Timesupport - Add timezone support
- Look into supporting other datetime formats (HTTP and various RFC formats)
- Look into supporting natural language dates (like Chronic)