Files
familienarchiv/frontend/src/lib/utils/time.ts
Marcel 655a2003cb 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>
2026-04-15 13:02:49 +02:00

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 });
}