From 1e90254d0a6d0589e2e8263b700f5ff4e372e488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Sun, 4 Oct 2026 15:57:22 +0800 Subject: [PATCH] =?UTF-8?q?perf(=E6=B3=A5=E7=82=B9):=20=E5=A4=8D=E7=94=A8?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E7=BA=A7=20Intl.DateTimeFormat=20=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=8C=96=E5=88=B7=E6=96=B0=E6=97=B6=E5=88=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - formatMudPointResetAt 原先每次调用都新建 Intl.DateTimeFormat,而它跑在多个渲染路径里 - locale / 时区 / 字段恒定,提升为模块级常量 MUD_POINT_RESET_FORMATTER 复用,输出不变 --- packages/shared/src/utils/mudPoints.ts | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/shared/src/utils/mudPoints.ts b/packages/shared/src/utils/mudPoints.ts index d65ec3ba3..080bdfbd8 100644 --- a/packages/shared/src/utils/mudPoints.ts +++ b/packages/shared/src/utils/mudPoints.ts @@ -64,6 +64,22 @@ export function shouldShowProfileDailyFreePool( ); } +/** + * 月度泥点刷新时刻的格式化器:locale / 时区 / 字段固定,提到模块级复用。 + * + * 固定 `Asia/Shanghai` 与 ADR「会员账期按开通日自然月」一致;`hourCycle: 'h23'` 避免 + * 午夜格式化成 24 点。该 formatter 会在多个渲染路径里被反复调用,构建一次即可。 + */ +const MUD_POINT_RESET_FORMATTER = new Intl.DateTimeFormat('en-CA', { + timeZone: 'Asia/Shanghai', + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit', + hourCycle: 'h23', +}); + /** * 月度泥点的刷新时刻展示文案。 * @@ -80,15 +96,7 @@ export function formatMudPointResetAt( if (Number.isNaN(parsed.getTime())) { return null; } - const parts = new Intl.DateTimeFormat('en-CA', { - timeZone: 'Asia/Shanghai', - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - hourCycle: 'h23', - }).formatToParts(parsed); + const parts = MUD_POINT_RESET_FORMATTER.formatToParts(parsed); const lookup = (type: Intl.DateTimeFormatPartTypes) => parts.find((part) => part.type === type)?.value ?? '00'; return `${lookup('year')}-${lookup('month')}-${lookup('day')} ${lookup('hour')}:${lookup(