diff --git a/app/shared/overnight-calendar/overnightUtils.js b/app/shared/overnight-calendar/overnightUtils.js index 058e295e7..5a2fe146f 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]; @@ -573,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) { diff --git a/app/shared/overnight-calendar/tests/overnightUtils.spec.js b/app/shared/overnight-calendar/tests/overnightUtils.spec.js index 51b608f47..9a8062e32 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,9 +992,36 @@ 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, + reservations: reservations2, + openingHours, + overnightStartTime, + overnightEndTime + })) + .toBe(false); expect(isSelectionContinous({ startDate: startDate5, endDate: endDate5, + reservations: reservations2B, + openingHours, + overnightStartTime, + overnightEndTime: overnightEndTime2 + })) + .toBe(false); + expect(isSelectionContinous({ + startDate: moment('2024-04-26').hours(13).toDate(), + endDate: moment('2024-04-28').toDate(), reservations: reservations2, openingHours, overnightStartTime,