pub struct TimeZoneInfo<Model>where
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> TimeZoneInfo<Model>where
Model: TimeZoneModel,
impl<Model> TimeZoneInfo<Model>where
Model: TimeZoneModel,
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 unknown() -> TimeZoneInfo<Base>
pub const fn unknown() -> TimeZoneInfo<Base>
Creates a time zone info with no information.
Sourcepub const fn utc() -> TimeZoneInfo<Base>
pub const fn utc() -> TimeZoneInfo<Base>
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> Clone for TimeZoneInfo<Model>where
Model: TimeZoneModel,
impl<Model> Clone for TimeZoneInfo<Model>where
Model: TimeZoneModel,
Source§fn clone(&self) -> TimeZoneInfo<Model>
fn clone(&self) -> TimeZoneInfo<Model>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<O> ConvertCalendar for TimeZoneInfo<O>where
O: TimeZoneModel,
impl<O> ConvertCalendar for TimeZoneInfo<O>where
O: TimeZoneModel,
Source§type Converted<'a> = TimeZoneInfo<O>
type Converted<'a> = TimeZoneInfo<O>
Source§fn to_calendar<'a>(
&self,
_: &'a AnyCalendar,
) -> <TimeZoneInfo<O> as ConvertCalendar>::Converted<'a>
fn to_calendar<'a>( &self, _: &'a AnyCalendar, ) -> <TimeZoneInfo<O> as ConvertCalendar>::Converted<'a>
self
to the specified AnyCalendar
.Source§impl<Model> Debug for TimeZoneInfo<Model>where
Model: Debug + TimeZoneModel,
<Model as TimeZoneModel>::ZoneNameTimestamp: Debug,
<Model as TimeZoneModel>::TimeZoneVariant: Debug,
impl<Model> Debug for TimeZoneInfo<Model>where
Model: Debug + TimeZoneModel,
<Model as TimeZoneModel>::ZoneNameTimestamp: Debug,
<Model as TimeZoneModel>::TimeZoneVariant: Debug,
Source§impl<O> GetField<()> for TimeZoneInfo<O>where
O: TimeZoneModel,
impl<O> GetField<()> for TimeZoneInfo<O>where
O: TimeZoneModel,
Source§impl<O> GetField<Option<UtcOffset>> for TimeZoneInfo<O>where
O: TimeZoneModel,
impl<O> GetField<Option<UtcOffset>> for TimeZoneInfo<O>where
O: TimeZoneModel,
Source§impl<O> GetField<TimeZone> for TimeZoneInfo<O>where
O: TimeZoneModel,
impl<O> GetField<TimeZone> for TimeZoneInfo<O>where
O: TimeZoneModel,
Source§impl<O> GetField<TimeZoneVariant> for TimeZoneInfo<O>where
O: TimeZoneModel<TimeZoneVariant = TimeZoneVariant>,
impl<O> GetField<TimeZoneVariant> for TimeZoneInfo<O>where
O: TimeZoneModel<TimeZoneVariant = TimeZoneVariant>,
Source§fn get_field(&self) -> TimeZoneVariant
fn get_field(&self) -> TimeZoneVariant
T
.Source§impl<O> GetField<ZoneNameTimestamp> for TimeZoneInfo<O>where
O: TimeZoneModel<ZoneNameTimestamp = ZoneNameTimestamp>,
impl<O> GetField<ZoneNameTimestamp> for TimeZoneInfo<O>where
O: TimeZoneModel<ZoneNameTimestamp = ZoneNameTimestamp>,
Source§fn get_field(&self) -> ZoneNameTimestamp
fn get_field(&self) -> ZoneNameTimestamp
T
.Source§impl<O> InSameCalendar for TimeZoneInfo<O>where
O: TimeZoneModel,
impl<O> InSameCalendar for TimeZoneInfo<O>where
O: TimeZoneModel,
Source§fn check_any_calendar_kind(
&self,
_: AnyCalendarKind,
) -> Result<(), MismatchedCalendarError>
fn check_any_calendar_kind( &self, _: AnyCalendarKind, ) -> Result<(), MismatchedCalendarError>
Source§impl<Model> PartialEq for TimeZoneInfo<Model>where
Model: PartialEq + TimeZoneModel,
<Model as TimeZoneModel>::ZoneNameTimestamp: PartialEq,
<Model as TimeZoneModel>::TimeZoneVariant: PartialEq,
impl<Model> PartialEq for TimeZoneInfo<Model>where
Model: PartialEq + TimeZoneModel,
<Model as TimeZoneModel>::ZoneNameTimestamp: PartialEq,
<Model as TimeZoneModel>::TimeZoneVariant: PartialEq,
impl<Model> Copy for TimeZoneInfo<Model>where
Model: TimeZoneModel,
impl<Model> Eq for TimeZoneInfo<Model>where
Model: Eq + TimeZoneModel,
<Model as TimeZoneModel>::ZoneNameTimestamp: Eq,
<Model as TimeZoneModel>::TimeZoneVariant: Eq,
impl<C, O> InFixedCalendar<C> for TimeZoneInfo<O>where
O: TimeZoneModel,
impl<Model> StructuralPartialEq for TimeZoneInfo<Model>where
Model: TimeZoneModel,
impl<O> UnstableSealed for TimeZoneInfo<O>where
O: TimeZoneModel,
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> GetField<T> for Twhere
T: Copy + UnstableSealed,
impl<T> GetField<T> for Twhere
T: Copy + UnstableSealed,
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