Skip to content

Commit

Permalink
use relative time on job detail created, add title w/ ISO utc time
Browse files Browse the repository at this point in the history
  • Loading branch information
bgentry committed May 15, 2024
1 parent eeddbd4 commit 100a512
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ui/src/components/JobDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import JobTimeline from "./JobTimeline";
import { FormEvent } from "react";
import { Link } from "@tanstack/react-router";
import TopNavTitleOnly from "./TopNavTitleOnly";
import RelativeTimeFormatter from "./RelativeTimeFormatter";

type JobDetailProps = {
cancel: () => void;
Expand Down Expand Up @@ -181,7 +182,7 @@ export default function JobDetail({ cancel, job, retry }: JobDetailProps) {
Created
</dt>
<dd className="mt-1 text-sm leading-6 text-slate-700 dark:text-slate-300 sm:mt-2">
{job.createdAt.toISOString()}
<RelativeTimeFormatter time={job.createdAt} addSuffix />
</dd>
</div>
</dl>
Expand Down
5 changes: 3 additions & 2 deletions ui/src/components/RelativeTimeFormatter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ const RelativeTimeFormatter = ({
includeSeconds,
humanize = false,
time,
}: RelativeTimeFormatterProps): string => {
}: RelativeTimeFormatterProps) => {
const nowSec = useTime();
const relative = useMemo(() => {
const now = new Date(nowSec * 1000);
return formatRelative(time, { addSuffix, includeSeconds, humanize, now });
}, [addSuffix, includeSeconds, humanize, nowSec, time]);
const utcTime = useMemo(() => time.toISOString(), [time]);

return relative;
return <span title={utcTime}>{relative}</span>;
};

export default RelativeTimeFormatter;

0 comments on commit 100a512

Please sign in to comment.