format peak time frame properly
Some checks failed
Publish Docker Image / docker (push) Has been cancelled
Some checks failed
Publish Docker Image / docker (push) Has been cancelled
This commit is contained in:
28
lib/utils/timeUtils.js
Normal file
28
lib/utils/timeUtils.js
Normal file
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Formats a time in milliseconds to a human readable format
|
||||
* eg: 1000ms -> 1s or 60000ms -> 1m
|
||||
*
|
||||
* @param ms the time in milliseconds
|
||||
* @returns the formatted time
|
||||
*/
|
||||
function formatMsToTime(ms) {
|
||||
// this is really fucking shitty but it works!
|
||||
const seconds = Math.floor(ms / 1000);
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const days = Math.floor(hours / 24);
|
||||
|
||||
if (days > 0) {
|
||||
return `${days}d`;
|
||||
} else if (hours > 0) {
|
||||
return `${hours}h`;
|
||||
} else if (minutes > 0) {
|
||||
return `${minutes}m`;
|
||||
} else {
|
||||
return `${seconds}s`;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
formatMsToTime,
|
||||
};
|
Reference in New Issue
Block a user