perf(泥点): 复用模块级 Intl.DateTimeFormat 格式化刷新时刻
- formatMudPointResetAt 原先每次调用都新建 Intl.DateTimeFormat,而它跑在多个渲染路径里 - locale / 时区 / 字段恒定,提升为模块级常量 MUD_POINT_RESET_FORMATTER 复用,输出不变
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user