From 06cfd69ad2fa2f22adc2c41358309bbf5d0c9869 Mon Sep 17 00:00:00 2001 From: Topvennie Date: Thu, 5 Sep 2024 23:42:26 +0200 Subject: [PATCH] vinvoor: retain scan time --- vinvoor/src/overview/heatmap/Day.tsx | 2 +- vinvoor/src/overview/heatmap/utils.ts | 11 +++++++++-- vinvoor/src/overview/streak/Streak.tsx | 5 +++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/vinvoor/src/overview/heatmap/Day.tsx b/vinvoor/src/overview/heatmap/Day.tsx index 3582bef..4732712 100644 --- a/vinvoor/src/overview/heatmap/Day.tsx +++ b/vinvoor/src/overview/heatmap/Day.tsx @@ -39,7 +39,7 @@ export const Day: FC = ({ const data = useMemo(() => { const normalizedScans = [...scans]; - normalizedScans.forEach(scan => scan.scanTime.setHours(0, 0, 0, 0)); + // normalizedScans.forEach(scan => scan.scanTime.setHours(0, 0, 0, 0)); const formattedScans = formatData(normalizedScans); const start = new Date( diff --git a/vinvoor/src/overview/heatmap/utils.ts b/vinvoor/src/overview/heatmap/utils.ts index 12f915a..3084efb 100644 --- a/vinvoor/src/overview/heatmap/utils.ts +++ b/vinvoor/src/overview/heatmap/utils.ts @@ -28,11 +28,18 @@ export const getColumnCountMonths = (startDate: Date, endDate: Date) => { export const getMondayIndexedDay = (date: Date) => (date.getDay() + 6) % 7; +const getNormalizedTime = (date: Date) => { + const result = new Date(date); + result.setHours(0, 0, 0, 0); + return result; +}; + export const formatData = (scans: Scan[]) => { const result: Record = {}; scans.forEach(scan => { - result[scan.scanTime.getTime()] = { - date: scan.scanTime, + const date = getNormalizedTime(scan.scanTime); + result[date.getTime()] = { + date: date, count: 1, }; }); diff --git a/vinvoor/src/overview/streak/Streak.tsx b/vinvoor/src/overview/streak/Streak.tsx index 699f39b..c92f36c 100644 --- a/vinvoor/src/overview/streak/Streak.tsx +++ b/vinvoor/src/overview/streak/Streak.tsx @@ -29,8 +29,9 @@ const isStreakDay = (date1: Date, date2: Date) => { const getStreak = (scans: readonly Scan[]): [boolean, number] => { const dates = scans .map(scan => { - scan.scanTime.setHours(0, 0, 0, 0); - return scan.scanTime; + const date = new Date(scan.scanTime); + date.setHours(0, 0, 0, 0); + return date; }) .filter((value, index, array) => { return (