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::calendar::Iso;
use icu::datetime::fieldsets::zone::GenericLong;
use icu::datetime::NoCalendarFormatter;
use icu::locale::locale;
use icu::time::zone::IanaParser;
use icu::time::zone::ZoneNameTimestamp;
use icu::time::ZonedDateTime;
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()
.with_zone_name_timestamp(ZoneNameTimestamp::from_zoned_date_time_iso(
ZonedDateTime::try_offset_only_from_str("2010-01-01T00:00Z", Iso)
.unwrap(),
));
let time_zone_info_2025 = metlakatla
.without_offset()
.with_zone_name_timestamp(ZoneNameTimestamp::from_zoned_date_time_iso(
ZonedDateTime::try_offset_only_from_str("2025-01-01T00:00Z", Iso)
.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_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()
Sourcepub fn from_zoned_date_time_iso(
zoned_date_time: ZonedDateTime<Iso, UtcOffset>,
) -> ZoneNameTimestamp
pub fn from_zoned_date_time_iso( zoned_date_time: ZonedDateTime<Iso, UtcOffset>, ) -> ZoneNameTimestamp
Creates an instance of ZoneNameTimestamp from a zoned datetime.
The datetime might be clamped and might lose precision.
§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_iso(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 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>
to_zoned_date_time_iso insteadRecovers 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
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 · 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