mirror of
https://github.com/DocNR/POWR.git
synced 2025-04-19 19:01:18 +00:00
25 lines
691 B
TypeScript
25 lines
691 B
TypeScript
// utils/formatTime.ts
|
|
/**
|
|
* Format milliseconds into MM:SS format
|
|
*/
|
|
export function formatTime(ms: number): string {
|
|
const totalSeconds = Math.floor(ms / 1000);
|
|
const minutes = Math.floor(totalSeconds / 60);
|
|
const seconds = totalSeconds % 60;
|
|
return `${minutes}:${seconds.toString().padStart(2, '0')}`;
|
|
}
|
|
|
|
/**
|
|
* Format milliseconds into a human-readable duration (e.g., "1h 30m")
|
|
*/
|
|
export function formatDuration(ms: number): string {
|
|
const totalSeconds = Math.floor(ms / 1000);
|
|
const hours = Math.floor(totalSeconds / 3600);
|
|
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
|
|
|
if (hours > 0) {
|
|
return `${hours}h ${minutes}m`;
|
|
}
|
|
return `${minutes}m`;
|
|
}
|