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>
13 lines
549 B
TypeScript
13 lines
549 B
TypeScript
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 });
|
|
}
|