sendou.ink/app/components/RelativeTime.tsx
2025-11-09 14:25:14 +02:00

33 lines
617 B
TypeScript

import type * as React from "react";
import { useIsMounted } from "~/hooks/useIsMounted";
import { useTimeFormat } from "~/hooks/useTimeFormat";
export function RelativeTime({
children,
timestamp,
}: {
children: React.ReactNode;
timestamp: number;
}) {
const isMounted = useIsMounted();
const { formatDateTime } = useTimeFormat();
return (
<abbr
title={
isMounted
? formatDateTime(new Date(timestamp), {
hour: "numeric",
minute: "numeric",
day: "numeric",
month: "long",
timeZoneName: "short",
})
: undefined
}
>
{children}
</abbr>
);
}