From 8ba2632c23dac3c4aa0b51b852c0bd48badb3a80 Mon Sep 17 00:00:00 2001 From: Ykrej Date: Fri, 20 Jun 2025 12:30:18 -0700 Subject: [PATCH] feat: added warranty rendering of months --- src/routes/components/ServerPartsGrid.svelte | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/routes/components/ServerPartsGrid.svelte b/src/routes/components/ServerPartsGrid.svelte index c2631ab..55860ae 100644 --- a/src/routes/components/ServerPartsGrid.svelte +++ b/src/routes/components/ServerPartsGrid.svelte @@ -53,17 +53,22 @@ }, { field: 'warrantyDays', - headerName: 'Warranty Duration', + headerName: 'Warranty', valueFormatter: ({ data }: { data: ServerPartsRecord }) => { if (!Number.isFinite(data.warrantyDays)) return 'NaN' - const totalDays = Math.floor(data.warrantyDays) - const years = Math.floor(totalDays / 365) - const days = totalDays % 365 + let remainingDays = Math.floor(data.warrantyDays) + const years = Math.floor(remainingDays / 365) + remainingDays = remainingDays % 365 + + const months = Math.floor(remainingDays / 30) + remainingDays = remainingDays % 30 let text = '' if (years > 0) text += `${years} Year${years > 1 ? 's' : ''}` - if (days > 0) text += ` ${days} Day${days > 1 ? 's' : ''}` + if (months > 0) text += ` ${months} Month${months > 1 ? 's' : ''}` + if (remainingDays > 0) + text += ` ${remainingDays} Day${remainingDays > 1 ? 's' : ''}` text = text.trim()