Timezone

Struct Timezone 

Source
pub struct Timezone {
    pub name: String,
    /* private fields */
}
Expand description

A named timezone from the IANA Time Zone Database

§Example

let utc = tzdata::Timezone::utc();
let now = utc.now();

for tzname in &["Europe/Paris", "America/New_York", "Asia/Seoul"] {
    let tz = tzdata::Timezone::new(tzname).unwrap();
    let now = now.project(&tz);
    println!("it is now {:?} in {}", now, tz.name);
}

Fields§

§name: String

The timezone name e.g. Europe/Paris.

Implementations§

Source§

impl Timezone

Source

pub fn new(timezone: &str) -> Result<Self>

Try to load a new Timezone. It assumes that the zoneinfo data are located under /usr/share/zoneinfo.

Source

pub fn local() -> Result<Self>

Load the local Timezone set by the system, disregarding the TZ environment variable.

Source

pub fn utc() -> Self

Returns the UTC timezone.

Source

pub fn fixed(sec: i32) -> Self

Returns a fixed offset to UTC timezone. The provided offset is in seconds.

Source

pub fn now(&self) -> Datetime<'_>

Return the Datetime representing now, relative to this Timezone.

Source

pub fn parse(&self, s: &str, fmt: &str) -> Datetime<'_>

Parse a Datetime relative to this Timezone according to the given format. Timezone-related field are ignored. Panics if the string does not match the format.

Source

pub fn unix(&self, stamp: i64, nano: i32) -> Datetime<'_>

Create a new Datetime from a Unix timestamp. The provided timestamp represents Unix seconds from the Epoch, discarding any leap seconds that may have happened in between. A Unix timestamp is ambiguous on leap second insertion (e.g. 1435708800 is equal to both 2015-06-30T23:59:60Z and 2015-07-01T00:00:00Z) however, unix will always choose the non-leap second. Panics if nano ∉ [0, 999999999].

Source

pub fn datetime( &self, year: i32, month: i32, day: i32, hour: i32, minute: i32, second: i32, nano: i32, ) -> Datetime<'_>

Create a new Datetime relative to this Timezone. Panics if the following constraints do not hold:

  • month ∊ [1, 12]
  • day ∊ [1, 31] and is valid within the month
  • hour ∊ [0, 23]
  • minute ∊ [0, 59]
  • second ∊ [0, 60]
  • nano ∊ [0, 999999999]

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> 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, 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.