mirror of
https://github.com/videojs/video.js.git
synced 2024-12-25 02:42:10 +02:00
@forbesjo updated formatTime to not go negative. closes #2821
This commit is contained in:
parent
b188781fa9
commit
8acd28c15a
@ -2,7 +2,7 @@ CHANGELOG
|
||||
=========
|
||||
|
||||
## HEAD (Unreleased)
|
||||
_(none)_
|
||||
* @forbesjo updated formatTime to not go negative ([view](https://github.com/videojs/video.js/pull/2821))
|
||||
|
||||
--------------------
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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(){
|
||||
|
Loading…
Reference in New Issue
Block a user