This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

relative timestamps

+6 -54
+3 -2
app/src/app/page.tsx
··· 5 5 import { useRouter } from 'next/navigation'; 6 6 import styles from './page.module.css'; 7 7 import { useAuth } from '@/lib/auth-context'; 8 - import { containsBannedWords, sanitizeText, formatRelativeTime } from '@/lib/content-filter'; 8 + import { containsBannedWords, sanitizeText } from '@/lib/content-filter'; 9 + import { formatRelativeTime } from '@/lib/time-utils'; 9 10 10 11 // Types for feed entries 11 12 interface FlushingEntry { ··· 385 386 </span> 386 387 </div> 387 388 <span className={styles.timestamp}> 388 - {new Date(entry.createdAt).toLocaleString()} 389 + {formatRelativeTime(entry.createdAt)} 389 390 </span> 390 391 </div> 391 392 </div>
+1 -52
app/src/lib/content-filter.ts
··· 147 147 return EXPLICIT_SLUR_REGEXES.some(regex => regex.test(text)); 148 148 } 149 149 150 - /** 151 - * Formats a date into a relative time string (e.g., "5 minutes ago", "2 days ago") 152 - * @param dateString The date string to format 153 - * @returns A relative time string 154 - */ 155 - export function formatRelativeTime(dateString: string): string { 156 - const date = new Date(dateString); 157 - const now = new Date(); 158 - const diffInSeconds = Math.floor((now.getTime() - date.getTime()) / 1000); 159 - 160 - // Less than a minute 161 - if (diffInSeconds < 60) { 162 - return 'just now'; 163 - } 164 - 165 - // Less than an hour 166 - if (diffInSeconds < 3600) { 167 - const minutes = Math.floor(diffInSeconds / 60); 168 - return `${minutes} ${minutes === 1 ? 'minute' : 'minutes'} ago`; 169 - } 170 - 171 - // Less than a day 172 - if (diffInSeconds < 86400) { 173 - const hours = Math.floor(diffInSeconds / 3600); 174 - return `${hours} ${hours === 1 ? 'hour' : 'hours'} ago`; 175 - } 176 - 177 - // Less than a week 178 - if (diffInSeconds < 604800) { 179 - const days = Math.floor(diffInSeconds / 86400); 180 - if (days === 1) { 181 - return 'yesterday'; 182 - } 183 - return `${days} days ago`; 184 - } 185 - 186 - // Less than a month 187 - if (diffInSeconds < 2592000) { 188 - const weeks = Math.floor(diffInSeconds / 604800); 189 - return `${weeks} ${weeks === 1 ? 'week' : 'weeks'} ago`; 190 - } 191 - 192 - // Less than a year 193 - if (diffInSeconds < 31536000) { 194 - const months = Math.floor(diffInSeconds / 2592000); 195 - return `${months} ${months === 1 ? 'month' : 'months'} ago`; 196 - } 197 - 198 - // More than a year 199 - const years = Math.floor(diffInSeconds / 31536000); 200 - return `${years} ${years === 1 ? 'year' : 'years'} ago`; 201 - } 150 + // Function removed and moved to time-utils.ts
+2
app/src/lib/time-utils.ts
··· 1 1 export function formatRelativeTime(dateString: string): string { 2 + if (!dateString) return ''; 3 + 2 4 const date = new Date(dateString); 3 5 const now = new Date(); 4 6 const diffInSeconds = Math.floor((now.getTime() - date.getTime()) / 1000);