Should be mostly working, doing some additional QOL

This commit is contained in:
gamer147
2025-11-30 23:00:40 -05:00
parent 8d6f0d6cfd
commit b2f4548807
24 changed files with 839 additions and 73 deletions

View File

@@ -0,0 +1,23 @@
import { formatDistanceToNow, format, differenceInDays } from 'date-fns';
/**
* Formats a date as relative time (e.g., "2 hours ago") if within 7 days,
* otherwise returns an absolute date (e.g., "Mar 15").
*/
export function formatRelativeTime(date: Date | string): string {
const d = typeof date === 'string' ? new Date(date) : date;
const daysDiff = differenceInDays(new Date(), d);
if (daysDiff <= 7) {
return formatDistanceToNow(d, { addSuffix: true });
}
return format(d, 'MMM d');
}
/**
* Formats a date as an absolute timestamp (e.g., "Mar 15, 2024, 3:30 PM").
*/
export function formatAbsoluteTime(date: Date | string): string {
const d = typeof date === 'string' ? new Date(date) : date;
return format(d, 'PPpp');
}