It seems to be a matter of evaluating whether the day is inside a range or not (number inside a range of numbers).
Assuming you're using days from Sunday to Saturday as 0 to 6, it should be like this:
// Evaluating if a day is inside working shift ('_from' starting shift, '_to' ending shift)
function inRange(day, _from, _to) {
if(day >= _from && day <= _to)
return true;
return false;
}
EDIT: After thinking about it, there are some edge cases we haven't considered.
Let's say you have non working day on Monday (which might be common in some countries). If you try to evaluate it using ranges, you'll find Sunday as a non working day as well (since Sunday is 0, but range starts from Monday, which is 1).
Hence, we need to change the logic to check whether the asked day is non-working or not.
The easiest way to do is by creating a dictionary, mapping each day to a boolean which will say if that day is free or not:
let workingDays = {
Sunday: true,
Monday: true,
Tuesday: true,
Wednesday: true,
Thursday: true,
Friday: true,
Saturday: true
}
Then, you'll only need to specify the non working days like so
// Working everyday except by Monday
workingDays.Monday = false;
Finally, you can peform verifications to check if the restaurant will be working on the requested day
// Am I working on Monday?
if(workingDays.Monday) {
// do something
} else {
// nope. Come another day.
}
You could also specify the field name as a string which is useful if you want to check using a variable
let requestedDay; // fill this variable somewhere else
...
// is the requested day available?
if(workingDays[requestedDay]) {
// Do something
}
Finally, since the return value of getDay() is an integer from 0 to 6, you might need to search by index:
// Monday == 1
if( workingDays[Object.keys(workingDays)[1]] )
// blabla
Or you could wrap it as a function to improve readability
// Wrap function inside workingDays dictionary
workingDays.at = function(n) { return this[Object.keys(this)[n]] };
// Usage
workingDays.at(1); // gives Monday status (boolean)
Final code:
// Creating dictionary
let workingDays = {
Sunday: true,
Monday: true,
Tuesday: true,
Wednesday: true,
Thursday: true,
Friday: true,
Saturday: true,
at: function(n) { return this[Object.keys(this)[n]] }
}
// Setting a day as non available
workingDays.Monday = false;
// or
workingDays["Monday"] = false;
// or
workingDays.at(1) = false;
// Verifying whether a given day is available
if(workingDays[givenDay]) {
// blabla
}
// or
if(workingDays.at(number)) {
// blabla
}