- Move Video Block JS files from xmodule/js/src/video/ to xmodule/assets/video/public/js/ - Update JavaScript files from RequireJS to ES6 import/export - test: Enable and fix Karma Js tests for Video XBlock (#37351) --------- Co-authored-by: salmannawaz <salman.nawaz@arbisoft.com>
42 lines
1.0 KiB
JavaScript
42 lines
1.0 KiB
JavaScript
// eslint-disable-next-line no-shadow
|
|
export function format(time, formatFull) {
|
|
let hours, minutes, seconds;
|
|
|
|
if (!_.isFinite(time) || time < 0) {
|
|
time = 0;
|
|
}
|
|
|
|
seconds = Math.floor(time);
|
|
minutes = Math.floor(seconds / 60);
|
|
hours = Math.floor(minutes / 60);
|
|
seconds %= 60;
|
|
minutes %= 60;
|
|
|
|
if (formatFull) {
|
|
return '' + _pad(hours) + ':' + _pad(minutes) + ':' + _pad(seconds % 60);
|
|
} else if (hours) {
|
|
return '' + hours + ':' + _pad(minutes) + ':' + _pad(seconds % 60);
|
|
} else {
|
|
return '' + minutes + ':' + _pad(seconds % 60);
|
|
}
|
|
}
|
|
|
|
export function formatFull(time) {
|
|
// The returned value will not be user-facing. So no need for
|
|
// internationalization.
|
|
return format(time, true);
|
|
}
|
|
|
|
export function convert(time, oldSpeed, newSpeed) {
|
|
// eslint-disable-next-line no-mixed-operators
|
|
return (time * oldSpeed / newSpeed).toFixed(3);
|
|
}
|
|
|
|
export function _pad(number) {
|
|
if (number < 10) {
|
|
return '0' + number;
|
|
} else {
|
|
return '' + number;
|
|
}
|
|
}
|