`); if (fullDate { const mstTime = convertToMSTTime(time); if (!bookedTimeSlots.includes(mstTime)) { // Exclude booked time slots const timeSlotElement = $(`
${mstTime}${convertToLocalTime(mstTime)}
`); timeSlotElement.data('time', mstTime); // Store the time in the element's data timeSlotElement.on('click', function () { handleTimeSlotRangeClick(timeSlotElement); }); timeSlotsContainer.append(timeSlotElement); } }); } // Convert local time to MST time function convertToMSTTime(time) { const [hours, minutes] = time.split(':').map(Number); const date = new Date(); date.setHours(hours, minutes, 0, 0); return date.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', hour12: true, timeZone: 'America/Denver' }); } // Convert MST time to local time function convertToLocalTime(mstTime) { const [mstHourMinute, period] = mstTime.split(' '); let [hours, minutes] = mstHourMinute.split(':').map(Number); if (period === 'PM' && hours !== 12) hours += 12; if (period === 'AM' && hours === 12) hours = 0; const date = new Date(); date.setHours(hours, minutes, 0, 0); return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', hour12: true, timeZone: userTimeZone }); } // Handle time slot range selection function handleTimeSlotRangeClick(element) { const time = element.data('time'); // If two slots are already selected, reset the selection if (selectedTimeRange.length === 2) { timeSlotsContainer.find('.schedule-item').removeClass('active'); selectedTimeRange = []; } // Add the time to the selected range selectedTimeRange.push(time); element.addClass('active'); // If two slots are selected, highlight the range between them if (selectedTimeRange.length === 2) { highlightTimeRange(selectedTimeRange); } } // Highlight the selected time range function highlightTimeRange(range) { const [start, end] = range; const startIndex = workingHours.findIndex(time => convertToMSTTime(time) === start); const endIndex = workingHours.findIndex(time => convertToMSTTime(time) === end); if (startIndex !== -1 && endIndex !== -1) { const [minIndex, maxIndex] = [Math.min(startIndex, endIndex), Math.max(startIndex, endIndex)]; for (let i = minIndex; i currentDate.getMonth()) { currentMonth--; updateCalendar(); } }); nextMonthBtn.on('click', function () { if (currentMonth