Skip to content

Commit

Permalink
Merge pull request #19 from joola/feature/JARVIS-418
Browse files Browse the repository at this point in the history
JARVIS-418 Minor fixes applied to the intToTime function to accomodate negative values
  • Loading branch information
orjoola committed Nov 3, 2013
2 parents cc54cef + 6ce15ad commit a45f6e9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/joolaio.string.js
Expand Up @@ -128,18 +128,24 @@ joolaio.string.shortenNumber = function (n) {
}

joolaio.string.intToTime = function (TimeInSeconds) {

var negative = false;
if (TimeInSeconds < 0) {
negative = true;
TimeInSeconds = Math.abs(TimeInSeconds);
}
var sHours = (Math.round(((TimeInSeconds / 60.0) / 60) - 0.5, 0)).toString();
var sMinutes = (Math.round((TimeInSeconds / 60.0) - 0.5, 0) % 60).toString();
var sSeconds = parseInt((TimeInSeconds % 60)).toString();

if (sHours.length == 1)
sHours = '0' + sHours;
if (sMinutes.length == 1)
sMinutes = '0' + sMinutes;
if (sSeconds.length == 1)
sSeconds = '0' + sSeconds;

return sHours + ':' + sMinutes + ':' + sSeconds;
if (!negative)
return sHours + ':' + sMinutes + ':' + sSeconds;
else
return '-' + sHours + ':' + sMinutes + ':' + sSeconds;

}

0 comments on commit a45f6e9

Please sign in to comment.