From a0184df7b2c7689451b7690b1fb5c0cae70919f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E4=BA=91=E9=BE=99?= <76432572+nankingjing@users.noreply.github.com> Date: Sat, 11 Jul 2026 19:46:22 +0800 Subject: [PATCH] fix(rollup): compute ISO week from UTC calendar fields --- src/rollup.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/rollup.ts b/src/rollup.ts index bcefdd0..766a830 100644 --- a/src/rollup.ts +++ b/src/rollup.ts @@ -51,8 +51,11 @@ function readWeeklyDigest(date: string): string | null { /** Format a date as ISO week string, e.g. "2026-W10". */ function toWeekStr(date: Date): string { - // ISO week: week containing the first Thursday of the year - const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate())); + // ISO week: week containing the first Thursday of the year. + // Read the calendar date via UTC getters: callers pass a CST timestamp whose + // UTC fields hold the intended CST date, so local getters would shift the day + // (and thus the week/year) whenever the process runs outside UTC. + const d = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate())); d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7)); const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1)); const week = Math.ceil(((d.getTime() - yearStart.getTime()) / 86400000 + 1) / 7);