Skip to content

Commit 9ac551c

Browse files
authored
Fix bug in areIntervalsOverlapping (#3628) (closes #3614)
Fixed bug in `areIntervalsOverlapping` caused by incorrect sorting
1 parent a49902e commit 9ac551c

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/areIntervalsOverlapping/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ export function areIntervalsOverlapping(
7171
const [leftStartTime, leftEndTime] = [
7272
+toDate(intervalLeft.start),
7373
+toDate(intervalLeft.end),
74-
].sort();
74+
].sort((a, b) => a - b);
7575
const [rightStartTime, rightEndTime] = [
7676
+toDate(intervalRight.start),
7777
+toDate(intervalRight.end),
78-
].sort();
78+
].sort((a, b) => a - b);
7979

8080
if (options?.inclusive)
8181
return leftStartTime <= rightEndTime && rightStartTime <= leftEndTime;

src/areIntervalsOverlapping/test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ describe("areIntervalsOverlapping", () => {
142142
assert(isOverlapping);
143143
});
144144

145+
it('sort timestamp', () => {
146+
const result = areIntervalsOverlapping(
147+
{ start: '1970-01-01T02:00:00.000Z', end: '1970-01-01T03:00:00.000Z' },
148+
{ start: '1969-12-31T23:30:00.000Z', end: '1970-01-01T02:30:00.000Z' },
149+
);
150+
assert(result);
151+
})
152+
145153
it("returns result for the normalized intervals if the start date of the initial time interval is after the end date", () => {
146154
const includedIntervalStart = new Date(2016, 10, 14);
147155
const includedIntervalEnd = new Date(2016, 10, 14);

0 commit comments

Comments
 (0)