feat: dashboard enrichment-list-block after batch upload (#296) #298
@@ -31,4 +31,11 @@ describe('relativeTimeDe', () => {
|
|||||||
expect(relativeTimeDe(NOW, NOW)).toMatch(/0/);
|
expect(relativeTimeDe(NOW, NOW)).toMatch(/0/);
|
||||||
expect(relativeTimeDe(NOW, NOW)).toMatch(/Minute/i);
|
expect(relativeTimeDe(NOW, NOW)).toMatch(/Minute/i);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('falls back to 0 minutes when the input Date is invalid', () => {
|
||||||
|
const invalid = new Date('not-a-real-date');
|
||||||
|
// Never crash the UI if the backend ever ships a malformed uploadedAt.
|
||||||
|
expect(relativeTimeDe(invalid, NOW)).toMatch(/0/);
|
||||||
|
expect(relativeTimeDe(invalid, NOW)).toMatch(/Minute/i);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ import * as m from '$lib/paraglide/messages.js';
|
|||||||
|
|
||||||
export function relativeTimeDe(from: Date, now: Date = new Date()): string {
|
export function relativeTimeDe(from: Date, now: Date = new Date()): string {
|
||||||
const minutes = Math.round((now.getTime() - from.getTime()) / 60_000);
|
const minutes = Math.round((now.getTime() - from.getTime()) / 60_000);
|
||||||
|
// Malformed input (e.g. Invalid Date from a broken backend string) must not
|
||||||
|
// crash the dashboard — fall back to "0 Minuten" rather than render NaN.
|
||||||
|
if (!Number.isFinite(minutes)) return m.comment_time_minutes({ count: 0 });
|
||||||
if (minutes < 60) return m.comment_time_minutes({ count: minutes });
|
if (minutes < 60) return m.comment_time_minutes({ count: minutes });
|
||||||
if (minutes < 1440) return m.comment_time_hours({ count: Math.round(minutes / 60) });
|
if (minutes < 1440) return m.comment_time_hours({ count: Math.round(minutes / 60) });
|
||||||
return m.comment_time_days({ count: Math.round(minutes / 1440) });
|
return m.comment_time_days({ count: Math.round(minutes / 1440) });
|
||||||
|
|||||||
Reference in New Issue
Block a user