Fixes some logic to runtime calculations format

This commit is contained in:
CrissZollo 2025-10-04 12:52:02 +02:00
parent 89416bd714
commit 64c2129b1d

View file

@ -98,11 +98,35 @@ const MetadataDetails: React.FC<MetadataDetailsProps> = ({
}));
function formatRuntime(runtime: string): string {
// Match formats like "1h55min" or "2h 7min" and convert to "1H 55M" or "2H 7M"
// Try to match formats like "1h55min", "2h 7min", "125 min", etc.
const match = runtime.match(/(?:(\d+)\s*h\s*)?(\d+)\s*min/i);
if (match) {
const h = match[1] ? parseInt(match[1], 10) : 0;
const m = match[2] ? parseInt(match[2], 10) : 0;
if (h > 0) {
return `${h}H ${m}M`;
}
if (m < 60) {
return `${m} MIN`;
}
const hours = Math.floor(m / 60);
const mins = m % 60;
return hours > 0 ? `${hours}H ${mins}M` : `${mins} MIN`;
}
// Fallback: treat as minutes if it's a number
const r = parseInt(runtime, 10);
if (isNaN(r) || r < 60) return runtime;
const h = Math.floor(r / 60);
const m = r % 60;
return `${h}H ${m}MIN`;
if (!isNaN(r)) {
if (r < 60) return `${r} MIN`;
const h = Math.floor(r / 60);
const m = r % 60;
return h > 0 ? `${h}H ${m}M` : `${m} MIN`;
}
// If not matched, return as is
return runtime;
}
return (