// create a human readable string like 01:23:45 from the given time in sec
// - optionally adds decimals: 01:23:45.67
// - strips empty hours 00:12:34 --> 12:34
export const timeToString = (time, decimals) => {
    const hours = Math.floor(time / 3600);
    time -= hours * 3600;
    const minutes = Math.floor(time / 60);
    time -= minutes * 60;
    const seconds = Math.floor(time);
    time -= seconds;

    return (
        // optional hours
        (hours ? ('0' + hours).substr(-2) + ':' : '') +
        // minutes
        ('0' + minutes).substr(-2) +
        ':' +
        // seconds
        ('0' + seconds).substr(-2) +
        // optionally 2 decimals
        (decimals
            ? '.' + (Math.round(time * 100) / 100 + '000').substr(2, 2)
            : '')
    );
};
