mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-05 22:07:10 -04:00
17 lines
484 B
TypeScript
17 lines
484 B
TypeScript
![]() |
import { formatDuration } from 'date-fns';
|
||
|
|
||
|
export function formatMsDuration(duration: number) {
|
||
|
const ms = Math.floor(duration % 1000);
|
||
|
const secs = Math.floor(((duration - ms) / 1000) % 60);
|
||
|
const mins = Math.floor((((duration - ms) / 1000 - secs) / 60) % 60);
|
||
|
const hrs = Math.floor((((duration - ms) / 1000 - secs) / 60 - mins) / 60);
|
||
|
|
||
|
return (
|
||
|
formatDuration({
|
||
|
hours: hrs,
|
||
|
minutes: mins,
|
||
|
seconds: secs,
|
||
|
}) + (ms > 0 ? ` ${ms} ms` : '')
|
||
|
);
|
||
|
}
|