feat: dashboard enrichment-list-block after batch upload (#296) #298

Merged
marcel merged 19 commits from feat/issue-296-enrichment-list-block into main 2026-04-21 08:59:32 +02:00
2 changed files with 42 additions and 0 deletions
Showing only changes of commit d5d1a463b8 - Show all commits

View File

@@ -0,0 +1,34 @@
import { describe, it, expect } from 'vitest';
import { relativeTimeDe } from './relativeTime';
const NOW = new Date('2026-04-20T12:00:00Z');
describe('relativeTimeDe', () => {
it('returns minutes for a gap under one hour', () => {
const from = new Date('2026-04-20T11:58:00Z');
expect(relativeTimeDe(from, NOW)).toContain('2');
expect(relativeTimeDe(from, NOW)).toMatch(/Minute/i);
});
it('returns hours for a gap between 1 and 24 hours', () => {
const from = new Date('2026-04-20T09:00:00Z');
expect(relativeTimeDe(from, NOW)).toContain('3');
expect(relativeTimeDe(from, NOW)).toMatch(/Stunde/i);
});
it('returns days for a gap of 24 hours or more', () => {
const from = new Date('2026-04-18T12:00:00Z');
expect(relativeTimeDe(from, NOW)).toContain('2');
expect(relativeTimeDe(from, NOW)).toMatch(/Tag/i);
});
it('rounds minutes to the nearest whole number', () => {
const from = new Date('2026-04-20T11:58:20Z');
expect(relativeTimeDe(from, NOW)).toContain('2');
});
it('handles zero gap as 0 minutes', () => {
expect(relativeTimeDe(NOW, NOW)).toMatch(/0/);
expect(relativeTimeDe(NOW, NOW)).toMatch(/Minute/i);
});
});

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