2023-02-23 00:19:10 +00:00
|
|
|
function section(t: number) {
|
|
|
|
|
if (t < 10) return `0${t}`;
|
|
|
|
|
return t;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-06 15:25:34 +00:00
|
|
|
export function secondsToTimestamp(seconds: number, force_hours = false) {
|
2023-02-23 00:19:10 +00:00
|
|
|
const hh = Math.floor(seconds / 3600);
|
|
|
|
|
const hh_remainder = seconds % 3600;
|
|
|
|
|
const mm = Math.floor(hh_remainder / 60);
|
|
|
|
|
const mm_remainder = hh_remainder % 60;
|
|
|
|
|
const ss = Math.floor(mm_remainder);
|
|
|
|
|
|
2023-03-06 15:25:34 +00:00
|
|
|
const hrs = force_hours || hh > 0 ? `${section(hh)}:` : '';
|
2023-02-23 00:19:10 +00:00
|
|
|
const mins = mm ? `${section(mm)}:` : '00:';
|
|
|
|
|
const secs = ss ? `${section(ss)}` : '00';
|
|
|
|
|
|
|
|
|
|
return `${hrs}${mins}${secs}`;
|
|
|
|
|
}
|