JavaScript shipping timer countdown -



JavaScript shipping timer countdown -

i have next javascript on site shows amount of time left order placed next day delivery.

if (document.getelementbyid('countdowntimer')) { pad = function(n, len) { // leading 0's var s = n.tostring(); homecoming (new array((len - s.length + 1)).join('0')) + s; }; var timerrunning = setinterval( function countdown() { var = new date(); if ((now.getday() >= 1) && (now.getday() <= 5)) { // mon fri var target = 15; // 15:00hrs cut-off point if (now.gethours() < target) { // don't if we're past cut-off point var hrs = (target - 1) - 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 = pad(hrs, 2) + ':' + pad(mins, 2) + '.<small>' + pad(secs, 2) + '</small>'; document.getelementbyid('countdowntimer').innerhtml = str; } } }, 1000 ); }

the problem on saturday , sunday displays 00:00:00 time. count hours on weekend done on site example: http://www.nakedwines.com/full_site

javascript not area , i'm totally @ loss on how can alter code this. help appreciated.

fiddle here http://jsfiddle.net/rwet0o5f/

i've moved now.getday() variable , should much more readable.

weekday contains 0 on sunday, 1 on mon , 6 on saturday. on saturday add together 48 hours time of deadline, on sunday add together 24 hours.

http://jsfiddle.net/37ox54bk/7/

if (document.getelementbyid('countdowntimer')) { pad = function(n, len) { // leading 0's var s = n.tostring(); homecoming (new array( (len - s.length + 1) ).join('0')) + s; }; var timerrunning = setinterval( function countdown() { var target = 15; // 15:00hrs cut-off point var = new date(); //put in variable convenience var weekday = now.getday(); if(weekday == 0){//sunday? add together 24hrs target += 24; } if(weekday == 6){//it's saturday? add together 48hrs target += 48; } //if between mon , friday, //check if we're past target hours, //and if are, abort. if((weekday>=1) && (weekday<=5)){ if (now.gethours() > target) { //stop clock homecoming 0; } } var hrs = (target - 1) - 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 = pad(hrs, 2) + ':' + pad(mins, 2) + '.<small>' + pad(secs, 2) + '</small>'; document.getelementbyid('countdowntimer').innerhtml = str; }, 1000 ); }

javascript

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -