Skip to content

Instantly share code, notes, and snippets.

@JoniWeiss
Created July 27, 2015 22:45
Show Gist options
  • Save JoniWeiss/0f95b79f46557cca0328 to your computer and use it in GitHub Desktop.
Save JoniWeiss/0f95b79f46557cca0328 to your computer and use it in GitHub Desktop.
var areWeOpen = function() {
var bizHours = [
["0900", "1800"],
["0630", "2000"],
["0630", "2000"],
["0630", "2000"],
["0630", "2000"],
["0630", "2000"],
["0800", "2000"]
];
var today = moment().format("e");
var tomorrow = moment().add(1, 'days').format("e");
var open = moment(bizHours[today][0], "HHmm").format("HHmm");
var close = moment(bizHours[today][1], "HHmm").format("HHmm");
var now = moment(now).format("HHmm");
var openStatus = function () {
var status = "Closed";
if (open <= now && now < close) {
status = "We are Open now... Why aren't you here?";
} else {
status = "We are closed and will re-open tomorrow morning at " +
moment(bizHours[tomorrow][0], "HHmm").format("HH[:]mm a");
}
return status;
};
return openStatus();
}
alert(areWeOpen());
@JoniWeiss
Copy link
Author

Requires the moment.js plugin. Use as you see fit.
Please let me know what changes you might make or suggest :)
I created this to be able to display the status of the business for the day on their website.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment