Skip to content

Commit

Permalink
Do not display negative time
Browse files Browse the repository at this point in the history
  • Loading branch information
jforbes committed Nov 17, 2015
1 parent d9b5fbc commit 1556bfb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/js/utils/format-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* @function formatTime
*/
function formatTime(seconds, guide=seconds) {
seconds = seconds < 0 ? 0 : seconds;
let s = Math.floor(seconds % 60);
let m = Math.floor(seconds / 60 % 60);
let h = Math.floor(seconds / 3600);
Expand Down
4 changes: 4 additions & 0 deletions test/unit/utils/format-time.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ test('should format time as a string', function(){
// Don't do extra leading zeros for hours
ok(formatTime(1,36000) === '0:00:01');
ok(formatTime(1,360000) === '0:00:01');

// Do not display negative time
ok(formatTime(-1) === '0:00');
ok(formatTime(-1,3600) === '0:00:00');
});

test('should format invalid times as dashes', function(){
Expand Down

0 comments on commit 1556bfb

Please sign in to comment.