The application must display the message whether the gate is open or closed depending on the current time of the day.
The gate opens between 8:00am and before 9:30am OR after 5:50pm and before 9:00pm while the rest of the time the gate remains closed. I want to display the message based on the time input. The below code output is unexpected and incorrect.
function isValid(date, h1, m1, h2, m2) {
var h = date.getHours();
var m = date.getMinutes();
return (h1 < h || h1 == h && m1 <= m) && (h < h2 || h == h2 && m <= m2);
}
function a() {
var current = new Date('2020-01-03 09:31:00');
if ((isValid(current, 8, 0, 9, 30)) || (isValid(current, 5, 50, 21, 0))) {
return 'Gate is open'
} else {
return 'Please come after 8:00am and before 9:30am OR after 5:50pm and before 9:00pm';
}
}a();