Fix :calendar crash on OTP 29 for IANA "24:00" transition times (fixes #166)#169
Open
patrols wants to merge 1 commit into
Open
Fix :calendar crash on OTP 29 for IANA "24:00" transition times (fixes #166)#169patrols wants to merge 1 commit into
patrols wants to merge 1 commit into
Conversation
Erlang/OTP 29 tightened :calendar.time_to_seconds/1 to reject hours
outside 0..23. The IANA tz database legally uses "24:00" for end-of-day
transition boundaries, which time_for_rule/transform_until_datetime parse
to an hour-24 datetime (e.g. {{2024, 3, 31}, {24, 0, 0}}). Passing that to
:calendar.datetime_to_gregorian_seconds/1 — which calls time_to_seconds/1
internally — crashed period building on OTP 29 with a FunctionClauseError.
OTP <= 28 accepted it and returned the value for the equivalent next-day
00:00.
Add Tzdata.Util.datetime_to_gregorian_seconds/1, which computes the value
directly (date_to_gregorian_days * 86400 + h*3600 + m*60 + s) so any hour
(including 24) is handled, matching the pre-OTP-29 result. Route both
Tzdata.Util.datetime_to_utc/3 and Tzdata.PeriodBuilder.datetime_to_utc/3
through it. Add a regression test.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #166.
Problem
Erlang/OTP 29 tightened
:calendar.time_to_seconds/1to reject hours outside0..23. The IANA tz database legally uses "24:00" for end-of-day transition boundaries, whichTzdata.Util.time_for_rule/2parses into an hour-24 datetime (e.g.{{Y, M, D}, {24, 0, 0}}).Tzdata.PeriodBuilder.datetime_to_utc/3andTzdata.Util.datetime_to_utc/3pass that datetime to:calendar.datetime_to_gregorian_seconds/1(which callstime_to_seconds/1internally), so on OTP 29 the:tzdata_release_updatercrashes during period building (as reported in #166):OTP ≤ 28 accepted
{24, 0, 0}and returned the value for the equivalent next-day00:00, so this only surfaces after upgrading to OTP 29.Fix
Add
Tzdata.Util.datetime_to_gregorian_seconds/1, which computes the value directly:This handles any hour (including 24) and is numerically identical to
:calendar.datetime_to_gregorian_seconds/1for hours 0–23 —24:00:00on day D ≡00:00:00on day D+1. Bothdatetime_to_utc/3implementations route through it.Tests
test/tz_util_test.exscovering:utc/:standard/:wallmodifiers with a24:00datetime.🤖 Generated with Claude Code