Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Commit

Permalink
Implement a switchatble timeago component
Browse files Browse the repository at this point in the history
By default it still shows when the data was created relativly to now e.g. 12 hours ago
But when the user clicks it it will show the exact time it was created/edited
  • Loading branch information
Dlurak committed Jan 24, 2024
1 parent 344d5e7 commit 009cf02
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/lib/dates/TimeAgo.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<script lang="ts">
import { onDestroy } from 'svelte';
import { i, type Token } from '../../languages/i18n';
import { currentLanguage } from '../../stores';
export let timestamp: number;
export let classes = '';
export let fullDate = false;
export let type: 'edited' | 'created' = 'created';
Expand Down Expand Up @@ -56,5 +58,11 @@
});
</script>

<!-- It's ok that this isn't in a I18n tag due to the interval-->
<p class={classes}>{timeDifference}</p>
<button on:click={() => (fullDate = !fullDate)} class="w-max">
{#if fullDate}
<p class={classes}>{new Date(timestamp).toLocaleString($currentLanguage)}</p>
{:else}
<!-- It's ok that this isn't in a I18n tag due to the interval-->
<p class={classes}>{timeDifference}</p>
{/if}
</button>

0 comments on commit 009cf02

Please sign in to comment.