Skip to content

Commit 947b2e7

Browse files
committed
refactor load function to improve start date calculation based on interval
1 parent 07e15aa commit 947b2e7

File tree

1 file changed

+14
-13
lines changed
  • src/routes/team/[team]/[env]/app/[app]/utilization2

1 file changed

+14
-13
lines changed

src/routes/team/[team]/[env]/app/[app]/utilization2/+page.ts

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
import { load_ResourceUtilizationForApp2 } from '$houdini';
22
import type { PageLoad } from './$houdini';
33

4-
export const ssr = false;
5-
export const load: PageLoad = async (event) => {
6-
const interval = event.url.searchParams.get('interval');
7-
const end = new Date(Date.now());
8-
let start = new Date(Date.now() - 7 * 24 * 1000 * 60 * 60);
4+
function getStart(interval: string | null) {
95
switch (interval) {
106
case '1h':
11-
start = new Date(Date.now() - 1000 * 60 * 60);
12-
break;
7+
return new Date(Date.now() - 1000 * 60 * 60);
138
case '6h':
14-
start = new Date(Date.now() - 6 * 1000 * 60 * 60);
15-
break;
9+
return new Date(Date.now() - 6 * 1000 * 60 * 60);
1610
case '1d':
17-
start = new Date(Date.now() - 24 * 1000 * 60 * 60);
18-
break;
11+
return new Date(Date.now() - 24 * 1000 * 60 * 60);
1912
case '30d':
20-
start = new Date(Date.now() - 30 * 24 * 1000 * 60 * 60);
21-
break;
13+
return new Date(Date.now() - 30 * 24 * 1000 * 60 * 60);
14+
default:
15+
return new Date(Date.now() - 7 * 24 * 1000 * 60 * 60);
2216
}
17+
}
18+
19+
export const ssr = false;
20+
export const load: PageLoad = async (event) => {
21+
const interval = event.url.searchParams.get('interval');
22+
const end = new Date(Date.now());
23+
const start = getStart(interval);
2324

2425
return {
2526
interval,

0 commit comments

Comments
 (0)