mirror of
https://github.com/streamyfin/streamyfin.git
synced 2025-08-20 18:37:18 +02:00
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
/**
|
|
* Converts ticks to a formatted string of hours and minutes.
|
|
* Assumes that ticks are in milliseconds.
|
|
*
|
|
* @param ticks The number of milliseconds.
|
|
* @returns A string formatted as "Xh Ym" where X is hours and Y is minutes.
|
|
*/
|
|
export const runtimeTicksToMinutes = (
|
|
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);
|
|
|
|
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`;
|
|
};
|