1
Fork 0
mirror of https://github.com/Steffo99/festa.git synced 2024-10-16 23:17:26 +00:00
festa/components/extensions/FestaMoment.tsx

26 lines
No EOL
590 B
TypeScript

import { useTranslation } from "next-i18next"
type FestaMomentProps = {
date: Date,
}
/**
* Component that formats a {@link Date} to a machine-readable and human-readable HTML `time[datetime]` element.
*/
export function FestaMoment({ date }: FestaMomentProps) {
const { t } = useTranslation()
if (Number.isNaN(date.getTime())) {
return (
<span className="disabled">
{t("dateNaN")}
</span>
)
}
return (
<time dateTime={date.toISOString()}>
{date.toLocaleString()}
</time>
)
}