1
0
mirror of https://github.com/videojs/video.js.git synced 2025-11-29 23:07:51 +02:00

feat(format time): add setFormatTime for overriding the time format (#4962)

Add setFormatTime for Video.js to allow users to change the time format. Example usage:

```js
videojs.setFormatTime((seconds, guide) => `${seconds}, ${guide}`));
```

Add resetFormatTime to reset the time format to the default.

Fixes #2931
This commit is contained in:
twosmalltrees
2018-03-08 06:37:10 +11:00
committed by Gary Katsevman
parent 62ff3f66a5
commit 2f96914b8e
3 changed files with 67 additions and 7 deletions

View File

@@ -1,7 +1,9 @@
/* eslint-env qunit */
import formatTime from '../../../src/js/utils/format-time.js';
import formatTime, { setFormatTime, resetFormatTime } from '../../../src/js/utils/format-time.js';
QUnit.module('format-time');
QUnit.module('format-time standard implementation', {
afterEach: resetFormatTime()
});
QUnit.test('should format time as a string', function(assert) {
assert.ok(formatTime(1) === '0:01');
@@ -33,3 +35,16 @@ QUnit.test('should format invalid times as dashes', function(assert) {
assert.equal(formatTime(10, Infinity), '0:00:10');
assert.equal(formatTime(90, NaN), '1:30');
});
QUnit.test('setFormatTime', function(assert) {
setFormatTime((seconds, guide) => `custom:${seconds}:${guide}`);
assert.equal(formatTime(1, 2), 'custom:1:2', 'it should replace the default formatTime implementation');
});
QUnit.test('resetFormatTime ', function(assert) {
setFormatTime((seconds, guide) => `custom:${seconds}:${guide}`);
assert.equal(formatTime(1, 2), 'custom:1:2');
resetFormatTime();
assert.equal(formatTime(1), '0:01', 'it should reset formatTime to the default implementation');
});