Skip to content

Commit

Permalink
Added Months to TimeAgo Method (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
brezden authored Dec 3, 2024
1 parent 1b6ac1f commit c12e6df
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Util/TimeStringConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default function timeAgo(updatedAt: string): string {
const minutes = Math.floor(diffInSeconds / 60);
const hours = Math.floor(minutes / 60);
const days = Math.floor(hours / 24);
const months = Math.floor(days / 30);
const years = Math.floor(days / 365);

if (diffInSeconds < 60) {
Expand All @@ -14,8 +15,10 @@ export default function timeAgo(updatedAt: string): string {
return `${minutes} ${minutes === 1 ? 'minute' : 'minutes'} ago`;
} else if (hours < 24) {
return `${hours} ${hours === 1 ? 'hour' : 'hours'} ago`;
} else if (days < 365) {
} else if (days < 30) {
return `${days} ${days === 1 ? 'day' : 'days'} ago`;
} else if (days < 365) {
return `${months} ${months === 1 ? 'month' : 'months'} ago`;
} else {
return `${years} ${years === 1 ? 'year' : 'years'} ago`;
}
Expand Down

0 comments on commit c12e6df

Please sign in to comment.