20 lines
623 B
JavaScript
20 lines
623 B
JavaScript
|
import { format } from 'date-fns';
|
||
|
|
||
|
export function formatDuration(duration, forceHours) {
|
||
|
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);
|
||
|
}
|