From 672fcb77e03084f94248c1556a3a6331a7711720 Mon Sep 17 00:00:00 2001 From: Kasper Birch Date: Fri, 31 May 2024 11:45:21 +0200 Subject: [PATCH 1/2] Remove unnecessary `date` value from `groupOpeningHoursByWeekday` This value is not used anywhere and is the same as `dateTime` --- src/apps/opening-hours/OpeningHoursHelpers.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/apps/opening-hours/OpeningHoursHelpers.ts b/src/apps/opening-hours/OpeningHoursHelpers.ts index d920274239..205b48aa45 100644 --- a/src/apps/opening-hours/OpeningHoursHelpers.ts +++ b/src/apps/opening-hours/OpeningHoursHelpers.ts @@ -80,7 +80,6 @@ export const groupOpeningHoursByWeekday = ( const daysWithOpeningHours: GroupedOpeningHours = allDays.map((day) => { return { dateTime: day, - date: day, openingHourEntries: openingHours.filter((individualOpeningHour) => dayjs(individualOpeningHour.date).isSame(day, "day") ) From 0324e476bdebc8e75530b1cc2c49a3004f491c2c Mon Sep 17 00:00:00 2001 From: Kasper Birch Date: Fri, 31 May 2024 11:49:14 +0200 Subject: [PATCH 2/2] Add sorting for opening hours MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ensure that opening hours are sorted in the correct chronological order based on `start_time` and `end_time` when `start_time` is identical: - Åbent 06:00 - 22:00 - Åbent 10:00 - 15:00 - Åbent 10:00 - 17:00 - Åbent 12:00 - 13:00 --- src/apps/opening-hours/OpeningHoursHelpers.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/apps/opening-hours/OpeningHoursHelpers.ts b/src/apps/opening-hours/OpeningHoursHelpers.ts index 205b48aa45..d94a676ae7 100644 --- a/src/apps/opening-hours/OpeningHoursHelpers.ts +++ b/src/apps/opening-hours/OpeningHoursHelpers.ts @@ -80,9 +80,19 @@ export const groupOpeningHoursByWeekday = ( const daysWithOpeningHours: GroupedOpeningHours = allDays.map((day) => { return { dateTime: day, - openingHourEntries: openingHours.filter((individualOpeningHour) => - dayjs(individualOpeningHour.date).isSame(day, "day") - ) + openingHourEntries: openingHours + .filter((individualOpeningHour) => + dayjs(individualOpeningHour.date).isSame(day, "day") + ) + .sort((a, b) => { + // The array is primarily sorted by the start_time property of each object. + const startTimeComparison = a.start_time.localeCompare(b.start_time); + if (startTimeComparison !== 0) { + return startTimeComparison; + } + // If two objects have the same start_time, they are then sorted by the end_time property. + return a.end_time.localeCompare(b.end_time); + }) }; });