Skip to content

Instantly share code, notes, and snippets.

@JoniWeiss
Last active August 29, 2015 14:28
Show Gist options
  • Save JoniWeiss/dc09c14d4d42e3de7de8 to your computer and use it in GitHub Desktop.
Save JoniWeiss/dc09c14d4d42e3de7de8 to your computer and use it in GitHub Desktop.
BizOpen2
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="Joni Weiss -- dba HandMade Pixels">
<style>
.open-close {
background-color: #2aabd2;
font-weight: bold;
border-radius: 12px;
}
</style>
</head>
<body>
<div>
<h1>Script to display open or closed status</h1>
<p class="text-center open-close"></p><br>
<p>Requires the moment.js plugin. Use as you see fit. <br>
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.
</p>
</div>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"></script>
<script>
var areWeOpen = function() {
var open = "noValue";
var timeNow = +moment().format('HHmm');
var dayOfWeek = +moment().format('e');
// console.log(open + " - " + timeNow + " - " + dayOfWeek);
if ((timeNow >= 0630) && (timeNow <= 2000) && ( dayOfWeek >= 1 && dayOfWeek <= 5)) {
open = "We're open today until 8 pm.";
// console.log("if-weekdays" + open);
} else if ((timeNow >= 0800) && (timeNow <= 2000) && ( dayOfWeek === 6)) {
open = "We're open today until 8 pm.";
// console.log("if-saturday" + open);
} else if ((timeNow >= 0900) && (timeNow <= 1800) && ( dayOfWeek === 0)) {
open = "We're open today until 6 pm.";
// console.log("if-sunday" + open);
} else if ( dayOfWeek >= 0 && dayOfWeek <= 4) {
open = "Closed. We open tomorrow at 6:30am.";
} else if ( dayOfWeek === 5) {
open = "Closed. We open tomorrow at 8 am.";
} else if ( dayOfWeek === 6) {
open = "Closed. We open tomorrow at 9 am.";
} else {
open = "We are currently closed.";
}
document.getElementsByClassName("open-close")[0].innerHTML=open;
return(open);
};
areWeOpen();
</script>
</body>
</html>
@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