2023-12-30 05:29:53 +00:00
|
|
|
import { format } from 'date-fns';
|
|
|
|
|
|
|
|
export function formatDuration(duration, forceHours) {
|
2024-10-08 19:30:55 +00:00
|
|
|
if (typeof duration !== 'number') {
|
|
|
|
return duration;
|
|
|
|
}
|
|
|
|
|
2023-12-30 05:29:53 +00:00
|
|
|
const hours = Math.floor(duration / 3600);
|
|
|
|
const minutes = Math.floor((duration % 3600) / 60);
|
|
|
|
const seconds = Math.floor(duration % 60);
|
|
|
|
|
|
|
|
const [formattedHours, formattedMinutes, formattedSeconds] = [hours, minutes, seconds].map((segment) => segment.toString().padStart(2, '0'));
|
|
|
|
|
|
|
|
if (duration >= 3600 || forceHours) {
|
|
|
|
return `${formattedHours}:${formattedMinutes}:${formattedSeconds}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return `${formattedMinutes}:${formattedSeconds}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function formatDate(date, template) {
|
|
|
|
return format(date, template);
|
|
|
|
}
|