1
Fork 0
mirror of https://github.com/Steffo99/festa.git synced 2024-12-23 15:14:23 +00:00
festa/components/extensions/FestaMoment.tsx

26 lines
585 B
TypeScript
Raw Normal View History

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>
)
}