Timex.Format.Duration.Formatters.Humanized (timex v3.7.6) View Source
Handles formatting timestamp values as human readable strings.
For formatting timestamps as points in time rather than intervals,
use Timex.format
Link to this section Summary
Functions
Return a human readable string representing the absolute value of duration (i.e. would return the same output for both negative and positive representations of a given duration)
Return a human readable string representing the time interval, translated to the given locale
Link to this section Functions
Specs
format(Timex.Duration.t()) :: String.t() | {:error, term()}
Return a human readable string representing the absolute value of duration (i.e. would return the same output for both negative and positive representations of a given duration)
Examples
iex> use Timex
...> Duration.from_erl({0, 1, 1_000_000}) |> Elixir.Timex.Format.Duration.Formatters.Humanized.format
"2 seconds"
iex> use Timex
...> Duration.from_erl({0, 1, 1_000_100}) |> Elixir.Timex.Format.Duration.Formatters.Humanized.format
"2 seconds, 100 microseconds"
iex> use Timex
...> Duration.from_erl({0, 65, 0}) |> Elixir.Timex.Format.Duration.Formatters.Humanized.format
"1 minute, 5 seconds"
iex> use Timex
...> Duration.from_erl({0, -65, 0}) |> Elixir.Timex.Format.Duration.Formatters.Humanized.format
"1 minute, 5 seconds"
iex> use Timex
...> Duration.from_erl({1435, 180354, 590264}) |> Elixir.Timex.Format.Duration.Formatters.Humanized.format
"45 years, 6 months, 5 days, 21 hours, 12 minutes, 34 seconds, 590.264 milliseconds"
Specs
lformat(Timex.Duration.t(), String.t()) :: String.t() | {:error, term()}
Return a human readable string representing the time interval, translated to the given locale
Examples
iex> use Timex
...> Duration.from_erl({0, 65, 0}) |> Elixir.Timex.Format.Duration.Formatters.Humanized.lformat("ru")
"1 минута, 5 секунд"
iex> use Timex
...> Duration.from_erl({1435, 180354, 590264}) |> Elixir.Timex.Format.Duration.Formatters.Humanized.lformat("ru")
"45 лет, 6 месяцев, 5 дней, 21 час, 12 минут, 34 секунды, 590.264 миллисекунд"