From 89f9321f0ee8ec2db87e5ec6e91f6dd583dbc1ca Mon Sep 17 00:00:00 2001 From: yzhe819 <68207314+yzhe819@users.noreply.github.com> Date: Mon, 3 Apr 2023 00:46:16 +1200 Subject: [PATCH 1/2] fix: use UTC for `published_at` --- src/hooks/useDate.ts | 3 +++ src/pages/dashboard/[subdomain]/editor.tsx | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/hooks/useDate.ts b/src/hooks/useDate.ts index 464b5012..d050cec5 100644 --- a/src/hooks/useDate.ts +++ b/src/hooks/useDate.ts @@ -32,5 +32,8 @@ export function useDate() { inLocalTimezone: (date: string | Date) => { return dayjs(date).tz().toDate() }, + inUTCTimezone: (date: string | Date) => { + return dayjs(date).utc().toDate() + }, } } diff --git a/src/pages/dashboard/[subdomain]/editor.tsx b/src/pages/dashboard/[subdomain]/editor.tsx index 9bd31ede..754e401f 100644 --- a/src/pages/dashboard/[subdomain]/editor.tsx +++ b/src/pages/dashboard/[subdomain]/editor.tsx @@ -179,6 +179,7 @@ export default function SubdomainEditor() { ...(visibility === PageVisibilityEnum.Draft ? {} : { pageId: pageId }), isPost: isPost, published, + publishedAt: getInputDatetimeValue(date.inUTCTimezone(values.publishedAt), date.dayjs.utc), externalUrl: (values.slug || defaultSlug) && `${getSiteLink({ @@ -225,7 +226,7 @@ export default function SubdomainEditor() { setValues({ title: page.data.title || "", - publishedAt: page.data.date_published, + publishedAt: getInputDatetimeValue(date.inLocalTimezone(page.data.published_at), date.dayjs), published: !!page.data.id, excerpt: page.data.summary?.content || "", slug: page.data.slug || "", From b2c606ade4ef02d415bf8a0b55f522ecd8f39a99 Mon Sep 17 00:00:00 2001 From: yzhe819 <68207314+yzhe819@users.noreply.github.com> Date: Mon, 3 Apr 2023 00:52:53 +1200 Subject: [PATCH 2/2] fix: timezone --- src/components/main/MainFeed.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/main/MainFeed.tsx b/src/components/main/MainFeed.tsx index 460d70d3..6b02c070 100644 --- a/src/components/main/MainFeed.tsx +++ b/src/components/main/MainFeed.tsx @@ -64,7 +64,7 @@ const Post = ({ {t("ago", { time: date.dayjs .duration( - date.dayjs(post?.createdAt).diff(date.dayjs(), "minute"), + date.dayjs(post?.createdAt).tz().diff(date.dayjs(), "minute"), "minute", ) .humanize(),