Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
How can I get the start time of the next appointment of a professional

I have a list of appointments with a start time, an end time and the practitioner's 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
},
];

I have filtered the appointments that belong to that professional, but now what I want to do is to be able to get the end time of the first appointment and the start time of the next appointment for further processing.

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
            }
        }
    });
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

forEach() has an index parameter you can use

appointmentsAux.forEach((appointmentAux, index) => {
  const nextAppointment = appointmentsAux[index + 1];
  if (nextAppointment) {
    // do something with the next appointment's info
    const nextStart = nextAppointment.start_time;
  }
...
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda