From 22477f2fa0a3b788820f48f88f63e00be03594f3 Mon Sep 17 00:00:00 2001 From: Benny Guo Date: Sun, 6 Aug 2023 14:10:21 +0800 Subject: [PATCH] fix: waline different date format cause formatting error --- src/utils/comments/waline-api.ts | 5 ++++- src/utils/index.ts | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/utils/comments/waline-api.ts b/src/utils/comments/waline-api.ts index 6e3b3c98..34db439b 100644 --- a/src/utils/comments/waline-api.ts +++ b/src/utils/comments/waline-api.ts @@ -111,7 +111,10 @@ export class WalineComments { } mapComment(comment: WalineComment): RecentComments { - const createdAt = formatTime(this.convertDateFormat(comment.insertedAt)) + // slice off the last 5 character to remove the timezone. + const createdAt = formatTime( + new Date(comment.time).toISOString().slice(0, -5) + ) return { id: comment.objectId, body: filterHTMLContent(comment.comment), diff --git a/src/utils/index.ts b/src/utils/index.ts index 134edda3..ff28109f 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -125,7 +125,6 @@ export function filterHTMLContent(content: string, length?: number): string { export function getDaysTillNow(from: string) { const today = new Date() const fromDate = new Date(from) - console.log(fromDate) // To calculate the time difference of two dates const timeDiff = today.getTime() - fromDate.getTime()