Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 1x 1x 3x 4x 4x | import { computed, type Ref } from 'vue';
export function useFormattedTime(seconds: Ref<number>) {
return computed(() => {
const totalSeconds = seconds.value;
const hrs = Math.floor(totalSeconds / 3600);
const mins = Math.floor((totalSeconds % 3600) / 60);
const secs = totalSeconds % 60;
const padded = (n: number) => String(n).padStart(2, '0');
const secsFormatted = Number.isInteger(secs) ? padded(secs) : (secs < 10 ? '0' : '') + secs.toFixed(1);
if (hrs > 0) {
return `${padded(hrs)}:${padded(mins)}:${secsFormatted}`;
}
return `${padded(mins)}:${secsFormatted}`;
});
}
|