Skip to content

Commit 52799e4

Browse files
CopilotRavelloH
andcommitted
fix: correct timezone-dependent SQL comparisons and email template timezone display
Co-authored-by: RavelloH <68409330+RavelloH@users.noreply.github.com>
1 parent a0eb1d9 commit 52799e4

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

apps/web/src/emails/templates/PasswordSet.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function PasswordSetTemplate({
5656

5757
{setAt && (
5858
<EmailParagraph>
59-
设置时间:{new Date(setAt).toLocaleString("zh-CN")}
59+
设置时间:{new Date(setAt).toLocaleString("zh-CN", { timeZone: "UTC" })} (UTC)
6060
</EmailParagraph>
6161
)}
6262

apps/web/src/emails/templates/SSOLinked.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function SSOLinkedTemplate({
6565

6666
{linkedAt && (
6767
<EmailParagraph>
68-
绑定时间:{new Date(linkedAt).toLocaleString("zh-CN")}
68+
绑定时间:{new Date(linkedAt).toLocaleString("zh-CN", { timeZone: "UTC" })} (UTC)
6969
</EmailParagraph>
7070
)}
7171

apps/web/src/emails/templates/SSOUnlinked.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function SSOUnlinkedTemplate({
6565

6666
{unlinkedAt && (
6767
<EmailParagraph>
68-
解绑时间:{new Date(unlinkedAt).toLocaleString("zh-CN")}
68+
解绑时间:{new Date(unlinkedAt).toLocaleString("zh-CN", { timeZone: "UTC" })} (UTC)
6969
</EmailParagraph>
7070
)}
7171

apps/web/src/lib/server/analytics-cron-report.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ async function collectRangeStats(
283283
COUNT(*)::bigint AS total_views,
284284
COUNT(DISTINCT "visitorId")::bigint AS unique_visitors
285285
FROM "PageView"
286-
WHERE "timestamp" >= (${startTs}::timestamp AT TIME ZONE ${timezone})
287-
AND "timestamp" < (${endTs}::timestamp AT TIME ZONE ${timezone})
286+
WHERE "timestamp" >= ((${startTs}::timestamp AT TIME ZONE ${timezone}) AT TIME ZONE 'UTC')
287+
AND "timestamp" < ((${endTs}::timestamp AT TIME ZONE ${timezone}) AT TIME ZONE 'UTC')
288288
AND ("deviceType" IS NULL OR "deviceType" <> 'bot')
289289
`;
290290

@@ -324,16 +324,16 @@ async function collectRangeStats(
324324
prisma.$queryRaw<Array<{ path: string; count: bigint }>>`
325325
SELECT "path", COUNT(*)::bigint AS count
326326
FROM "PageView"
327-
WHERE "timestamp" >= (${startTs}::timestamp AT TIME ZONE ${timezone})
328-
AND "timestamp" < (${endTs}::timestamp AT TIME ZONE ${timezone})
327+
WHERE "timestamp" >= ((${startTs}::timestamp AT TIME ZONE ${timezone}) AT TIME ZONE 'UTC')
328+
AND "timestamp" < ((${endTs}::timestamp AT TIME ZONE ${timezone}) AT TIME ZONE 'UTC')
329329
AND ("deviceType" IS NULL OR "deviceType" <> 'bot')
330330
GROUP BY "path"
331331
`,
332332
prisma.$queryRaw<Array<{ referer: string | null; count: bigint }>>`
333333
SELECT "referer", COUNT(*)::bigint AS count
334334
FROM "PageView"
335-
WHERE "timestamp" >= (${startTs}::timestamp AT TIME ZONE ${timezone})
336-
AND "timestamp" < (${endTs}::timestamp AT TIME ZONE ${timezone})
335+
WHERE "timestamp" >= ((${startTs}::timestamp AT TIME ZONE ${timezone}) AT TIME ZONE 'UTC')
336+
AND "timestamp" < ((${endTs}::timestamp AT TIME ZONE ${timezone}) AT TIME ZONE 'UTC')
337337
AND ("deviceType" IS NULL OR "deviceType" <> 'bot')
338338
GROUP BY "referer"
339339
`,

0 commit comments

Comments
 (0)