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) switched between Pacific Time and Alaska Time multiple times between 2010 and 2025.
use icu::time::zone::IanaParser;
use icu::time::zone::ZoneNameTimestamp;
use icu::datetime::NoCalendarFormatter;
use icu::datetime::fieldsets::zone::GenericLong;
use icu::locale::locale;
use writeable::assert_writeable_eq;
let metlakatla = IanaParser::new().parse("America/Metlakatla");
let zone_formatter = NoCalendarFormatter::try_new(
    locale!("en-US").into(),
    GenericLong,
)
.unwrap();
let time_zone_info_2010 = metlakatla.without_offset().at_date_time_iso("2010-01-01T00:00".parse().unwrap());
let time_zone_info_2025 = metlakatla.without_offset().at_date_time_iso("2025-01-01T00:00".parse().unwrap());
// TimeZoneInfo::at_date_time_iso and ZoneNameTimestamp::from_date_time_iso are equivalent:
assert_eq!(
    time_zone_info_2010.zone_name_timestamp(),
    ZoneNameTimestamp::from_date_time_iso("2010-01-01T00:00".parse().unwrap())
);
assert_eq!(
    time_zone_info_2025.zone_name_timestamp(),
    ZoneNameTimestamp::from_date_time_iso("2025-01-01T00:00".parse().unwrap())
);
// Check the display names:
let name_2010 = zone_formatter.format(&time_zone_info_2010);
let name_2025 = zone_formatter.format(&time_zone_info_2025);
assert_writeable_eq!(name_2010, "Pacific Time");
assert_writeable_eq!(name_2025, "Alaska Time");Implementations§
Source§impl ZoneNameTimestamp
 
impl ZoneNameTimestamp
Sourcepub fn to_date_time_iso(self) -> DateTime<Iso>
 
pub fn to_date_time_iso(self) -> DateTime<Iso>
Recovers the local datetime for this ZoneNameTimestamp.
For more information, see Self::from_date_time_iso().
Sourcepub fn from_date_time_iso(date_time: DateTime<Iso>) -> ZoneNameTimestamp
 
pub fn from_date_time_iso(date_time: DateTime<Iso>) -> ZoneNameTimestamp
Creates an instance of ZoneNameTimestamp from a local datetime.
The datetime might be clamped and might lose precision.
Note: Currently, this type cannot represent ambiguous times in the period after a time zone transition. For example, if a “fall back” time zone transition occurs at 02:00, then the times 01:00-02:00 occur twice. To ensure that you get the correct time zone display name after a transition, you can pick any time later in the day.
§Examples
DateTime does not necessarily roundtrip:
use icu::calendar::Date;
use icu::time::zone::ZoneNameTimestamp;
use icu::time::{DateTime, Time};
let date_time = DateTime {
    date: Date::try_new_iso(2025, 4, 30).unwrap(),
    time: Time::try_new(13, 58, 16, 500000000).unwrap(),
};
let zone_name_timestamp = ZoneNameTimestamp::from_date_time_iso(date_time);
let recovered_date_time = zone_name_timestamp.to_date_time_iso();
// The datetime doesn't roundtrip:
assert_ne!(date_time, recovered_date_time);
// The exact behavior is subject to change. For illustration only:
assert_eq!(recovered_date_time.date, date_time.date);
assert_eq!(recovered_date_time.time.hour, date_time.time.hour);
assert_eq!(recovered_date_time.time.minute.number(), 45); // rounded down
assert_eq!(recovered_date_time.time.second.number(), 0); // always zero
assert_eq!(recovered_date_time.time.subsecond.number(), 0); // always zeroSourcepub 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 · Source§fn clone_from(&mut self, source: &Self)
 
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ZoneNameTimestamp
 
impl Debug for ZoneNameTimestamp
Source§impl<'de> Deserialize<'de> for ZoneNameTimestamp
 
impl<'de> Deserialize<'de> for ZoneNameTimestamp
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>,
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<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 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 · 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§impl PartialOrd for ZoneNameTimestamp
 
impl PartialOrd for ZoneNameTimestamp
Source§impl Serialize for ZoneNameTimestamp
 
impl Serialize for ZoneNameTimestamp
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,
Source§impl<'a> ZeroMapKV<'a> for ZoneNameTimestamp
 
impl<'a> ZeroMapKV<'a> for ZoneNameTimestamp
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 moreimpl Copy for ZoneNameTimestamp
impl Eq for ZoneNameTimestamp
impl StructuralPartialEq for ZoneNameTimestamp
Auto Trait Implementations§
impl Freeze for ZoneNameTimestamp
impl RefUnwindSafe for ZoneNameTimestamp
impl Send for ZoneNameTimestamp
impl Sync for ZoneNameTimestamp
impl Unpin 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,
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