-1

Im trying to have my store hours posted aswell as a displaying of open or closed + closing soon and the website seems to be an hour behind i just dont know why it closes at 7 instead of 6 on the and sometimes it closses at 11 instead of 10 on the website.

  function isStoreOpen() {
    const now = new Date();
    const offset = -4; // Eastern Time offset (UTC-4 during standard time)
    const easternTime = new Date(now.getTime() + offset * 3600000); // Convert to Eastern Time
  
    const day = easternTime.getUTCDay();
    const hour = easternTime.getUTCHours();
  
    if (day === 0) { // Sunday
      return hour >= 10.5 && hour <= 18;
    } else if (day === 6) { // Saturday
      return hour >= 10.5 && hour <= 23;
    } else if (day === 3) { // Wednesday
      return hour >= 10.5 && hour <= 21; // Adjusted closing time to 9 PM
    } else { // Monday, Tuesday, Thursday, Friday
      return hour >= 10.5 && hour <= 22;
    }
  }

  document.addEventListener('DOMContentLoaded', function() {
    const storeStatusElement = document.getElementById('store-status');
    const isOpen = isStoreOpen();
  
    if (isOpen) {
      storeStatusElement.textContent = 'Open';
      storeStatusElement.style.color = 'maroon';
    } else {
      storeStatusElement.textContent = 'Closed';
      storeStatusElement.style.color = 'maroon';
    }
  });
  /* Your CSS styles here */
  .store-container {
    text-align: left;
    display: flex;
    align-items: flex-start;
    margin-left: 0;
  }

  .store-hours {
    text-align: left;
    flex: 1;
  }

  .store-hours ul {
    list-style: none;
    padding: 0;
  }

  .banquet-container {
    background-color: #f7f7f7;
    padding: 20px;
    border: 2px solid maroon;
    width: 52%;
    margin-left: 40px;
  }

  .banquet-container h2 {
    color: maroon;
  }

  .banquet-container p {
    color: maroon;
  }

  #store-status {
    font-weight: bold;
  }

  @media (max-width: 768px) {
    .store-container {
      flex-direction: column;
    }
    .banquet-container {
      width: 100%;
      margin-left: 0;
    }
  }
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>

<div class="store-container">
  <div class="store-hours">
    <p><strong>Store Hours:</strong></p>
    <ul>
      <li><span class="day">Sunday:</span> 10:30 AM - 6:00 PM</li>
      <li><span class="day">Monday:</span> 11:00 AM - 10:00 PM</li>
      <li><span class="day">Tuesday:</span> 11:00 AM - 10:00 PM</li>
      <li><span class="day">Wednesday:</span> 11:00 AM - 10:00 PM</li>
      <li><span class="day">Thursday:</span> 11:00 AM - 10:00 PM</li>
      <li><span class="day">Friday:</span> 11:00 AM - 11:00 PM</li>
      <li><span class="day">Saturday:</span> 11:00 AM - 11:00 PM</li>
    </ul>
    <p><strong>Store Status:</strong> <span id="store-status"></span></p>
  </div>
  <div class="banquet-container">
    <h2>Banquet Room</h2>
    <p>Lock 9 is pleased to offer a banquet space perfectly suited for hosting class reunions. Whether you're reconnecting with old friends or reminiscing about the good times, our banquet facility provides an ideal setting to bring your classmates together. With its spacious layout, the space comfortably accommodates gatherings of varying sizes. Our dedicated team ensures your reunion is a memorable experience, handling everything from setup to catering with attention. Choose Lock 9's banquet space to create a warm and nostalgic atmosphere where cherished memories can be relived and new ones can be made.</p>
  </div>
</div>

</body>
</html>

i tried implementing php into the site and its not working

corn on the cob
  • 2,093
  • 3
  • 18
  • 29
  • Could it be related to timezones? – jabaa Aug 27 '23 at 21:22
  • thats what i thought but the php i have sets it to eastern time zone – Larkin Jarrett Aug 27 '23 at 21:23
  • i also set the html to eastern time – Larkin Jarrett Aug 27 '23 at 21:23
  • What exactly is the problem? You have hardcoded times in the HTML file and a JavaScript code. Do you have a problem with the JavaScript code? Could it be a problem with daylight saving time? – jabaa Aug 27 '23 at 21:29
  • okay so i have the code on the website and it is displaying the store is open, when the store is closed it is currently 6 pm and it still doesnt say closed. – Larkin Jarrett Aug 27 '23 at 22:08
  • Have you tried stepping line by line through the code with your debugger? – jabaa Aug 27 '23 at 22:09
  • no, ive tried setting thee close time to an hour before actually closing and still nothing – Larkin Jarrett Aug 27 '23 at 22:11
  • So, the next step is to start the code in your debugger and inspect the values. You can read [How to debug small programs](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) and [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) Check the value of `hour`. It's probably not, what you expect. The value is `18` at this moment and `hour >= 10.5 && hour <= 18` returns `true`. Or `hour <= 18` should be `hour < 18`. – jabaa Aug 27 '23 at 22:17
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Aug 29 '23 at 01:10

0 Answers0