Skip to content

Commit

Permalink
fix ComplexSchedulePicker for all timezones
Browse files Browse the repository at this point in the history
  • Loading branch information
celineung committed Dec 19, 2024
1 parent 6c20369 commit c745c1b
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
TimePeriodsDto,
calculateNumberOfWorkedDays,
calculateTotalImmersionHoursFromComplexSchedule,
convertLocaleDateToUtcTimezoneDate,
} from "shared";
import { useStyles } from "tss-react/dsfr";
import { DayPicker } from "./DayPicker";
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit c745c1b

Please sign in to comment.