From c7317c7278a982fcdb32ed31e57eded9bdbe7036 Mon Sep 17 00:00:00 2001 From: ajnart Date: Mon, 27 Mar 2023 11:42:17 +0900 Subject: [PATCH] Address PR comments --- src/widgets/rss/RssWidgetTile.tsx | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/widgets/rss/RssWidgetTile.tsx b/src/widgets/rss/RssWidgetTile.tsx index 0b2156f0f..b594803e6 100644 --- a/src/widgets/rss/RssWidgetTile.tsx +++ b/src/widgets/rss/RssWidgetTile.tsx @@ -78,17 +78,11 @@ function RssTile({ widget }: RssTileProps) { const inputDate = dayjs(new Date(input)); const now = dayjs(); // Current date and time - const diffInHours = now.diff(inputDate, 'hour'); - const diffInDays = now.diff(inputDate, 'day'); - - // If the input date is more than 2 weeks ago, return the formatted date - if (diffInDays > 14) { - return inputDate.format('DD MMM YYYY'); - } - if (diffInDays >= 1) { - return `${diffInDays} days ago`; - } - return `${diffInHours} hours ago`; + // The difference between the input date and now + const difference = now.diff(inputDate, 'ms'); + const duration = dayjs.duration(difference, 'ms'); + const humanizedDuration = duration.humanize(); + return `${humanizedDuration} ago`; } if (!data || isLoading) {