You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

23 lines
633 B

/**
* prettyTime returns a human-friendly time representation from milliseconds.
* @param {number} ms
* @returns {(string)[]}
*/
export function prettyTime(ms) {
const seconds = (ms / 1000).toFixed(1)
const minutes = (ms / (1000 * 60)).toFixed(1)
const hours = (ms / (1000 * 60 * 60)).toFixed(1)
const days = (ms / (1000 * 60 * 60 * 24)).toFixed(1)
if (ms < 1000) {
return [ms, 'Milliseconds']
} else if (seconds < 60) {
return [seconds, 'Seconds']
} else if (minutes < 60) {
return [minutes, 'Minutes']
} else if (hours < 24) {
return [hours, 'Hours']
} else {
return [days, 'Days']
}
}