aboutsummaryrefslogtreecommitdiff
path: root/src/tools/chronometer/chronometer.service.ts
blob: 62fb8195aa234139ebabc0bcc592348705d19ef7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
export function formatMs(msTotal: number) {
  const ms = msTotal % 1000;
  const secs = ((msTotal - ms) / 1000) % 60;
  const mins = (((msTotal - ms) / 1000 - secs) / 60) % 60;
  const hrs = (((msTotal - ms) / 1000 - secs) / 60 - mins) / 60;
  const hrsString = hrs > 0 ? `${hrs.toString().padStart(2, '0')}:` : '';

  return `${hrsString}${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}.${ms
    .toString()
    .padStart(3, '0')}`;
}