From 4771caf2042eea52fd5f5c878c5e0b280634c0c6 Mon Sep 17 00:00:00 2001 From: Mary <148872143+mary-ext@users.noreply.github.com> Date: Sat, 24 Feb 2024 03:38:14 +0700 Subject: [PATCH] Normalize relative day (#2874) * fix: normalize relative date * chore: add comments * refactor: skip flooring normalized diff * refactor: let -> const * fix: get own copy of date to prevent mutating * refactor: rounding does the same trick --- src/lib/strings/time.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/strings/time.ts b/src/lib/strings/time.ts index 05a60e94..3e162af1 100644 --- a/src/lib/strings/time.ts +++ b/src/lib/strings/time.ts @@ -23,7 +23,7 @@ export function ago(date: number | string | Date): string { } else if (diffSeconds < DAY) { return `${Math.floor(diffSeconds / HOUR)}h` } else if (diffSeconds < MONTH) { - return `${Math.floor(diffSeconds / DAY)}d` + return `${Math.round(diffSeconds / DAY)}d` } else if (diffSeconds < YEAR) { return `${Math.floor(diffSeconds / MONTH)}mo` } else {