Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
cómo obtener un elemento basado en fecha y hora en js

tengo un objeto como este:

 0: {start: '2022-02-23T09:30:00', end: '2022-02-23T10:00:00',…} 1: {start: '2022-02-23T10:00:00', end: '2022-02-23T10:30:00',…} 2: {start: '2022-02-23T10:30:00', end: '2022-02-23T11:00:00',…} 3: {start: '2022-02-23T11:00:00', end: '2022-02-23T11:30:00',…} 4: {start: '2022-02-23T12:00:00', end: '2022-02-23T12:30:00',…} 5: {start: '2022-02-23T13:00:00', end: '2022-02-23T13:30:00',…} 6: {start: '2022-02-23T13:30:00', end: '2022-02-23T14:00:00',…} 7: {start: '2022-02-23T14:00:00', end: '2022-02-23T14:30:00',…} 8: {start: '2022-02-23T14:30:00', end: '2022-02-23T15:00:00',…} 9: {start: '2022-02-23T15:00:00', end: '2022-02-23T15:30:00',…} 10: {start: '2022-02-23T15:30:00', end: '2022-02-23T16:00:00',…} 11: {start: '2022-02-23T16:00:00', end: '2022-02-23T16:30:00',…} 12: {start: '2022-02-23T16:30:00', end: '2022-02-23T17:00:00',…}

lo que estoy tratando de hacer es obtener el primer elemento que tiene un tiempo libre entre el start y el end

Por ejemplo, si nos fijamos en el tercer elemento, comienza a las 11:00 y finaliza a las 11:30 y los elementos anteriores son contiguos. En cambio, el cuarto elemento comienza a las 12:00, por lo que a partir de las 11:30 y las 12:00 hay 30 minutos gratis. Entonces, lo que debo hacer es obtener la propiedad end (o el elemento completo) del primer elemento que tiene un elemento siguiente que no tiene un start contiguo

actualización: intenté algo como esto

 const latestAppointment = [...appointments].sort((a, b) => (new Date(a.end)) < (new Date(b.end)) ? -1 : 1)

espero haberme explicado gracias

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

¿Buscas algo como esto?

 myArray.filter((e, i, o) => e.end !== o[i+1]?.start)?.shift(); 

 const times = { 0: { start: '2022-02-23T09:30:00', end: '2022-02-23T10:00:00' }, 1: { start: '2022-02-23T10:00:00', end: '2022-02-23T10:30:00' }, 2: { start: '2022-02-23T10:30:00', end: '2022-02-23T11:00:00' }, 3: { start: '2022-02-23T11:00:00', end: '2022-02-23T11:30:00' }, 4: { start: '2022-02-23T12:00:00', end: '2022-02-23T12:30:00' }, 5: { start: '2022-02-23T13:00:00', end: '2022-02-23T13:30:00' }, 6: { start: '2022-02-23T13:30:00', end: '2022-02-23T14:00:00' }, 7: { start: '2022-02-23T14:00:00', end: '2022-02-23T14:30:00' }, 8: { start: '2022-02-23T14:30:00', end: '2022-02-23T15:00:00' }, 9: { start: '2022-02-23T15:00:00', end: '2022-02-23T15:30:00' }, 10: { start: '2022-02-23T15:30:00', end: '2022-02-23T16:00:00' }, 11: { start: '2022-02-23T16:00:00', end: '2022-02-23T16:30:00' }, 12: { start: '2022-02-23T16:30:00', end: '2022-02-23T17:00:00' } } const res = Object.values(times).filter((e, i, o) => e.end !== o[i+1]?.start)?.shift(); console.log(res);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!