fix: show date on herocard closes #2

This commit is contained in:
Max Richter
2025-10-22 16:39:23 +02:00
parent d9a2f63865
commit 3a120e32fc
3 changed files with 37 additions and 8 deletions

View File

@@ -0,0 +1,25 @@
<script lang="ts">
export let date: string | Date;
const toDate = (d: string | Date) =>
typeof d === "string" ? new Date(d) : d;
const iso = (d: string | Date) => {
const v = toDate(d);
return isNaN(v.getTime()) ? "" : v.toISOString();
};
const formatDate = (d: string | Date) =>
new Intl.DateTimeFormat("de-DE", {
day: "2-digit",
month: "long",
year: "numeric",
}).format(toDate(d));
</script>
<div class="flex gap-5">
{#if date}
<time class="text-sm text-neutral" datetime={iso(date)}
>{formatDate(date)}</time>
{/if}
</div>