mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
15 lines
500 B
TypeScript
15 lines
500 B
TypeScript
import { Trans } from "@lingui/macro"
|
|
import dayjs from "dayjs"
|
|
import { useEffect, useState } from "react"
|
|
|
|
export function RelativeDate(props: { date: Date | number | undefined }) {
|
|
const [now, setNow] = useState(new Date())
|
|
useEffect(() => {
|
|
const interval = setInterval(() => setNow(new Date()), 60 * 1000)
|
|
return () => clearInterval(interval)
|
|
}, [])
|
|
|
|
if (!props.date) return <Trans>N/A</Trans>
|
|
return <>{dayjs(props.date).from(dayjs(now))}</>
|
|
}
|