refactor(time): extract relativeTime into shared time.ts utility
Move relativeTime from notifications.ts (Intl.RelativeTimeFormat) to a new time.ts that uses the Paraglide comment_time_* message keys — the same logic that was already in CommentThread's timeAgo(). Remove the duplicate timeAgo() from CommentThread and re-export relativeTime from notifications.ts for backwards compatibility. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
12
frontend/src/lib/utils/time.ts
Normal file
12
frontend/src/lib/utils/time.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { m } from '$lib/paraglide/messages.js';
|
||||
|
||||
export function relativeTime(isoString: string, now: Date = new Date()): string {
|
||||
const diff = now.getTime() - new Date(isoString).getTime();
|
||||
const minutes = Math.floor(diff / 60_000);
|
||||
if (minutes < 1) return m.comment_time_just_now();
|
||||
if (minutes < 60) return m.comment_time_minutes({ count: minutes });
|
||||
const hours = Math.floor(minutes / 60);
|
||||
if (hours < 24) return m.comment_time_hours({ count: hours });
|
||||
const days = Math.floor(hours / 24);
|
||||
return m.comment_time_days({ count: days });
|
||||
}
|
||||
Reference in New Issue
Block a user