vibe coded v1
This commit is contained in:
5
src/utils/format.ts
Normal file
5
src/utils/format.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export function formatBytes(bytes: number): string {
|
||||
if (bytes < 1024) return `${bytes} B`;
|
||||
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
||||
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
||||
}
|
||||
14
src/utils/relativeTime.ts
Normal file
14
src/utils/relativeTime.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" });
|
||||
|
||||
export function relativeTime(dateStr: string): string {
|
||||
const diff = new Date(dateStr).getTime() - Date.now(); // negative = past
|
||||
const abs = Math.abs(diff) / 1000;
|
||||
|
||||
if (abs < 60) return rtf.format(-Math.round(abs), "second");
|
||||
if (abs < 3600) return rtf.format(-Math.round(abs / 60), "minute");
|
||||
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");
|
||||
return rtf.format(-Math.round(abs / 365 / 86400), "year");
|
||||
}
|
||||
Reference in New Issue
Block a user