2023-12-30 05:29:53 +00:00
|
|
|
import { format } from 'date-fns';
|
|
|
|
|
2024-10-27 21:51:04 +00:00
|
|
|
export function formatDuration(rawDuration, forceHours) {
|
|
|
|
const duration = Number(rawDuration);
|
|
|
|
|
|
|
|
if (Number.isNaN(duration)) {
|
|
|
|
return rawDuration;
|
2024-10-08 19:30:55 +00:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|