UNPKG

753 BJavaScriptView Raw
1const secondsToTime = require('./secondsToTime')
2
3module.exports = function prettyETA (seconds) {
4 const time = secondsToTime(seconds)
5
6 // Only display hours and minutes if they are greater than 0 but always
7 // display minutes if hours is being displayed
8 // Display a leading zero if the there is a preceding unit: 1m 05s, but 5s
9 const hoursStr = time.hours ? `${time.hours}h ` : ''
10 const minutesVal = time.hours ? (`0${time.minutes}`).substr(-2) : time.minutes
11 const minutesStr = minutesVal ? `${minutesVal}m` : ''
12 const secondsVal = minutesVal ? (`0${time.seconds}`).substr(-2) : time.seconds
13 const secondsStr = time.hours ? '' : (minutesVal ? ` ${secondsVal}s` : `${secondsVal}s`)
14
15 return `${hoursStr}${minutesStr}${secondsStr}`
16}