Displaying based on operating hours

Hello Community,

I am seeking to develop a code which checks a predefined opening and closing time and compares this to the current time to display relevant content. The code works partially. I say partially because I noticed it only runs effectively after a specific time- which incidentally is the opening time of the first record in the database.

Grateful for any assistance.

import wixData from 'wix-data';
 let today = new Date();
 let currentTime = today.toLocaleTimeString();
 let now= today.getHours().valueOf()
 let nowminutes=today.getMinutes().valueOf()
 
nowminutes = nowminutes > 9 ? nowminutes : '0' + nowminutes;
let nowminutestring= nowminutes.toLocaleString()
let nowstring= now.toLocaleString()
let newtimestring= (nowstring+nowminutes).valueOf()
let newtimeidk=(nowstring+nowminutes)

console.log(currentTime)
console.log(now)
console.log(nowminutes)
console.log(newtimestring)
console.log(newtimestring)

$w.onReady(function () {

  $w("#dataset1").onReady (() => {

  $w("#repeater1").forEachItem( ($item, itemData1, index1) => {

 let itemDataopening = itemData1.openingtime;
 let itemDataclosing= itemData1.closingtime;
 let grubid= itemData1.grubid

  console.log(grubid, itemDataopening, itemDataclosing)

 
wixData.query('Grubcovers')
.eq("grubid", grubid)
      .gt("openingtime", newtimeidk)
                .or(wixData.query("Grubcovers")
                .eq("grubid", grubid)
                .lt("closingtime", newtimeidk) 
             )

.or(wixData.query("Grubcovers")
.eq("grubid", grubid)
       .eq("status", "Not accepting orders")
)
 
                .find()

        .then((results) => {

 
          console.log (results)

 let firstItem = results[0];
 if(results.items.length > 0) {
            $item("#text60").collapse();
                        $item('#text86').expand();
                        $item("#button13").collapse()

 
    } else {
 
 // handle case where no matching items found
    }
  } )
});
  })
  })