From 3bd692a995db6f0fda27b5b3b23434c995f63fa5 Mon Sep 17 00:00:00 2001 From: Diana Birsan Date: Tue, 4 Feb 2025 18:39:09 +0200 Subject: [PATCH] fix logic for restricting UTC+12:00 --- .../time-selection/time-selection.tsx | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/ui/apps/everest/src/components/time-selection/time-selection.tsx b/ui/apps/everest/src/components/time-selection/time-selection.tsx index 77398ec9f..ed02e45f8 100644 --- a/ui/apps/everest/src/components/time-selection/time-selection.tsx +++ b/ui/apps/everest/src/components/time-selection/time-selection.tsx @@ -48,21 +48,32 @@ export const TimeSelection = ({ shouldRestrictSelectableHours && isFirstDayOfTheMonthAndPositiveOffset; const FIRST_HOUR_AVAILABLE = - TIMEZONE_OFFSET_HOURS < 12 + TIMEZONE_OFFSET_HOURS <= 12 ? TIMEZONE_OFFSET_HOURS : TIMEZONE_OFFSET_HOURS - 12; const shouldRestrictAmPm = - (amPm === AmPM.AM && TIMEZONE_OFFSET_HOURS < 12) || - (TIMEZONE_OFFSET_HOURS >= 12 && amPm === AmPM.PM); - - const selectableHours = - changeSelectableTime && shouldRestrictAmPm - ? Array.from( - { length: 12 - FIRST_HOUR_AVAILABLE }, - (_, i) => i + FIRST_HOUR_AVAILABLE - ) - : HOURS_AM_PM; + (amPm === AmPM.AM && TIMEZONE_OFFSET_HOURS <= 12) || + (TIMEZONE_OFFSET_HOURS > 12 && amPm === AmPM.PM); + + const selectableHours = useMemo( + () => + TIMEZONE_OFFSET_HOURS === 12 && amPm === AmPM.AM + ? [12] + : changeSelectableTime && shouldRestrictAmPm + ? Array.from( + { length: 12 - FIRST_HOUR_AVAILABLE }, + (_, i) => i + FIRST_HOUR_AVAILABLE + ) + : HOURS_AM_PM, + [ + FIRST_HOUR_AVAILABLE, + TIMEZONE_OFFSET_HOURS, + amPm, + changeSelectableTime, + shouldRestrictAmPm, + ] + ); const selectableAmPm = changeSelectableTime && TIMEZONE_OFFSET_HOURS > 12