From e6d3b488555844afc5df0a1009713b537bcbcf8d Mon Sep 17 00:00:00 2001 From: ThisBirchWood Date: Thu, 10 Jul 2025 00:05:53 +0200 Subject: [PATCH] ADD support for displaying months and years in time ago format --- frontend/src/utils/utils.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/frontend/src/utils/utils.ts b/frontend/src/utils/utils.ts index 818d042..79dd989 100644 --- a/frontend/src/utils/utils.ts +++ b/frontend/src/utils/utils.ts @@ -43,7 +43,7 @@ function dateToTimeAgo(date: Date): string { } return `${hours} hours ago`; - } else { + } else if (secondsAgo < 2592000) { const days = Math.floor(secondsAgo / 86400); if (days === 1) { @@ -51,6 +51,22 @@ function dateToTimeAgo(date: Date): string { } return `${days} days ago`; + } else if (secondsAgo < 31536000) { + const months = Math.floor(secondsAgo / 2592000); + + if (months === 1) { + return "1 month ago"; + } + + return `${months} months ago`; + } else { + const years = Math.floor(secondsAgo / 31536000); + + if (years === 1) { + return "1 year ago"; + } + + return `${years} years ago`; } }