Reputation: 37
Trying to develop a script that highlights text when a business is open. The hours are 8:30-12:30, 1:30-5:00. I tried just highlighting based on day and that worked fine, but when I tried the hours my logic messes up. can anyone suggest a better way of doing this or lead me in the right direction. I am trying to see if there is a shorter statement to do this.
if(day==2 && ((hour >= 8 && min >= 30) ||(hour <= 13 && min <= 30))){
$("#Tuesday").attr('id','open-hour')
}
Upvotes: 0
Views: 362
Reputation: 3261
Have you tried using momentjs (http://momentjs.com/docs/)? It might be useful to check if the current time is within the range of working hours (http://momentjs.com/docs/#/manipulating/min/)?
Upvotes: 1
Reputation: 4669
This will pretty much always return true:
if(day==2 && ((hour >= 8 && min >= 30) ||(hour <= 13 && min <= 30))){
$("#Tuesday").attr('id','open-hour')
}
This is because the hour will always be greater than 8 OR less than 13. If the hour is 14, it's still greater than 8.
You should split that statement into 2 pieces.
Upvotes: 0