add ping command

This commit is contained in:
Darius
2025-09-29 00:11:55 +02:00
parent 10eee0c0fd
commit dbfb4f5d86
7 changed files with 108 additions and 23 deletions

View File

@@ -25,3 +25,33 @@ export async function promptForInput(prompt: string): Promise<string> {
});
});
}
export function calculateSecondsBetween(
start: number,
end: number,
): { seconds: number; toReadable: () => string } {
const seconds = (end - start) / 1000;
return {
seconds,
toReadable: () => secondsToReadable(seconds),
};
}
export function secondsToReadable(secs: number): string {
var days = Math.floor(secs / (3600 * 24));
var hours = Math.floor((secs % (3600 * 24)) / 3600);
var minutes = Math.floor((secs % 3600) / 60);
var seconds = Math.floor(secs % 60);
var dayDisplay = days > 0 ? days + (days === 1 ? " day, " : " days, ") : "";
var hourDisplay =
hours > 0 ? hours + (hours === 1 ? " hour, " : " hours, ") : "";
var minuteDisplay =
minutes > 0 ? minutes + (minutes === 1 ? " minute, " : " minutes, ") : "";
var secondDisplay =
seconds > 0 ? seconds + (seconds === 1 ? " second" : " seconds") : "";
return (dayDisplay + hourDisplay + minuteDisplay + secondDisplay).replace(
/,\s*$/,
"",
);
}