Skip to content

Commit

Permalink
feat: add getRelativeTime method
Browse files Browse the repository at this point in the history
  • Loading branch information
harshtandiya committed Oct 22, 2024
1 parent 2989bb6 commit fc8af86
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions frontend/src/utils/helpers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
import isToday from 'dayjs/plugin/isToday'
import isYesterday from 'dayjs/plugin/isYesterday'

dayjs.extend(relativeTime)
dayjs.extend(isToday)
dayjs.extend(isYesterday)

export const getRedirectUrl = (route) => {
return window.location.origin + '/' + route
}

export const generateRandomId = () => {
return Math.random().toString(36).slice(2, 8)
}

export const getRelativeTime = (datetime) => {
const date = dayjs(datetime)
if (date.isToday()) {
return 'Today'
} else if (date.isYesterday()) {
return 'Yesterday'
} else {
return date.fromNow()
}
}

0 comments on commit fc8af86

Please sign in to comment.