Struct tzdata::Timezone [] [src]

pub struct Timezone {
    pub name: String,
    // some fields omitted
}

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.

Methods

impl Timezone
[src]

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

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

fn local() -> Result<Self>

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

fn utc() -> Self

Returns the UTC timezone.

fn fixed(sec: i32) -> Self

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

fn now(&self) -> Datetime

Return the Datetime representing now, relative to this Timezone.

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.

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, 59]
  • nano ∊ [0, 999999999]