Skip to content

Carry a rule from an earlier year into the start of a zone line - #197

Open
bardrop wants to merge 1 commit into
lau:masterfrom
bardrop-oss:fix-rule-from-earlier-year
Open

bardrop wants to merge 1 commit into
lau:masterfrom
bardrop-oss:fix-rule-from-earlier-year

Conversation

@bardrop

@bardrop bardrop commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

When a zone line with named rules starts, the period builder starts with std_off 0 and only looks at rules from the zone line's own start year onward. If the rule set's last change was in an earlier year, that rule is lost, even though it is still in effect. zic uses that rule's save and letter at the start of the zone line.

Example, America/Phoenix:

-7:00	US	M%sT	1944 Jan  1  0:01
-7:00	-	MST	1944 Apr  1  0:01
-7:00	US	M%sT	1944 Oct  1  0:01

The last US rule before 1944 is the 1942 war time rule (save 1:00, letter W). zdump -v -c 1944,1945 America/Phoenix:

Sat Apr  1 07:01:00 1944 UT = Sat Apr  1 01:01:00 1944 MWT isdst=1 gmtoff=-21600
Sun Oct  1 06:01:00 1944 UT = Sat Sep 30 23:01:00 1944 MST isdst=0 gmtoff=-25200

On master, DateTime.shift_zone(~U[1944-04-01 08:01:00Z], "America/Phoenix", Tzdata.TimeZoneDatabase) gives MST, -07:00. It should be MWT, -06:00.

Same bug, other zones:

  • Europe/Budapest: CET instead of CEST from 1941-04-07 to 1942-11-02 (C-Eur rule from 1940).
  • Many other European zones in 1940-1942 (Kyiv, Minsk, Riga, Tallinn, Vilnius, Chisinau, Simferopol, Belgrade, Kaliningrad, Brussels, Amsterdam, Luxembourg, CET, MET).
  • Asia/Manila: PST instead of PDT from 1945-03-04 to 1945-11-30.
  • America/Argentina/San_Luis 2008, Asia/Gaza and Asia/Hebron 1996.

Fix

In calc_periods/5, for a zone line with named rules, find the last rule of that rule set that took effect in a year before the zone line starts. If there is one, start the zone line with its save and letter. Rules in the start year itself were already handled.

Test

New test in test/tz_period_builder_test.exs checks the 1944 MWT period of America/Phoenix and the 1941-1942 CEST period of Europe/Budapest against zdump.

  • Before the fix: mix test test/tz_period_builder_test.exs -> 18/19 passed (new test fails: got "MST", want "MWT").
  • After the fix: 19/19 passed. Full suite: 76 passed (17 doctests, 59 tests). mix format --check-formatted and mix compile --warnings-as-errors are clean.

I also compared all zones (tzdata 2026d source) with the system zoneinfo, at every transition ±1 s from 1900 to 2060. Mismatches went from 150 to 91, and no new ones showed up. The rest are other cases (for example 1 hour of CST instead of CDT in America/Indiana/Knox on 2006-04-02, where a zone line ends at the same wall time a rule fires) and release differences, not this bug.

When a zone line with named rules started, the period builder began
with std_off 0 and only looked at rules from the zone line's own start
year onward. If the rule set's last change was in an earlier year, it
was ignored. zic uses that rule's save and letter at the start.

For example America/Phoenix showed MST instead of MWT from 1944-04-01
to 1944-10-01, and Europe/Budapest showed CET instead of CEST from
1941-04-07 to 1942-11-02.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant