Skip to content

Instantly share code, notes, and snippets.

@lpirola
Created February 15, 2011 16:52
Show Gist options
  • Save lpirola/827790 to your computer and use it in GitHub Desktop.
Save lpirola/827790 to your computer and use it in GitHub Desktop.
/* INI: TIME REMAINS */
function restTime( YY , MM , DD , HH , MI, i ) {
var
SS = 00,
h = new Date(),
ff = new Date( YY , MM-1 , DD , HH , MI , SS ),
ss = parseInt( (ff - h) / 1000 ),
mm = parseInt( ss / 60 ),
hh = parseInt( mm / 60 ),
dd = parseInt( hh / 24 ),
ss = ss - ( mm * 60 ),
mm = mm - ( hh * 60 ),
hh = hh - ( dd * 24 );
var remainingTime = [];
remainingTime.push( ( dd && dd > 1 ) ? '<strong>' + dd + '</strong> dias, ' : ( dd == 1 ? '<strong>1</strong> dia, ' : '' ) );
remainingTime.push( ( toString(hh).length ) ? '<strong>' + hh + '</strong> horas e ' : '' );
remainingTime.push( ( toString(mm).length ) ? '<strong>' + mm + '</strong> minutos e ' : '' );
remainingTime.push( '<strong>' + ss + '</strong> segundos' );
if( dd + hh + mm + ss > 0 ){
$( '#restTime' + i ).html( 'Oferta encerra em ' + remainingTime.join('') );
setTimeout(function(){restTime( YY , MM , DD , HH , MI , i )},1000);
}else{
$( '#restTime' + i ).html( '<span class="noOffer">Esta Oferta não está mais Disponível</span>' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment