From 68b23f6998fec95042c0af33aa6b3670a45b8379 Mon Sep 17 00:00:00 2001 From: secondl1ght Date: Mon, 18 Dec 2023 22:29:37 -0700 Subject: [PATCH] handle edge case for ytd selection at beginning of year --- src/routes/dashboard/+page.svelte | 41 +++++++++++++++++-------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/routes/dashboard/+page.svelte b/src/routes/dashboard/+page.svelte index de501a06..57ad11fa 100644 --- a/src/routes/dashboard/+page.svelte +++ b/src/routes/dashboard/+page.svelte @@ -522,26 +522,29 @@ } else { const latestReport = statsSorted[statsSorted.length - 1]; const dateHistory = getChartHistoryDate(); + const reportIsCurrent = + today.getDate() === dateHistory.getDate() && + today.getMonth() === dateHistory.getMonth() && + today.getFullYear() === dateHistory.getFullYear(); + + statsFiltered.push({ + ...latestReport, + date: `${dateHistory.getFullYear()}-${ + dateHistory.getMonth() + 1 + }-${dateHistory.getDate()}`, + created_at: dateHistory.toISOString(), + updated_at: dateHistory.toISOString() + }); - statsFiltered.push( - ...[ - { - ...latestReport, - date: `${dateHistory.getFullYear()}-${ - dateHistory.getMonth() + 1 - }-${dateHistory.getDate()}`, - created_at: dateHistory.toISOString(), - updated_at: dateHistory.toISOString() - }, - { - ...latestReport, - id: latestReport.id + 1, - date: `${today.getFullYear()}-${today.getMonth() + 1}-${today.getDate()}`, - created_at: today.toISOString(), - updated_at: today.toISOString() - } - ] - ); + if (!reportIsCurrent) { + statsFiltered.push({ + ...latestReport, + id: latestReport.id + 1, + date: `${today.getFullYear()}-${today.getMonth() + 1}-${today.getDate()}`, + created_at: today.toISOString(), + updated_at: today.toISOString() + }); + } statsFiltered = statsFiltered; }