2022-06-08 15:31:34 +00:00
|
|
|
import { useTranslation } from "next-i18next"
|
|
|
|
|
|
|
|
type HumanDateProps = {
|
|
|
|
date: Date
|
|
|
|
}
|
|
|
|
|
2022-06-09 21:55:49 +00:00
|
|
|
/**
|
|
|
|
* Component that formats a {@link Date} to a machine-readable and human-readable HTML `time[datetime]` element.
|
|
|
|
*/
|
|
|
|
export function FestaMoment({ date }: HumanDateProps) {
|
|
|
|
const { t } = useTranslation()
|
2022-06-08 15:31:34 +00:00
|
|
|
|
2022-06-09 21:55:49 +00:00
|
|
|
if (Number.isNaN(date.getTime())) {
|
2022-06-08 15:31:34 +00:00
|
|
|
return (
|
|
|
|
<span className="disabled">
|
|
|
|
{t("dateNaN")}
|
|
|
|
</span>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<time dateTime={date.toISOString()}>
|
|
|
|
{date.toLocaleString()}
|
|
|
|
</time>
|
|
|
|
)
|
|
|
|
}
|