[][src]Crate libtzfile

This low-level library reads the system timezone information files and returns a Tz struct representing the TZfile fields as described in the man page (http://man7.org/linux/man-pages/man5/tzfile.5.html). Only compatible with V1 (32 bits) format version for the moment.

For higher level parsing, see my high-level parsing library.

To keep the low-level aspect of the library, since 0.5.0 chrono is an optional feature which is not enabled by default, so tzh_timecnt_data is now the raw i32 timestamp. For libtzfile to return tzh_timecnt_data as DateTime<Utc>, you can either use the version 0.4.0 of libtzfile, or add this in Cargo.toml:

[dependencies.libtzfile]
version = "0.5.0"
features = ["with-chrono"]

Here is an example:

 extern crate libtzfile;

 fn main() {
     println!("{:?}", libtzfile::parse("America/Phoenix").expect("Timezone not found"));
 }

which outputs (with chrono enabled):

 Tz { tzh_timecnt_data: [1918-03-31T09:00:00Z, 1918-10-27T08:00:00Z,
 1919-03-30T09:00:00Z, 1919-10-26T08:00:00Z, 1942-02-09T09:00:00Z,
 1944-01-01T06:01:00Z, 1944-04-01T07:01:00Z, 1944-10-01T06:01:00Z,
 1967-04-30T09:00:00Z, 1967-10-29T08:00:00Z],
 tzh_timecnt_indices: [0, 1, 0, 1, 2, 1, 2, 1, 0, 1],
 tzh_typecnt: [Ttinfo { tt_gmtoff: -21600, tt_isdst: 1, tt_abbrind: 0 },
 Ttinfo { tt_gmtoff: -25200, tt_isdst: 0, tt_abbrind: 1 },
 Ttinfo { tt_gmtoff: -21600, tt_isdst: 1, tt_abbrind: 2 }],
 tz_abbr: ["MDT", "MST", "MWT"] }

By default, with chrono disabled, tzh_timecnt_data will be like:

tzh_timecnt_data: [9EA63A90, 9FBB0780, A0861C90, A19AE980, CB890C90, CF17DF1C, CF8FE5AC,
D0811A1C, FAF87510, FBE85800]

It uses system TZfiles (default location on Linux and Macos /usr/share/zoneinfo). On Windows, default expected location is HOME/.zoneinfo. You can override the TZfiles default location with the TZFILES_DIR environment variable. Example for Windows:

$env:TZFILES_DIR="C:\Users\nbauw\Dev\rs-tzfile\zoneinfo"; cargo run

The tests (cargo test) are written to match 2019c version of timezone database.

Structs

Ttinfo
Tz

Enums

TzError

Functions

parse