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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

areIntervalsOverlapping returns false for overlapping interval #3614

Closed
skbogner opened this issue Dec 19, 2023 · 2 comments
Closed

areIntervalsOverlapping returns false for overlapping interval #3614

skbogner opened this issue Dec 19, 2023 · 2 comments

Comments

@skbogner
Copy link

There is an issue with the areIntervalsOverlapping function

The problem

馃捇 Code demonstrating the problem

https://stackblitz.com/edit/date-fns-playground-c8oyu9?file=index.ts

import { areIntervalsOverlapping } from 'date-fns';

const left = {
start: '1970-01-01T02:00:00.000Z',
end: '1970-01-01T03:00:00.000Z',
};
const right = {
start: '1969-12-31T23:30:00.000Z',
end: '1970-01-01T02:30:00.000Z',
};

console.log(areIntervalsOverlapping(left, right, { inclusive: true }));
// => false

馃檨 Actual behavior

areIntervalsOverlapping returns false

馃檪 Expected behavior

areIntervalsOverlapping returns true

Debug information

  • date-fns version: 3.0.0
  • Browser/Node.js version: Multiple/Any
  • Your timezone: Europe/Copenhagen
  • Your current time: 10:00-11:00
@pekala
Copy link

pekala commented Dec 19, 2023

For additional context, seems related to crossing 1970:

areIntervalsOverlapping(
    {start: new Date('2024-01-01T02:00:00.000Z'), end: new Date('2024-01-01T03:00:00.000Z')}, 
    {start: new Date('2023-12-31T23:30:00.000Z'),  end: new Date('2024-01-01T02:30:00.000Z')}
)
// true

areIntervalsOverlapping(
    {start: new Date('1970-01-01T02:00:00.000Z'), end: new Date('1970-01-01T03:00:00.000Z')}, 
    {start: new Date('1969-12-31T23:30:00.000Z'),  end: new Date('1970-01-01T02:30:00.000Z')}
)
// false (true in v2)

areIntervalsOverlapping(
    {start: new Date('1971-01-01T02:00:00.000Z'), end: new Date('1971-01-01T03:00:00.000Z')}, 
    {start: new Date('1970-12-31T23:30:00.000Z'),  end: new Date('1971-01-01T02:30:00.000Z')}
)
// true

@kossnocorp
Copy link
Member

Fixed and shipped with date-fns@3.0.6

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

3 participants