Skip to content

Interval.difference/2 broken with left_open: true on 2nd arg #788

@tisdall

Description

@tisdall

While looking at #787, I was trying other cases and was curious if I'd get back 2 zero-length intervals, but then got some really unexpected results.

I was expecting to get back 2 zero-length intervals for the beginning and end:

iex(4)> (
             Interval.difference(
                 Interval.new(from: ~N[2025-01-01 12:00:00], until: ~N[2025-01-01 13:00:00], left_open: false, right_open: false), 
                 Interval.new(from: ~N[2025-01-01 12:00:00], until: ~N[2025-01-01 13:00:00], left_open: true, right_open: true)
             )
         )
[
  %Timex.Interval{
    from: ~N[2025-01-01 12:00:00],
    until: ~N[2025-01-01 13:00:00],
    left_open: false,
    right_open: false,
    step: [days: 1]
  }
]

Then I tried just making sure the 2nd arg completely covered the 1st and got this:

iex(5)> (
             Interval.difference(
                 Interval.new(from: ~N[2025-01-01 12:00:00], until: ~N[2025-01-01 13:00:00], left_open: false, right_open: false), 
                 Interval.new(from: ~N[2025-01-01 11:00:00], until: ~N[2025-01-01 14:00:00], left_open: true, right_open: true)
             )
         )
[
  %Timex.Interval{
    from: ~N[2025-01-01 12:00:00],
    until: ~N[2025-01-01 13:00:00],
    left_open: false,
    right_open: false,
    step: [days: 1]
  }
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions