Use react-timeago for DynamicDate component, improve relative timing display

This commit is contained in:
2024-05-09 22:09:42 -05:00
parent 1b78d7e37c
commit 757adcf385
3 changed files with 9 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
import type { FunctionComponent } from "react";
import { useBoolean } from "usehooks-ts";
import { format, formatDistanceToNow } from "date-fns";
import TimeAgo from "react-timeago";
type DynamicDateProps = {
value: Date | number;
@@ -23,11 +24,8 @@ const DynamicDate: FunctionComponent<DynamicDateProps> = ({
<button onClick={toggleFormat}>
<span title={date.toISOString()}>
{showAbsolute
? format(date, absoluteFormat ?? "LLL do, y HH:mm:ss")
: formatDistanceToNow(date, {
includeSeconds: true,
addSuffix: true,
})}
? format(date, absoluteFormat ?? "LLL do, y HH:mm:ss xxx")
: <TimeAgo date={date} />}
</span>
</button>
);