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

168
Vistas
Iterate between two dates till first date is before the second

I have two dates in unix:

let start: number = 1632988953;
const end: number  = 1638259353;

I need to iterate over this two dates, witch will calculate the new start date in each iteration.

So, I have a while structure like below:

const datesArray = [];
while (start <= end) {
    let newDate = dayjs.unix(start).add(5, 'day').unix();

    datesArray.push(newDate);
    
    start = newDate;
}

When I start this while in the function, it iterates infinitely killing my browser, can someone tell me what is wrong here?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It is working fine, execute the snippet to see for yourself

let start = 1632988953;
const end  = 1638259353;

let condition = true;
console.log("before : ",condition);
const datesArray = [];
while (start <= end) {
    let newDate = dayjs.unix(start).add(5, 'day').unix();
    datesArray.push(newDate);
    start = newDate;
    condition = start <= end;
}
console.log("after : ",condition);
<script src="https://unpkg.com/dayjs@1.8.21/dayjs.min.js"></script>
<script>dayjs().format()</script>

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