HumanTime (human_time v0.4.0)

A module to convert time intervals into human-readable strings with support for localization.

Summary

Functions

Converts a duration (in milliseconds or DateTime) into a human-readable string with optional localization.

Functions

human(input, opts \\ [])

@spec human(
  integer() | DateTime.t(),
  keyword()
) :: String.t()

Converts a duration (in milliseconds or DateTime) into a human-readable string with optional localization.

Examples

iex> HumanTime.human(754000)
"12 minutes from now"

iex> HumanTime.human(-754000)
"12 minutes ago"

iex> HumanTime.human(DateTime.utc_now() |> DateTime.add(5, :second))
"5 seconds from now"

iex> HumanTime.human(DateTime.utc_now() |> DateTime.add(-5, :second))
"5 seconds ago"

iex> HumanTime.human(-754000, locale: "fr")
"il y a 12 minutes"