Files
electric-cherry/src/lib/ui/components/RelativeTime.svelte
T

19 lines
703 B
Svelte

<script lang="ts">
import { browser } from '$app/environment';
import { timestampISO, type Timestamp } from '$lib/time-zone.js';
import { timeFormat } from '$ui/stores/time-zone.js';
import { uiNow } from '$ui/stores/servers.js';
let {
value,
missing = '—',
class: className
}: { value: Timestamp; missing?: string; class?: string } = $props();
const iso = $derived(timestampISO(value));
const now = $derived(browser ? $uiNow : Date.now());
</script>
{#if iso}<time class={className} datetime={iso} title={$timeFormat.dateTime(value)}
>{$timeFormat.relative(value, now)}</time
>{:else}<span class={className}>{missing}</span>{/if}