pub struct ZoneNameTimestamp(/* private fields */);Expand description
The moment in time for resolving a time zone name.
What is this for? Most software deals with time zone transitions, computing the UTC offset on a given point in time. In ICU4X, we deal with time zone display names. Whereas time zone transitions occur multiple times per year in some time zones, the set of display names changes more rarely. For example, ICU4X needs to know when a region switches from Eastern Time to Central Time.
This type can only represent display name changes after 1970, and only to a coarse (15-minute) granularity, which is sufficient for CLDR and TZDB data within that time frame.
§Examples
The region of Metlakatla (Alaska) used to be on Pacific Time but is now on Alaska Time.
use icu::calendar::Iso;
use icu::datetime::fieldsets::zone::GenericLong;
use icu::datetime::NoCalendarFormatter;
use icu::locale::locale;
use icu::time::zone::TimeZone;
use icu::time::zone::ZoneNameTimestamp;
use icu::time::ZonedDateTime;
use writeable::assert_writeable_eq;
let metlakatla = TimeZone::from_iana_id("America/Metlakatla");
let zone_formatter =
NoCalendarFormatter::try_new(locale!("en-US").into(), GenericLong)
.unwrap();
let time_zone_info_past = metlakatla
.without_offset()
.with_zone_name_timestamp(ZoneNameTimestamp::far_in_past());
let time_zone_info_future = metlakatla
.without_offset()
.with_zone_name_timestamp(ZoneNameTimestamp::far_in_future());
// Check the display names:
let name_past = zone_formatter.format(&time_zone_info_past);
let name_future = zone_formatter.format(&time_zone_info_future);
assert_writeable_eq!(name_past, "Pacific Time");
assert_writeable_eq!(name_future, "Alaska Time");Implementations§
Source§impl ZoneNameTimestamp
impl ZoneNameTimestamp
Sourcepub fn to_zoned_date_time_iso(self) -> ZonedDateTime<Iso, UtcOffset>
pub fn to_zoned_date_time_iso(self) -> ZonedDateTime<Iso, UtcOffset>
Recovers the UTC datetime for this ZoneNameTimestamp.
This will always return a ZonedDateTime with UtcOffset::zero()
§Examples
ZonedDateTime does not necessarily roundtrip:
use icu::calendar::Date;
use icu::time::zone::ZoneNameTimestamp;
use icu::time::{ZonedDateTime, Time, zone::UtcOffset};
let zoned_date_time = ZonedDateTime {
date: Date::try_new_iso(2025, 4, 30).unwrap(),
time: Time::try_new(13, 58, 16, 500000000).unwrap(),
zone: UtcOffset::zero(),
};
let zone_name_timestamp = ZoneNameTimestamp::from_zoned_date_time(zoned_date_time);
let recovered_zoned_date_time = zone_name_timestamp.to_zoned_date_time_iso();
// The datetime doesn't roundtrip:
assert_ne!(zoned_date_time, recovered_zoned_date_time);
// The exact behavior is subject to change. For illustration only:
assert_eq!(recovered_zoned_date_time.date, zoned_date_time.date);
assert_eq!(recovered_zoned_date_time.time.hour, zoned_date_time.time.hour);
assert_eq!(recovered_zoned_date_time.time.minute.number(), 45); // rounded down
assert_eq!(recovered_zoned_date_time.time.second.number(), 0); // always zero
assert_eq!(recovered_zoned_date_time.time.subsecond.number(), 0); // always zeroSourcepub fn from_zoned_date_time<C>(
zoned_date_time: ZonedDateTime<C, UtcOffset>,
) -> ZoneNameTimestampwhere
C: AsCalendar,
pub fn from_zoned_date_time<C>(
zoned_date_time: ZonedDateTime<C, UtcOffset>,
) -> ZoneNameTimestampwhere
C: AsCalendar,
Creates an instance of ZoneNameTimestamp from a ZonedDateTime with an explicit UtcOffset.
Sourcepub fn from_zoned_date_time_iso(
zoned_date_time: ZonedDateTime<Iso, UtcOffset>,
) -> ZoneNameTimestamp
👎Deprecated since 2.2.0: use Self::from_zoned_date_time
pub fn from_zoned_date_time_iso( zoned_date_time: ZonedDateTime<Iso, UtcOffset>, ) -> ZoneNameTimestamp
use Self::from_zoned_date_time
Sourcepub fn from_epoch_seconds(seconds: i64) -> ZoneNameTimestamp
pub fn from_epoch_seconds(seconds: i64) -> ZoneNameTimestamp
Creates an instance of ZoneNameTimestamp from a number of seconds since the UNIX epoch.
Sourcepub fn to_date_time_iso(self) -> DateTime<Iso>
👎Deprecated since 2.1.0: returns a UTC DateTime, which is the wrong type. Use to_zoned_date_time_iso instead
pub fn to_date_time_iso(self) -> DateTime<Iso>
returns a UTC DateTime, which is the wrong type. Use to_zoned_date_time_iso instead
Recovers the UTC datetime for this ZoneNameTimestamp.
Sourcepub fn from_date_time_iso(_: DateTime<Iso>) -> ZoneNameTimestamp
👎Deprecated since 2.1.0: implicitly interprets the DateTime as UTC. Use from_zoned_date_time_iso instead.
pub fn from_date_time_iso(_: DateTime<Iso>) -> ZoneNameTimestamp
implicitly interprets the DateTime as UTC. Use from_zoned_date_time_iso instead.
Creates an instance of ZoneNameTimestamp from a UTC datetime.
The datetime might be clamped and might lose precision.
Sourcepub fn far_in_past() -> ZoneNameTimestamp
pub fn far_in_past() -> ZoneNameTimestamp
Returns a ZoneNameTimestamp for a time far in the past.
Sourcepub fn far_in_future() -> ZoneNameTimestamp
pub fn far_in_future() -> ZoneNameTimestamp
Returns a ZoneNameTimestamp for a time far in the future.
Trait Implementations§
Source§impl AsULE for ZoneNameTimestamp
impl AsULE for ZoneNameTimestamp
Source§fn to_unaligned(self) -> <ZoneNameTimestamp as AsULE>::ULE
fn to_unaligned(self) -> <ZoneNameTimestamp as AsULE>::ULE
Source§fn from_unaligned(
unaligned: <ZoneNameTimestamp as AsULE>::ULE,
) -> ZoneNameTimestamp
fn from_unaligned( unaligned: <ZoneNameTimestamp as AsULE>::ULE, ) -> ZoneNameTimestamp
Source§impl Clone for ZoneNameTimestamp
impl Clone for ZoneNameTimestamp
Source§fn clone(&self) -> ZoneNameTimestamp
fn clone(&self) -> ZoneNameTimestamp
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ZoneNameTimestamp
Source§impl Debug for ZoneNameTimestamp
impl Debug for ZoneNameTimestamp
Source§impl<'de> Deserialize<'de> for ZoneNameTimestamp
Available on crate feature serde only.
impl<'de> Deserialize<'de> for ZoneNameTimestamp
serde only.Source§fn deserialize<D>(
deserializer: D,
) -> Result<ZoneNameTimestamp, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<ZoneNameTimestamp, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
impl Eq for ZoneNameTimestamp
Source§impl<C, A, Z> GetField<ZoneNameTimestamp> for ZonedDateTime<A, Z>
impl<C, A, Z> GetField<ZoneNameTimestamp> for ZonedDateTime<A, Z>
Source§fn get_field(&self) -> ZoneNameTimestamp
fn get_field(&self) -> ZoneNameTimestamp
T.Source§impl<Z> GetField<ZoneNameTimestamp> for ZonedTime<Z>where
Z: GetField<ZoneNameTimestamp>,
Available on crate feature unstable only.
impl<Z> GetField<ZoneNameTimestamp> for ZonedTime<Z>where
Z: GetField<ZoneNameTimestamp>,
unstable only.Source§fn get_field(&self) -> ZoneNameTimestamp
fn get_field(&self) -> ZoneNameTimestamp
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 IntoOption<ZoneNameTimestamp> for ZoneNameTimestamp
impl IntoOption<ZoneNameTimestamp> for ZoneNameTimestamp
Source§fn into_option(self) -> Option<ZoneNameTimestamp>
fn into_option(self) -> Option<ZoneNameTimestamp>
self as an Option<T>Source§impl Ord for ZoneNameTimestamp
impl Ord for ZoneNameTimestamp
Source§fn cmp(&self, other: &ZoneNameTimestamp) -> Ordering
fn cmp(&self, other: &ZoneNameTimestamp) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for ZoneNameTimestamp
impl PartialEq for ZoneNameTimestamp
Source§fn eq(&self, other: &ZoneNameTimestamp) -> bool
fn eq(&self, other: &ZoneNameTimestamp) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialOrd for ZoneNameTimestamp
impl PartialOrd for ZoneNameTimestamp
Source§impl Serialize for ZoneNameTimestamp
Available on crate feature serde only.
impl Serialize for ZoneNameTimestamp
serde only.Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
impl StructuralPartialEq for ZoneNameTimestamp
Source§impl<'a> ZeroMapKV<'a> for ZoneNameTimestamp
Available on crate feature alloc only.
impl<'a> ZeroMapKV<'a> for ZoneNameTimestamp
alloc only.Source§type Container = ZeroVec<'a, ZoneNameTimestamp>
type Container = ZeroVec<'a, ZoneNameTimestamp>
ZeroVec or VarZeroVec.type Slice = ZeroSlice<ZoneNameTimestamp>
Source§type GetType = <ZoneNameTimestamp as AsULE>::ULE
type GetType = <ZoneNameTimestamp as AsULE>::ULE
Container::get() Read moreSource§type OwnedType = ZoneNameTimestamp
type OwnedType = ZoneNameTimestamp
Container::replace() and Container::remove(),
also used during deserialization. If Self is human readable serialized,
deserializing to Self::OwnedType should produce the same value once
passed through Self::owned_as_self() Read moreAuto Trait Implementations§
impl Freeze for ZoneNameTimestamp
impl RefUnwindSafe for ZoneNameTimestamp
impl Send for ZoneNameTimestamp
impl Sync for ZoneNameTimestamp
impl Unpin for ZoneNameTimestamp
impl UnsafeUnpin for ZoneNameTimestamp
impl UnwindSafe for ZoneNameTimestamp
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<T> ErasedDestructor for Twhere
T: 'static,
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