Struct icu_timezone::CustomTimeZone
source · [−]pub struct CustomTimeZone {
pub gmt_offset: Option<GmtOffset>,
pub time_zone_id: Option<TimeZoneBcp47Id>,
pub metazone_id: Option<MetaZoneId>,
pub time_variant: Option<TimeVariant>,
}
Expand description
A utility type that can hold time zone information
Examples
use icu::timezone::{GmtOffset, CustomTimeZone};
let tz1 = CustomTimeZone::new(
Some(GmtOffset::default()),
/* time_zone_id */ None,
/* metazone_id */ None,
/* time_variaint */ None,
);
let tz2: CustomTimeZone = "+05:00".parse().expect("Failed to parse a time zone.");
Fields
gmt_offset: Option<GmtOffset>
The GMT offset in seconds.
time_zone_id: Option<TimeZoneBcp47Id>
The IANA time-zone identifier
metazone_id: Option<MetaZoneId>
The CLDR metazone identifier
time_variant: Option<TimeVariant>
The time variant e.g. “daylight” or “standard”
Implementations
sourceimpl CustomTimeZone
impl CustomTimeZone
sourcepub fn new(
gmt_offset: Option<GmtOffset>,
time_zone_id: Option<TimeZoneBcp47Id>,
metazone_id: Option<MetaZoneId>,
time_variant: Option<TimeVariant>
) -> Self
pub fn new(
gmt_offset: Option<GmtOffset>,
time_zone_id: Option<TimeZoneBcp47Id>,
metazone_id: Option<MetaZoneId>,
time_variant: Option<TimeVariant>
) -> Self
Creates a new CustomTimeZone
.
A GMT offset is required, as it is used as a final fallback for formatting.
The other arguments optionally allow access to more robust formats.
sourcepub fn maybe_set_metazone(
&mut self,
local_datetime: &DateTime<Iso>,
metazone_calculator: &MetaZoneCalculator
) -> &mut Self
pub fn maybe_set_metazone(
&mut self,
local_datetime: &DateTime<Iso>,
metazone_calculator: &MetaZoneCalculator
) -> &mut Self
Overwrite the metazone id in MockTimeZone.
Examples
use icu::timezone::GmtOffset;
use icu::timezone::MetaZoneCalculator;
use icu::timezone::CustomTimeZone;
use icu::timezone::provider::{MetaZoneId, TimeZoneBcp47Id};
use icu_calendar::DateTime;
use icu_locid::locale;
use tinystr::tinystr;
let provider = icu_testdata::get_provider();
let mzc = MetaZoneCalculator::try_new_with_buffer_provider(&provider).expect("data exists");
let mut tz = CustomTimeZone::new(
/* gmt_offset */ Some("+11".parse().expect("Failed to parse a GMT offset.")),
/* time_zone_id */ Some(TimeZoneBcp47Id(tinystr!(8, "gugum"))),
/* metazone_id */ None,
/* time_variaint */ None,
);
tz.maybe_set_metazone(
&DateTime::new_iso_datetime(1971, 10, 31, 2, 0, 0).unwrap(),
&mzc,
);
assert_eq!(tz.metazone_id, Some(MetaZoneId(tinystr!(4, "guam"))));
Trait Implementations
sourceimpl Debug for CustomTimeZone
impl Debug for CustomTimeZone
sourceimpl Default for CustomTimeZone
impl Default for CustomTimeZone
sourcefn default() -> CustomTimeZone
fn default() -> CustomTimeZone
Returns the “default value” for a type. Read more
sourceimpl FromStr for CustomTimeZone
impl FromStr for CustomTimeZone
sourcefn from_str(input: &str) -> Result<Self, Self::Err>
fn from_str(input: &str) -> Result<Self, Self::Err>
Parse a CustomTimeZone
from a string.
This utility is for easily creating time zones, not a complete robust solution.
The offset must range from GMT-12 to GMT+14. The string must be an ISO-8601 time zone designator: e.g. Z e.g. +05 e.g. +0500 e.g. +05:00
Examples
use icu::timezone::CustomTimeZone;
let tz0: CustomTimeZone = "Z".parse().expect("Failed to parse a time zone.");
let tz1: CustomTimeZone = "+02".parse().expect("Failed to parse a time zone.");
let tz2: CustomTimeZone = "-0230".parse().expect("Failed to parse a time zone.");
let tz3: CustomTimeZone = "+02:30".parse().expect("Failed to parse a time zone.");
type Err = TimeZoneError
type Err = TimeZoneError
The associated error which can be returned from parsing.
Auto Trait Implementations
impl RefUnwindSafe for CustomTimeZone
impl Send for CustomTimeZone
impl Sync for CustomTimeZone
impl Unpin for CustomTimeZone
impl UnwindSafe for CustomTimeZone
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