From d4709ef07fc8c2dc92344c7f5ddc48f174151a84 Mon Sep 17 00:00:00 2001 From: imwh0im Date: Sun, 20 Feb 2022 14:09:45 +0900 Subject: [PATCH 1/4] fix(is-overlap): modify policy same date overlap --- src/index.ts | 10 +++++++--- test/range.test.ts | 20 +++++++++++++------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/index.ts b/src/index.ts index cb046ea..abc45ae 100644 --- a/src/index.ts +++ b/src/index.ts @@ -41,9 +41,13 @@ class DayjsRange { } return ( - (this.startDate >= other.startDate && this.startDate <= other.endDate) || - (this.endDate >= other.startDate && this.endDate <= other.endDate) || - (this.startDate <= other.startDate && this.endDate >= other.endDate) + (this.startDate > other.startDate && this.startDate < other.endDate) || + (this.endDate >= other.startDate && + this.endDate < other.endDate && + !this.endDate.isSame(other.startDate)) || + (this.startDate <= other.startDate && this.endDate > other.endDate) || + (this.startDate.isSame(other.startDate) && + this.endDate.isSame(other.endDate)) ); } diff --git a/test/range.test.ts b/test/range.test.ts index 93209df..2d6eceb 100644 --- a/test/range.test.ts +++ b/test/range.test.ts @@ -43,20 +43,23 @@ it('range isOverlap', () => { const otherDate2 = '2021-07-19 00:00:00'; expect( - dayjsRange(startDate, endDate).isOverlap(dayjsRange(startDate, endDate)), - ).toBe(true); - expect( - dayjsRange(endDate, startDate).isOverlap(dayjsRange(startDate, endDate)), - ).toBe(true); + dayjsRange(startDate, endDate).isOverlap(dayjsRange(otherDate, otherDate2)), + ).toBe(false); expect( dayjsRange(startDate, endDate).isOverlap(dayjsRange(endDate, otherDate)), - ).toBe(true); + ).toBe(false); expect( - dayjsRange(startDate, endDate).isOverlap(dayjsRange(otherDate, otherDate2)), + dayjsRange(startDate, startDate).isOverlap(dayjsRange(startDate, endDate)), ).toBe(false); expect( dayjsRange(startDate, otherDate).isOverlap(dayjsRange(endDate, otherDate2)), ).toBe(true); + expect( + dayjsRange(endDate, otherDate).isOverlap(dayjsRange(endDate, otherDate2)), + ).toBe(true); + expect( + dayjsRange(startDate, endDate).isOverlap(dayjsRange(startDate, endDate)), + ).toBe(true); expect( dayjsRange(startDate, otherDate2).isOverlap(dayjsRange(endDate, otherDate)), ).toBe(true); @@ -67,6 +70,9 @@ it('range isOverlap', () => { expect( dayjsRange(startDate, endDate).isOverlap(dayjsRange(startDate, null)), ).toBe(false); + expect( + dayjsRange(startDate, endDate).isOverlap(dayjsRange(endDate, endDate)), + ).toBe(false); }); it('range get date', () => { From 25d555d8b41966c2233c8f22db7018215f59d1d1 Mon Sep 17 00:00:00 2001 From: henry <48340699+imwh0im@users.noreply.github.com> Date: Mon, 21 Feb 2022 18:26:52 +0900 Subject: [PATCH 2/4] fix(is-overlap): add test case --- test/range.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/range.test.ts b/test/range.test.ts index 2d6eceb..9c90b20 100644 --- a/test/range.test.ts +++ b/test/range.test.ts @@ -60,6 +60,9 @@ it('range isOverlap', () => { expect( dayjsRange(startDate, endDate).isOverlap(dayjsRange(startDate, endDate)), ).toBe(true); + expect( + dayjsRange(startDate, otherDate).isOverlap(dayjsRange(startDate, endDate)), + ).toBe(true); expect( dayjsRange(startDate, otherDate2).isOverlap(dayjsRange(endDate, otherDate)), ).toBe(true); From 2a13a79c417a3878aca5d8d34c689efd9ffb1f45 Mon Sep 17 00:00:00 2001 From: henry <48340699+imwh0im@users.noreply.github.com> Date: Mon, 21 Feb 2022 19:30:12 +0900 Subject: [PATCH 3/4] fix(is-overlap): modify date comparative --- src/index.ts | 13 ++++++++----- test/range.test.ts | 40 +++++++++++++++++++++++++++++----------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/index.ts b/src/index.ts index abc45ae..66e2b21 100644 --- a/src/index.ts +++ b/src/index.ts @@ -41,11 +41,14 @@ class DayjsRange { } return ( - (this.startDate > other.startDate && this.startDate < other.endDate) || - (this.endDate >= other.startDate && - this.endDate < other.endDate && - !this.endDate.isSame(other.startDate)) || - (this.startDate <= other.startDate && this.endDate > other.endDate) || + (this.startDate.isAfter(other.startDate) && + this.startDate.isBefore(other.endDate)) || + (this.endDate.isAfter(other.startDate) && + this.endDate.isBefore(other.endDate)) || + (other.startDate.isAfter(this.startDate) && + other.startDate.isBefore(this.endDate)) || + (other.endDate.isAfter(this.startDate) && + other.endDate.isBefore(this.endDate)) || (this.startDate.isSame(other.startDate) && this.endDate.isSame(other.endDate)) ); diff --git a/test/range.test.ts b/test/range.test.ts index 9c90b20..6a610e0 100644 --- a/test/range.test.ts +++ b/test/range.test.ts @@ -42,23 +42,14 @@ it('range isOverlap', () => { const otherDate = '2021-07-17 00:00:00'; const otherDate2 = '2021-07-19 00:00:00'; - expect( - dayjsRange(startDate, endDate).isOverlap(dayjsRange(otherDate, otherDate2)), - ).toBe(false); - expect( - dayjsRange(startDate, endDate).isOverlap(dayjsRange(endDate, otherDate)), - ).toBe(false); - expect( - dayjsRange(startDate, startDate).isOverlap(dayjsRange(startDate, endDate)), - ).toBe(false); expect( dayjsRange(startDate, otherDate).isOverlap(dayjsRange(endDate, otherDate2)), ).toBe(true); expect( - dayjsRange(endDate, otherDate).isOverlap(dayjsRange(endDate, otherDate2)), + dayjsRange(endDate, otherDate2).isOverlap(dayjsRange(startDate, otherDate)), ).toBe(true); expect( - dayjsRange(startDate, endDate).isOverlap(dayjsRange(startDate, endDate)), + dayjsRange(startDate, endDate).isOverlap(dayjsRange(startDate, otherDate)), ).toBe(true); expect( dayjsRange(startDate, otherDate).isOverlap(dayjsRange(startDate, endDate)), @@ -69,6 +60,33 @@ it('range isOverlap', () => { expect( dayjsRange(endDate, otherDate).isOverlap(dayjsRange(startDate, otherDate2)), ).toBe(true); + expect( + dayjsRange(startDate, endDate).isOverlap(dayjsRange(startDate, endDate)), + ).toBe(true); + expect( + dayjsRange(startDate, endDate).isOverlap(dayjsRange(otherDate, otherDate2)), + ).toBe(false); + expect( + dayjsRange(otherDate, otherDate2).isOverlap(dayjsRange(startDate, endDate)), + ).toBe(false); + expect( + dayjsRange(startDate, endDate).isOverlap(dayjsRange(endDate, otherDate)), + ).toBe(false); + expect( + dayjsRange(endDate, otherDate).isOverlap(dayjsRange(startDate, endDate)), + ).toBe(false); + expect( + dayjsRange(startDate, startDate).isOverlap(dayjsRange(startDate, endDate)), + ).toBe(false); + expect( + dayjsRange(startDate, endDate).isOverlap(dayjsRange(startDate, startDate)), + ).toBe(false); + expect( + dayjsRange(endDate, endDate).isOverlap(dayjsRange(startDate, endDate)), + ).toBe(false); + expect( + dayjsRange(startDate, endDate).isOverlap(dayjsRange(endDate, endDate)), + ).toBe(false); expect(dayjsRange(endDate, otherDate).isOverlap()).toBe(false); expect( dayjsRange(startDate, endDate).isOverlap(dayjsRange(startDate, null)), From 7e2b94bb0db259e1735a2b2db74a529a05618a22 Mon Sep 17 00:00:00 2001 From: henry <48340699+imwh0im@users.noreply.github.com> Date: Tue, 22 Feb 2022 10:28:29 +0900 Subject: [PATCH 4/4] fix(is-overlap): modify conditional statements --- src/index.ts | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/index.ts b/src/index.ts index 66e2b21..3733e44 100644 --- a/src/index.ts +++ b/src/index.ts @@ -40,18 +40,7 @@ class DayjsRange { return false; } - return ( - (this.startDate.isAfter(other.startDate) && - this.startDate.isBefore(other.endDate)) || - (this.endDate.isAfter(other.startDate) && - this.endDate.isBefore(other.endDate)) || - (other.startDate.isAfter(this.startDate) && - other.startDate.isBefore(this.endDate)) || - (other.endDate.isAfter(this.startDate) && - other.endDate.isBefore(this.endDate)) || - (this.startDate.isSame(other.startDate) && - this.endDate.isSame(other.endDate)) - ); + return this.startDate < other.endDate && this.endDate > other.startDate; } /**