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

TimeZoneFormat uses data from the DataProvider, the selected Locale, and the provided TimeZoneFormatConfig to collect all data necessary to format time zones into that locale.

The various time-zone configs specified in UTS-35 require different sets of data for formatting. As such,TimeZoneFormat will pull in only the resources needed to format the config that it is given upon construction.

For that reason, one should think of the process of formatting a time zone in two steps: first, a computationally heavy construction of TimeZoneFormat, and then fast formatting of the time-zone data using the instance.

Examples

use icu_locid::Locale;
use icu::locid::macros::langid;
use icu_datetime::{TimeZoneFormat, TimeZoneFormatConfig};
use icu_datetime::date::GmtOffset;
use icu_datetime::mock::time_zone::MockTimeZone;
use icu_provider::inv::InvariantDataProvider;

let locale: Locale = langid!("en").into();
let provider = InvariantDataProvider;

let tzf = TimeZoneFormat::try_from_config(locale, TimeZoneFormatConfig::GenericNonLocationLong, &provider)
    .expect("Failed to create TimeZoneFormat");

let time_zone = MockTimeZone::new(
       GmtOffset::default(),
       None,
       None,
       None,
);

let value = tzf.format_to_string(&time_zone);

Implementations

Constructor that selectively loads data based on what is required to format the given config into the given locale.

Examples
use icu_locid::Locale;
use icu::locid::macros::langid;
use icu_datetime::{TimeZoneFormat, TimeZoneFormatConfig};
use icu_datetime::mock::time_zone::MockTimeZone;
use icu_provider::inv::InvariantDataProvider;

let locale: Locale = langid!("en").into();
let provider = InvariantDataProvider;

let tzf = TimeZoneFormat::try_from_config(locale, TimeZoneFormatConfig::LocalizedGMT, &provider);

assert!(tzf.is_ok());

Takes a TimeZoneInput implementer and returns an instance of a FormattedTimeZone that contains all information necessary to display a formatted time zone and operate on it.

Examples
use icu_locid::Locale;
use icu::locid::macros::langid;
use icu_datetime::{TimeZoneFormat, TimeZoneFormatConfig};
use icu_datetime::date::GmtOffset;
use icu_datetime::mock::time_zone::MockTimeZone;
use icu_provider::inv::InvariantDataProvider;

let locale: Locale = langid!("en").into();
let provider = InvariantDataProvider;

let tzf = TimeZoneFormat::try_from_config(locale, TimeZoneFormatConfig::LocalizedGMT, &provider)
    .expect("Failed to create TimeZoneFormat");

let time_zone = MockTimeZone::new(
       GmtOffset::default(),
       None,
       None,
       None,
);

let _ = tzf.format(&time_zone);

Takes a mutable reference to anything that implements the Write trait and a TimeZoneInput implementer that populates the buffer with a formatted value.

Examples
use icu_locid::Locale;
use icu::locid::macros::langid;
use icu_datetime::{TimeZoneFormat, TimeZoneFormatConfig};
use icu_datetime::date::GmtOffset;
use icu_datetime::mock::time_zone::MockTimeZone;
use icu_provider::inv::InvariantDataProvider;

let locale: Locale = langid!("en").into();
let provider = InvariantDataProvider;

let tzf = TimeZoneFormat::try_from_config(locale, TimeZoneFormatConfig::LocalizedGMT, &provider)
    .expect("Failed to create TimeZoneFormat");

let time_zone = MockTimeZone::new(
       GmtOffset::default(),
       None,
       None,
       None,
);

let mut buffer = String::new();
tzf.format_to_write(&mut buffer, &time_zone)
    .expect("Failed to write to a buffer.");

let _ = format!("Time Zone: {}", buffer);

Takes a TimeZoneInput implementer and returns a string with the formatted value.

Examples
use icu_locid::Locale;
use icu::locid::macros::langid;
use icu_datetime::{TimeZoneFormat, TimeZoneFormatConfig};
use icu_datetime::date::GmtOffset;
use icu_datetime::mock::time_zone::MockTimeZone;
use icu_provider::inv::InvariantDataProvider;

let locale: Locale = langid!("en").into();
let provider = InvariantDataProvider;

let tzf = TimeZoneFormat::try_from_config(locale, TimeZoneFormatConfig::LocalizedGMT, &provider)
    .expect("Failed to create TimeZoneFormat");

let time_zone = MockTimeZone::new(
       GmtOffset::default(),
       None,
       None,
       None,
);

let _ = tzf.format_to_string(&time_zone);

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

Creates a filterable data provider with the given name for debugging. Read more

Performs the conversion.

Performs the conversion.

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.