Struct TimeZone

Source
#[repr(transparent)]
pub struct TimeZone(pub Subtag);
Expand description

A CLDR time zone identity.

The primary definition of this type is in the icu_time crate. Other ICU4X crates re-export it for convenience.

This can be created directly from BCP-47 strings, or it can be parsed from IANA IDs.

CLDR uses difference equivalence classes than IANA. For example, Europe/Oslo is an alias to Europe/Berlin in IANA (because they agree since 1970), but these are different identities in CLDR, as we want to be able to say “Norway Time” and “Germany Time”. On the other hand Europe/Belfast and Europe/London are the same CLDR identity (“UK Time”).

See the docs on zone for more information.

use icu::locale::subtags::subtag;
use icu::time::zone::{IanaParser, TimeZone};

let parser = IanaParser::new();
assert_eq!(parser.parse("Europe/Oslo"), TimeZone(subtag!("noosl")));
assert_eq!(parser.parse("Europe/Berlin"), TimeZone(subtag!("deber")));
assert_eq!(parser.parse("Europe/Belfast"), TimeZone(subtag!("gblon")));
assert_eq!(parser.parse("Europe/London"), TimeZone(subtag!("gblon")));

Tuple Fields§

§0: Subtag

Implementations§

Source§

impl TimeZone

Source

pub const UNKNOWN: Self

The synthetic Etc/Unknown time zone.

This is the result of parsing unknown zones. It’s important that such parsing does not fail, as new zones are added all the time, and ICU4X might not be up to date.

Source

pub const fn is_unknown(self) -> bool

Whether this TimeZone equals TimeZone::UNKNOWN.

Source§

impl TimeZone

Source

pub const fn with_offset(self, offset: Option<UtcOffset>) -> TimeZoneInfo<Base>

Associates this TimeZone with a UTC offset, returning a TimeZoneInfo.

Source

pub const fn without_offset(self) -> TimeZoneInfo<Base>

Converts this TimeZone into a TimeZoneInfo without an offset.

Methods from Deref<Target = Subtag>§

Source

pub fn as_str(&self) -> &str

A helper function for displaying as a &str.

Source

pub fn to_string(&self) -> String

Converts the given value to a String.

Under the hood, this uses an efficient [Writeable] implementation. However, in order to avoid allocating a string, it is more efficient to use [Writeable] directly.

Source

pub fn len(&self) -> usize

Returns the length of self.

§Examples
use icu::locale::subtags::subtag;
let s = subtag!("foo");
assert_eq!(s.len(), 3);

Trait Implementations§

Source§

impl AsULE for TimeZone

Source§

type ULE = TimeZone

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 TimeZone

Source§

fn clone(&self) -> TimeZone

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 TimeZone

Source§

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

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

impl Deref for TimeZone

Source§

type Target = Subtag

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'de> Deserialize<'de> for TimeZone

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 Hash for TimeZone

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl IntoOption<TimeZone> for TimeZone

Source§

fn into_option(self) -> Option<Self>

Return self as an Option<T>
Source§

impl Ord for TimeZone

Source§

fn cmp(&self, other: &TimeZone) -> 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 TimeZone

Source§

fn eq(&self, other: &TimeZone) -> 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 TimeZone

Source§

fn partial_cmp(&self, other: &TimeZone) -> 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 ULE for TimeZone

Source§

fn validate_bytes(bytes: &[u8]) -> Result<(), UleError>

Validates a byte slice, &[u8]. Read more
Source§

fn parse_bytes_to_slice(bytes: &[u8]) -> Result<&[Self], UleError>

Parses a byte slice, &[u8], and return it as &[Self] with the same lifetime. Read more
Source§

unsafe fn slice_from_bytes_unchecked(bytes: &[u8]) -> &[Self]

Takes a byte slice, &[u8], and return it as &[Self] with the same lifetime, assuming that this byte slice has previously been run through Self::parse_bytes_to_slice() with success. Read more
Source§

fn slice_as_bytes(slice: &[Self]) -> &[u8]

Given &[Self], returns a &[u8] with the same lifetime. Read more
Source§

impl<'a> Yokeable<'a> for TimeZone
where Self: Sized,

Source§

type Output = TimeZone

This type MUST be Self with the 'static replaced with 'a, i.e. Self<'a>
Source§

fn transform(&self) -> &Self::Output

This method must cast self between &'a Self<'static> and &'a Self<'a>. Read more
Source§

fn transform_owned(self) -> Self::Output

This method must cast self between Self<'static> and Self<'a>. Read more
Source§

unsafe fn make(this: Self::Output) -> Self

This method can be used to cast away Self<'a>’s lifetime. Read more
Source§

fn transform_mut<F>(&'a mut self, f: F)
where F: 'static + for<'b> FnOnce(&'b mut Self::Output),

This method must cast self between &'a mut Self<'static> and &'a mut Self<'a>, and pass it to f. Read more
Source§

impl<'a> ZeroMapKV<'a> for TimeZone

Source§

type Container = ZeroVec<'a, TimeZone>

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

type Slice = ZeroSlice<TimeZone>

Source§

type GetType = TimeZone

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

type OwnedType = TimeZone

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 TimeZone

Source§

impl Eq for TimeZone

Source§

impl StructuralPartialEq for TimeZone

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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,