Timeanator v0.0.1 Timeanator

This module provides a friendly API for getting time represented in seconds.

  import Timeanator
  1 |> minute #=> 60
  30 |> Timeanator.minutes #=> 1800

additionally, when methods from_now or ago are used erlang time tuples are provided

import Timeanator
15 |> minutes |> ago #=> {:ok, {{2016, 11, 3}, {9, 59, 38}}}
15 |> minutes |> from_now #=> {:ok, {{2016, 11, 3}, {10, 31, 13}}}

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<2016-11-03 20:59:42>}
15 |> minutes |> from_now(:ecto) #=> {:ok, #Ecto.DateTime<2016-11-03 22:00:31>}

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

Summary

Functions

returns a erlang date that is X seconds in the past

returns a erlang date that is X seconds in the past. Raises if there is a problem

returns one day in seconds

returns the amount provided in seconds

returns a erlang date that is X seconds in the future

returns a erlang date that is X seconds in the future. Raises if there is a problem

returns one hour in seconds

returns the amount provided in seconds

returns one minute in seconds

returns the amount provided in seconds

returns one second

returns the amount provided in seconds

Functions

ago(seconds, cast_option \\ nil)
ago(integer, :ecto | nil) ::
  {:ok, :calendar.datetime} |
  {:ok, %Ecto.DateTime{day: term, hour: term, min: term, month: term, sec: term, usec: term, year: term}} |
  {:error, atom}

returns a erlang date that is X seconds in the past.

ago!(seconds, cast_option \\ nil)
ago!(integer, :ecto | nil) ::
  :calendar.datetime |
  %Ecto.DateTime{day: term, hour: term, min: term, month: term, sec: term, usec: term, year: term}

returns a erlang date that is X seconds in the past. Raises if there is a problem

day(int)
day(integer) :: integer

returns one day in seconds

days(int)
days(integer) :: integer

returns the amount provided in seconds

from_now(seconds, cast_option \\ nil)
from_now(integer, :ecto | nil) ::
  {:ok, :calendar.datetime} |
  {:ok, %Ecto.DateTime{day: term, hour: term, min: term, month: term, sec: term, usec: term, year: term}} |
  {:error, atom}
from_now(integer, :ecto | nil) ::
  :calendar.datetime |
  %Ecto.DateTime{day: term, hour: term, min: term, month: term, sec: term, usec: term, year: term}

returns a erlang date that is X seconds in the future.

from_now!(seconds, cast_options \\ nil)

returns a erlang date that is X seconds in the future. Raises if there is a problem

hour(int)
hour(integer) :: integer

returns one hour in seconds

hours(int)
hours(integer) :: integer

returns the amount provided in seconds

minute(int)
minute(integer) :: integer

returns one minute in seconds

minutes(int)
minutes(integer) :: integer

returns the amount provided in seconds

second(int)
second(integer) :: integer

returns one second

seconds(int)
seconds(integer) :: integer

returns the amount provided in seconds