BurntSushi / jiff

A date-time library for Rust that encourages you to jump into the pit of success.
The Unlicense
1.77k stars 35 forks source link

`jiff_tzdb` potentially not up to date with current TZDB #120

Closed nekevss closed 2 months ago

nekevss commented 2 months ago

Hi there! I was doing some testing with jiff_tzdb as a way to potentially source TZifs. I noticed during testing that currently block 2 only has a timecnt of 175 compared to my filesystem's timecnt of 236 for the identifier "America/Chicago".

Just to note: I am using the tzif crate to parse the data returned from jiff_tzdb.

Below is a super simplified version of the code.

// jiff_tzdb
let Some((_, data)) = jiff_tzdb::get("America/Chicago") else { ... };
let (tzif_data, _) = tzif::parse::tzif::tzif().parse(data)?;
// Output for header2: Some(TzifHeader { version: 2, isutcnt: 0, isstdcnt: 0, leapcnt: 0, timecnt: 175, typecnt: 6, charcnt: 24 })

// fs
let data = tzif::parse_tzif_file("/usr/share/zoneinfo/America/Chicago");
// Output for header2: Some(TzifHeader { version: 2, isutcnt: 8, isstdcnt: 8, leapcnt: 0, timecnt: 236, typecnt: 8, charcnt: 24 })

Am I missing something about using jiff_tzdb?

BurntSushi commented 2 months ago

The tzdb files in jiff-tzdb are compiled using the "slim" format. Your system tzdb is probably compiled using the "fat" format to support broken applications or code that otherwise hasn't been updated to support v2 of TZif (which is extremely old itself).

The slim version doesn't include transitions that are described by the POSIX tz rule near the end of the TZif data because they are strictly redundant.

This is very likely what explains the difference.

nekevss commented 2 months ago

Ah okay. I think tzif currently only supports the version 2 blocks and not the version 1 blocks, so tzif would need to be updated to fully support version 1 blocks to be interoperable with jiff_tzdb.

BurntSushi commented 2 months ago

Eh? From the tzif README:

Also includes a parser for POSIX time-zone strings, which is used by the TZif parser, but also available separately.

I'm not sure what you mean by version 1 and version 2 blocks. The slim versus fat formats are related to transitions redundant with the TZ string.

BurntSushi commented 2 months ago

From looking at https://docs.rs/tzif/0.2.3/tzif/data/tzif/struct.TzifData.html, there isn't anything obviously missing there by my eye. So I'm not sure any updates are needed. This is almost certainly due to slim versus fat. It's an option you pass to the zic compiler: https://github.com/BurntSushi/jiff/blob/92a9dda8213dd12d3c1e6ea60dc0bae85cee6a59/jiff-cli/cmd/generate/zoneinfo.rs#L133

nekevss commented 2 months ago

This is almost certainly due to slim versus fat.

Yeah, it definitely looks like it. I was initially concerned that there was something happening in data block one that couldn't be seen (obviously not the case).