Struct libtzfile::Tz

source ·
pub struct Tz {
    pub tzh_timecnt_data: Vec<i64>,
    pub tzh_timecnt_indices: Vec<u8>,
    pub tzh_typecnt: Vec<Ttinfo>,
    pub tz_abbr: Vec<String>,
    /* private fields */
}
Expand description

This is the crate’s primary structure, which contains the TZfile fields.

Fields§

§tzh_timecnt_data: Vec<i64>

transition times timestamps table

§tzh_timecnt_indices: Vec<u8>

indices for the next field

§tzh_typecnt: Vec<Ttinfo>

a struct containing UTC offset, daylight saving time, abbreviation index

§tz_abbr: Vec<String>

abbreviations table

Implementations§

source§

impl Tz

source

pub fn new(tz: &str) -> Result<Tz, TzError>

Creates a Tz struct from a TZ system file

 use libtzfile::Tz;
 let tzfile: &str = "/usr/share/zoneinfo/America/Phoenix";
 println!("{:?}", Tz::new(tzfile).unwrap());
 Tz { tzh_timecnt_data: [-2717643600, -1633273200, -1615132800, -1601823600, -1583683200, -880210800, -820519140, -812653140, -796845540, -84380400, -68659200], tzh_timecnt_indices: [2, 1, 2, 1, 2, 3, 2, 3, 2, 1, 2], tzh_typecnt: [Ttinfo { tt_utoff: -26898, tt_isdst: 0, tt_abbrind: 0 }, Ttinfo { tt_utoff: -21600, tt_isdst: 1, tt_abbrind: 1 }, Ttinfo { tt_utoff: -25200, tt_isdst: 0, tt_abbrind: 2 }, Ttinfo { tt_utoff: -21600, tt_isdst: 1, tt_abbrind: 3 }], tz_abbr: ["LMT", "MDT", "MST", "MWT"] }
source

pub fn transition_times( &self, y: Option<i32> ) -> Result<Vec<TransitionTime>, TzError>

Returns year’s transition times for a timezone. If year is Some(0), returns current year’s transition times. If there’s no transition time for selected year, returns the last occured transition time (zone’s current parameters). If no year (None) is specified, returns all transition times recorded in the TZfile .

use libtzfile::Tz;
println!("{:?}", Tz::new(tzfile).unwrap().transition_times(Some(2020)).unwrap());
[TransitionTime { time: 2020-03-29T01:00:00Z, utc_offset: 7200, isdst: true, abbreviation: "CEST" }, TransitionTime { time: 2020-10-25T01:00:00Z, utc_offset: 3600, isdst: false, abbreviation: "CET" }]
source

pub fn zoneinfo(&self) -> Result<Tzinfo, TzError>

Returns convenient data about a timezone for current date and time.

use libtzfile::Tz;
println!("{:?}", Tz::new(tzfile).unwrap().zoneinfo().unwrap());
Tzinfo { timezone: "Europe/Paris", utc_datetime: 2020-09-05T16:41:44.279502100Z, datetime: 2020-09-05T18:41:44.279502100+02:00, dst_from: Some(2020-03-29T01:00:00Z), dst_until: Some(2020-10-25T01:00:00Z), dst_period: true, raw_offset: 3600, dst_offset: 7200, utc_offset: +02:00, abbreviation: "CEST", week_number: 36 }

Trait Implementations§

source§

impl Debug for Tz

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Tz

§

impl RefUnwindSafe for Tz

§

impl Send for Tz

§

impl Sync for Tz

§

impl Unpin for Tz

§

impl UnwindSafe for Tz

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

§

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

§

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.