fix: invalid dates

This commit is contained in:
Xyphyn committed 2023-10-03 16:07:40 -07:00
1 parent facb1081c9
commit 0d08df2ad5
7 files changed
+23 -19

No files matched your search

@@ -1,6 +1,7 @@
<script lang="ts">
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte'
import { publishedToDate } from '$lib/components/util/date.js'
import { getInstance } from '$lib/lemmy.js'
import { userSettings } from '$lib/settings.js'
import type { CommentView } from 'lemmy-js-client'
@@ -23,7 +24,7 @@
deleted={false}
featured={false}
nsfw={comment.post.nsfw}
published={new Date(comment.post.published + 'Z')}
published={publishedToDate(comment.comment.published)}
saved={false}
community={community ? comment.community : undefined}
/>
+2 -1
View File
@@ -11,6 +11,7 @@
import ExpandableImage from '$lib/components/ui/ExpandableImage.svelte'
import { bestImageURL, postLink } from '$lib/components/lemmy/post/helpers.js'
import Empty from '$lib/components/helper/Empty.svelte'
import { publishedToDate } from '$lib/components/util/date.js'
export let post: PostView
export let actions: boolean = true
@@ -48,7 +49,7 @@
<PostMeta
community={hideCommunity ? undefined : post.community}
user={post.creator}
published={new Date(post.post.published + 'Z')}
published={publishedToDate(post.post.published)}
upvotes={post.counts.upvotes}
downvotes={post.counts.downvotes}
deleted={post.post.deleted}
+1 -11
View File
@@ -22,12 +22,7 @@
{#if avatar}
<Avatar url={user.avatar} alt={user.name} width={avatarSize} />
{/if}
<span
class="flex flex-wrap gap-0"
class:ml-0.5={avatar}
class:text-red-500={user.admin}
class:font-bold={user.admin}
>
<span class="flex flex-wrap gap-0" class:ml-0.5={avatar}>
<span class:font-medium={showInstance}>
{user.display_name || user.name}
</span>
@@ -38,11 +33,6 @@
{/if}
</span>
{#if badges}
{#if user.admin}
<div class="text-red-500" title="Admin">
<ShieldIcon width={12} filled />
</div>
{/if}
{#if user.banned}
<div class="text-red-500" title="Banned">
<Icon src={NoSymbol} mini size="12" />
@@ -0,0 +1,7 @@
<script lang="ts">
import { routes } from '$lib/util.js'
export let route: { id: string } | undefined = undefined
$: title = route ? routes[(route.id as keyof typeof routes) ?? ''] : ''
</script>
+9 -2
View File
@@ -1,2 +1,9 @@
export const publishedToDate = (published: string) =>
published.endsWith('Z') ? new Date(published) : new Date(`${published}Z`)
export const publishedToDate = (published: string): Date => {
console.log(published)
published.endsWith('Z')
? console.log('includes a z. Not doing anything.')
: console.log("doesn't include a z. adding it.")
return published.endsWith('Z')
? new Date(published)
: new Date(`${published}Z`)
}