From 3efdd446a98589ae2607aa7f824251ab7acd5d76 Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Thu, 14 Mar 2024 23:41:43 +0530 Subject: [PATCH] Update availabilityHelper.js --- .../widget/helpers/availabilityHelper.js | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/app/javascript/widget/helpers/availabilityHelper.js b/app/javascript/widget/helpers/availabilityHelper.js index a3f65ff23..03293b5d8 100644 --- a/app/javascript/widget/helpers/availabilityHelper.js +++ b/app/javascript/widget/helpers/availabilityHelper.js @@ -1,3 +1,4 @@ +// Array defining days of the week const daysOfWeek = [ 'Sunday', 'Monday', @@ -8,7 +9,14 @@ const daysOfWeek = [ 'Saturday', ]; -// Function to find the next available time +/** + * Function to find the next available time + * @param {Array} workingHours - Array of working hours for each day + * @param {number} currentDayOfWeek - Index of the current day of the week (0 for Sunday, 1 for Monday, etc.) + * @param {number} currentHour - Current hour of the day (24-hour format) + * @param {number} currentMinutes - Current minutes of the hour + * @returns {Object|null} - Object containing next available time information or null if not available + */ const findNextAvailableTime = ( workingHours, currentDayOfWeek, @@ -49,7 +57,7 @@ const findNextAvailableTime = ( nextAvailableTime = { hour: nextDay.open_hour, minutes: nextDay.open_minutes, - day: nextDay.day_of_week, + day: nextDayIndex, }; break; } @@ -59,7 +67,12 @@ const findNextAvailableTime = ( return nextAvailableTime; }; -// Function to get the next availability message +/** + * Function to get the next availability message + * @param {Array} workingHours - Array of working hours for each day + * @param {Date} currentTime - Current time object + * @returns {string} - Next availability message + */ export const getNextAvailabilityMessage = (workingHours, currentTime) => { const currentDayOfWeek = currentTime.getDay(); // 0 for Sunday, 1 for Monday, ... const currentHour = currentTime.getHours(); @@ -80,7 +93,7 @@ export const getNextAvailabilityMessage = (workingHours, currentTime) => { const differenceInHours = Math.floor(differenceInMinutes / 60); // Check if the next available time is tomorrow - if (nextAvailableTime.day === currentDayOfWeek + 1) { + if (nextAvailableTime.day === (currentDayOfWeek + 1) % 7) { return `We will be back online tomorrow`; }