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

79
Vistas
Day extension - moment js

There is a service that opens and closes on the days of the week (for example: Mon from 22:00 - 01:20, Tue: from 04:00 - 13:00, Wed: from 17:00 - 21:00 ...). At the moment my code works so let's say today is Monday and the time is 23:58 - the service is running .. the time is 00:00 the service is not working and will open at 04:00 .. (the time from 00:00 to 01:20 is not fixed because the day It's already Tuesday and the date is changing). I need some kind of flag solution that will not switch the day and keep the service open until 01:20 and close until 04:00

console data - startTime - endTime

time settings

        let startTime = moment(foundScheduleItem.open_at, 'HH:mm')
        let endTime = moment(foundScheduleItem.close_at, 'HH:mm')

        const afterStart = moment().isSameOrAfter(startTime)
        const isToday = afterStart && moment().isSameOrAfter(moment('00:00', 'HH:mm'))
        const beforeClose = moment().isSameOrBefore(endTime)

        if (service.extended) { //  extended - флаг
            const checkTodayBeforeMidnight = isToday && afterStart; 

            // If more than 00:00 but less than close time we dont add the day
            if (!beforeClose && checkTodayBeforeMidnight) {
                endTime = moment('23:59', 'HH:mm'); // no work
             } else {
                startTime = moment('00:00', 'HH:mm');
             }
        }
about 4 years ago · Juan Pablo Isaza
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