lbry-desktop/ui/util/formatMediaDuration.js
Tobias Speicher 21af8f4f28 refactor: replace deprecated String.prototype.substr()
.substr() is deprecated so we replace it with .slice() which works similarily but isn't deprecated

Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
2022-03-23 12:12:44 -04:00

24 lines
564 B
JavaScript

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);
let timeString = date.toISOString().slice(11, 19);
if (timeString.startsWith('00:')) {
timeString = timeString.slice(3);
}
return timeString;
}