Skip to content

Commit e190bf3

Browse files
fix: Drill down date range selection
1 parent 849e6a9 commit e190bf3

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

frontend/src/composables/useAnalytics.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ export function useAnalytics({
144144
window.open(`/${row.route}`, "_blank");
145145
};
146146

147+
const formatDateToString = (date: Date): string => {
148+
const year = date.getFullYear();
149+
const month = String(date.getMonth() + 1).padStart(2, "0");
150+
const day = String(date.getDate()).padStart(2, "0");
151+
return `${year}-${month}-${day}`;
152+
};
153+
147154
const getDateRangeFromPreset = (preset: string): CustomDateRange => {
148155
const toDate = new Date();
149156
const fromDate = new Date();
@@ -182,8 +189,8 @@ export function useAnalytics({
182189
}
183190

184191
return {
185-
from_date: fromDate.toISOString().split("T")[0],
186-
to_date: toDate.toISOString().split("T")[0],
192+
from_date: formatDateToString(fromDate),
193+
to_date: formatDateToString(toDate),
187194
};
188195
};
189196

@@ -263,16 +270,16 @@ export function useAnalytics({
263270
let newInterval: string;
264271

265272
if (currentInterval === "monthly") {
266-
newFromDate = new Date(clickedDate.getFullYear(), clickedDate.getMonth(), 1)
267-
.toISOString()
268-
.split("T")[0];
269-
newToDate = new Date(clickedDate.getFullYear(), clickedDate.getMonth() + 1, 0)
270-
.toISOString()
271-
.split("T")[0];
273+
const firstDayOfMonth = new Date(clickedDate.getFullYear(), clickedDate.getMonth(), 1);
274+
const lastDayOfMonth = new Date(clickedDate.getFullYear(), clickedDate.getMonth() + 1, 0);
275+
276+
newFromDate = formatDateToString(firstDayOfMonth);
277+
newToDate = formatDateToString(lastDayOfMonth);
272278
newInterval = "daily";
273279
} else if (currentInterval === "daily") {
274-
newFromDate = clickedDate.toISOString().split("T")[0];
275-
newToDate = clickedDate.toISOString().split("T")[0];
280+
const exactDate = new Date(clickedDate.getFullYear(), clickedDate.getMonth(), clickedDate.getDate());
281+
newFromDate = formatDateToString(exactDate);
282+
newToDate = formatDateToString(exactDate);
276283
newInterval = "hourly";
277284
} else {
278285
return;

0 commit comments

Comments
 (0)