File tree 1 file changed +15
-3
lines changed
site/src/pages/TemplatePage/TemplateInsightsPage
1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,14 @@ import {
25
25
useId ,
26
26
} from "react" ;
27
27
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" ;
29
36
import { useSearchParams } from "react-router-dom" ;
30
37
import "react-date-range/dist/styles.css" ;
31
38
import "react-date-range/dist/theme/default.css" ;
@@ -146,9 +153,14 @@ const getDateRange = (
146
153
}
147
154
148
155
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 ( ) ;
149
160
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 ) ,
152
164
} ;
153
165
}
154
166
You can’t perform that action at this time.
0 commit comments