Struct icu::timezone::MetazoneCalculator
source · [−]pub struct MetazoneCalculator { /* private fields */ }
Expand description
MetazoneCalculator
uses data from the data provider to calculate metazone id.
Implementations
sourceimpl MetazoneCalculator
impl MetazoneCalculator
sourcepub fn try_new_unstable<P>(
zone_provider: &P
) -> Result<MetazoneCalculator, TimeZoneError> where
P: DataProvider<MetazonePeriodV1Marker> + ?Sized,
pub fn try_new_unstable<P>(
zone_provider: &P
) -> Result<MetazoneCalculator, TimeZoneError> where
P: DataProvider<MetazonePeriodV1Marker> + ?Sized,
Constructor that loads data before calculating metazone id.
⚠️ The bounds on this function may change over time, including in SemVer minor releases.
Examples
use icu::timezone::MetazoneCalculator;
use icu_locid::locale;
let mzc = MetazoneCalculator::try_new_unstable(&icu_testdata::unstable());
assert!(mzc.is_ok());
sourcepub fn try_new_with_any_provider(
provider: &impl AnyProvider
) -> Result<MetazoneCalculator, TimeZoneError>
pub fn try_new_with_any_provider(
provider: &impl AnyProvider
) -> Result<MetazoneCalculator, TimeZoneError>
Creates a new instance using an AnyProvider
.
For details on the behavior of this function, see: Self::try_new_unstable
sourcepub fn try_new_with_buffer_provider(
provider: &impl BufferProvider
) -> Result<MetazoneCalculator, TimeZoneError>
pub fn try_new_with_buffer_provider(
provider: &impl BufferProvider
) -> Result<MetazoneCalculator, TimeZoneError>
✨ Enabled with the "serde"
feature.
Creates a new instance using a BufferProvider
.
For details on the behavior of this function, see: Self::try_new_unstable
sourcepub fn compute_metazone_from_time_zone(
&self,
time_zone_id: TimeZoneBcp47Id,
local_datetime: &DateTime<Iso>
) -> Option<MetazoneId>
pub fn compute_metazone_from_time_zone(
&self,
time_zone_id: TimeZoneBcp47Id,
local_datetime: &DateTime<Iso>
) -> Option<MetazoneId>
Calculate metazone id from timezone id and local datetime.
Examples
use icu::timezone::provider::{MetazoneId, TimeZoneBcp47Id};
use icu::timezone::MetazoneCalculator;
use icu_calendar::DateTime;
use icu_locid::locale;
use tinystr::tinystr;
let mzc = MetazoneCalculator::try_new_unstable(&icu_testdata::unstable())
.expect("data exists");
assert_eq!(
mzc.compute_metazone_from_time_zone(
TimeZoneBcp47Id(tinystr!(8, "gugum")),
&DateTime::try_new_iso_datetime(1969, 1, 1, 0, 0, 0).unwrap()
),
None
);
assert_eq!(
mzc.compute_metazone_from_time_zone(
TimeZoneBcp47Id(tinystr!(8, "gugum")),
&DateTime::try_new_iso_datetime(1970, 1, 1, 0, 0, 0).unwrap()
),
Some(MetazoneId(tinystr!(4, "guam")))
);
assert_eq!(
mzc.compute_metazone_from_time_zone(
TimeZoneBcp47Id(tinystr!(8, "gugum")),
&DateTime::try_new_iso_datetime(1975, 1, 1, 0, 0, 0).unwrap()
),
Some(MetazoneId(tinystr!(4, "guam")))
);
assert_eq!(
mzc.compute_metazone_from_time_zone(
TimeZoneBcp47Id(tinystr!(8, "gugum")),
&DateTime::try_new_iso_datetime(2000, 12, 22, 15, 0, 0).unwrap()
),
Some(MetazoneId(tinystr!(4, "cham")))
);
Auto Trait Implementations
impl RefUnwindSafe for MetazoneCalculator
impl Send for MetazoneCalculator
impl Sync for MetazoneCalculator
impl Unpin for MetazoneCalculator
impl UnwindSafe for MetazoneCalculator
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