A friendly api for erlang date tuples and ecto datetimes.
If available in Hex, the package can be installed as:
- Add
timeanatorto your list of dependencies inmix.exs:
```elixir
def deps do
[{:timeanator, "~> 1.0.0"}]
end
```
This module provides a friendly API for getting time represented in milliseconds.
import Timeanator
1 |> minute #=> 60000
30 |> Timeanator.minutes #=> 1800000
additionally, when methods from_now or ago are used erlang time tuples
are provided
import Timeanator
15 |> minutes |> ago #=> {:ok, {{2019, 11, 4}, {1, 24, 14}}}
15 |> minutes |> from_now #=> {:ok, {{2019, 11, 4}, {1, 54, 24}}}
from_now and ago can return Ecto.DateTime structs. This is done by
providing the :ecto atom to either the from_now or ago functions
import Timeanator
15 |> minutes |> ago(:ecto) #=> {:ok, #Ecto.DateTime<2019-11-04 01:24:37>}
15 |> minutes |> from_now(:ecto) #=> {:ok, #Ecto.DateTime<2019-11-04 01:54:38>}
Lastly, there are from_now! and ago! variants that raise either
Timeanator.Cast or Timeanator.UnsupportedCastingOption exceptions. They also
do not return a {:ok, value} tuple, but instead just return value