feat: formatting function

This commit is contained in:
Fredrik Burmester
2024-08-15 21:08:03 +02:00
parent e9182dc4ca
commit d0baf56fd8

View File

@@ -6,7 +6,7 @@
* @returns A string formatted as "Xh Ym" where X is hours and Y is minutes.
*/
export const runtimeTicksToMinutes = (
ticks: number | null | undefined
ticks: number | null | undefined,
): string => {
if (!ticks) return "0h 0m";
@@ -18,3 +18,19 @@ export const runtimeTicksToMinutes = (
return `${hours}h ${minutes}m`;
};
export const runtimeTicksToSeconds = (
ticks: number | null | undefined,
): string => {
if (!ticks) return "0h 0m";
const ticksPerMinute = 600000000;
const ticksPerHour = 36000000000;
const hours = Math.floor(ticks / ticksPerHour);
const minutes = Math.floor((ticks % ticksPerHour) / ticksPerMinute);
const seconds = Math.floor((ticks % ticksPerMinute) / 10000000);
if (hours > 0) return `${hours}h ${minutes}m ${seconds}s`;
else return `${minutes}m ${seconds}s`;
};