feat(frontend): add relativeTimeDe helper for dashboard meta lines
Pure function with injectable now — lets the dashboard enrichment block render "vor 2 Min." / "vor 3 Std." / "vor 2 Tagen" without clock-based test flakiness. Reuses the existing comment_time_minutes / _hours / _days Paraglide keys, no new translations needed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
8
frontend/src/lib/relativeTime.ts
Normal file
8
frontend/src/lib/relativeTime.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import * as m from '$lib/paraglide/messages.js';
|
||||
|
||||
export function relativeTimeDe(from: Date, now: Date = new Date()): string {
|
||||
const minutes = Math.round((now.getTime() - from.getTime()) / 60_000);
|
||||
if (minutes < 60) return m.comment_time_minutes({ count: minutes });
|
||||
if (minutes < 1440) return m.comment_time_hours({ count: Math.round(minutes / 60) });
|
||||
return m.comment_time_days({ count: Math.round(minutes / 1440) });
|
||||
}
|
||||
Reference in New Issue
Block a user