From 73beffe36b8515fff16286a6698fff909b29392b Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Thu, 7 Nov 2024 18:37:29 +0100 Subject: [PATCH] update analyst forecast --- .../stocks/[tickerID]/forecast/+page.svelte | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/routes/stocks/[tickerID]/forecast/+page.svelte b/src/routes/stocks/[tickerID]/forecast/+page.svelte index e49a9d94..95406989 100644 --- a/src/routes/stocks/[tickerID]/forecast/+page.svelte +++ b/src/routes/stocks/[tickerID]/forecast/+page.svelte @@ -431,6 +431,25 @@ let optionsData = getPlotOptions() || null; let optionsPieChart = getPieChart() || null; let optionsPriceForecast = getPriceForecastChart() || null; + + function latestInfoDate(inputDate) { + // Convert the input date string to milliseconds since epoch + const inputDateMs = Date?.parse(inputDate); + + // Get today's date in milliseconds since epoch + const todayMs = Date?.now(); + + // Calculate the difference in milliseconds + const differenceInMs = todayMs - inputDateMs; + + // Convert milliseconds to days + const differenceInDays = Math?.floor( + differenceInMs / (1000 * 60 * 60 * 24), + ); + + // Return the difference in days + return differenceInDays <= 1; + } @@ -586,9 +605,20 @@ class="flex flex-col justify-between p-1 lg:max-w-[32%] text-white" >
-

Latest Analyst Report

+
+

Latest Analyst Report

+ {#if latestInfoDate(data?.getAnalystInsight?.date)} + + {/if} +
{#if Object?.keys(data?.getAnalystInsight)?.length > 0}

{data?.getAnalystInsight?.insight}

+

+ Updated {data?.getAnalystInsight?.date} +

{:else}

According to {numOfAnalyst} stock analyst, the rating for {$displayCompanyName}