Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

areIntervalsOverlapping works inconsistently with zero-length intervals. #3781

Open
chatoo2412 opened this issue Apr 25, 2024 · 2 comments
Open

Comments

@chatoo2412
Copy link

chatoo2412 commented Apr 25, 2024

The problem

areIntervalsOverlapping works inconsistently with zero-length intervals.
It returns false as expected, if the interval is very left or very right of another one.
The problem is when the interval is middle of another one, which returns true.

Demo

import { areIntervalsOverlapping } from 'date-fns';

console.log(areIntervalsOverlapping({ start: 0, end: 10 }, { start: 1, end: 1 })); // true
console.log(areIntervalsOverlapping({ start: 0, end: 10 }, { start: 0, end: 0 })); // false
console.log(areIntervalsOverlapping({ start: 0, end: 10 }, { start: 10, end: 10 })); // false

Expected Behavior

all cases return false

Debug Information

  • date-fns version: v3.6.0
@IgnusG
Copy link

IgnusG commented Apr 25, 2024

I think this is expected. Your interval from 1 to 1 is inside of the other interval from 0 to 10 so areIntervalsOverlapping correctly returns true. The edges only return false since the third option (inclusive is not turned on). If you turn it on where it considers intervals adjacent to each other as overlapping it will return correctly true:

console.log(areIntervalsOverlapping({ start: 0, end: 10 }, { start: 10, end: 10 })); // false - intervals not overlapping
console.log(areIntervalsOverlapping({ start: 0, end: 10 }, { start: 10, end: 10 }, { inclusive: true })); // true - intervals not overlapping but adjacent to each other

@chatoo2412
Copy link
Author

I got it, but still hard to understand intuitively. :(
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants