如何获得专业人员下次预约的开始时间?



我有一个包含开始时间、结束时间和从业者id的约会列表。

const appointments = [
{
date: '2022-06-01',
start_time: '15:40:00',
end_time: '16:10:00',
id_professional: 2
},
{
date: '2022-06-01',
start_time: '16:30:00',
end_time: '16:50:00',
id_professional: 2
},
{
date: '2022-06-01',
start_time: '16:30:00',
end_time: '16:50:00',
id_professional: 3
},
];

我已经过滤了属于该专业人员的约会,但是现在我想做的是能够获得第一次约会的结束时间和下一次约会的开始时间,以便进一步处理。

let timeAux = startTimeInSeconds;
professionalIds.forEach(professionalId => {
const appointmentsAux = appointments.filter(appointment => {
return appointment.id_professional === professionalId;
});
appointmentsAux.forEach(appointmentAux => {
const startTimeAux = appointmentAux.start_time;
const [startTimeAuxHours, startTimeAuxMinutes] = startTimeAux.split(':');
const startTimeAuxInSeconds = (parseInt(startTimeAuxHours) * 60 * 60 + parseInt(startTimeAuxMinutes) * 60);
const endTimeAux = appointmentAux.end_time;
const [endTimeAuxHours, endTimeAuxMinutes] = endTimeAux.split(':');
const endTimeAuxInSeconds = (parseInt(endTimeAuxHours) * 60 * 60 + parseInt(endTimeAuxMinutes) * 60);
if(endTimeAuxInSeconds > startTimeInSeconds){ //appointmen.end_time
// We need the following appointment to get its start_time and see if it fits the time.
//how do we get the next appointment?
if (endTimeAuxInSeconds - startTimeAuxInSeconds >  startTimeInSeconds){
//insert cita
}
}
});
});

forEach()有一个索引参数,你可以使用

appointmentsAux.forEach((appointmentAux, index) => {
const nextAppointment = appointmentsAux[index + 1];
if (nextAppointment) {
// do something with the next appointment's info
const nextStart = nextAppointment.start_time;
}
...

最新更新