export function getRelativeTimeString(dateString: string): string { const date = new Date(dateString); date.setHours(0, 0, 0, 0); const today = new Date(); today.setHours(0, 0, 0, 0); const diff = date.getTime() - today.getTime(); const unitDiff = Math.round(diff / (1000 * 60 * 60 * 24)); // Check if the date is more than one week old if (Math.abs(unitDiff) > 7) { return new Intl.DateTimeFormat(undefined, { day: "numeric", month: "long", }).format(date); } // Intl.RelativeTimeFormat for dates within the last week const rtf = new Intl.RelativeTimeFormat(undefined, { numeric: "auto" }); return ucFirst(rtf.format(unitDiff, "day")); } function ucFirst(str: string): string { return str.charAt(0).toUpperCase() + str.slice(1); }