From 4d9857ce1875d042a1a1823477dc1b614f47cc87 Mon Sep 17 00:00:00 2001 From: apixandru Date: Wed, 7 Dec 2022 19:24:36 -0500 Subject: [PATCH] fix: update UsageHeatMap.tsx to account for daylight savings (#696) --- web/src/components/UsageHeatMap.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/web/src/components/UsageHeatMap.tsx b/web/src/components/UsageHeatMap.tsx index de77055f..50292c97 100644 --- a/web/src/components/UsageHeatMap.tsx +++ b/web/src/components/UsageHeatMap.tsx @@ -46,7 +46,11 @@ const UsageHeatMap = () => { for (const record of data) { const index = (utils.getDateStampByDate(record * 1000) - beginDayTimestamp) / (1000 * 3600 * 24) - 1; if (index >= 0) { - newStat[index].count += 1; + // because of dailight savings, some days may be 23 hours long instead of 24 hours long + // this causes the calculations to yield weird indices such as 40.93333333333 + // rounding them may not give you the exact day on the heat map, but it's not too bad + const exactIndex = +index.toFixed(0); + newStat[exactIndex].count += 1; } } setAllStat([...newStat]);