tzif/parser
Parser for Time Zone Information File formatted data, also knows as tzfile formatted files. This parser can parse version 1, 2, 3, and 4 TZif files. Be aware that version 1 files use 32-bit integers to represent time and therefore have a limited time range. Versions 2 and higher use 64 bit integers and do not suffer from those limitations. All modern tz database distributions use version 2 or higher.
This parser will parse the header and initial data section for
all TZif files. It does not parse the extensions for versions 3 format and version 4
format files, however the data is returned as unparsed binary data in the remains
portion of the TzFile
record.
Types
This record represents the ttinfo structs as defined within the tzfile format man page. These structures contain the raw time zone parameters which are used to convert from UTC to a particular time zone.
pub type TtInfo {
TtInfo(utoff: Int, isdst: Int, desigidx: Int)
}
Constructors
-
TtInfo(utoff: Int, isdst: Int, desigidx: Int)
Parsed tzfile record containing the header, fields, as well as
any remaining data after the parsed fields. The remaining data is usually
an ASCII string starting with a newline. The format of the remaining
data is described in the tzfile
man page and will depend on the version number given in the header
record.
pub type TzFile {
TzFile(
header: TzFileHeader,
fields: TzFileFields,
remains: BitArray,
)
}
Constructors
-
TzFile( header: TzFileHeader, fields: TzFileFields, remains: BitArray, )
Time zone parser error
pub type TzFileError {
HeaderParseError
HeaderVersionError
BodyParseError
TransitionTimeParseError
TtInfoParseError
LeapSecondParseError
}
Constructors
-
HeaderParseError
Error parsing header
-
HeaderVersionError
Unexpected file format version
-
BodyParseError
Error parsing fields not specified elsewhere from the body of a TZif file.
-
TransitionTimeParseError
Transition time parsing error
-
TtInfoParseError
TtInfo parsing error
-
LeapSecondParseError
Error Parsing leap second section
Fields within the tzfile. These fields are described in the tzfile man page and are labeled in the same order as presented on that page and within the file itself.
pub type TzFileFields {
TzFileFields(
transition_times: List(Int),
time_types: List(Int),
ttinfos: List(TtInfo),
designations: List(String),
leapsecond_values: List(#(Int, Int)),
standard_or_wall: List(Int),
ut_or_local: List(Int),
)
}
Constructors
-
TzFileFields( transition_times: List(Int), time_types: List(Int), ttinfos: List(TtInfo), designations: List(String), leapsecond_values: List(#(Int, Int)), standard_or_wall: List(Int), ut_or_local: List(Int), )
Header of the tzfile. This uses the same label names as
the extensions of the tzh_
integer variables
defined in the tzfile
man page. The names of the labels in the record match those
described in the web page without the tzf_
prefix.
pub type TzFileHeader {
TzFileHeader(
version: Int,
ttisutcnt: Int,
ttisstdcnt: Int,
leapcnt: Int,
timecnt: Int,
typecnt: Int,
charcnt: Int,
)
}
Constructors
-
TzFileHeader( version: Int, ttisutcnt: Int, ttisstdcnt: Int, leapcnt: Int, timecnt: Int, typecnt: Int, charcnt: Int, )
Values
pub fn parse(tzdata: BitArray) -> Result(TzFile, TzFileError)
Parse a bitarray in the format described by the tzfile man page.