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

219
Views
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
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!