MCPcopy Create free account
hub / github.com/freeCodeCamp/freeCodeCamp / formatSecondsToTime

Function formatSecondsToTime

client/src/utils/format-seconds.ts:1–15  ·  view source on GitHub ↗
(s: number)

Source from the content-addressed store, hash-verified

1export function formatSecondsToTime(s: number) {
2 const hourInSeconds = 60 * 60;
3 const minuteInSeconds = 60;
4 const h = Math.floor(s / hourInSeconds);
5 s -= h * hourInSeconds;
6
7 const minutes = Math.floor(s / minuteInSeconds);
8 s -= minutes * minuteInSeconds;
9
10 const mm = minutes < 10 && h >= 1 ? `0${minutes}` : minutes;
11 const seconds = s % 60;
12 const ss = seconds < 10 ? `0${seconds}` : seconds;
13
14 return h > 0 ? `${h}:${mm}:${ss}` : `${mm}:${ss}`;
15}

Callers 3

ExamResultsModalFunction · 0.90
ShowExamFunction · 0.90
ExamResultsFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected