fixed the conversion function to accomodate mustache. popcorn-port
authorhamidouk
Wed, 16 Nov 2011 12:28:18 +0100
branchpopcorn-port
changeset 254 cafaa694b709
parent 253 95c6b77f005e
child 255 af3adcf7cb20
fixed the conversion function to accomodate mustache.
src/js/utils.js
unittests/tests/utils.js
--- a/src/js/utils.js	Wed Nov 16 11:40:57 2011 +0100
+++ b/src/js/utils.js	Wed Nov 16 12:28:18 2011 +0100
@@ -34,12 +34,12 @@
 /* convert a number of seconds to a tuple of the form 
    [hours, minutes, seconds]
 */
-IriSP.secondsToTime = function(secs) {
+IriSP.secondsToTime = function(secs) {  
   var hours = Math.abs(parseInt( secs / 3600 ) % 24);
   var minutes = Math.abs(parseInt( secs / 60 ) % 60);
-  var seconds = Math.abs(secs % 60);
+  var seconds = parseFloat(Math.abs(secs % 60).toFixed(0));
   
-  return [hours, minutes, seconds];
+  return {"hours" : hours, "minutes" : minutes, "seconds" : seconds};
 }
 /* for ie compatibility
 if (Object.prototype.__defineGetter__&&!Object.defineProperty) {
--- a/unittests/tests/utils.js	Wed Nov 16 11:40:57 2011 +0100
+++ b/unittests/tests/utils.js	Wed Nov 16 12:28:18 2011 +0100
@@ -27,9 +27,10 @@
   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;
-    deepEqual(IriSP.secondsToTime(t), [h, m, s], "the converted time is correct");
+    deepEqual(IriSP.secondsToTime(t), {"hours" : h, "minutes" : m, "seconds" : s}, 
+              "the converted time is correct");
     
     t = -t;
-    deepEqual(IriSP.secondsToTime(t), [h, m, s], "the function is immune to negative numbers.");
+    deepEqual(IriSP.secondsToTime(t),  {"hours" : h, "minutes" : m, "seconds" : s}, "the function is immune to negative numbers.");
   });
 }
\ No newline at end of file