Struct icu_datetime::time_zone::TimeZoneFormatter
source · [−]pub struct TimeZoneFormatter { /* private fields */ }
Expand description
TimeZoneFormatter
uses data from the data provider, the selected locale, and the provided
TimeZoneFormatterConfig
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,TimeZoneFormatter
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 TimeZoneFormatter
, and then fast formatting
of the time-zone data using the instance.
Examples
use icu::timezone::{GmtOffset, CustomTimeZone};
use icu_datetime::{TimeZoneFormatter, TimeZoneFormatterConfig, TimeZoneFormatterOptions};
use icu_locid::locale;
let provider = icu_testdata::get_provider();
let tzf = TimeZoneFormatter::try_from_config_with_buffer_provider(
&provider,
&locale!("en").into(),
TimeZoneFormatterConfig::GenericNonLocationLong,
TimeZoneFormatterOptions::default(),
)
.expect("Failed to create TimeZoneFormatter");
let time_zone = CustomTimeZone::new(Some(GmtOffset::default()), None, None, None);
let value = tzf.format_to_string(&time_zone);
Implementations
sourceimpl TimeZoneFormatter
impl TimeZoneFormatter
sourcepub fn try_from_config_unstable<ZP>(
zone_provider: &ZP,
locale: &DataLocale,
config: TimeZoneFormatterConfig,
options: TimeZoneFormatterOptions
) -> Result<Self, DateTimeFormatterError> where
ZP: DataProvider<TimeZoneFormatsV1Marker> + DataProvider<ExemplarCitiesV1Marker> + DataProvider<MetaZoneGenericNamesLongV1Marker> + DataProvider<MetaZoneGenericNamesShortV1Marker> + DataProvider<MetaZoneSpecificNamesLongV1Marker> + DataProvider<MetaZoneSpecificNamesShortV1Marker> + ?Sized,
pub fn try_from_config_unstable<ZP>(
zone_provider: &ZP,
locale: &DataLocale,
config: TimeZoneFormatterConfig,
options: TimeZoneFormatterOptions
) -> Result<Self, DateTimeFormatterError> where
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::timezone::CustomTimeZone;
use icu_datetime::{TimeZoneFormatter, TimeZoneFormatterConfig, TimeZoneFormatterOptions};
use icu_locid::locale;
let provider = icu_testdata::get_provider();
let tzf = TimeZoneFormatter::try_from_config_unstable(
&provider,
&locale!("en").into(),
TimeZoneFormatterConfig::LocalizedGMT,
TimeZoneFormatterOptions::default(),
);
assert!(tzf.is_ok());
sourcepub fn try_from_config_with_any_provider(
provider: &impl AnyProvider + ?Sized,
locale: &DataLocale,
config: TimeZoneFormatterConfig,
options: TimeZoneFormatterOptions
) -> Result<Self, DateTimeFormatterError>
pub fn try_from_config_with_any_provider(
provider: &impl AnyProvider + ?Sized,
locale: &DataLocale,
config: TimeZoneFormatterConfig,
options: TimeZoneFormatterOptions
) -> Result<Self, DateTimeFormatterError>
Create a new instance using an AnyProvider
.
See also: Self::try_from_config_unstable
sourcepub fn try_from_config_with_buffer_provider(
provider: &impl BufferProvider + ?Sized,
locale: &DataLocale,
config: TimeZoneFormatterConfig,
options: TimeZoneFormatterOptions
) -> Result<Self, DateTimeFormatterError>
pub fn try_from_config_with_buffer_provider(
provider: &impl BufferProvider + ?Sized,
locale: &DataLocale,
config: TimeZoneFormatterConfig,
options: TimeZoneFormatterOptions
) -> Result<Self, DateTimeFormatterError>
Create a new instance using a BufferProvider
. Enabled with the "serde"
feature.
See also: Self::try_from_config_unstable
sourcepub fn load_generic_non_location_long<ZP>(
&mut self,
zone_provider: &ZP
) -> Result<&mut TimeZoneFormatter, DateTimeFormatterError> where
ZP: DataProvider<MetaZoneGenericNamesLongV1Marker> + ?Sized,
pub fn load_generic_non_location_long<ZP>(
&mut self,
zone_provider: &ZP
) -> Result<&mut TimeZoneFormatter, DateTimeFormatterError> where
ZP: DataProvider<MetaZoneGenericNamesLongV1Marker> + ?Sized,
Load generic non location long format for timezone. For example, Pacific Time.
sourcepub fn load_generic_non_location_short<ZP>(
&mut self,
zone_provider: &ZP
) -> Result<&mut TimeZoneFormatter, DateTimeFormatterError> where
ZP: DataProvider<MetaZoneGenericNamesShortV1Marker> + ?Sized,
pub fn load_generic_non_location_short<ZP>(
&mut self,
zone_provider: &ZP
) -> Result<&mut TimeZoneFormatter, DateTimeFormatterError> where
ZP: DataProvider<MetaZoneGenericNamesShortV1Marker> + ?Sized,
Load generic non location short format for timezone. For example, PT.
sourcepub fn load_specific_non_location_long<ZP>(
&mut self,
zone_provider: &ZP
) -> Result<&mut TimeZoneFormatter, DateTimeFormatterError> where
ZP: DataProvider<MetaZoneSpecificNamesLongV1Marker> + ?Sized,
pub fn load_specific_non_location_long<ZP>(
&mut self,
zone_provider: &ZP
) -> Result<&mut TimeZoneFormatter, DateTimeFormatterError> where
ZP: DataProvider<MetaZoneSpecificNamesLongV1Marker> + ?Sized,
Load specific non location long format for timezone. For example, Pacific Standard Time.
sourcepub fn load_specific_non_location_short<ZP>(
&mut self,
zone_provider: &ZP
) -> Result<&mut TimeZoneFormatter, DateTimeFormatterError> where
ZP: DataProvider<MetaZoneSpecificNamesShortV1Marker> + ?Sized,
pub fn load_specific_non_location_short<ZP>(
&mut self,
zone_provider: &ZP
) -> Result<&mut TimeZoneFormatter, DateTimeFormatterError> where
ZP: DataProvider<MetaZoneSpecificNamesShortV1Marker> + ?Sized,
Load specific non location short format for timezone. For example, PDT.
sourcepub fn load_generic_location_format<ZP>(
&mut self,
zone_provider: &ZP
) -> Result<&mut TimeZoneFormatter, DateTimeFormatterError> where
ZP: DataProvider<ExemplarCitiesV1Marker> + ?Sized,
pub fn load_generic_location_format<ZP>(
&mut self,
zone_provider: &ZP
) -> Result<&mut TimeZoneFormatter, DateTimeFormatterError> where
ZP: DataProvider<ExemplarCitiesV1Marker> + ?Sized,
Load generic location format for timezone. For example, Los Angeles Time.
sourcepub fn load_localized_gmt_format(
&mut self
) -> Result<&mut TimeZoneFormatter, DateTimeFormatterError>
pub fn load_localized_gmt_format(
&mut self
) -> Result<&mut TimeZoneFormatter, DateTimeFormatterError>
Load localized GMT format for timezone. For example, GMT-07:00.
sourcepub fn load_iso_8601_format(
&mut self,
format: IsoFormat,
minutes: IsoMinutes,
seconds: IsoSeconds
) -> Result<&mut TimeZoneFormatter, DateTimeFormatterError>
pub fn load_iso_8601_format(
&mut self,
format: IsoFormat,
minutes: IsoMinutes,
seconds: IsoSeconds
) -> Result<&mut TimeZoneFormatter, DateTimeFormatterError>
Load Iso8601 format for timezone. For example, -07:00.
sourcepub 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::timezone::{GmtOffset, CustomTimeZone};
use icu_datetime::{TimeZoneFormatter, TimeZoneFormatterConfig, TimeZoneFormatterOptions};
use icu_locid::locale;
let provider = icu_testdata::get_provider();
let tzf = TimeZoneFormatter::try_from_config_with_buffer_provider(
&provider,
&locale!("en").into(),
TimeZoneFormatterConfig::LocalizedGMT,
TimeZoneFormatterOptions::default(),
)
.expect("Failed to create TimeZoneFormatter");
let time_zone = CustomTimeZone::new(Some(GmtOffset::default()), None, None, None);
let _ = tzf.format(&time_zone);
sourcepub fn format_to_write(
&self,
w: &mut impl Write,
value: &impl TimeZoneInput
) -> Result
pub fn format_to_write(
&self,
w: &mut impl Write,
value: &impl TimeZoneInput
) -> Result
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::timezone::{GmtOffset, CustomTimeZone};
use icu_datetime::{TimeZoneFormatter, TimeZoneFormatterConfig, TimeZoneFormatterOptions};
use icu_locid::locale;
let provider = icu_testdata::get_provider();
let tzf = TimeZoneFormatter::try_from_config_with_buffer_provider(
&provider,
&locale!("en").into(),
TimeZoneFormatterConfig::LocalizedGMT,
TimeZoneFormatterOptions::default(),
)
.expect("Failed to create TimeZoneFormatter");
let time_zone = CustomTimeZone::new(Some(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);
sourcepub fn format_to_string(&self, value: &impl TimeZoneInput) -> String
pub fn format_to_string(&self, value: &impl TimeZoneInput) -> String
Takes a TimeZoneInput
implementer and returns a string with the formatted value.
Examples
use icu::timezone::{GmtOffset, CustomTimeZone};
use icu_datetime::{TimeZoneFormatter, TimeZoneFormatterConfig, TimeZoneFormatterOptions};
use icu_locid::locale;
let provider = icu_testdata::get_provider();
let tzf = TimeZoneFormatter::try_from_config_with_buffer_provider(
&provider,
&locale!("en").into(),
TimeZoneFormatterConfig::LocalizedGMT,
TimeZoneFormatterOptions::default(),
)
.expect("Failed to create TimeZoneFormatter");
let time_zone = CustomTimeZone::new(Some(GmtOffset::default()), None, None, None);
let _ = tzf.format_to_string(&time_zone);
Auto Trait Implementations
impl RefUnwindSafe for TimeZoneFormatter
impl Send for TimeZoneFormatter
impl Sync for TimeZoneFormatter
impl Unpin for TimeZoneFormatter
impl UnwindSafe for TimeZoneFormatter
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more