26 lines
593 B
Svelte
26 lines
593 B
Svelte
<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>
|