Struct ZoneNameTimestamp

Source
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

Source

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().

Source

pub fn from_date_time_iso(date_time: DateTime<Iso>) -> Self

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 zero
Source

pub fn far_in_past() -> Self

Returns a ZoneNameTimestamp for a time far in the past.

Source

pub fn far_in_future() -> Self

Returns a ZoneNameTimestamp for a time far in the future.

Trait Implementations§

Source§

impl AsULE for ZoneNameTimestamp

Source§

type ULE = <u32 as AsULE>::ULE

The ULE type corresponding to Self. Read more
Source§

fn to_unaligned(self) -> Self::ULE

Converts from Self to Self::ULE. Read more
Source§

fn from_unaligned(unaligned: Self::ULE) -> Self

Converts from Self::ULE to Self. Read more
Source§

impl Clone for ZoneNameTimestamp

Source§

fn clone(&self) -> ZoneNameTimestamp

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ZoneNameTimestamp

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ZoneNameTimestamp

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl IntoOption<ZoneNameTimestamp> for ZoneNameTimestamp

Source§

fn into_option(self) -> Option<Self>

Return self as an Option<T>
Source§

impl Ord for ZoneNameTimestamp

Source§

fn cmp(&self, other: &ZoneNameTimestamp) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for ZoneNameTimestamp

Source§

fn eq(&self, other: &ZoneNameTimestamp) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for ZoneNameTimestamp

Source§

fn partial_cmp(&self, other: &ZoneNameTimestamp) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for ZoneNameTimestamp

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'a> ZeroMapKV<'a> for ZoneNameTimestamp

Source§

type Container = ZeroVec<'a, ZoneNameTimestamp>

The container that can be used with this type: ZeroVec or VarZeroVec.
Source§

type Slice = ZeroSlice<ZoneNameTimestamp>

Source§

type GetType = <ZoneNameTimestamp as AsULE>::ULE

The type produced by Container::get() Read more
Source§

type OwnedType = ZoneNameTimestamp

The type produced by 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 more
Source§

impl Copy for ZoneNameTimestamp

Source§

impl Eq for ZoneNameTimestamp

Source§

impl StructuralPartialEq for ZoneNameTimestamp

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,