datetime::zone

Struct TimeZone

Source
pub struct TimeZone(pub TimeZoneSource<'static>);
Expand description

A time zone, which here is a list of timespans, each containing a fixed offset for the current location’s time from UTC.

Tuple Fields§

§0: TimeZoneSource<'static>

Implementations§

Source§

impl TimeZone

Source

pub fn zone_name(&self) -> Option<&str>

Source

pub fn offset(&self, datetime: LocalDateTime) -> i64

Returns the total offset from UTC, in seconds, that this time zone has at the given datetime.

Source

pub fn name(&self, datetime: LocalDateTime) -> String

Returns the time zone abbreviation that this time zone has at the given datetime. As always, abbreviations are notoriously vague, and should only be used when referring to a known timezone.

Source

pub fn is_fixed(&self) -> bool

Whether this time zone is “fixed”: a fixed time zone has no transitions, meaning it will always be at the same offset from UTC.

There are relatively few of these, namely the European timezones WET, CET, MET, and EET, and the North American timezones EST5EDT, CST6CDT, MST7MDT, and PST8PDT, none of which actually corresponds to a geographical location.

Source

pub fn to_zoned(&self, datetime: LocalDateTime) -> LocalDateTime

Converts a local datetime in UTC to a zoned datetime that uses this time zone.

Source

pub fn convert_local(&self, local: LocalDateTime) -> LocalTimes<'_>

Converts a local datetime that is already informally in this time zone into a zoned datetime that actually uses this time zone.

For example, say you have the current time for a time zone, but you don’t know what the current offset from UTC is. This method computes the offset, then subtracts rather than adds it, resulting in a value that gets displayed as the current time. In other words, calling hour() or year() or any of the other view methods on one of the resulting values will always return the same as the datetime initially passed in, no matter what the current offset is.

This method can return 0, 1, or 2 values, depending on whether the datetime passed in falls between two timespans (an impossible time) or overlaps two separate timespans (an ambiguous time). The result will almost always be precise, but there are edge cases you need to watch out for.

Trait Implementations§

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

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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, 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.