View Source Timex.Format.Duration.Formatters.Default (timex v3.7.11)

Handles formatting Duration values as ISO 8601 durations as described below.

Durations are represented by the format P[n]Y[n]M[n]DT[n]H[n]M[n]S. In this representation, the [n] is replaced by the value for each of the date and time elements that follow the [n]. Leading zeros are not required, but the maximum number of digits for each element should be agreed to by the communicating parties. The capital letters P, Y, M, W, D, T, H, M, and S are designators for each of the date and time elements and are not replaced.

  • P is the duration designator (historically called "period") placed at the start of the duration representation.
  • Y is the year designator that follows the value for the number of years.
  • M is the month designator that follows the value for the number of months.
  • D is the day designator that follows the value for the number of days.
  • T is the time designator that precedes the time components of the representation.
  • H is the hour designator that follows the value for the number of hours.
  • M is the minute designator that follows the value for the number of minutes.
  • S is the second designator that follows the value for the number of seconds.

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)

Link to this section Functions

@spec 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

Examples

iex> use Timex
...> Duration.from_erl({0, 1, 1_000_000}) |> Elixir.Timex.Format.Duration.Formatters.Default.format
"PT2S"

iex> use Timex
...> Duration.from_erl({0, 1, 1_000_100}) |> Elixir.Timex.Format.Duration.Formatters.Default.format
"PT2.0001S"

iex> use Timex
...> Duration.from_erl({0, 65, 0}) |> Elixir.Timex.Format.Duration.Formatters.Default.format
"PT1M5S"

iex> use Timex
...> Duration.from_erl({0, -65, 0}) |> Elixir.Timex.Format.Duration.Formatters.Default.format
"PT1M5S"

iex> use Timex
...> Duration.from_erl({1435, 180354, 590264}) |> Elixir.Timex.Format.Duration.Formatters.Default.format
"P45Y6M5DT21H12M34.590264S"

iex> use Timex
...> Duration.from_erl({0, 0, 0}) |> Elixir.Timex.Format.Duration.Formatters.Default.format
"PT0S"
Link to this function

lformat(duration, locale)

View Source

Callback implementation for Timex.Format.Duration.Formatter.lformat/2.