I am trying to check if current time lies between the two timing using "isBetween" function of moment, but it is not working. I need to find the shift where this time belong to. Any suggestion or any other method.
var Time = [{
"shiftName": "Shift A",
"shiftCode": "shiftA",
"startTime": "07:00",
"endTime": "15:00",
},
{
"shiftName": "Shift B",
"shiftCode": "shiftB",
"startTime": "15:00",
"endTime": "23:00",
},
{
"shiftName": "Shift C",
"shiftCode": "shiftC",
"startTime": "23:00",
"endTime": "07:00",
}
]
Time.forEach(element => {
var st = moment(element.startTime, 'HH:mm');
var et = moment(element.endTime, 'HH:mm');
if (moment().isBetween(st, et)) {
console.log(element.shiftName)
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>