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
duration
is a duration of typet()
returned byCldr.Calendar.Duration.new/2
options
is a Keyword list of options
Options
:except
is a list of time units to be omitted from the formatted output. It may be useful to useexcept: [:microsecond]
for example. The default is[]
.locale
is any valid locale name returned byCldr.known_locale_names/1
or aCldr.LanguageTag
struct returned byCldr.Locale.new!/2
The default isCldr.get_locale/0
backend
is any module that includesuse Cldr
and therefore is aCldr
backend module. The default isCldr.default_backend/0
:list_options
is a list of options passed toCldr.List.to_string/3
to 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
0
are 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"}