diff --git a/src/routes/options-flow/+page.svelte b/src/routes/options-flow/+page.svelte index d6031c69..4e13dc77 100644 --- a/src/routes/options-flow/+page.svelte +++ b/src/routes/options-flow/+page.svelte @@ -373,10 +373,14 @@ function handleViewData(optionData) { previousCallVolume = displayCallVolume ?? 0; if(mode === true) { try { - const newData = JSON.parse(event.data); + let newData = JSON.parse(event.data); if(rawData?.length !== newData?.length) { newIncomingData = true; } + newData = newData?.forEach((item) => { + item.dte = daysLeft(item?.date_expiration); + }); + rawData = [...newData]; if(ruleOfList?.length !== 0 || filterQuery?.length !== 0) { @@ -404,11 +408,25 @@ function handleViewData(optionData) { } } + +function daysLeft(targetDate) { + const targetTime = new Date(targetDate).getTime(); + const currentTime = new Date().getTime(); + const difference = targetTime - currentTime; + + const millisecondsPerDay = 1000 * 60 * 60 * 24; + const daysLeft = Math?.ceil(difference / millisecondsPerDay); + + return daysLeft; +} onMount(async () => { audio = new Audio(notifySound); rawData = data?.getOptionsFlowFeed; + rawData?.forEach((item) => { + item.dte = daysLeft(item?.date_expiration); + }); displayedData = rawData; calculateStats(rawData); @@ -1049,17 +1067,18 @@ $: {