Skip to content

Commit a20ec66

Browse files
authored
fix(site): use correct default insights time for day interval (#10837)
1 parent 89c13c2 commit a20ec66

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

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

+15-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ import {
2525
useId,
2626
} from "react";
2727
import chroma from "chroma-js";
28-
import { subDays, addWeeks, format } from "date-fns";
28+
import {
29+
subDays,
30+
addWeeks,
31+
format,
32+
startOfDay,
33+
startOfHour,
34+
addHours,
35+
} from "date-fns";
2936
import { useSearchParams } from "react-router-dom";
3037
import "react-date-range/dist/styles.css";
3138
import "react-date-range/dist/theme/default.css";
@@ -146,9 +153,14 @@ const getDateRange = (
146153
}
147154

148155
if (interval === "day") {
156+
// Only instantiate new Date once so that we don't get the wrong interval if
157+
// start is 23:59:59.999 and the clock shifts to 00:00:00 before the second
158+
// instantiation.
159+
const today = new Date();
149160
return {
150-
startDate: subDays(new Date(), 6),
151-
endDate: new Date(),
161+
startDate: startOfDay(subDays(today, 6)),
162+
// Add one hour to endDate to include real-time data for today.
163+
endDate: addHours(startOfHour(today), 1),
152164
};
153165
}
154166

0 commit comments

Comments
 (0)