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

227
Visualizações
Issue checking if current time has already passed an hour interval with moment.js

in my app I have timed discounts (Example: 10:00 - 12:00), I want to display in a list these active discounts BUT for the discounts that will also be active tomorrow and the active deal time has already passed I want to have the word TOMORROW next to them, instead of TODAY.

When using moment to see if the active deal has already passed I can't get it to work properly...

let activeTableDiscount = null;
let activeTableDiscountText = 'TODAY';
let filteredTablesDiscountsToday = { /*same object*/ };
let filteredTablesDiscountTomorrow = {};

        var start = moment('10:00', 'HH:mm');
        var end = moment('12:00', 'HH:mm');

        if (end.isBefore(start))
        {
            // If end is before start, then it must end must be tomorrow.
            activeTableDiscount = filteredTablesDiscountsToday;
            activeTableDiscountText = 'TODAY';
        }
        if (now.isBetween(start, end))
          {
            activeTableDiscount = filteredTablesDiscountsToday;
            activeTableDiscountText = 'TODAY';
          } 
          else {
            if (start.isBefore(now)) {
              // If start is before now and the range
              // is not active, then start is tomorrow.
              //start.add(1, "day");
              activeTableDiscount = filteredTablesDiscountsTomorrow;
              activeTableDiscountText = 'TOMORROW';
            }
            //activeTableDiscount = filteredTablesDiscountsTomorrow;
            //activeTableDiscountText = 'Hoy';
            
          }

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
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