v1 review pass: fixed some minor bugs

This commit is contained in:
khannurien
2026-03-16 11:08:39 +00:00
parent e88fed4e98
commit 867e64cb5b
37 changed files with 1228 additions and 400 deletions

View File

@@ -1,7 +1,7 @@
const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" });
export function relativeTime(dateStr: string): string {
const diff = new Date(dateStr).getTime() - Date.now(); // negative = past
export function relativeTime(date: Date): string {
const diff = date.getTime() - Date.now(); // negative = past
const abs = Math.abs(diff) / 1000;
if (abs < 60) return rtf.format(-Math.round(abs), "second");
@@ -9,6 +9,8 @@ export function relativeTime(dateStr: string): string {
if (abs < 86400) return rtf.format(-Math.round(abs / 3600), "hour");
if (abs < 7 * 86400) return rtf.format(-Math.round(abs / 86400), "day");
if (abs < 30 * 86400) return rtf.format(-Math.round(abs / 7 / 86400), "week");
if (abs < 365 * 86400) return rtf.format(-Math.round(abs / 30 / 86400), "month");
if (abs < 365 * 86400) {
return rtf.format(-Math.round(abs / 30 / 86400), "month");
}
return rtf.format(-Math.round(abs / 365 / 86400), "year");
}