Skip to content

Commit 9388674

Browse files
authored
fix(is-overlap): modify policy same date overlap (#8)
* fix(is-overlap): modify policy same date overlap * fix(is-overlap): add test case * fix(is-overlap): modify date comparative * fix(is-overlap): modify conditional statements
1 parent 40686a3 commit 9388674

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

src/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ class DayjsRange {
4040
return false;
4141
}
4242

43-
return (
44-
(this.startDate >= other.startDate && this.startDate <= other.endDate) ||
45-
(this.endDate >= other.startDate && this.endDate <= other.endDate) ||
46-
(this.startDate <= other.startDate && this.endDate >= other.endDate)
47-
);
43+
return this.startDate < other.endDate && this.endDate > other.startDate;
4844
}
4945

5046
/**

test/range.test.ts

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,57 @@ it('range isOverlap', () => {
4343
const otherDate2 = '2021-07-19 00:00:00';
4444

4545
expect(
46-
dayjsRange(startDate, endDate).isOverlap(dayjsRange(startDate, endDate)),
46+
dayjsRange(startDate, otherDate).isOverlap(dayjsRange(endDate, otherDate2)),
4747
).toBe(true);
4848
expect(
49-
dayjsRange(endDate, startDate).isOverlap(dayjsRange(startDate, endDate)),
49+
dayjsRange(endDate, otherDate2).isOverlap(dayjsRange(startDate, otherDate)),
5050
).toBe(true);
5151
expect(
52-
dayjsRange(startDate, endDate).isOverlap(dayjsRange(endDate, otherDate)),
52+
dayjsRange(startDate, endDate).isOverlap(dayjsRange(startDate, otherDate)),
5353
).toBe(true);
5454
expect(
55-
dayjsRange(startDate, endDate).isOverlap(dayjsRange(otherDate, otherDate2)),
56-
).toBe(false);
57-
expect(
58-
dayjsRange(startDate, otherDate).isOverlap(dayjsRange(endDate, otherDate2)),
55+
dayjsRange(startDate, otherDate).isOverlap(dayjsRange(startDate, endDate)),
5956
).toBe(true);
6057
expect(
6158
dayjsRange(startDate, otherDate2).isOverlap(dayjsRange(endDate, otherDate)),
6259
).toBe(true);
6360
expect(
6461
dayjsRange(endDate, otherDate).isOverlap(dayjsRange(startDate, otherDate2)),
6562
).toBe(true);
63+
expect(
64+
dayjsRange(startDate, endDate).isOverlap(dayjsRange(startDate, endDate)),
65+
).toBe(true);
66+
expect(
67+
dayjsRange(startDate, endDate).isOverlap(dayjsRange(otherDate, otherDate2)),
68+
).toBe(false);
69+
expect(
70+
dayjsRange(otherDate, otherDate2).isOverlap(dayjsRange(startDate, endDate)),
71+
).toBe(false);
72+
expect(
73+
dayjsRange(startDate, endDate).isOverlap(dayjsRange(endDate, otherDate)),
74+
).toBe(false);
75+
expect(
76+
dayjsRange(endDate, otherDate).isOverlap(dayjsRange(startDate, endDate)),
77+
).toBe(false);
78+
expect(
79+
dayjsRange(startDate, startDate).isOverlap(dayjsRange(startDate, endDate)),
80+
).toBe(false);
81+
expect(
82+
dayjsRange(startDate, endDate).isOverlap(dayjsRange(startDate, startDate)),
83+
).toBe(false);
84+
expect(
85+
dayjsRange(endDate, endDate).isOverlap(dayjsRange(startDate, endDate)),
86+
).toBe(false);
87+
expect(
88+
dayjsRange(startDate, endDate).isOverlap(dayjsRange(endDate, endDate)),
89+
).toBe(false);
6690
expect(dayjsRange(endDate, otherDate).isOverlap()).toBe(false);
6791
expect(
6892
dayjsRange(startDate, endDate).isOverlap(dayjsRange(startDate, null)),
6993
).toBe(false);
94+
expect(
95+
dayjsRange(startDate, endDate).isOverlap(dayjsRange(endDate, endDate)),
96+
).toBe(false);
7097
});
7198

7299
it('range get date', () => {

0 commit comments

Comments
 (0)