# HG changeset patch # User hamidouk # Date 1321438852 -3600 # Node ID fd84e0fb26d89ec54c9855028b368052c4383274 # Parent 116c86db7e174b6f565f2c1ce0018834256456b2 added a function to convert a number of seconds to an hour, minutes, seconds. diff -r 116c86db7e17 -r fd84e0fb26d8 src/js/utils.js --- a/src/js/utils.js Wed Nov 16 10:54:13 2011 +0100 +++ b/src/js/utils.js Wed Nov 16 11:20:52 2011 +0100 @@ -29,6 +29,16 @@ return Math.floor((time/timetotal) * 100); }; +/* convert a number of seconds to a tuple of the form + [hours, minutes, seconds] +*/ +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); + + return [hours, minutes, seconds]; +} /* for ie compatibility if (Object.prototype.__defineGetter__&&!Object.defineProperty) { Object.defineProperty=function(obj,prop,desc) { diff -r 116c86db7e17 -r fd84e0fb26d8 unittests/index.html --- a/unittests/index.html Wed Nov 16 10:54:13 2011 +0100 +++ b/unittests/index.html Wed Nov 16 11:20:52 2011 +0100 @@ -27,11 +27,12 @@ - + + + + - - @@ -42,11 +43,12 @@ IriSP.jQuery = jQuery; test_dataloader(); - test_serializer(); + test_serializer(); test_mockSerializer(); test_mockTweetSerializer(); test_JSONSerializer(); test_serializerFactory(); + test_utils(); test_widget(); test_player_widget(); test_annotations_widget(); diff -r 116c86db7e17 -r fd84e0fb26d8 unittests/tests/utils.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/unittests/tests/utils.js Wed Nov 16 11:20:52 2011 +0100 @@ -0,0 +1,12 @@ +function test_utils() { + module("Utility function tests"); + + 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"); + + t = -t; + deepEqual(IriSP.secondsToTime(t), [h, m, s], "the function is immune to negative numbers."); + }); +} \ No newline at end of file