1

I write a little function to check if the store is open or close. But the function don't work.

I try to change the hour but it the same result.

   this.openTime.setHours(8);
    this.openTime.setMinutes(0); 
    this.closeTime.setHours(20);
    this.closeTime.setMinutes(30);


    var open = moment(this.openTime).format('H:mm');
    var close = moment(this.closeTime).format('H:mm');
    var now = moment(Date.now()).format('H:mm');
    console.log(close)
    console.log(now)
    if(now < close){
      console.log('open') // i have close in console !
    }else {
      console.log('close')
    }

Thanks !

georgeawg
  • 48,608
  • 13
  • 72
  • 95

1 Answers1

0

You can use the .set() of moment.js

The example .

    const day = moment('2017-08-01');
    day.set({ hours: 8, minutes:0 });

    const night = moment('2017-08-01');
    night.set({ hours: 20, minutes: 30 });

    var open = moment(day).format('H:mm');
    var close = moment(night).format('H:mm');
    var now = moment(Date.now()).format('H:mm');
    console.log(open)
    console.log(close)
    if(now < close){
      console.log('open') // You will have open in console !
    }else {
      console.log('close')
    }
Pushprajsinh Chudasama
  • 7,772
  • 4
  • 20
  • 43