From eba9ce6c90e6ffe74a9c8ca8d19e28e31d4f5066 Mon Sep 17 00:00:00 2001 From: Darshan Date: Tue, 25 Mar 2025 12:02:27 +0530 Subject: [PATCH] updates: seconds logic, cleanup. --- src/lib/components/dualTimeView.svelte | 51 ++++++++++++++++---------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/src/lib/components/dualTimeView.svelte b/src/lib/components/dualTimeView.svelte index 0cd8ccac3..d56140537 100644 --- a/src/lib/components/dualTimeView.svelte +++ b/src/lib/components/dualTimeView.svelte @@ -24,12 +24,28 @@ { label: 'month', value: Math.floor(diffInSeconds / SECONDS_IN_MONTH) }, { label: 'day', value: Math.floor(diffInSeconds / SECONDS_IN_DAY) % 30 }, { label: 'hour', value: Math.floor(diffInSeconds / SECONDS_IN_HOUR) % 24 }, - { label: 'minute', value: Math.floor(diffInSeconds / SECONDS_IN_MINUTE) % 60 } + { label: 'minute', value: Math.floor(diffInSeconds / SECONDS_IN_MINUTE) % 60 }, + { label: 'second', value: diffInSeconds % 60 } ]; - const formattedTime = timeParts - .filter((unit) => unit.value > 0) - .slice(0, 3) + const month = timeParts[0].value; + const day = timeParts[1].value; + const hour = timeParts[2].value; + const second = timeParts[4].value; + + let outputParts: { label: string; value: number }[]; + + if (month === 0 && day === 0 && hour === 0 && second > 0) { + // Seconds exist but no months, days, hours — show minutes + seconds + outputParts = timeParts.slice(3).filter((unit) => unit.value > 0); + } else { + // Normal logic — top 3 non-zero units, no seconds. + outputParts = timeParts + .filter((unit) => unit.label !== 'second' && unit.value > 0) + .slice(0, 3); + } + + const formattedTime = outputParts .map((unit) => `${unit.value} ${unit.label}${unit.value > 1 ? 's' : ''}`) .join(', '); @@ -54,7 +70,7 @@ - @@ -77,26 +93,21 @@ -
- -
+
-
- -
- +