Skip to content

Commit

Permalink
fix logic for restricting UTC+12:00
Browse files Browse the repository at this point in the history
  • Loading branch information
dianabirs committed Feb 4, 2025
1 parent 8868d36 commit 3bd692a
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions ui/apps/everest/src/components/time-selection/time-selection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3bd692a

Please sign in to comment.