# HG changeset patch # User hamidouk # Date 1321455978 -3600 # Node ID 8e1181b855bdc0c607f6b59d3b9c70de70652544 # Parent af3adcf7cb205b1034a5ce0402d0b71e5efd300e 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. diff -r af3adcf7cb20 -r 8e1181b855bd src/js/utils.js --- 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] */ diff -r af3adcf7cb20 -r 8e1181b855bd unittests/tests/utils.js --- 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;