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

TimeZoneFormat uses data from the data provider, 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_datetime::{TimeZoneFormat, TimeZoneFormatConfig, TimeZoneFormatOptions};
use icu_datetime::date::GmtOffset;
use icu_datetime::mock::time_zone::MockTimeZone;
use icu_provider::inv::InvariantDataProvider;

let provider = InvariantDataProvider;

let tzf = TimeZoneFormat::try_from_config(locale!("en"), TimeZoneFormatConfig::GenericNonLocationLong, &provider, &TimeZoneFormatOptions::default())
    .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_datetime::{TimeZoneFormat, TimeZoneFormatConfig, TimeZoneFormatOptions};
use icu_datetime::mock::time_zone::MockTimeZone;
use icu_provider::inv::InvariantDataProvider;

let provider = InvariantDataProvider;

let tzf = TimeZoneFormat::try_from_config(locale!("en"), TimeZoneFormatConfig::LocalizedGMT, &provider, &TimeZoneFormatOptions::default());

assert!(tzf.is_ok());

Load generic non location long format for timezone. For example, Pacific Time.

Load generic non location short format for timezone. For example, PT.

Load specific non location long format for timezone. For example, Pacific Standard Time.

Load specific non location short format for timezone. For example, PDT.

Load generic location format for timezone. For example, Los Angeles Time.

Load localized GMT format for timezone. For example, GMT-07:00.

Load Iso8601 format for timezone. For example, -07:00.

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_datetime::{TimeZoneFormat, TimeZoneFormatConfig, TimeZoneFormatOptions};
use icu_datetime::date::GmtOffset;
use icu_datetime::mock::time_zone::MockTimeZone;
use icu_provider::inv::InvariantDataProvider;

let provider = InvariantDataProvider;

let tzf = TimeZoneFormat::try_from_config(locale!("en"), TimeZoneFormatConfig::LocalizedGMT, &provider, &TimeZoneFormatOptions::default())
    .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_datetime::{TimeZoneFormat, TimeZoneFormatConfig, TimeZoneFormatOptions};
use icu_datetime::date::GmtOffset;
use icu_datetime::mock::time_zone::MockTimeZone;
use icu_provider::inv::InvariantDataProvider;

let provider = InvariantDataProvider;

let tzf = TimeZoneFormat::try_from_config(locale!("en"), TimeZoneFormatConfig::LocalizedGMT, &provider, &TimeZoneFormatOptions::default())
    .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_datetime::{TimeZoneFormat, TimeZoneFormatConfig, TimeZoneFormatOptions};
use icu_datetime::date::GmtOffset;
use icu_datetime::mock::time_zone::MockTimeZone;
use icu_provider::inv::InvariantDataProvider;

let provider = InvariantDataProvider;

let tzf = TimeZoneFormat::try_from_config(locale!("en"), TimeZoneFormatConfig::LocalizedGMT, &provider, &TimeZoneFormatOptions::default())
    .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

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.