mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-29 07:21:16 -07:00
Fix: ensure correct relative dates formatter uses calendar days (#7174)
Docker CI / Docker Build & Push (push) Has been cancelled
Lint / Linting Checks (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Release Drafter / Auto Label PR (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled
Docker CI / Docker Build & Push (push) Has been cancelled
Lint / Linting Checks (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Release Drafter / Auto Label PR (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled
This commit is contained in:
@@ -106,6 +106,12 @@ function relativeDate(date, formatter) {
|
||||
const unitIndex = cutoffs.findIndex((cutoff) => cutoff > Math.abs(delta));
|
||||
const divisor = unitIndex ? cutoffs[unitIndex - 1] : 1;
|
||||
|
||||
if (units[unitIndex] === "day") {
|
||||
// compare calendar days, not elapsed 24h blocks
|
||||
const startOfDay = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate());
|
||||
return formatter.format(Math.round((startOfDay(date) - startOfDay(new Date())) / 86400000), "day");
|
||||
}
|
||||
|
||||
return formatter.format(Math.floor(delta / divisor), units[unitIndex]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user