-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
Overview
Create utility for displaying relative time.
Parent Epic: #70
Priority: P1
Prerequisites
- 1.3: Set Up TypeScript Configuration #73 (1.3: Set Up TypeScript Configuration)
Next Issues (after this is complete)
- Can be used by Story and Comment components
Acceptance Criteria
-
app/javascript/lib/timeAgo.tscreated - Converts Unix timestamp to relative time string
- Handles: "just now", "X minutes ago", "X hours ago", "X days ago"
- Handles edge cases (future dates, very old dates)
- Unit tests with Jest/Vitest
- TypeScript types exported
Implementation Notes
export function timeAgo(timestamp: number): string {
const seconds = Math.floor(Date.now() / 1000 - timestamp);
if (seconds < 60) return 'just now';
if (seconds < 3600) return `${Math.floor(seconds / 60)} minutes ago`;
if (seconds < 86400) return `${Math.floor(seconds / 3600)} hours ago`;
return `${Math.floor(seconds / 86400)} days ago`;
}Note: This could also be done server-side in Ruby (in the presenters). Decide based on where it's most useful.
coderabbitai