2022-01-24 07:38:29 +00:00
|
|
|
import dayjs from 'dayjs'
|
|
|
|
import relativeTime from 'dayjs/plugin/relativeTime'
|
|
|
|
dayjs.extend(relativeTime)
|
|
|
|
|
|
|
|
export function fromNow(time: number) {
|
|
|
|
return dayjs(time).fromNow()
|
|
|
|
}
|
2022-06-24 17:14:20 +00:00
|
|
|
|
|
|
|
export function formatTime(time: number, includeTime: boolean) {
|
|
|
|
const d = dayjs(time)
|
|
|
|
|
|
|
|
if (d.isSame(Date.now(), 'day')) return d.format('ha')
|
|
|
|
|
|
|
|
if (includeTime) return dayjs(time).format('MMM D, ha')
|
|
|
|
|
|
|
|
return dayjs(time).format('MMM D')
|
|
|
|
}
|