From c745c1bc9507f8dcb5ca87bdcff2219b6502a38d Mon Sep 17 00:00:00 2001 From: celineung Date: Thu, 19 Dec 2024 15:25:19 +0100 Subject: [PATCH] fix ComplexSchedulePicker for all timezones --- .../SchedulePicker/ComplexSchedulePicker.tsx | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/front/src/app/components/forms/commons/SchedulePicker/ComplexSchedulePicker.tsx b/front/src/app/components/forms/commons/SchedulePicker/ComplexSchedulePicker.tsx index 05a67034c9..e2390d465e 100644 --- a/front/src/app/components/forms/commons/SchedulePicker/ComplexSchedulePicker.tsx +++ b/front/src/app/components/forms/commons/SchedulePicker/ComplexSchedulePicker.tsx @@ -10,6 +10,7 @@ import { TimePeriodsDto, calculateNumberOfWorkedDays, calculateTotalImmersionHoursFromComplexSchedule, + convertLocaleDateToUtcTimezoneDate, } from "shared"; import { useStyles } from "tss-react/dsfr"; import { DayPicker } from "./DayPicker"; @@ -40,8 +41,10 @@ export const ComplexSchedulePicker = ({ complexSchedule={values.schedule.complexSchedule} selectedDate={selectedDate} interval={{ - start: new Date(values.dateStart), - end: new Date(values.dateEnd), + start: convertLocaleDateToUtcTimezoneDate( + new Date(values.dateStart), + ), + end: convertLocaleDateToUtcTimezoneDate(new Date(values.dateEnd)), }} onChange={(lastSelectedDate) => { const updatedSchedule = clone(values.schedule); @@ -69,7 +72,12 @@ export const ComplexSchedulePicker = ({ values.schedule.complexSchedule.find( (dailySchedule) => selectedDate && - isSameDay(selectedDate, new Date(dailySchedule.date)), + isSameDay( + selectedDate, + convertLocaleDateToUtcTimezoneDate( + new Date(dailySchedule.date), + ), + ), )?.timePeriods ?? [] } onValueChange={(newTimePeriods) => { @@ -105,7 +113,11 @@ const makeUpdatedScheduleWithTimePeriodForSelectedDate = ( newTimePeriods: TimePeriodsDto, ): ScheduleDto => { const newComplexSchedule = schedule.complexSchedule.map((dailySchedule) => - selectedDate && isSameDay(selectedDate, new Date(dailySchedule.date)) + selectedDate && + isSameDay( + selectedDate, + convertLocaleDateToUtcTimezoneDate(new Date(dailySchedule.date)), + ) ? { ...dailySchedule, timePeriods: newTimePeriods,