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