pub struct TimeZoneInfo<Model: TimeZoneModel> { /* private fields */ }Expand description
A utility type that can hold time zone information.
The primary definition of this type is in the icu_time crate. Other ICU4X crates re-export it for convenience.
See the docs on zone for more information.
§Examples
use icu::calendar::Date;
use icu::locale::subtags::subtag;
use icu::time::zone::IanaParser;
use icu::time::zone::TimeZoneVariant;
use icu::time::DateTime;
use icu::time::Time;
use icu::time::TimeZone;
// Parse the IANA ID
let id = IanaParser::new().parse("America/Chicago");
// Alternatively, use the BCP47 ID directly
let id = TimeZone(subtag!("uschi"));
// Create a TimeZoneInfo<Base> by associating the ID with an offset
let time_zone = id.with_offset("-0600".parse().ok());
// Extend to a TimeZoneInfo<AtTime> by adding a local time
let time_zone_at_time = time_zone.at_date_time_iso(DateTime {
    date: Date::try_new_iso(2023, 12, 2).unwrap(),
    time: Time::start_of_day(),
});
// Extend to a TimeZoneInfo<Full> by adding a zone variant
let time_zone_with_variant =
    time_zone_at_time.with_variant(TimeZoneVariant::Standard);Implementations§
Source§impl<Model: TimeZoneModel> TimeZoneInfo<Model>
 
impl<Model: TimeZoneModel> TimeZoneInfo<Model>
Source§impl<Model> TimeZoneInfo<Model>where
    Model: TimeZoneModel<ZoneNameTimestamp = ZoneNameTimestamp>,
 
impl<Model> TimeZoneInfo<Model>where
    Model: TimeZoneModel<ZoneNameTimestamp = ZoneNameTimestamp>,
Sourcepub fn zone_name_timestamp(self) -> ZoneNameTimestamp
 
pub fn zone_name_timestamp(self) -> ZoneNameTimestamp
The time at which to interpret the time zone.
Source§impl<Model> TimeZoneInfo<Model>where
    Model: TimeZoneModel<TimeZoneVariant = TimeZoneVariant>,
 
impl<Model> TimeZoneInfo<Model>where
    Model: TimeZoneModel<TimeZoneVariant = TimeZoneVariant>,
Sourcepub fn variant(self) -> TimeZoneVariant
 
pub fn variant(self) -> TimeZoneVariant
The time variant e.g. daylight or standard, if known.
This field is not enforced to be consistent with the time zone id and offset.
Source§impl TimeZoneInfo<Base>
 
impl TimeZoneInfo<Base>
Sourcepub const fn utc() -> Self
 
pub const fn utc() -> Self
Creates a new TimeZoneInfo for the UTC time zone.
Sourcepub fn with_zone_name_timestamp(
    self,
    zone_name_timestamp: ZoneNameTimestamp,
) -> TimeZoneInfo<AtTime>
 
pub fn with_zone_name_timestamp( self, zone_name_timestamp: ZoneNameTimestamp, ) -> TimeZoneInfo<AtTime>
Sets the ZoneNameTimestamp field.
Sourcepub fn at_date_time_iso(self, date_time: DateTime<Iso>) -> TimeZoneInfo<AtTime>
 
pub fn at_date_time_iso(self, date_time: DateTime<Iso>) -> TimeZoneInfo<AtTime>
Sets the ZoneNameTimestamp to the given local datetime.
Source§impl TimeZoneInfo<AtTime>
 
impl TimeZoneInfo<AtTime>
Sourcepub const fn with_variant(self, variant: TimeZoneVariant) -> TimeZoneInfo<Full>
 
pub const fn with_variant(self, variant: TimeZoneVariant) -> TimeZoneInfo<Full>
Sets a TimeZoneVariant on this time zone.
Sourcepub fn infer_variant(
    self,
    calculator: VariantOffsetsCalculatorBorrowed<'_>,
) -> TimeZoneInfo<Full>
 
pub fn infer_variant( self, calculator: VariantOffsetsCalculatorBorrowed<'_>, ) -> TimeZoneInfo<Full>
Sets the zone variant by calculating it using a VariantOffsetsCalculator.
If offset() is None, or if it doesn’t match either of the
timezone’s standard or daylight offset around local_time(),
the variant will be set to TimeZoneVariant::Standard and the time zone
to TimeZone::UNKNOWN.
§Example
use icu::calendar::Date;
use icu::locale::subtags::subtag;
use icu::time::zone::TimeZoneVariant;
use icu::time::zone::VariantOffsetsCalculator;
use icu::time::DateTime;
use icu::time::Time;
use icu::time::TimeZone;
// Chicago at UTC-6
let info = TimeZone(subtag!("uschi"))
    .with_offset("-0600".parse().ok())
    .at_date_time_iso(DateTime {
        date: Date::try_new_iso(2023, 12, 2).unwrap(),
        time: Time::start_of_day(),
    })
    .infer_variant(VariantOffsetsCalculator::new());
assert_eq!(info.variant(), TimeZoneVariant::Standard);
// Chicago at at UTC-5
let info = TimeZone(subtag!("uschi"))
    .with_offset("-0500".parse().ok())
    .at_date_time_iso(DateTime {
        date: Date::try_new_iso(2023, 6, 2).unwrap(),
        time: Time::start_of_day(),
    })
    .infer_variant(VariantOffsetsCalculator::new());
assert_eq!(info.variant(), TimeZoneVariant::Daylight);
// Chicago at UTC-7
let info = TimeZone(subtag!("uschi"))
    .with_offset("-0700".parse().ok())
    .at_date_time_iso(DateTime {
        date: Date::try_new_iso(2023, 12, 2).unwrap(),
        time: Time::start_of_day(),
    })
    .infer_variant(VariantOffsetsCalculator::new());
// Whatever it is, it's not Chicago
assert_eq!(info.id(), TimeZone::UNKNOWN);
assert_eq!(info.variant(), TimeZoneVariant::Standard);Trait Implementations§
Source§impl<Model: TimeZoneModel> Clone for TimeZoneInfo<Model>
 
impl<Model: TimeZoneModel> Clone for TimeZoneInfo<Model>
Source§impl<Model: Debug + TimeZoneModel> Debug for TimeZoneInfo<Model>
 
impl<Model: Debug + TimeZoneModel> Debug for TimeZoneInfo<Model>
Source§impl<Model: PartialEq + TimeZoneModel> PartialEq for TimeZoneInfo<Model>
 
impl<Model: PartialEq + TimeZoneModel> PartialEq for TimeZoneInfo<Model>
impl<Model: TimeZoneModel> Copy for TimeZoneInfo<Model>
impl<Model: Eq + TimeZoneModel> Eq for TimeZoneInfo<Model>
impl<Model: TimeZoneModel> StructuralPartialEq for TimeZoneInfo<Model>
Auto Trait Implementations§
impl<Model> Freeze for TimeZoneInfo<Model>where
    <Model as TimeZoneModel>::ZoneNameTimestamp: Freeze,
    <Model as TimeZoneModel>::TimeZoneVariant: Freeze,
impl<Model> RefUnwindSafe for TimeZoneInfo<Model>where
    <Model as TimeZoneModel>::ZoneNameTimestamp: RefUnwindSafe,
    <Model as TimeZoneModel>::TimeZoneVariant: RefUnwindSafe,
impl<Model> Send for TimeZoneInfo<Model>where
    <Model as TimeZoneModel>::ZoneNameTimestamp: Send,
    <Model as TimeZoneModel>::TimeZoneVariant: Send,
impl<Model> Sync for TimeZoneInfo<Model>where
    <Model as TimeZoneModel>::ZoneNameTimestamp: Sync,
    <Model as TimeZoneModel>::TimeZoneVariant: Sync,
impl<Model> Unpin for TimeZoneInfo<Model>where
    <Model as TimeZoneModel>::ZoneNameTimestamp: Unpin,
    <Model as TimeZoneModel>::TimeZoneVariant: Unpin,
impl<Model> UnwindSafe for TimeZoneInfo<Model>where
    <Model as TimeZoneModel>::ZoneNameTimestamp: UnwindSafe,
    <Model as TimeZoneModel>::TimeZoneVariant: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
    T: Clone,
 
impl<T> CloneToUninit for Twhere
    T: Clone,
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>
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>
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