From b2d68fba5f9d8eb144ef4a05561808be82222afb Mon Sep 17 00:00:00 2001 From: Yang Jun Date: Sun, 10 May 2026 13:01:49 +0800 Subject: [PATCH] refactor(strftime): simplify %N width parsing logic Use regex-backed width assumptions to simplify %N width normalization and padding memory accounting while keeping behavior equivalent. Co-authored-by: Cursor --- src/util/strftime.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/util/strftime.ts b/src/util/strftime.ts index 36fa9d370..f1fe0dcfb 100644 --- a/src/util/strftime.ts +++ b/src/util/strftime.ts @@ -98,11 +98,9 @@ const formatCodes: Record unknow m: (d: LiquidDate) => d.getMonth() + 1, M: (d: LiquidDate) => d.getMinutes(), N: (d: LiquidDate, opts: FormatOptions) => { - let width = Number(opts.width) || 9 - if (!Number.isFinite(width) || width < 0) width = 9 - if (width > MAX_STRFTIME_PAD) width = MAX_STRFTIME_PAD + const width = Math.min(Number(opts.width) || 9, MAX_STRFTIME_PAD) const str = String(d.getMilliseconds()).slice(0, width) - opts.memoryLimit?.use(Math.max(0, width - str.length)) + opts.memoryLimit?.use(width - str.length) return padEnd(str, width, '0') }, p: (d: LiquidDate) => (d.getHours() < 12 ? 'AM' : 'PM'),