Skip to content

Commit afc2850

Browse files
authored
fix: apply user timeZone for Event Trends on /insights (calcom#21787)
1 parent e6497c8 commit afc2850

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

packages/features/insights/server/events.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ class EventsInsights {
8080
whereConditional: Prisma.BookingTimeStatusDenormalizedWhereInput,
8181
startDate: Dayjs,
8282
endDate: Dayjs,
83-
dateRanges: DateRange[]
83+
dateRanges: DateRange[],
84+
timeZone: string
8485
): Promise<AggregateResult> => {
8586
const formattedStartDate = dayjs(startDate).format("YYYY-MM-DD HH:mm:ss");
8687
const formattedEndDate = dayjs(endDate).format("YYYY-MM-DD HH:mm:ss");
@@ -96,14 +97,14 @@ class EventsInsights {
9697
}[]
9798
>`
9899
SELECT
99-
DATE("createdAt") as "date",
100+
"date",
100101
CAST(COUNT(*) AS INTEGER) AS "bookingsCount",
101102
CAST(COUNT(CASE WHEN "isNoShowGuest" = true THEN 1 END) AS INTEGER) AS "noShowGuests",
102103
"timeStatus",
103104
"noShowHost"
104105
FROM (
105106
SELECT
106-
"createdAt",
107+
DATE("createdAt" AT TIME ZONE ${timeZone}) as "date",
107108
"a"."noShow" AS "isNoShowGuest",
108109
"timeStatus",
109110
"noShowHost"
@@ -116,7 +117,7 @@ class EventsInsights {
116117
AND ${Prisma.raw(whereClause)}
117118
) AS bookings
118119
GROUP BY
119-
DATE("createdAt"),
120+
"date",
120121
"timeStatus",
121122
"noShowHost"
122123
ORDER BY

packages/features/insights/server/trpc-router.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,8 @@ export const insightsRouter = router({
489489
whereConditional,
490490
dayjs(startDate),
491491
dayjs(endDate),
492-
dateRanges
492+
dateRanges,
493+
ctx.user.timeZone
493494
);
494495

495496
const result = dateRanges.map(({ formattedDate }) => {

0 commit comments

Comments
 (0)