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
590 B
TypeScript
Raw Normal View History

2022-06-08 15:31:34 +00:00
import { useTranslation } from "next-i18next"
2022-06-09 22:22:47 +00:00
type FestaMomentProps = {
date: Date,
2022-06-08 15:31:34 +00:00
}
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.
*/
2022-06-09 22:22:47 +00:00
export function FestaMoment({ date }: FestaMomentProps) {
2022-06-09 21:55:49 +00:00
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>
)
}