Resources
Code Sheet
Functionality
-
<div class="sf-opening-hours"></div>
<script>
// Store opening hours (replace with actual shopping hours)
const storeHours = {
Monday: { open: "2:00 PM", close: "8:00 PM" },
Tuesday: { open: "2:00 PM", close: "8:00 PM" },
Wednesday: { open: "2:00 PM", close: "8:00 PM" },
Thursday: { open: "2:00 PM", close: "10:00 PM" },
Friday: { open: "2:00 PM", close: "10:00 PM" },
Saturday: { open: "12:00 PM", close: "10:00 PM" },
Sunday: { open: "12:00 PM", close: "8:00 PM" },
};
// Get the current day and time according to the locale specified
const today = new Date();
const currentDay = today.toLocaleDateString("en-US", { weekday: "long" });
const currentTime = today.toLocaleTimeString("en-US");
// Find the opening hours div on the page
const openingHours = document.querySelector(".sf-opening-hours");
// Check if the store is open
if (storeHours[currentDay].open !== "Closed" && storeHours[currentDay].close !== "Closed") {
const openTime = storeHours[currentDay].open;
const closeTime = storeHours[currentDay].close;
openingHours.textContent = `Today's opening hours: ${openTime} - ${closeTime}`;
} else {
openingHours.textContent = "Sorry, the store is closed today.";
}
</script>