mirror of
https://github.com/khairul169/home-lab.git
synced 2025-04-28 08:39:34 +07:00
16 lines
596 B
TypeScript
16 lines
596 B
TypeScript
export const formatBytes = (bytes: number) => {
|
|
const sizes = ["Bytes", "KB", "MB", "GB", "TB"];
|
|
if (bytes === 0) return "n/a";
|
|
const i = parseInt(String(Math.floor(Math.log(bytes) / Math.log(1024))), 10);
|
|
if (i === 0) return `${bytes} ${sizes[i]}`;
|
|
return `${(bytes / 1024 ** i).toFixed(2)} ${sizes[i]}`;
|
|
};
|
|
|
|
export const secondsToTime = (seconds: number) => {
|
|
const d = Math.floor(seconds / (3600 * 24));
|
|
const h = Math.floor((seconds % (3600 * 24)) / 3600);
|
|
const m = Math.floor((seconds % 3600) / 60);
|
|
// const s = Math.floor(seconds % 60);
|
|
return `${d}d ${h}h ${m}m`;
|
|
};
|