MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / getDatesFromRange

Function getDatesFromRange

packages/db/src/services/date.service.ts:15–235  ·  view source on GitHub ↗
(range: IChartRange, timezone: string)

Source from the content-addressed store, hash-verified

13}
14
15export function getDatesFromRange(range: IChartRange, timezone: string) {
16 if (range === '30min' || range === 'lastHour') {
17 const minutes = range === '30min' ? 30 : 60;
18 const startDate = DateTime.now()
19 .minus({ minute: minutes })
20 .startOf('minute')
21 .setZone(timezone)
22 .toFormat('yyyy-MM-dd HH:mm:ss');
23 const endDate = DateTime.now()
24 .setZone(timezone)
25 .endOf('minute')
26 .toFormat('yyyy-MM-dd HH:mm:ss');
27
28 return {
29 startDate,
30 endDate,
31 };
32 }
33
34 if (range === 'last24h') {
35 const startDate = DateTime.now()
36 .minus({ hour: 24 })
37 .startOf('minute')
38 .setZone(timezone)
39 .toFormat('yyyy-MM-dd HH:mm:ss');
40 const endDate = DateTime.now()
41 .setZone(timezone)
42 .endOf('minute')
43 .toFormat('yyyy-MM-dd HH:mm:ss');
44
45 return {
46 startDate,
47 endDate,
48 };
49 }
50
51 if (range === 'today') {
52 const startDate = DateTime.now()
53 .setZone(timezone)
54 .startOf('day')
55 .toFormat('yyyy-MM-dd HH:mm:ss');
56 const endDate = DateTime.now()
57 .setZone(timezone)
58 .endOf('day')
59 .toFormat('yyyy-MM-dd HH:mm:ss');
60
61 return {
62 startDate,
63 endDate,
64 };
65 }
66
67 if (range === 'yesterday') {
68 const startDate = DateTime.now()
69 .minus({ day: 1 })
70 .setZone(timezone)
71 .startOf('day')
72 .toFormat('yyyy-MM-dd HH:mm:ss');

Callers 3

resolveRangeFunction · 0.90
resolveDateRangeFunction · 0.90
getChartStartEndDateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected