Icu.RelativeTime (icu v0.4.0)
High-level API for ICU4X-powered relative time formatting.
Use format/4 to generate localized relative phrases like “in 3 days”, or
build reusable formatter structs with formatter/2 for repeated usage.
Summary
Types
Controls the overall style of the relative time output.
Opaque reference to an ICU4X relative time formatter.
Controls whether relative phrases can be non-numeric.
Map form of the supported options.
Keyword form of the supported options.
Supported relative time units.
Functions
Formats a relative value using an existing formatter.
Convenience helper that creates a formatter and formats in one step.
Formats and raises on error.
Convenience helper that raises on error.
Formats to parts using an existing formatter.
Convenience helper that formats to parts in one step.
Formats to parts and raises on error.
Convenience helper that formats to parts and raises on error.
Builds a reusable formatter for the given locale and options.
Builds a reusable formatter and raises on error.
Types
@type format() :: :wide | :short | :narrow
Controls the overall style of the relative time output.
@type format_error() ::
:invalid_formatter
| :invalid_locale
| :invalid_options
| :invalid_unit
| :unsupported_fraction
@type formatter() :: Icu.RelativeTime.Formatter.t()
Opaque reference to an ICU4X relative time formatter.
@type numeric() :: :always | :auto
Controls whether relative phrases can be non-numeric.
@type options() :: %{ optional(:format) => format(), optional(:numeric) => numeric(), optional(:locale) => Icu.LanguageTag.t() | nil }
Map form of the supported options.
@type options_input() :: options() | options_list() | nil
@type options_list() :: [ format: format(), numeric: numeric(), locale: Icu.LanguageTag.t() | nil ]
Keyword form of the supported options.
@type unit() :: :second | :minute | :hour | :day | :week | :month | :quarter | :year
Supported relative time units.
Functions
@spec format(formatter(), number(), unit()) :: {:ok, String.t()} | {:error, format_error()}
Formats a relative value using an existing formatter.
@spec format(number(), unit(), Icu.LanguageTag.t() | String.t(), options_input()) :: {:ok, String.t()} | {:error, format_error()}
Convenience helper that creates a formatter and formats in one step.
Formats and raises on error.
@spec format!(number(), unit(), Icu.LanguageTag.t() | String.t(), options_input()) :: String.t()
Convenience helper that raises on error.
@spec format_to_parts(formatter(), number(), unit()) :: {:ok, [map()]} | {:error, format_error()}
Formats to parts using an existing formatter.
@spec format_to_parts( number(), unit(), Icu.LanguageTag.t() | String.t(), options_input() ) :: {:ok, [map()]} | {:error, format_error()}
Convenience helper that formats to parts in one step.
Formats to parts and raises on error.
@spec format_to_parts!( number(), unit(), Icu.LanguageTag.t() | String.t(), options_input() ) :: [map()]
Convenience helper that formats to parts and raises on error.
@spec formatter(Icu.LanguageTag.t() | String.t(), options_input()) :: {:ok, formatter()} | {:error, format_error()}
Builds a reusable formatter for the given locale and options.
@spec formatter!(Icu.LanguageTag.t() | String.t(), options_input()) :: formatter()
Builds a reusable formatter and raises on error.