Debian Codegraph @

README.md

raw symbols SCIP
1 # parse-zoneinfo
2
3 [![parse-zoneinfo GitHub Actions][gh-image]][gh-checks]
4 [![parse-zoneinfo on crates.io][cratesio-image]][cratesio]
5 [![parse-zoneinfo on docs.rs][docsrs-image]][docsrs]
6 [![Chat][discord-image]][discord]
7
8 [gh-image]: https://github.com/chronotope/chrono-tz/actions/workflows/rust.yml/badge.svg
9 [gh-checks]: https://github.com/chronotope/chrono-tz/actions/workflows/rust.yml
10 [cratesio-image]: https://img.shields.io/crates/v/parse-zoneinfo.svg
11 [cratesio]: https://crates.io/crates/parse-zoneinfo
12 [docsrs-image]: https://docs.rs/parse-zoneinfo/badge.svg
13 [docsrs]: https://docs.rs/parse-zoneinfo
14 [discord-image]: https://img.shields.io/discord/976380008299917365?logo=discord
15 [discord]: https://discord.gg/sXpav4PS7M
16
17 Rust library for reading the text files comprising the [zoneinfo database], which records time zone changes and offsets across the world from multiple sources.
18
19 The zoneinfo database is distributed in one of two formats: a raw text format with one file per continent, and a compiled binary format with one file per time zone. This crate deals with the text format.
20
21 The database itself is maintained by IANA. For more information, see [IANA’s page on the time zone database][iana]. You can also find the text files in [the tz repository][tz].
22
23 Parse-zoneinfo is a fork of [`zoneinfo_parse`] by Benjamin Sago (now unmaintained). It is used by [`chrono-tz`].
24
25 [iana]: https://www.iana.org/time-zones
26 [tz]: https://github.com/eggert/tz
27 [zoneinfo database]: https://en.wikipedia.org/wiki/Tz_database
28 [`zoneinfo_parse`]: https://crates.io/crates/zoneinfo_parse
29 [`chrono-tz`]: https://crates.io/crates/chrono-tz
30
31 ## Rust version requirements
32
33 The Minimum Supported Rust Version (MSRV) is currently **Rust 1.57.0**.
34
35 # Usage
36
37 The zoneinfo files contains `Zone`, `Rule`, and `Link` information. Each type of line forms a variant in the `line::Line` enum.
38
39 To get started, here are a few lines representing what time is like in the `Europe/Madrid` time zone:
40 ```
41 # Zone NAME GMTOFF RULES FORMAT [UNTIL]
42 Zone Europe/Madrid -0:14:44 - LMT 1901 Jan 1 0:00u
43 0:00 Spain WE%sT 1940 Mar 16 23:00
44 1:00 Spain CE%sT 1979
45 1:00 EU CE%sT
46 ```
47
48 The first line is a comment. The second starts with `Zone`, so we know
49
50 So parsing these five lines would return the five following results:
51
52 - A `line::Line::Space` for the comment, because the line doesn’t contain any information (but isn’t strictly *invalid* either).
53 - A `line::Line::Zone` for the first `Zone` entry. This contains a `Zone` struct that holds the name of the zone. All the other fields are stored in the `ZoneInfo` struct.
54 - A `line::Line::Continuation` for the next entry. This is different from the line above as it doesn’t contain a name field; it only has the information in a `ZoneInfo` struct.
55 - The fourth line contains the same types of data as the third.
56 - As does the fifth.
57
58 Lines with rule definitions look like this:
59 ```
60 # Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S
61 Rule Spain 1918 only - Apr 15 23:00 1:00 S
62 Rule Spain 1918 1919 - Oct 6 24:00s 0 -
63 Rule Spain 1919 only - Apr 6 23:00 1:00 S
64 Rule Spain 1924 only - Apr 16 23:00 1:00 S
65 Rule Spain 1924 only - Oct 4 24:00s 0 -
66 ```
67
68 All these lines follow the same pattern: A `line::Line::Rule` that contains a `Rule` struct, which has a field for each column of data.
69
70 Finally, there are lines that link one zone to another’s name:
71 ```
72 # Link TARGET LINK-NAME #= TARGET1
73 link Australia/Sydney Australia/ACT #= Australia/Canberra
74 ```
75
76 The `Link` struct simply contains the names of both the existing and new time zones.
77
78 ## Interpretation
79
80 Once the input lines have been parsed, they must be *interpreted* to form a table of time zone data.
81
82 The easiest way to do this is with a `TableBuilder`. You can add various lines to the builder, and it will throw an error as soon as it detects that something’s wrong, such as a duplicate or a missing entry. When all the lines have been fed to the builder, you can use the `build` method to produce a `Table` containing fields for the rule, zone, and link lines.
83
84 ## Example program
85
86 The `example` folder of this crate contains a basic parser example.
87
88 `parse-zoneinfo` is used to produce the data for [`chrono-tz`]. For a full example of its use see [`chrono-tz-build`].
89
90 [`chrono-tz-build`]: https://github.com/chronotope/chrono-tz/tree/main/chrono-tz-build
91