🐛 Fix issue with applying times after midnight (#727)

This commit is contained in:
Luke Vella 2023-07-06 14:50:30 +01:00 committed by GitHub
parent 96e175e277
commit a45464bd57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 20 deletions

View file

@ -150,6 +150,7 @@ const MonthCalendar: React.FunctionComponent<DateTimePickerProps> = ({
: {
type: "timeSlot",
start: formatDateWithoutTz(selectedDate),
duration,
end: formatDateWithoutTz(
dayjs(selectedDate)
.add(duration, "minutes")
@ -225,6 +226,7 @@ const MonthCalendar: React.FunctionComponent<DateTimePickerProps> = ({
return {
type: "timeSlot",
start: formatDateWithoutTz(startDate),
duration: duration,
end: formatDateWithoutTz(endDate),
};
}),
@ -346,6 +348,7 @@ const MonthCalendar: React.FunctionComponent<DateTimePickerProps> = ({
{
type: "timeSlot",
start: startTime,
duration,
end: formatDateWithoutTz(
dayjs(new Date(startTime))
.add(duration, "minutes")
@ -382,6 +385,7 @@ const MonthCalendar: React.FunctionComponent<DateTimePickerProps> = ({
startTime: option.start.substring(
option.start.indexOf("T"),
),
duration: option.duration,
endTime: option.end.substring(
option.end.indexOf("T"),
),
@ -392,10 +396,15 @@ const MonthCalendar: React.FunctionComponent<DateTimePickerProps> = ({
Object.keys(optionsByDay).forEach(
(dateString) => {
times.forEach((time) => {
const start =
dateString + time.startTime;
newOptions.push({
type: "timeSlot",
start: dateString + time.startTime,
end: dateString + time.endTime,
start: start,
duration,
end: dayjs(start)
.add(duration, "minutes")
.format("YYYY-MM-DDTHH:mm"),
});
});
},

View file

@ -6,6 +6,7 @@ export type DateOption = {
export type TimeOption = {
type: "timeSlot";
start: string;
duration: number;
end: string;
};

View file

@ -157,6 +157,7 @@ const WeekCalendar: React.FunctionComponent<DateTimePickerProps> = ({
const newEvent: DateTimeOption = {
type: "timeSlot",
start: formatDateWithoutTz(startDate),
duration: dayjs(endDate).diff(endDate, "minutes"),
end: formatDateWithoutTz(endDate),
};

View file

@ -67,6 +67,7 @@ const Page: NextPageWithLayout = () => {
? {
type: "timeSlot",
start: start.format("YYYY-MM-DDTHH:mm:ss"),
duration: option.duration,
end: start
.add(option.duration, "minute")
.format("YYYY-MM-DDTHH:mm:ss"),

View file

@ -40,8 +40,6 @@ export interface ParsedTimeSlotOption {
export type ParsedDateTimeOpton = ParsedDateOption | ParsedTimeSlotOption;
const isTimeSlot = (value: string) => value.indexOf("/") !== -1;
export const getDuration = (startTime: dayjs.Dayjs, endTime: dayjs.Dayjs) => {
const hours = Math.floor(endTime.diff(startTime, "hours"));
const minutes = Math.floor(endTime.diff(startTime, "minute") - hours * 60);
@ -157,19 +155,3 @@ export const expectTimeOption = (d: DateTimeOption): TimeOption => {
}
return d;
};
export const parseValue = (value: string): DateTimeOption => {
if (isTimeSlot(value)) {
const [start, end] = value.split("/");
return {
type: "timeSlot",
start,
end,
};
} else {
return {
type: "date",
date: value,
};
}
};