-1

I'm new to this and have been piecing this together by finding code on line. I need to display the earliest delivery date based on the current date and time EST. Block out dates are Sunday and Monday. I have it working based on the local machine time zone however I need it to be based on EST only. The cutoff EST is 3pm so Pacific time the cutoff would be 12pm. I hope this makes sense. Here's the code that I have so far.

<i class="fa fa-calendar" aria-hidden="true"></i> Choose your delivery date at checkout.

<script src='//cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js'></script>

<script type="text/javascript">

var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
var seconds = currentTime.getSeconds()

</script>


<h4 class="delivery">Earliest Delivery Date: <span id="eDelivery" class="eDelivery"></span></h4>
<script>
  
  var eDelivery = Date.today().addDays(1);
      
  if(hours >= 15 && eDelivery.is().tuesday()){
    eDelivery = Date.today().addDays(2);
  }
  if(hours >= 15 && eDelivery.is().wednesday()){
    eDelivery = Date.today().addDays(2);
  } 
  if(hours >= 15 && eDelivery.is().thursday()){
    eDelivery = Date.today().addDays(2);
  } 
  if(hours >= 15 && eDelivery.is().friday()){
    eDelivery = Date.today().addDays(2);
  } 
  if(hours >= 15 && eDelivery.is().saturday()){
    eDelivery = Date.today().addDays(2);
  } 
  
  if (eDelivery.is().sunday() || eDelivery.is().monday()) { 
    eDelivery = eDelivery.next().tuesday();
  }
    
  document.getElementById('eDelivery').innerHTML = eDelivery.toString('dddd, MMMM dS');
</script>

Can someone please help me with the EST integration of this as well as let me know if there is any improvements I can make?

Much appreciated.

1 Answers1

0

JS native Date API is very outdated and complicated, take a look on http://momentjs.com, is the best date/time lib in JS IMO.

There are a lot of examples and docs out there.

Jean
  • 9
  • 2
  • This isn't an answer, it should be a comment. The built–in Date is very simple, it has a time value and some basic methods, that's it. – RobG May 27 '16 at 23:18