pub struct RelativeTimeFormatter { /* private fields */ }
Expand description

A formatter to render locale-sensitive relative time.

Example

use icu_relativetime::{RelativeTimeFormatter, RelativeTimeFormatterOptions};
use icu_locid::locale;
use writeable::assert_writeable_eq;
use fixed_decimal::FixedDecimal;

let relative_time_formatter = RelativeTimeFormatter::try_new_long_second_unstable(
    &icu_testdata::unstable(),
    &locale!("en").into(),
    RelativeTimeFormatterOptions::default()
)
.expect("Data should load successfully.");

assert_writeable_eq!(
        relative_time_formatter.format(FixedDecimal::from(5i8)),
        "in 5 seconds"
);
assert_writeable_eq!(
        relative_time_formatter.format(FixedDecimal::from(-10i8)),
        "10 seconds ago"
);

Example

use icu_relativetime::{RelativeTimeFormatter, RelativeTimeFormatterOptions};
use icu_relativetime::options::Numeric;
use icu_locid::locale;
use writeable::assert_writeable_eq;
use fixed_decimal::FixedDecimal;

let relative_time_formatter = RelativeTimeFormatter::try_new_short_day_unstable(
    &icu_testdata::unstable(),
    &locale!("es").into(),
    RelativeTimeFormatterOptions { numeric: Numeric::Auto }
)
.expect("Data should load successfully.");

assert_writeable_eq!(
        relative_time_formatter.format(FixedDecimal::from(0u8)),
        "hoy"
);
assert_writeable_eq!(
        relative_time_formatter.format(FixedDecimal::from(-2i8)),
        "anteayer"
);
assert_writeable_eq!(
        relative_time_formatter.format(FixedDecimal::from(2u8)),
        "pasado mañana"
);
assert_writeable_eq!(
        relative_time_formatter.format(FixedDecimal::from(15i8)),
        "dentro de 15 d"
);

Example

use icu_relativetime::{RelativeTimeFormatter, RelativeTimeFormatterOptions};
use icu_relativetime::options::Numeric;
use icu_locid::locale;
use writeable::assert_writeable_eq;
use fixed_decimal::FixedDecimal;

let relative_time_formatter = RelativeTimeFormatter::try_new_narrow_year_unstable(
    &icu_testdata::unstable(),
    &locale!("bn").into(),
    RelativeTimeFormatterOptions::default()
)
.expect("Data should load successfully.");

assert_writeable_eq!(
        relative_time_formatter.format(FixedDecimal::from(3u8)),
        "৩ বছরে"
);
assert_writeable_eq!(
        relative_time_formatter.format(FixedDecimal::from(-15i8)),
        "১৫ বছর পূর্বে"
);

Implementations

Create a new RelativeTimeFormatter

Create a new RelativeTimeFormatter

Create a new RelativeTimeFormatter

Create a new RelativeTimeFormatter

Create a new RelativeTimeFormatter

Create a new RelativeTimeFormatter

Create a new RelativeTimeFormatter

Create a new RelativeTimeFormatter

Create a new RelativeTimeFormatter

Create a new RelativeTimeFormatter

Create a new RelativeTimeFormatter

Create a new RelativeTimeFormatter

Create a new RelativeTimeFormatter

Create a new RelativeTimeFormatter

Create a new RelativeTimeFormatter

Create a new RelativeTimeFormatter

Create a new RelativeTimeFormatter

Create a new RelativeTimeFormatter

Create a new RelativeTimeFormatter

Create a new RelativeTimeFormatter

Create a new RelativeTimeFormatter

Create a new RelativeTimeFormatter

Create a new RelativeTimeFormatter

Create a new RelativeTimeFormatter

Format a value according to the locale and formatting options of RelativeTimeFormatter.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.