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"> <script lang="ts">
import Comment from '$lib/components/lemmy/comment/Comment.svelte' import Comment from '$lib/components/lemmy/comment/Comment.svelte'
import PostMeta from '$lib/components/lemmy/post/PostMeta.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 { getInstance } from '$lib/lemmy.js'
import { userSettings } from '$lib/settings.js' import { userSettings } from '$lib/settings.js'
import type { CommentView } from 'lemmy-js-client' import type { CommentView } from 'lemmy-js-client'
@@ -23,7 +24,7 @@
deleted={false} deleted={false}
featured={false} featured={false}
nsfw={comment.post.nsfw} nsfw={comment.post.nsfw}
published={new Date(comment.post.published + 'Z')} published={publishedToDate(comment.comment.published)}
saved={false} saved={false}
community={community ? comment.community : undefined} community={community ? comment.community : undefined}
/> />
+2 -1
View File
@@ -11,6 +11,7 @@
import ExpandableImage from '$lib/components/ui/ExpandableImage.svelte' import ExpandableImage from '$lib/components/ui/ExpandableImage.svelte'
import { bestImageURL, postLink } from '$lib/components/lemmy/post/helpers.js' import { bestImageURL, postLink } from '$lib/components/lemmy/post/helpers.js'
import Empty from '$lib/components/helper/Empty.svelte' import Empty from '$lib/components/helper/Empty.svelte'
import { publishedToDate } from '$lib/components/util/date.js'
export let post: PostView export let post: PostView
export let actions: boolean = true export let actions: boolean = true
@@ -48,7 +49,7 @@
<PostMeta <PostMeta
community={hideCommunity ? undefined : post.community} community={hideCommunity ? undefined : post.community}
user={post.creator} user={post.creator}
published={new Date(post.post.published + 'Z')} published={publishedToDate(post.post.published)}
upvotes={post.counts.upvotes} upvotes={post.counts.upvotes}
downvotes={post.counts.downvotes} downvotes={post.counts.downvotes}
deleted={post.post.deleted} deleted={post.post.deleted}
+1 -11
View File
@@ -22,12 +22,7 @@
{#if avatar} {#if avatar}
<Avatar url={user.avatar} alt={user.name} width={avatarSize} /> <Avatar url={user.avatar} alt={user.name} width={avatarSize} />
{/if} {/if}
<span <span class="flex flex-wrap gap-0" class:ml-0.5={avatar}>
class="flex flex-wrap gap-0"
class:ml-0.5={avatar}
class:text-red-500={user.admin}
class:font-bold={user.admin}
>
<span class:font-medium={showInstance}> <span class:font-medium={showInstance}>
{user.display_name || user.name} {user.display_name || user.name}
</span> </span>
@@ -38,11 +33,6 @@
{/if} {/if}
</span> </span>
{#if badges} {#if badges}
{#if user.admin}
<div class="text-red-500" title="Admin">
<ShieldIcon width={12} filled />
</div>
{/if}
{#if user.banned} {#if user.banned}
<div class="text-red-500" title="Banned"> <div class="text-red-500" title="Banned">
<Icon src={NoSymbol} mini size="12" /> <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) => export const publishedToDate = (published: string): Date => {
published.endsWith('Z') ? new Date(published) : new Date(`${published}Z`) 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`)
}
@@ -33,9 +33,6 @@
class="flex items-center gap-1 text-green-600 dark:text-green-400 font-medium" class="flex items-center gap-1 text-green-600 dark:text-green-400 font-medium"
> >
<UserLink showInstance={true} avatar user={item.moderator} /> <UserLink showInstance={true} avatar user={item.moderator} />
{#if !item.moderator.admin}
<ShieldIcon filled width={16} />
{/if}
</span> </span>
{/if} {/if}
{#if item.moderatee} {#if item.moderatee}
@@ -39,6 +39,7 @@
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte' import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
import { userSettings } from '$lib/settings.js' import { userSettings } from '$lib/settings.js'
import { feature } from '$lib/version.js' import { feature } from '$lib/version.js'
import { publishedToDate } from '$lib/components/util/date.js'
export let data export let data
@@ -162,7 +163,7 @@
featured={post.post_view.post.featured_community || featured={post.post_view.post.featured_community ||
post.post_view.post.featured_local} post.post_view.post.featured_local}
nsfw={post.post_view.post.nsfw} nsfw={post.post_view.post.nsfw}
published={new Date(post.post_view.post.published + 'Z')} published={publishedToDate(post.post_view.post.published)}
saved={post.post_view.saved} saved={post.post_view.saved}
/> />
</div> </div>