@prana-w/btw
Version:
btw_cli (btw: by-the-W) is a simple and powerful Command Line Interface (CLI) designed to help you perform various useful tasks directly from your terminal.
26 lines (22 loc) • 669 B
JavaScript
// Takes a time in milliseconds and converts it to the largest possible unit (seconds, minutes, or hours).
export default function convertTime(timeInMilliseconds) {
let time = timeInMilliseconds;
let unit = 'milliseconds';
// Conversion to required units
if (time >= 1000) {
time /= 1000; // Convert milliseconds to seconds
unit = 'seconds';
}
if (time >= 60) {
time /= 60; // Convert seconds to minutes
unit = 'minutes';
}
if (time >= 60) {
time /= 60; // Convert minutes to hours
unit = 'hours';
}
return {
convertedTime: time.toFixed(2),
unit: unit,
};
}