Timeanator v1.0.0 Timeanator View Source

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

Link to this section Summary

Functions

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

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

returns one day in milliseconds

returns the amount provided in milliseconds

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

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

returns one hour in milliseconds

returns the amount provided in milliseconds

returns the amount provided in milliseconds

returns the amount provided in milliseconds

returns one minute in milliseconds

returns the amount provided in milliseconds

returns one second in milliseconds

returns the amount of seconds provided in milliseconds

Link to this section Functions

Link to this function

ago(milliseconds, cast_option \\ nil)

View Source
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 milliseconds in the past.

Link to this function

ago!(milliseconds, cast_option \\ nil)

View Source
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 milliseconds in the past. Raises if there is a problem

returns one day in milliseconds

returns the amount provided in milliseconds

Link to this function

from_now(milliseconds, cast_option \\ nil)

View Source
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 milliseconds in the future.

Link to this function

from_now!(milliseconds, cast_options \\ nil)

View Source

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

returns one hour in milliseconds

returns the amount provided in milliseconds

Link to this function

millisecond(int)

View Source
millisecond(integer()) :: integer()

returns the amount provided in milliseconds

Link to this function

milliseconds(int)

View Source
milliseconds(integer()) :: integer()

returns the amount provided in milliseconds

returns one minute in milliseconds

returns the amount provided in milliseconds

returns one second in milliseconds

returns the amount of seconds provided in milliseconds