v1 review pass: fixed some minor bugs
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user