Updated TimePicker to disable future times and allow only current or past selections
This commit is contained in:
parent
5b88c86df5
commit
054ef8fd17
@ -27,16 +27,37 @@ const TimePicker = ({ label, onChange, interval = 10, value }) => {
|
|||||||
|
|
||||||
return `${hoursFormatted}:${minutesFormatted} ${period}`;
|
return `${hoursFormatted}:${minutesFormatted} ${period}`;
|
||||||
};
|
};
|
||||||
|
// all slots
|
||||||
|
// const generateTimeSlots = () => {
|
||||||
|
// const slots = [];
|
||||||
|
// let currentTime = new Date(getCurrentTime());
|
||||||
|
// for (let i = 0; i < 144; i++) { // 24 hours with custom interval
|
||||||
|
// slots.push(formatTime(currentTime));
|
||||||
|
// currentTime.setMinutes(currentTime.getMinutes() + interval);
|
||||||
|
// }
|
||||||
|
// return slots;
|
||||||
|
// };
|
||||||
|
|
||||||
|
// imit slots to current time:
|
||||||
const generateTimeSlots = () => {
|
const generateTimeSlots = () => {
|
||||||
const slots = [];
|
const slots = [];
|
||||||
let currentTime = new Date(getCurrentTime());
|
let currentTime = new Date();
|
||||||
for (let i = 0; i < 144; i++) { // 24 hours with custom interval
|
currentTime.setSeconds(0);
|
||||||
slots.push(formatTime(currentTime));
|
currentTime.setMilliseconds(0);
|
||||||
currentTime.setMinutes(currentTime.getMinutes() + interval);
|
|
||||||
|
const endTime = new Date(currentTime); // current time as upper limit
|
||||||
|
|
||||||
|
let slotTime = new Date();
|
||||||
|
slotTime.setHours(0, 0, 0, 0); // start from 00:00
|
||||||
|
|
||||||
|
while (slotTime <= endTime) {
|
||||||
|
slots.push(formatTime(new Date(slotTime)));
|
||||||
|
slotTime.setMinutes(slotTime.getMinutes() + interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
return slots;
|
return slots;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const handleSelect = (selectedTime) => {
|
const handleSelect = (selectedTime) => {
|
||||||
setTime(selectedTime);
|
setTime(selectedTime);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user