Improved time picker logic (#1166)

This commit is contained in:
Luke Vella 2024-06-19 12:14:30 +01:00 committed by GitHub
parent e5be3166ea
commit a1af535eb7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -34,9 +34,19 @@ const TimePicker: React.FunctionComponent<TimePickerProps> = ({
: dayjs(value).startOf("day");
const res: string[] = [];
while (cursor.isSame(value, "day")) {
res.push(cursor.toISOString());
cursor = cursor.add(15, "minutes");
if (after) {
let cursor = dayjs(after).add(15, "minutes");
while (cursor.diff(after, "hours") < 24) {
res.push(cursor.toISOString());
cursor = cursor.add(15, "minutes");
}
} else {
cursor = dayjs(value).startOf("day");
while (cursor.isSame(value, "day")) {
res.push(cursor.toISOString());
cursor = cursor.add(15, "minutes");
}
}
return res;
}, [after, open, value]);