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}`;
|
||||
};
|
||||
// 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 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);
|
||||
let currentTime = new Date();
|
||||
currentTime.setSeconds(0);
|
||||
currentTime.setMilliseconds(0);
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
const handleSelect = (selectedTime) => {
|
||||
setTime(selectedTime);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user