JSFiddle - React, Tailwind, and code Playground
HTML
<div id="deliveryTimer">
<span id="countdownTimer">Just checking the time...</span>
</div>
JavaScript
var timerRunning = setInterval(
function countDown() {
var target = 14.5; // This is the cut-off point
var now = new Date();
//Put this in a variable for convenience
var weekday = now.getDay();
var despatchday = 'TODAY!';
if(weekday == 0){//Sunday? Add 24hrs
target += 24;
despatchday='on Monday';
}//keep this before the saturday, trust me :>
if(weekday == 6){//It's Saturday? Add 48hrs
target += 48;
despatchday='on Monday';
}
if((weekday == 5) && (now.getHours() > target) && (now.getHours() <= 24) ){
target += 72;
despatchday='on Monday';
}
//If between Monday and Friday,
//check if we're past the target hours,
//and if we are, abort.
if((weekday>=1 ) && (weekday<=5)){
if ((now.getHours() > target) && (now.getHours() <= 24)) { //stop the clock
target += 24;
despatchday = 'tomorrow';
}else if (now.getHours() > target) { //stop the clock
return 0;
despatchday = 'today';
}
}
var hrs = (target) - now.getHours();
if (hrs < 0) hrs = 0;
var mins = 59 - now.getMinutes();
if (mins < 0) mins = 0;
var secs = 59 - now.getSeconds();
if (secs < 0) secs = 0;
var str ='Order in the next ' + hrs + 'hrs ' + mins + 'mins ' + secs + 'secs for despatch ' + despatchday;
document.getElementById('countdownTimer').innerHTML = str;
}, 1000
);