Skip to content

Refine Time.to_seconds_after_midnight/1 return type#15570

Merged
josevalim merged 1 commit into
elixir-lang:mainfrom
nseaSeb:fix-time-seconds-after-midnight-spec
Jul 9, 2026
Merged

Refine Time.to_seconds_after_midnight/1 return type#15570
josevalim merged 1 commit into
elixir-lang:mainfrom
nseaSeb:fix-time-seconds-after-midnight-spec

Conversation

@nseaSeb

@nseaSeb nseaSeb commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

The first tuple element is the number of seconds after midnight, which is always in [0, 86400): the implementation builds iso_days = {0, ...} with the day count hardcoded to 0, so Calendar.ISO.iso_days_to_unit/2 returns only the (non-negative) fraction-of-day part. The spec declared the first element as the broad integer(); narrow it to non_neg_integer() to match — the name and docstring ("seconds after midnight") already imply a non-negative value.

Unlike NaiveDateTime.to_gregorian_seconds/1, which shares the same tuple shape but whose first element is genuinely negative for pre-epoch instants, here negatives are structurally impossible.

Assisted-by: Claude Code:claude-opus-4-8

The first tuple element is the number of seconds after midnight, which is
always in `[0, 86400)`: the implementation builds `iso_days = {0, ...}`
with the day count hardcoded to `0`, so `Calendar.ISO.iso_days_to_unit/2`
returns only the (non-negative) fraction-of-day part. The spec declared
the first element as the broad `integer()`; narrow it to `non_neg_integer()`
to match — the name and docstring ("seconds after midnight") already imply
a non-negative value.

Unlike `NaiveDateTime.to_gregorian_seconds/1`, which shares the same tuple
shape but whose first element is genuinely negative for pre-epoch instants,
here negatives are structurally impossible.

Assisted-by: Claude Code:claude-opus-4-8
@josevalim josevalim merged commit e746c04 into elixir-lang:main Jul 9, 2026
@josevalim

Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants