Skip to content

Commit

Permalink
Add singular units of time (#444)
Browse files Browse the repository at this point in the history
* Add singular units of time

* Simplify the change and fix typing regression
  • Loading branch information
iamlogand authored Mar 16, 2024
1 parent 91080b3 commit 1a38a12
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions frontend/functions/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ export const formatElapsedDate = (date: Date, timezone: string) => {

const minutes = Math.floor(seconds / 60)
if (minutes < 60) {
return `${minutes} mins ago`
return `${minutes} ${minutes === 1 ? "min" : "mins"} ago`
}

const hours = Math.floor(minutes / 60)
if (hours < 24) {
return `${hours} hours ago`
return `${hours} ${hours === 1 ? "hour" : "hours"} ago`
}

const days = Math.floor(hours / 24)
if (days < 7) {
return `${days} days ago`
return `${days} ${days === 1 ? "day" : "days"} ago`
}

const weeks = Math.floor(days / 7)
if (weeks < 4) {
return `${weeks} weeks ago`
return `${weeks} ${weeks === 1 ? "week" : "weeks"} ago`
}

const months = Math.floor(days / 30)
if (months < 12) {
return `${months} months ago`
return `${months} ${months === 1 ? "month" : "months"} ago`
}

const years = Math.floor(days / 365)
return `${years} years ago`
return `${years} ${years === 1 ? "year" : "years"} ago`
}

export default formatDate

0 comments on commit 1a38a12

Please sign in to comment.