Skip to content

Commit 928ed56

Browse files
committed
fix(site): use correct insights start time when switching interavl to day
1 parent 89c13c2 commit 928ed56

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

site/src/pages/TemplatePage/TemplateInsightsPage/TemplateInsightsPage.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
useId,
2626
} from "react";
2727
import chroma from "chroma-js";
28-
import { subDays, addWeeks, format } from "date-fns";
28+
import { subDays, addWeeks, format, startOfDay } from "date-fns";
2929
import { useSearchParams } from "react-router-dom";
3030
import "react-date-range/dist/styles.css";
3131
import "react-date-range/dist/theme/default.css";
@@ -146,9 +146,13 @@ const getDateRange = (
146146
}
147147

148148
if (interval === "day") {
149+
// Only instantiate new Date once so that we don't get the wrong interval if
150+
// start is 23:59:59.999 and the clock shifts to 00:00:00 before the second
151+
// instantiation.
152+
const today = new Date();
149153
return {
150-
startDate: subDays(new Date(), 6),
151-
endDate: new Date(),
154+
startDate: startOfDay(subDays(today, 6)),
155+
endDate: today,
152156
};
153157
}
154158

0 commit comments

Comments
 (0)