24 lines
683 B
JavaScript
24 lines
683 B
JavaScript
import { format } from 'date-fns';
|
|
|
|
export function formatDuration(duration, forceHours) {
|
|
if (typeof duration !== 'number') {
|
|
return duration;
|
|
}
|
|
|
|
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);
|
|
}
|