From 93c48e08e6764dc3bafbd790c6a19e363ac0f96d Mon Sep 17 00:00:00 2001 From: SanttuA Date: Thu, 30 May 2024 08:54:39 +0300 Subject: [PATCH 1/4] Fix to overnight calendar continous reservation check Previously when overnight start and end time were the same time, continous reservation check would falsely detect next and previous day selections to break continous selection. This change fixes the issue. --- app/shared/overnight-calendar/overnightUtils.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/shared/overnight-calendar/overnightUtils.js b/app/shared/overnight-calendar/overnightUtils.js index 058e295e7..e4af324a2 100644 --- a/app/shared/overnight-calendar/overnightUtils.js +++ b/app/shared/overnight-calendar/overnightUtils.js @@ -550,6 +550,10 @@ export function isSelectionContinous({ dates[0] = setDatesTime(dates[0], overnightStartTime).toDate(); dates[dates.length - 1] = setDatesTime(dates[dates.length - 1], overnightEndTime).toDate(); + if (overnightStartTime === overnightEndTime) { + dates[0].setMinutes(dates[0].getMinutes() + 1); + dates[dates.length - 1].setMinutes(dates[dates.length - 1].getMinutes() - 1); + } for (let index = 0; index < dates.length; index += 1) { const date = dates[index]; From 82753dfa946508f754260e236951061376ab98fd Mon Sep 17 00:00:00 2001 From: SanttuA Date: Thu, 30 May 2024 09:10:32 +0300 Subject: [PATCH 2/4] Added more tests for overnight continous check --- .../tests/overnightUtils.spec.js | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/app/shared/overnight-calendar/tests/overnightUtils.spec.js b/app/shared/overnight-calendar/tests/overnightUtils.spec.js index 51b608f47..e3341f5d7 100644 --- a/app/shared/overnight-calendar/tests/overnightUtils.spec.js +++ b/app/shared/overnight-calendar/tests/overnightUtils.spec.js @@ -785,12 +785,24 @@ describe('app/shared/overnight-calendar/overnightUtils', () => { end: '2024-04-29T09:00:00+03:00' }) ]; + const reservationsB = [ + Reservation.build({ + begin: '2024-04-27T13:00:00+03:00', + end: '2024-04-29T13:00:00+03:00' + }) + ]; const reservations2 = [ Reservation.build({ begin: '2024-04-27T13:00:00+03:00', end: '2024-04-28T09:00:00+03:00' }) ]; + const reservations2B = [ + Reservation.build({ + begin: '2024-04-27T13:00:00+03:00', + end: '2024-04-28T13:00:00+03:00' + }) + ]; const openingHours = [ { date: '2024-04-19', closes: null, opens: null }, { date: '2024-04-20', closes: '2024-04-20T20:00:00+03:00', opens: '2024-04-20T06:00:00+03:00' }, @@ -807,6 +819,7 @@ describe('app/shared/overnight-calendar/overnightUtils', () => { ]; const overnightStartTime = '13:00:00'; const overnightEndTime = '09:00:00'; + const overnightEndTime2 = '13:00:00'; test('returns true when no reservations or closed days in selection', () => { const startDate = moment('2024-04-23').toDate(); @@ -823,6 +836,15 @@ describe('app/shared/overnight-calendar/overnightUtils', () => { startDate, endDate, reservations, openingHours, overnightStartTime, overnightEndTime })) .toBe(true); + expect(isSelectionContinous({ + startDate, + endDate, + reservations: reservationsB, + openingHours, + overnightStartTime, + overnightEndTime: overnightEndTime2 + })) + .toBe(true); expect(isSelectionContinous({ startDate: startDate2, endDate: endDate2, @@ -832,6 +854,15 @@ describe('app/shared/overnight-calendar/overnightUtils', () => { overnightEndTime })) .toBe(true); + expect(isSelectionContinous({ + startDate: startDate2, + endDate: endDate2, + reservations: reservations2B, + openingHours, + overnightStartTime, + overnightEndTime: overnightEndTime2 + })) + .toBe(true); expect(isSelectionContinous({ startDate: startDate3, endDate: endDate3, @@ -841,6 +872,15 @@ describe('app/shared/overnight-calendar/overnightUtils', () => { overnightEndTime })) .toBe(true); + expect(isSelectionContinous({ + startDate: startDate3, + endDate: endDate3, + reservations: reservations2B, + openingHours, + overnightStartTime, + overnightEndTime: overnightEndTime2 + })) + .toBe(true); }); test('returns false when reservations or closed days in selection', () => { const startDate1 = moment('2024-04-23').toDate(); @@ -862,6 +902,15 @@ describe('app/shared/overnight-calendar/overnightUtils', () => { overnightEndTime })) .toBe(false); + expect(isSelectionContinous({ + startDate: startDate1, + endDate: endDate1, + reservations: reservationsB, + openingHours, + overnightStartTime, + overnightEndTime: overnightEndTime2 + })) + .toBe(false); expect(isSelectionContinous({ startDate: startDate1, endDate: endDate1, @@ -871,6 +920,15 @@ describe('app/shared/overnight-calendar/overnightUtils', () => { overnightEndTime })) .toBe(false); + expect(isSelectionContinous({ + startDate: startDate1, + endDate: endDate1, + reservations: reservations2B, + openingHours, + overnightStartTime, + overnightEndTime: overnightEndTime2 + })) + .toBe(false); expect(isSelectionContinous({ startDate: startDate2, endDate: endDate2, @@ -880,6 +938,15 @@ describe('app/shared/overnight-calendar/overnightUtils', () => { overnightEndTime })) .toBe(false); + expect(isSelectionContinous({ + startDate: startDate2, + endDate: endDate2, + reservations: reservationsB, + openingHours, + overnightStartTime, + overnightEndTime: overnightEndTime2 + })) + .toBe(false); expect(isSelectionContinous({ startDate: startDate2, endDate: endDate2, @@ -889,6 +956,15 @@ describe('app/shared/overnight-calendar/overnightUtils', () => { overnightEndTime })) .toBe(false); + expect(isSelectionContinous({ + startDate: startDate2, + endDate: endDate2, + reservations: reservations2B, + openingHours, + overnightStartTime, + overnightEndTime: overnightEndTime2 + })) + .toBe(false); expect(isSelectionContinous({ startDate: startDate3, endDate: endDate3, @@ -898,6 +974,15 @@ describe('app/shared/overnight-calendar/overnightUtils', () => { overnightEndTime })) .toBe(false); + expect(isSelectionContinous({ + startDate: startDate3, + endDate: endDate3, + reservations: reservationsB, + openingHours, + overnightStartTime, + overnightEndTime: overnightEndTime2 + })) + .toBe(false); expect(isSelectionContinous({ startDate: startDate4, endDate: endDate4, @@ -907,6 +992,15 @@ describe('app/shared/overnight-calendar/overnightUtils', () => { overnightEndTime })) .toBe(false); + expect(isSelectionContinous({ + startDate: startDate4, + endDate: endDate4, + reservations: reservations2B, + openingHours, + overnightStartTime, + overnightEndTime: overnightEndTime2 + })) + .toBe(false); expect(isSelectionContinous({ startDate: startDate5, endDate: endDate5, @@ -916,6 +1010,15 @@ describe('app/shared/overnight-calendar/overnightUtils', () => { overnightEndTime })) .toBe(false); + expect(isSelectionContinous({ + startDate: startDate5, + endDate: endDate5, + reservations: reservations2B, + openingHours, + overnightStartTime, + overnightEndTime: overnightEndTime2 + })) + .toBe(false); }); }); From 134f16eb0b602c82742bb39c979480c70c2abbce Mon Sep 17 00:00:00 2001 From: SanttuA Date: Thu, 30 May 2024 13:25:09 +0300 Subject: [PATCH 3/4] Fix continous check's create date array func --- app/shared/overnight-calendar/overnightUtils.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/shared/overnight-calendar/overnightUtils.js b/app/shared/overnight-calendar/overnightUtils.js index e4af324a2..5a2fe146f 100644 --- a/app/shared/overnight-calendar/overnightUtils.js +++ b/app/shared/overnight-calendar/overnightUtils.js @@ -577,6 +577,8 @@ export function isSelectionContinous({ export function createDateArray(startDate, endDate) { const start = new Date(startDate); const end = new Date(endDate); + start.setHours(0, 0, 0, 0); + end.setHours(0, 0, 0, 0); const dateArray = []; while (start <= end) { From f23d14a28a7da888fcb15cd64f54a05b5deffec8 Mon Sep 17 00:00:00 2001 From: SanttuA Date: Thu, 30 May 2024 13:52:32 +0300 Subject: [PATCH 4/4] Added new test for isSelectionContinous --- .../overnight-calendar/tests/overnightUtils.spec.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/shared/overnight-calendar/tests/overnightUtils.spec.js b/app/shared/overnight-calendar/tests/overnightUtils.spec.js index e3341f5d7..9a8062e32 100644 --- a/app/shared/overnight-calendar/tests/overnightUtils.spec.js +++ b/app/shared/overnight-calendar/tests/overnightUtils.spec.js @@ -1019,6 +1019,15 @@ describe('app/shared/overnight-calendar/overnightUtils', () => { overnightEndTime: overnightEndTime2 })) .toBe(false); + expect(isSelectionContinous({ + startDate: moment('2024-04-26').hours(13).toDate(), + endDate: moment('2024-04-28').toDate(), + reservations: reservations2, + openingHours, + overnightStartTime, + overnightEndTime + })) + .toBe(false); }); });