From 34c712c01c77ee4c08e704d4690f262e3fb105cd Mon Sep 17 00:00:00 2001 From: Thomas J Faughnan Jr Date: Fri, 28 Jul 2023 19:45:43 -0400 Subject: [PATCH] fix: parse date strings as UTC For posts, comments, and other objects, the `published` attribute is a string containing an ISO 8601 timestamp. This timestamp is UTC, though it is not explicit in the string's contents. When the `Date` constructor is used on such strings, they are parsed as though they are local timestamps. According to [1]: > When the time zone offset is absent, date-only forms are > interpreted as a UTC time and date-time forms are interpreted as local > time. This is due to a historical spec error that was not consistent > with ISO 8601 but could not be changed due to web > compatibility. This patch explicitly appends a 'Z' to the `published` string when it is used as the argument to the `Date` constructor. [1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date --- src/lib/components/lemmy/SiteCard.svelte | 2 +- src/lib/components/lemmy/comment/Comment.svelte | 2 +- src/lib/components/lemmy/comment/CommentItem.svelte | 2 +- src/lib/components/lemmy/community/CommunityCard.svelte | 2 +- src/lib/components/lemmy/post/Post.svelte | 2 +- src/routes/post/[instance]/[id]/+page.svelte | 2 +- src/routes/u/[name]/+page.svelte | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lib/components/lemmy/SiteCard.svelte b/src/lib/components/lemmy/SiteCard.svelte index 69f3dca7..92de61c4 100644 --- a/src/lib/components/lemmy/SiteCard.svelte +++ b/src/lib/components/lemmy/SiteCard.svelte @@ -33,7 +33,7 @@ - +
diff --git a/src/lib/components/lemmy/comment/Comment.svelte b/src/lib/components/lemmy/comment/Comment.svelte index 8f501fa2..a60d6e98 100644 --- a/src/lib/components/lemmy/comment/Comment.svelte +++ b/src/lib/components/lemmy/comment/Comment.svelte @@ -101,7 +101,7 @@ {node.comment_view.counts.score}
{/if} - + • {Math.floor( diff --git a/src/lib/components/lemmy/comment/CommentItem.svelte b/src/lib/components/lemmy/comment/CommentItem.svelte index 667da902..a71cd3ae 100644 --- a/src/lib/components/lemmy/comment/CommentItem.svelte +++ b/src/lib/components/lemmy/comment/CommentItem.svelte @@ -16,7 +16,7 @@ deleted={false} featured={false} nsfw={comment.post.nsfw} - published={new Date(comment.post.published)} + published={new Date(comment.post.published + 'Z')} saved={false} />