19 lines
696 B
TypeScript
19 lines
696 B
TypeScript
export function formatTime(seconds: number): string {
|
|
const hrs = Math.floor(seconds / 3600);
|
|
const mins = Math.floor((seconds % 3600) / 60);
|
|
const secs = Math.floor(seconds % 60);
|
|
|
|
if (hrs > 0) {
|
|
return `${hrs}:${String(mins).padStart(2, "0")}:${String(secs).padStart(2, "0")}`;
|
|
}
|
|
return `${mins}:${String(secs).padStart(2, "0")}`;
|
|
}
|
|
|
|
export function formatPace(distanceMeters: number, durationSeconds: number): string {
|
|
if (distanceMeters === 0) return "--:--";
|
|
const paceSeconds = (durationSeconds / distanceMeters) * 100;
|
|
const mins = Math.floor(paceSeconds / 60);
|
|
const secs = Math.floor(paceSeconds % 60);
|
|
return `${mins}:${String(secs).padStart(2, "0")}/100m`;
|
|
}
|