bitwalker / bitwalker/timex

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

Open
#788 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Elixir
Stars
1.8k
Forks
407
PR merge metrics
No merged PRs in 30d

Description

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:
```elixir
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:
```elixir
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]
}
]
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.