Struct icu_datetime::time_zone::TimeZoneFormat
source · [−]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
pub fn try_from_config<L, ZP>(
locale: L,
config: TimeZoneFormatConfig,
zone_provider: &ZP
) -> Result<Self, DateTimeFormatError> where
L: Into<Locale>,
ZP: DataProvider<TimeZoneFormatsV1Marker> + DataProvider<ExemplarCitiesV1Marker> + DataProvider<MetaZoneGenericNamesLongV1Marker> + DataProvider<MetaZoneGenericNamesShortV1Marker> + DataProvider<MetaZoneSpecificNamesLongV1Marker> + DataProvider<MetaZoneSpecificNamesShortV1Marker> + ?Sized,
pub fn try_from_config<L, ZP>(
locale: L,
config: TimeZoneFormatConfig,
zone_provider: &ZP
) -> Result<Self, DateTimeFormatError> where
L: Into<Locale>,
ZP: DataProvider<TimeZoneFormatsV1Marker> + DataProvider<ExemplarCitiesV1Marker> + DataProvider<MetaZoneGenericNamesLongV1Marker> + DataProvider<MetaZoneGenericNamesShortV1Marker> + DataProvider<MetaZoneSpecificNamesLongV1Marker> + DataProvider<MetaZoneSpecificNamesShortV1Marker> + ?Sized,
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());
pub fn format<'l, T>(&'l self, value: &'l T) -> FormattedTimeZone<'l, T> where
T: TimeZoneInput,
pub fn format<'l, T>(&'l self, value: &'l T) -> FormattedTimeZone<'l, T> where
T: TimeZoneInput,
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
impl RefUnwindSafe for TimeZoneFormat
impl !Send for TimeZoneFormat
impl !Sync for TimeZoneFormat
impl Unpin for TimeZoneFormat
impl UnwindSafe for TimeZoneFormat
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn filterable(
self,
filter_name: &'static str
) -> RequestFilterDataProvider<T, fn(&DataRequest) -> bool>
pub fn filterable(
self,
filter_name: &'static str
) -> RequestFilterDataProvider<T, fn(&DataRequest) -> bool>
Creates a filterable data provider with the given name for debugging. Read more