2021-07-16 01:12:11 +02:00
|
|
|
import moment from 'moment';
|
|
|
|
|
|
|
|
export default function formatMediaDuration(duration = 0, config) {
|
|
|
|
const options = {
|
|
|
|
screenReader: false,
|
|
|
|
...config,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Optimize for screen readers
|
|
|
|
if (options.screenReader) {
|
|
|
|
return moment.utc(moment.duration(duration, 'seconds').asMilliseconds()).format('HH:mm:ss');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Normal format
|
|
|
|
let date = new Date(null);
|
|
|
|
date.setSeconds(duration);
|
|
|
|
|
2022-03-22 08:38:46 +01:00
|
|
|
let timeString = date.toISOString().slice(11, 19);
|
2021-07-16 01:12:11 +02:00
|
|
|
if (timeString.startsWith('00:')) {
|
2022-03-22 08:38:46 +01:00
|
|
|
timeString = timeString.slice(3);
|
2021-07-16 01:12:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return timeString;
|
|
|
|
}
|