Files
Jyotisha/frontend/src/lib/session-shanghai-clock.ts
T
jesse-ux e4e73f56c0
Independent Staging Quality Gate / publish (push) Canceled after 0s
Independent Staging Quality Gate / validate (push) Canceled after 9m33s
fix(web): 四个页面共用一份会话列表,空会话不入列
对话、星盘、星历、报告进同一 (app) 外壳,列表只拉一次。服务端不再列出空咨询;新建复用已有空会话。新标题改成「生时校正 · M月D日」,侧栏副标题用创建时间。
2026-09-17 21:27:40 +08:00

42 lines
1.2 KiB
TypeScript

/** Product UI dates for session titles and subtitles are wall-clock in China. */
export const SESSION_CLOCK_TIMEZONE = "Asia/Shanghai";
function part(
parts: Intl.DateTimeFormatPart[],
type: Intl.DateTimeFormatPartTypes,
): string {
return parts.find((item) => item.type === type)?.value ?? "";
}
export function shanghaiDateParts(at: Date, timeZone = SESSION_CLOCK_TIMEZONE): {
month: number;
day: number;
} {
const parts = new Intl.DateTimeFormat("en-US", {
timeZone,
month: "numeric",
day: "numeric",
}).formatToParts(at);
return {
month: Number(part(parts, "month")),
day: Number(part(parts, "day")),
};
}
export function shanghaiDateTimeLabel(at: Date, timeZone = SESSION_CLOCK_TIMEZONE): string {
const parts = new Intl.DateTimeFormat("en-US", {
timeZone,
month: "numeric",
day: "numeric",
hour: "2-digit",
minute: "2-digit",
hourCycle: "h23",
}).formatToParts(at);
const month = Number(part(parts, "month"));
const day = Number(part(parts, "day"));
const hour = part(parts, "hour").padStart(2, "0");
const minute = part(parts, "minute").padStart(2, "0");
return `${month}月${day}日 ${hour}:${minute}`;
}