Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilkka Korhonen authored and Ilkka Korhonen committed Jun 26, 2024
1 parent 9da87b8 commit 4b57462
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/BookingView/BookingView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ function BookingView(props: BookingViewProps) {
) : (
<AvailableRoomList
bookingDuration={bookingDuration}
startingTime={startingTime}
startingTime={startingTime}
setStartingTime={setStartingTime}
rooms={displayRooms}
bookings={bookings}
Expand Down
36 changes: 20 additions & 16 deletions frontend/src/components/BookingView/StartingTimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,40 @@ const StartingTimeButton = styled(ToggleButton)(() => ({

type StartingTimePickerProps = {
onChange: (startingTime: string) => void;
startingTime: string
startingTime: string;
title: string;
setStartingTime: React.Dispatch<React.SetStateAction<string>>;
};

const timeFormat = (h: number, m: number) => {
return h.toString() + ':' + (m < 10 ? '0' + m.toString(): m.toString())
}
return h.toString() + ':' + (m < 10 ? '0' + m.toString() : m.toString());
};

const formatTimeToHalfAndFullHours = (startingTime: DateTime, addition: number): string => {
const formatTimeToHalfAndFullHours = (
startingTime: DateTime,
addition: number
): string => {
let timeObj = DateTime.fromObject({
hour: Number(startingTime.hour),
minute: Number(startingTime.minute),
second: 0})
second: 0
})
.plus({ minutes: addition })
.toObject()
.toObject();

if (timeObj.minute! < 30) {
timeObj.minute = 30
timeObj.minute = 30;
} else if (timeObj.minute! > 30) {
timeObj = DateTime.fromObject({
hour: Number(timeObj.hour),
minute: 0,
second: 0
})
.plus({ hours: 1 })
.toObject()
.toObject();
}
return timeFormat(timeObj.hour!, timeObj.minute!)
}
return timeFormat(timeObj.hour!, timeObj.minute!);
};

const StartingTimePicker = (props: StartingTimePickerProps) => {
const { onChange, title, startingTime, setStartingTime } = props;
Expand All @@ -54,11 +58,11 @@ const StartingTimePicker = (props: StartingTimePickerProps) => {
}
};

const now = DateTime.now()
const startingTimeNow = timeFormat(now.hour, now.minute)
const startingTime2 = formatTimeToHalfAndFullHours(now, 0)
const startingTime3 = formatTimeToHalfAndFullHours(now, 30)
const startingTime4 = formatTimeToHalfAndFullHours(now, 60)
const now = DateTime.now();
const startingTimeNow = timeFormat(now.hour, now.minute);
const startingTime2 = formatTimeToHalfAndFullHours(now, 0);
const startingTime3 = formatTimeToHalfAndFullHours(now, 30);
const startingTime4 = formatTimeToHalfAndFullHours(now, 60);

return (
<div>
Expand Down

0 comments on commit 4b57462

Please sign in to comment.