added a function to pad a number with zeros. waiting for the helpers to land into
the main mustache.js repo to use it in the number display.
--- a/src/js/utils.js Wed Nov 16 12:30:04 2011 +0100
+++ b/src/js/utils.js Wed Nov 16 16:06:18 2011 +0100
@@ -31,6 +31,13 @@
return Math.floor((time/timetotal) * 100);
};
+IriSP.padWithZeros = function(num) {
+ if (Math.abs(num) < 10) {
+ return "0" + num.toString();
+ } else {
+ return num.toString();
+ }
+};
/* convert a number of seconds to a tuple of the form
[hours, minutes, seconds]
*/
--- a/unittests/tests/utils.js Wed Nov 16 12:30:04 2011 +0100
+++ b/unittests/tests/utils.js Wed Nov 16 16:06:18 2011 +0100
@@ -24,6 +24,10 @@
equal(IriSP.timeToPourcent(2, 3), 66, "the function is immune to negative numbers");
});
+ test("test padding function", function() {
+ equal(IriSP.padWithZeros(3), "03", "function works correctly");
+ });
+
test("test function to convert from seconds to a time", function() {
var h = 13, m = 7, s = 41;
var t = 13 * 3600 + 7* 60 + 41;