Module parse_zoneinfo::line
source · Expand description
Parsing zoneinfo data files, line-by-line.
This module provides functions that take a line of input from a zoneinfo
data file and attempts to parse it, returning the details of the line if
it gets parsed successfully. It classifies them as Rule
, Link
,
Zone
, or Continuation
lines.
Line
is the type that parses and holds zoneinfo line data. To try to
parse a string, use the Line::from_str
constructor. (This isn’t the
FromStr
trait, so you can’t use parse
on a string. Sorry!)
§Examples
Parsing a Rule
line:
use parse_zoneinfo::line::*;
let parser = LineParser::default();
let line = parser.parse_str("Rule EU 1977 1980 - Apr Sun>=1 1:00u 1:00 S");
assert_eq!(line, Ok(Line::Rule(Rule {
name: "EU",
from_year: Year::Number(1977),
to_year: Some(Year::Number(1980)),
month: Month::April,
day: DaySpec::FirstOnOrAfter(Weekday::Sunday, 1),
time: TimeSpec::HoursMinutes(1, 0).with_type(TimeType::UTC),
time_to_add: TimeSpec::HoursMinutes(1, 0),
letters: Some("S"),
})));
Parsing a Zone
line:
use parse_zoneinfo::line::*;
let parser = LineParser::default();
let line = parser.parse_str("Zone Australia/Adelaide 9:30 Aus AC%sT 1971 Oct 31 2:00:00");
assert_eq!(line, Ok(Line::Zone(Zone {
name: "Australia/Adelaide",
info: ZoneInfo {
utc_offset: TimeSpec::HoursMinutes(9, 30),
saving: Saving::Multiple("Aus"),
format: "AC%sT",
time: Some(ChangeTime::UntilTime(
Year::Number(1971),
Month::October,
DaySpec::Ordinal(31),
TimeSpec::HoursMinutesSeconds(2, 0, 0).with_type(TimeType::Wall))
),
},
})));
Parsing a Link
line:
use parse_zoneinfo::line::*;
let parser = LineParser::default();
let line = parser.parse_str("Link Europe/Istanbul Asia/Istanbul");
assert_eq!(line, Ok(Line::Link(Link {
existing: "Europe/Istanbul",
new: "Asia/Istanbul",
})));
Structs§
- A rule definition line.
- A zone definition line.
- The information contained in both zone lines and zone continuation lines.
Enums§
- The time at which the rules change for a location.
- A day definition field.
- A month field, which is actually just a wrapper around
datetime::Month
. - The amount of daylight saving time (DST) to apply to this timespan. This is a special type for a certain field in a zone line, which can hold different types of value.
- A time definition field.
- A weekday field, which is actually just a wrapper around
datetime::Weekday
. - A year definition field.