mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-16 00:19:39 +02:00
fix(matrix): handle invalid timestamps gracefully
Add validation before formatting dates to prevent "Invalid time value" errors when messages have undefined or invalid timestamps. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
41354d58ee
commit
56d49f8fe2
1 changed files with 8 additions and 3 deletions
|
|
@ -1,7 +1,7 @@
|
|||
<script lang="ts">
|
||||
import type { SimpleMessage } from '$lib/matrix';
|
||||
import { matrixStore } from '$lib/matrix';
|
||||
import { format, isToday, isYesterday } from 'date-fns';
|
||||
import { format, isToday, isYesterday, isValid } from 'date-fns';
|
||||
import { de } from 'date-fns/locale';
|
||||
import {
|
||||
ArrowBendUpLeft,
|
||||
|
|
@ -88,10 +88,15 @@
|
|||
return `${mins}:${secs.toString().padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
let formattedTime = $derived(format(message.timestamp, 'HH:mm'));
|
||||
let formattedTime = $derived(() => {
|
||||
const date = new Date(message.timestamp);
|
||||
if (!isValid(date)) return '--:--';
|
||||
return format(date, 'HH:mm');
|
||||
});
|
||||
|
||||
let formattedDate = $derived(() => {
|
||||
const date = new Date(message.timestamp);
|
||||
if (!isValid(date)) return '';
|
||||
if (isToday(date)) return 'Heute';
|
||||
if (isYesterday(date)) return 'Gestern';
|
||||
return format(date, 'EEEE, d. MMMM', { locale: de });
|
||||
|
|
@ -366,7 +371,7 @@
|
|||
<div
|
||||
class="flex items-center gap-2 mt-1.5 px-1 opacity-0 group-hover:opacity-100 transition-opacity"
|
||||
>
|
||||
<span class="text-xs text-muted-foreground">{formattedTime}</span>
|
||||
<span class="text-xs text-muted-foreground">{formattedTime()}</span>
|
||||
</div>
|
||||
|
||||
<!-- Message actions (hover) -->
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue