From c16fd97eb821e6badd2a2f11370a71eef175afd9 Mon Sep 17 00:00:00 2001 From: wuyangfan Date: Tue, 26 May 2026 09:41:18 +0800 Subject: [PATCH] perf: precompute time unit constants Replace runtime multiplication chains with literal millisecond values for each unit constant. Fixes #271 --- src/index.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index d50e3c7..9b77a3f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,10 @@ const s = 1000; -const m = s * 60; -const h = m * 60; -const d = h * 24; -const w = d * 7; -const y = d * 365.25; -const mo = y / 12; +const m = 60_000; +const h = 3_600_000; +const d = 86_400_000; +const w = 604_800_000; +const y = 31_557_600_000; +const mo = 2_629_800_000; type Years = 'years' | 'year' | 'yrs' | 'yr' | 'y'; type Months = 'months' | 'month' | 'mo';