Cldr.Calendar.Duration.to_string
to_string, go back to Cldr.Calendar.Duration module for more information.
Returns a string formatted representation of a duration.
Note that time units that are zero are ommitted from the output.
Formatting is
Arguments
durationis a duration of typet()returned byCldr.Calendar.Duration.new/2optionsis a Keyword list of options
Options
:exceptis a list of time units to be omitted from the formatted output. It may be useful to useexcept: [:microsecond]for example. The default is[].localeis any valid locale name returned byCldr.known_locale_names/1or aCldr.LanguageTagstruct returned byCldr.Locale.new!/2The default isCldr.get_locale/0backendis any module that includesuse Cldrand therefore is aCldrbackend module. The default isCldr.default_backend/0:list_optionsis a list of options passed toCldr.List.to_string/3to control the final list output.
Any other options are passed to Cldr.Number.to_string/3 and
Cldr.Unit.to_string/3 during the formatting process.
Note
- Any duration parts that are
0are not output.
Example
iex> {:ok, duration} = Cldr.Calendar.Duration.new(~D[2019-01-01], ~D[2019-12-31])
iex> Cldr.Calendar.Duration.to_string(duration)
{:ok, "11 months and 30 days"}