Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Fix timezone handling for current-day buckets (#973)

Perrschya5add65c0f98
diff --git a/server/src/api/analytics/getOverviewBucketed.ts b/server/src/api/analytics/getOverviewBucketed.ts
index a4ea7e5cc..d33c2ec60 100644
--- a/server/src/api/analytics/getOverviewBucketed.ts
+++ b/server/src/api/analytics/getOverviewBucketed.ts
@@ -20,7 +20,7 @@ function getTimeStatementFill(params: FilterParams, bucket: TimeBucket) {
)
TO if(
toDate(${SqlString.escape(end_date)}) = toDate(now(), ${SqlString.escape(time_zone)}),
- now(),
+ toTimeZone(now(), 'UTC'),
toTimeZone(
toDateTime(${TimeBucketToFn[validatedBucket]}(toDateTime(${SqlString.escape(end_date)}, ${SqlString.escape(
time_zone
diff --git a/server/src/api/analytics/performance/getPerformanceTimeSeries.ts b/server/src/api/analytics/performance/getPerformanceTimeSeries.ts
index d2ad891e0..220b72c1c 100644
--- a/server/src/api/analytics/performance/getPerformanceTimeSeries.ts
+++ b/server/src/api/analytics/performance/getPerformanceTimeSeries.ts
@@ -20,7 +20,7 @@ function getTimeStatementFill(params: FilterParams, bucket: TimeBucket) {
)
TO if(
toDate(${SqlString.escape(end_date)}) = toDate(now(), ${SqlString.escape(time_zone)}),
- now(),
+ toTimeZone(now(), 'UTC'),
toTimeZone(
toDateTime(${TimeBucketToFn[validatedBucket]}(toDateTime(${SqlString.escape(end_date)}, ${SqlString.escape(
time_zone
diff --git a/server/src/api/analytics/utils/utils.ts b/server/src/api/analytics/utils/utils.ts
index 10076a951..4fa8a1e48 100644
--- a/server/src/api/analytics/utils/utils.ts
+++ b/server/src/api/analytics/utils/utils.ts
@@ -38,7 +38,7 @@ export function getTimeStatement(
)
AND timestamp < if(
toDate(${SqlString.escape(end_date)}) = toDate(now(), ${SqlString.escape(time_zone)}),
- now(),
+ toTimeZone(now(), 'UTC'),
toTimeZone(
toStartOfDay(toDateTime(${SqlString.escape(end_date)}, ${SqlString.escape(time_zone)})) + INTERVAL 1 DAY,
'UTC'