icu_time::zone

Struct VariantOffsetsCalculatorBorrowed

Source
pub struct VariantOffsetsCalculatorBorrowed<'a> { /* private fields */ }
Expand description

The borrowed version of a VariantOffsetsCalculator

Implementations§

Source§

impl VariantOffsetsCalculatorBorrowed<'static>

Source

pub const fn new() -> Self

Constructs a VariantOffsetsCalculatorBorrowed using compiled data.

Enabled with the compiled_data Cargo feature.

📚 Help choosing a constructor

Source

pub fn static_to_owned(&self) -> VariantOffsetsCalculator

Cheaply converts a [VariantOffsetsCalculatorBorrowed<'static>] into a VariantOffsetsCalculator.

Note: Due to branching and indirection, using VariantOffsetsCalculator might inhibit some compile-time optimizations that are possible with VariantOffsetsCalculatorBorrowed.

Source§

impl VariantOffsetsCalculatorBorrowed<'_>

Source

pub fn compute_offsets_from_time_zone( &self, time_zone_id: TimeZone, dt: (Date<Iso>, Time), ) -> Option<VariantOffsets>

Calculate zone offsets from timezone and local datetime.

§Examples
use icu::calendar::Date;
use icu::time::zone::UtcOffset;
use icu::time::zone::VariantOffsetsCalculator;
use icu::time::Time;
use icu::time::TimeZone;
use tinystr::tinystr;

let zoc = VariantOffsetsCalculator::new();

// America/Denver observes DST
let offsets = zoc
    .compute_offsets_from_time_zone(
        TimeZone(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(
        TimeZone(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<'a> Debug for VariantOffsetsCalculatorBorrowed<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for VariantOffsetsCalculatorBorrowed<'static>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> ErasedDestructor for T
where T: 'static,