Skip to content

Commit 15843e0

Browse files
fix: Add accurate month logic to generateElapsedTimeText function (#29)
1 parent b6064d8 commit 15843e0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/utils/commonUtils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,14 @@ export const generateElapsedTimeText = (timeString: string) => {
6363
const minutes = Math.floor(seconds / 60);
6464
const hours = Math.floor(minutes / 60);
6565
const days = Math.floor(hours / 24);
66+
const months = Math.floor(days / 30);
6667
const years = Math.floor(days / 365);
6768

6869
if (millisecondsDiff < 60000) return 'Just now';
6970
else if (minutes < 60) return minutes === 1 ? '1 minute ago' : `${minutes} minutes ago`;
7071
else if (hours < 24) return hours === 1 ? '1 hour ago' : `${hours} hours ago`;
71-
else if (days < 365) return days === 1 ? '1 day ago' : `${days} days ago`;
72+
else if (days < 30) return days === 1 ? '1 day ago' : `${days} days ago`;
73+
else if (months < 12) return months === 1 ? '1 month ago' : `${months} months ago`;
7274
else return years === 1 ? '1 year ago' : `${years} years ago`;
7375
};
7476

0 commit comments

Comments
 (0)