Struct icu_timezone::ZoneOffsetCalculator
source · pub struct ZoneOffsetCalculator { /* private fields */ }
Expand description
ZoneOffsetCalculator
uses data from the data provider to calculate time zone offsets.
Implementations§
source§impl ZoneOffsetCalculator
impl ZoneOffsetCalculator
sourcepub const fn new() -> Self
pub const fn new() -> Self
Constructs a ZoneOffsetCalculator
using compiled data.
✨ Enabled with the compiled_data
Cargo feature.
sourcepub fn try_new_with_any_provider(
provider: &(impl AnyProvider + ?Sized),
) -> Result<Self, DataError>
pub fn try_new_with_any_provider( provider: &(impl AnyProvider + ?Sized), ) -> Result<Self, DataError>
A version of [Self :: new
] that uses custom data provided by an AnyProvider
.
sourcepub fn try_new_with_buffer_provider(
provider: &(impl BufferProvider + ?Sized),
) -> Result<Self, DataError>
pub fn try_new_with_buffer_provider( provider: &(impl BufferProvider + ?Sized), ) -> Result<Self, DataError>
A version of [Self :: new
] that uses custom data provided by a BufferProvider
.
✨ Enabled with the serde
feature.
sourcepub fn try_new_unstable(
provider: &(impl DataProvider<ZoneOffsetPeriodV1Marker> + ?Sized),
) -> Result<Self, DataError>
pub fn try_new_unstable( provider: &(impl DataProvider<ZoneOffsetPeriodV1Marker> + ?Sized), ) -> Result<Self, DataError>
A version of Self::new
that uses custom data provided by a DataProvider
.
⚠️ The bounds on provider may change over time, including in SemVer minor releases.
sourcepub fn compute_offsets_from_time_zone(
&self,
time_zone_id: TimeZoneBcp47Id,
(date, time): (Date<Iso>, Time),
) -> Option<ZoneOffsets>
pub fn compute_offsets_from_time_zone( &self, time_zone_id: TimeZoneBcp47Id, (date, time): (Date<Iso>, Time), ) -> Option<ZoneOffsets>
Calculate zone offsets from timezone and local datetime.
§Examples
use icu::calendar::{Date, Time};
use icu::timezone::TimeZoneBcp47Id;
use icu::timezone::UtcOffset;
use icu::timezone::ZoneOffsetCalculator;
use tinystr::tinystr;
let zoc = ZoneOffsetCalculator::new();
// America/Denver observes DST
let offsets = zoc
.compute_offsets_from_time_zone(
TimeZoneBcp47Id(tinystr!(8, "usden")),
(Date::try_new_iso(2024, 1, 1).unwrap(), Time::midnight()),
)
.unwrap();
assert_eq!(
offsets.standard,
UtcOffset::try_from_seconds(-7 * 3600).unwrap()
);
assert_eq!(
offsets.daylight,
Some(UtcOffset::try_from_seconds(-6 * 3600).unwrap())
);
// America/Phoenix does not
let offsets = zoc
.compute_offsets_from_time_zone(
TimeZoneBcp47Id(tinystr!(8, "usphx")),
(Date::try_new_iso(2024, 1, 1).unwrap(), Time::midnight()),
)
.unwrap();
assert_eq!(
offsets.standard,
UtcOffset::try_from_seconds(-7 * 3600).unwrap()
);
assert_eq!(offsets.daylight, None);
Trait Implementations§
source§impl Debug for ZoneOffsetCalculator
impl Debug for ZoneOffsetCalculator
Auto Trait Implementations§
impl Freeze for ZoneOffsetCalculator
impl RefUnwindSafe for ZoneOffsetCalculator
impl Send for ZoneOffsetCalculator
impl Sync for ZoneOffsetCalculator
impl Unpin for ZoneOffsetCalculator
impl UnwindSafe for ZoneOffsetCalculator
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more