Skip to content

Fix Time.from_seconds_after_midnight/3 not validates microsecond and produce invalid Time - #15721

Merged
josevalim merged 1 commit into
elixir-lang:mainfrom
AlexGx:ag-from_seconds_after_midnight-fix
Aug 7, 2026
Merged

Fix Time.from_seconds_after_midnight/3 not validates microsecond and produce invalid Time#15721
josevalim merged 1 commit into
elixir-lang:mainfrom
AlexGx:ag-from_seconds_after_midnight-fix

Conversation

@AlexGx

@AlexGx AlexGx commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Time.from_seconds_after_midnight/3 not validates microsecond and produce invalid Time struct,
which later can misbehave in Time.diff/3, Time.compare/2 etc.

iex> time = Time.from_seconds_after_midnight(0, {999_999_999, 6})
#Inspect.Error<
  got FunctionClauseError with message:

      """
      no function clause matching in Calendar.ISO.time_to_iodata/5
      """

  while inspecting:

      %{
        microsecond: {999999999, 6},
        second: 0,
        calendar: Calendar.ISO,
        __struct__: Time,
        minute: 0,
        hour: 0
      }
...

iex> time.microsecond
{999999999, 6}

Inspect error, but Time is constructed

@josevalim
josevalim merged commit 8b58414 into elixir-lang:main Aug 7, 2026
15 checks passed
@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