PDA

View Full Version : Universal Countdown : 2-digit minimum?



jyeager
01-05-2010, 04:14 PM
1) Script Title:
Universal Countdown

2) Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex6/universalcountdown.htm

3) Describe problem:

Would it be possible to ensure that the Hours, Minutes and Seconds (only) fields always be 2 digits? In other words, "01" instead of "1". This is not important for the days, because the days can be 1, 2 or 3 digits... but since the hours, minutes and seconds can never be more than 2 digits -- and most often ARE 2 digits -- it would be helpful for those 3 specific fields.

The reason is that when 10 seconds becomes 9 seconds, everything moves. When 10 minutes becomes 9 minutes, same thing.

Just having 10 become 09 instead of 9 would make everything look a lot better, and behave more professionally (I find).

BONUS: If we can change the color of the "0" that gets added to the single digit, that would be even better (we could make it slightly darker, for a nice effect).

But just having 01, 02, 03 instead of 1, 2, 3 would be a great help.

thanks!

jscheuer1
01-05-2010, 04:32 PM
This would best be done in the format results function used. For example, in the one for the LCD display:


//2) Display countdown with a stylish LCD look, and display an alert on target date/time
function formatresults2(){
if (this.timesup==false){ //if target date/time not yet met
function pad(n){
return n - 0 < 10? '<span class="darker">0<\/span>' + n : n;
}
var displaystring="<span class='lcdstyle'>"+arguments[0]+" <sup>days</sup> "+pad(arguments[1])+" <sup>hours</sup> "+pad(arguments[2])+" <sup>minutes</sup> "+pad(arguments[3])+" <sup>seconds</sup></span> left until launch time"
}
else{ //else if target date/time met
var displaystring="" //Don't display any text
alert("Launch time!") //Instead, perform a custom alert
}
return displaystring
}

Now (to make the added zero actually darker) you could put in your style section a rule something like so:


.darker {
color: #0b0;
}

jyeager
01-05-2010, 05:13 PM
Awesome! :-)

(Another satisfied customer!) :D