/** 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}`; }