mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-28 18:36:23 +02:00
feat: implement relative date formatting for last indexed timestamps in connector views
This commit is contained in:
parent
59dd9554b3
commit
ca7e45405c
3 changed files with 33 additions and 48 deletions
25
surfsense_web/lib/format-date.ts
Normal file
25
surfsense_web/lib/format-date.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { differenceInDays, differenceInMinutes, format, isToday, isYesterday } from "date-fns";
|
||||
|
||||
/**
|
||||
* Format a date string as a human-readable relative time
|
||||
* - < 1 min: "Just now"
|
||||
* - < 60 min: "15m ago"
|
||||
* - Today: "Today, 2:30 PM"
|
||||
* - Yesterday: "Yesterday, 2:30 PM"
|
||||
* - < 7 days: "3d ago"
|
||||
* - Older: "Jan 15, 2026"
|
||||
*/
|
||||
export function formatRelativeDate(dateString: string): string {
|
||||
const date = new Date(dateString);
|
||||
const now = new Date();
|
||||
const minutesAgo = differenceInMinutes(now, date);
|
||||
const daysAgo = differenceInDays(now, date);
|
||||
|
||||
if (minutesAgo < 1) return "Just now";
|
||||
if (minutesAgo < 60) return `${minutesAgo}m ago`;
|
||||
if (isToday(date)) return `Today, ${format(date, "h:mm a")}`;
|
||||
if (isYesterday(date)) return `Yesterday, ${format(date, "h:mm a")}`;
|
||||
if (daysAgo < 7) return `${daysAgo}d ago`;
|
||||
return format(date, "MMM d, yyyy");
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue