time.ts 529 B

123456789101112131415161718
  1. import dayjs, { type ConfigType } from 'dayjs'
  2. import utc from 'dayjs/plugin/utc'
  3. import relativeTime from 'dayjs/plugin/relativeTime'
  4. dayjs.extend(utc)
  5. dayjs.extend(relativeTime)
  6. export const isAfter = (date: ConfigType, compare: ConfigType) => {
  7. return dayjs(date).isAfter(dayjs(compare))
  8. }
  9. export const formatTime = ({ date, dateFormat }: { date: ConfigType; dateFormat: string }) => {
  10. return dayjs(date).format(dateFormat)
  11. }
  12. export const formatDistanceToNow = (date: ConfigType) => {
  13. return dayjs(date).fromNow()
  14. }