I have a list of days with corresponding opening and closing hours, now I need to find the operating hours for today. For instance, if it's Friday, then the current hours should be "11:30 AM – 9:30 PM". How can I achieve this using JavaScript?
["Monday: 11:30 AM – 2:30 PM, 5:30 – 10:30 PM", "Tuesday: 11:30 AM – 2:30 PM, 5:30 – 10:30 PM",
"Wednesday: 11:30 AM – 2:30 PM, 5:30 – 10:30 PM", "Thursday: 11:30 AM – 2:30 PM, 5:30 – 10:30 PM",
"Friday: 11:30 AM – 9:30 PM", "Saturday: 11:30 AM – 9:30 PM",
"Sunday: 11:30 AM – 9:00 PM"]
let currentTime = new Date().toString().split(' ')[4];
let a = currentTime.split(':');
if(a[2]>1){
a[1]=parseInt(a[1])+1
}
let hours = a[0]
let minutes = a[1]
Furthermore, how do I determine if a specific time (e.g., 15:02:01pm) falls within the operating hours like between 11:30 AM – 2:30 PM or 15:02:01pm between 11:30 AM – 2:30 PM, 5:30 – 10:30 PM?