function MessagesManager() {
var getTime = function (h, m) {
return new Date((new Date()).setHours(h, m, 0, 0));
};
var responses = [
/* days represent the day of the week. 0=Sunday, 1=Monday, ... */
{ days: [1, 2, 3, 4, 5], from: getTime(8, 0), to: getTime(19, 29), message: "We’re open and can see you today." },
{ days: [1, 2, 3, 4, 5], from: getTime(0, 0), to: getTime(7, 59), message: "We’re closed but will reopen tomorrow at 8 AM." },
/* FILL IN THE REST */
];
var isInRange = function (response, date) {
date = date || new Date();
return response.days.indexOf(date.getDay()) > -1 && date >= response.from && date <= response.to;
};
this.getMessage = function () {
for (var i = 0; i < responses.length; i++) {
var response = responses[i];
if (isInRange(response)) {
return response.message;
}
}
return 'Message not found'; // you can even use this as the default closed message
};
}
var msgs = new MessagesManager();
document.getElementById('display').innerHTML = msgs.getMessage();
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.