Skip to main content

TimeZone

Struct TimeZone 

Source
pub struct TimeZone { /* private fields */ }
Expand description

A time zone: UTC, a fixed offset, or a named IANA zone.

Values are cheap to copy. Named zones are backed by the embedded database (or, with the timezone-system feature, by data read from the system) and never require allocation to use.

§Invariants

A value can only be constructed through TimeZone::UTC, TimeZone::fixed, TimeZone::named or TimeZone::system, so:

Implementations§

Source§

impl TimeZone

Source

pub const UTC: TimeZone

The UTC time zone.

Source

pub const fn fixed(offset: i32) -> Result<TimeZone, Error>

Returns a fixed-offset time zone.

§Errors

Returns an error if offset is outside -25:59:59 ..= 25:59:59.

Source

pub fn named(name: &str) -> Result<TimeZone, Error>

Looks up an IANA time zone by name.

"UTC", "GMT", "Etc/UTC" and the other UTC names in the database are returned as ordinary named zones, so their canonical name, abbreviation and RFC 9557 annotation are preserved. The bare "z" convenience alias resolves to TimeZone::UTC. "local" resolves to the system time zone when the timezone-system feature is enabled. Matching is case-insensitive.

§Errors

Returns ErrorKind::UnknownTimeZone if name is not present in the database.

Source

pub const fn name(&self) -> Option<&'static str>

Returns the canonical name of this time zone, if it has one.

Source

pub fn ambiguity( self, year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, ) -> Result<Ambiguity, Error>

Classifies how the given civil time maps to offsets in this zone.

§Errors

Returns an error if a field is out of range.

Source

pub fn system() -> Result<TimeZone, Error>

Determines the system’s local time zone.

This reads the TZ environment variable, then /etc/localtime, then the platform zoneinfo directory. It never calls localtime_r. The time zone data that a detected value uses must parse; otherwise the lookup fails. The detected zone is determined once per process and cached, so a later change of TZ (or of /etc/localtime) is not observed, and the process leaks one small allocation of detected data at most.

§Errors

Returns ErrorKind::UnknownSystemTimeZone when no system zone can be determined, or ErrorKind::UnknownTimeZone when TZ names a zone that cannot be found.

Trait Implementations§

Source§

impl Clone for TimeZone

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for TimeZone

Source§

impl Debug for TimeZone

Source§

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

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

impl Display for TimeZone

Source§

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

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

impl Eq for TimeZone

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.