From fc268cd180624ecace357f062c4cfb44bed332d8 Mon Sep 17 00:00:00 2001 From: redfast00 Date: Tue, 10 Dec 2024 10:15:38 +0100 Subject: [PATCH] vinvoor: fix #114 timezone offset --- vinvoor/src/overview/heatmap/Day.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/vinvoor/src/overview/heatmap/Day.tsx b/vinvoor/src/overview/heatmap/Day.tsx index df596e6..1b096b8 100644 --- a/vinvoor/src/overview/heatmap/Day.tsx +++ b/vinvoor/src/overview/heatmap/Day.tsx @@ -95,10 +95,11 @@ export const Day: FC = ({ {isDayVariant(variant) ? Array.from({ length: DAYS_IN_WEEK }, (_, cidx) => { - const currentDate = new Date( - data.start.getTime() - + MILLISECONDS_IN_DAY * (idx * DAYS_IN_WEEK + cidx), - ); + const currentDate = new Date(data.start); + // This is a timezone safe way to add 1 day (see https://stackoverflow.com/questions/563406/how-to-add-days-to-date) + // The new date is guaranteed to have the same hour and minute value + // (in our case, already normalized to 0) + currentDate.setDate(currentDate.getDate() + (idx * DAYS_IN_WEEK + cidx)); if (currentDate.getTime() < startDate.getTime()) return null;