Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda