feat: improved date
This commit is contained in:
parent
c53ddcd287
commit
b8f271fdb2
27
src/lib/Date.svelte
Normal file
27
src/lib/Date.svelte
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
const { date }: { date: Date } = $props();
|
||||||
|
const difference = new Date().getTime() / 1000 - date.getTime() / 1000;
|
||||||
|
const seconds = ~~(difference % 60);
|
||||||
|
const minutes = ~~(difference / 60) % 60;
|
||||||
|
const hours = ~~(difference / 3600) % 24;
|
||||||
|
const days = ~~(difference / 86400);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<p class="group underline">
|
||||||
|
<span class="group-hover:hidden">
|
||||||
|
about
|
||||||
|
{#if minutes == 0}
|
||||||
|
<span>{seconds}s</span>
|
||||||
|
{:else if hours == 0}
|
||||||
|
<span>{minutes}m</span>
|
||||||
|
{:else if days == 0}
|
||||||
|
<span>{hours}h</span>
|
||||||
|
{:else}
|
||||||
|
<span>{days}d</span>
|
||||||
|
{/if}
|
||||||
|
ago
|
||||||
|
</span>
|
||||||
|
<span class="hidden group-hover:block">
|
||||||
|
{date.toLocaleString()}
|
||||||
|
</span>
|
||||||
|
</p>
|
@ -5,6 +5,7 @@
|
|||||||
import GameVersion from './GameVersion.svelte';
|
import GameVersion from './GameVersion.svelte';
|
||||||
import Separator from './Separator.svelte';
|
import Separator from './Separator.svelte';
|
||||||
import type { Room } from './types';
|
import type { Room } from './types';
|
||||||
|
import Date from './Date.svelte';
|
||||||
|
|
||||||
let { room }: { room: Room } = $props();
|
let { room }: { room: Room } = $props();
|
||||||
|
|
||||||
@ -43,7 +44,7 @@
|
|||||||
{room.players.length} / 4
|
{room.players.length} / 4
|
||||||
<Separator />
|
<Separator />
|
||||||
<Calendar class="inline-block w-6" />
|
<Calendar class="inline-block w-6" />
|
||||||
{room.createdAt.toLocaleString()}
|
<Date date={room.createdAt} />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2 sm:grid-rows-2">
|
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2 sm:grid-rows-2">
|
||||||
|
Loading…
Reference in New Issue
Block a user