Skip to content

Commit c5f88fe

Browse files
committed
fix: use UTC arithmetic for sparkline bucket keys to avoid timezone mismatches with ClickHouse
1 parent 410e397 commit c5f88fe

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

apps/webapp/app/presenters/v3/PromptPresenter.server.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,19 @@ export class PromptPresenter extends BasePresenter {
124124
return {};
125125
}
126126

127-
// Build a map of slug -> 24 hourly buckets
127+
// Build a map of slug -> 24 hourly buckets (use UTC to match ClickHouse)
128128
const now = new Date();
129-
const startHour = new Date(now);
130-
startHour.setMinutes(0, 0, 0);
131-
startHour.setHours(startHour.getHours() - 23);
129+
const startHour = new Date(Date.UTC(
130+
now.getUTCFullYear(),
131+
now.getUTCMonth(),
132+
now.getUTCDate(),
133+
now.getUTCHours() - 23,
134+
0, 0, 0
135+
));
132136

133137
const bucketKeys: string[] = [];
134138
for (let i = 0; i < 24; i++) {
135-
const h = new Date(startHour);
136-
h.setHours(h.getHours() + i);
139+
const h = new Date(startHour.getTime() + i * 3600_000);
137140
// Format to match ClickHouse's toStartOfHour output: "YYYY-MM-DD HH:MM:SS"
138141
bucketKeys.push(
139142
h.toISOString().slice(0, 13).replace("T", " ") + ":00:00"

0 commit comments

Comments
 (0)