Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat: add timestamp tooltip

Marc Seitz80929073593c
diff --git a/components/analytics/documents-table.tsx b/components/analytics/documents-table.tsx
index 1607e1ec..9c6eda79 100644
--- a/components/analytics/documents-table.tsx
+++ b/components/analytics/documents-table.tsx
@@ -34,6 +34,7 @@ import {
TableHeader,
TableRow,
} from "@/components/ui/table";
+import { TimestampTooltip } from "@/components/ui/timestamp-tooltip";
import { DataTablePagination } from "@/components/visitors/data-table-pagination";
import { usePlan } from "@/lib/swr/use-billing";
@@ -151,11 +152,20 @@ const columns: ColumnDef<Document>[] = [
</Button>
);
},
- cell: ({ row }) => (
- <div className="text-sm text-muted-foreground">
- {row.original.lastViewed ? timeAgo(row.original.lastViewed) : "-"}
- </div>
- ),
+ cell: ({ row }) =>
+ row.original.lastViewed ? (
+ <TimestampTooltip
+ timestamp={row.original.lastViewed}
+ side="right"
+ rows={["local", "utc", "unix"]}
+ >
+ <div className="select-none text-sm text-muted-foreground">
+ {timeAgo(row.original.lastViewed)}
+ </div>
+ </TimestampTooltip>
+ ) : (
+ <div className="text-sm text-muted-foreground">-</div>
+ ),
},
];
diff --git a/components/analytics/links-table.tsx b/components/analytics/links-table.tsx
index f50e82eb..17eb9f90 100644
--- a/components/analytics/links-table.tsx
+++ b/components/analytics/links-table.tsx
@@ -27,6 +27,11 @@ import {
import { toast } from "sonner";
import useSWR from "swr";
+import { usePlan } from "@/lib/swr/use-billing";
+import { cn, timeAgo } from "@/lib/utils";
+import { fetcher } from "@/lib/utils";
+import { downloadCSV } from "@/lib/utils/csv";
+
import { Button } from "@/components/ui/button";
import {
Table,
@@ -36,13 +41,9 @@ import {
TableHeader,
TableRow,
} from "@/components/ui/table";
+import { TimestampTooltip } from "@/components/ui/timestamp-tooltip";
import { DataTablePagination } from "@/components/visitors/data-table-pagination";
-import { usePlan } from "@/lib/swr/use-billing";
-import { cn, timeAgo } from "@/lib/utils";
-import { fetcher } from "@/lib/utils";
-import { downloadCSV } from "@/lib/utils/csv";
-
import { UpgradeButton } from "../ui/upgrade-button";
interface Link {
@@ -213,11 +214,20 @@ const columns: ColumnDef<Link>[] = [
</Button>
);
},
- cell: ({ row }) => (
- <div className="text-sm text-muted-foreground">
- {row.original.lastViewed ? timeAgo(row.original.lastViewed) : "-"}
- </div>
- ),
+ cell: ({ row }) =>
+ row.original.lastViewed ? (
+ <TimestampTooltip
+ timestamp={row.original.lastViewed}
+ side="right"
+ rows={["local", "utc", "unix"]}
+ >
+ <div className="select-none text-sm text-muted-foreground">
+ {timeAgo(row.original.lastViewed)}
+ </div>
+ </TimestampTooltip>
+ ) : (
+ <div className="text-sm text-muted-foreground">-</div>
+ ),
},
];
diff --git a/components/analytics/views-table.tsx b/components/analytics/views-table.tsx
index f4cb9797..00309045 100644
--- a/components/analytics/views-table.tsx
+++ b/components/analytics/views-table.tsx
@@ -32,7 +32,12 @@ import { toast } from "sonner";
import useSWR from "swr";
import { usePlan } from "@/lib/swr/use-billing";
-import { cn, durationFormat, fetcher, timeAgo } from "@/lib/utils";
+import {
+ cn,
+ durationFormat,
+ fetcher,
+ timeAgo,
+} from "@/lib/utils";
import { downloadCSV } from "@/lib/utils/csv";
import { Button } from "@/components/ui/button";
@@ -45,6 +50,7 @@ import {
TableHeader,
TableRow,
} from "@/components/ui/table";
+import { TimestampTooltip } from "@/components/ui/timestamp-tooltip";
import { BadgeTooltip } from "@/components/ui/tooltip";
import { DataTablePagination } from "@/components/visitors/data-table-pagination";
import { VisitorAvatar } from "@/components/visitors/visitor-avatar";
@@ -259,9 +265,15 @@ const columns: ColumnDef<View>[] = [
);
},
cell: ({ row }) => (
- <div className="text-sm text-muted-foreground">
- {timeAgo(row.original.viewedAt)}
- </div>
+ <TimestampTooltip
+ timestamp={row.original.viewedAt}
+ side="right"
+ rows={["local", "utc", "unix"]}
+ >
+ <div className="select-none text-sm text-muted-foreground">
+ {timeAgo(row.original.viewedAt)}
+ </div>
+ </TimestampTooltip>
),
},
];
diff --git a/components/links/links-table.tsx b/components/links/links-table.tsx
index ccc9bca4..3ecdc749 100644
--- a/components/links/links-table.tsx
+++ b/components/links/links-table.tsx
@@ -56,6 +56,7 @@ import {
TableHeader,
TableRow,
} from "@/components/ui/table";
+import { TimestampTooltip } from "@/components/ui/timestamp-tooltip";
import FileProcessStatusBar from "../documents/file-process-status-bar";
import BarChart from "../shared/icons/bar-chart";
@@ -823,13 +824,20 @@ export default function LinksTable({
</TableCell>
<TableCell className="text-sm text-muted-foreground">
{link.views[0] ? (
- <time
- dateTime={new Date(
- link.views[0].viewedAt,
- ).toISOString()}
+ <TimestampTooltip
+ timestamp={link.views[0].viewedAt}
+ side="right"
+ rows={["local", "utc", "unix"]}
>
- {timeAgo(link.views[0].viewedAt)}
- </time>
+ <time
+ className="select-none"
+ dateTime={new Date(
+ link.views[0].viewedAt,
+ ).toISOString()}
+ >
+ {timeAgo(link.views[0].viewedAt)}
+ </time>
+ </TimestampTooltip>
) : (
"-"
)}
diff --git a/components/ui/timestamp-tooltip.tsx b/components/ui/timestamp-tooltip.tsx
new file mode 100644
index 00000000..4b099d33
--- /dev/null
+++ b/components/ui/timestamp-tooltip.tsx
@@ -0,0 +1,269 @@
+/**
+ * Portions of this file are adapted from dub.co (github.com/dubinc/dub).
+ * Copyright (c) Dub, Inc. and contributors. Published under AGPLv3 license.
+ * Source: https://github.com/dubinc/dub/blob/aaba1095e692e1756a29808181cca5bbf18ac06d/packages/ui/src/timestamp-tooltip.tsx
+ */
+
+"use client";
+
+import { useEffect, useMemo, useState } from "react";
+
+import { formatDuration, intervalToDuration } from "date-fns";
+import { toast } from "sonner";
+
+import { cn } from "@/lib/utils";
+
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipPortal,
+ TooltipTrigger,
+} from "./tooltip";
+
+const DAY_MS = 24 * 60 * 60 * 1000;
+const MONTH_MS = 30 * DAY_MS;
+
+export type TimestampTooltipProps = {
+ timestamp: Date | string | number | null | undefined;
+ rows?: ("local" | "utc" | "unix")[];
+ interactive?: boolean;
+ className?: string;
+ side?: "top" | "right" | "bottom" | "left";
+ align?: "start" | "center" | "end";
+ children?: React.ReactNode;
+};
+
+function getLocalTimeZone(): string {
+ if (typeof Intl !== "undefined") {
+ try {
+ return Intl.DateTimeFormat().resolvedOptions().timeZone || "Local";
+ } catch (e) {}
+ }
+ return "Local";
+}
+
+export function TimestampTooltip({
+ timestamp,
+ rows = ["local", "utc"],
+ interactive = true,
+ side = "top",
+ align = "center",
+ className,
+ children,
+}: TimestampTooltipProps) {
+ if (!timestamp || new Date(timestamp).toString() === "Invalid Date")
+ return <>{children}</>;
+
+ return (
+ <Tooltip>
+ <TooltipTrigger asChild onClick={(e) => e.stopPropagation()}>
+ {children}
+ </TooltipTrigger>
+ <TooltipPortal>
+ <TooltipContent
+ className={cn("p-0", className)}
+ side={side}
+ align={align}
+ sideOffset={8}
+ >
+ <TimestampTooltipContent
+ timestamp={timestamp}
+ rows={rows}
+ interactive={interactive}
+ />
+ </TooltipContent>
+ </TooltipPortal>
+ </Tooltip>
+ );
+}
+
+function TimestampTooltipContent({
+ timestamp,
+ rows = ["local", "utc"],
+ interactive,
+}: Pick<TimestampTooltipProps, "timestamp" | "rows" | "interactive">) {
+ if (!timestamp)
+ throw new Error("Falsy timestamp not permitted in TimestampTooltipContent");
+
+ const date = new Date(timestamp);
+ const commonFormat: Intl.DateTimeFormatOptions = {
+ year: "numeric",
+ month: "short",
+ day: "numeric",
+ hour: "numeric",
+ minute: "numeric",
+ second: "numeric",
+ hour12: true,
+ };
+
+ const diff = new Date().getTime() - date.getTime();
+ const relativeDuration = intervalToDuration({
+ start: date,
+ end: new Date(),
+ });
+
+ const relative =
+ formatDuration(relativeDuration, {
+ delimiter: ", ",
+ format: [
+ "years",
+ "months",
+ "days",
+ ...(diff < MONTH_MS
+ ? [
+ "hours" as const,
+ ...(diff < DAY_MS
+ ? ["minutes" as const, "seconds" as const]
+ : []),
+ ]
+ : []),
+ ],
+ }) + " ago";
+
+ const items: {
+ label: string;
+ shortLabel?: string;
+ successMessageLabel: string;
+ value: string;
+ valueMono?: boolean;
+ }[] = useMemo(
+ () =>
+ rows.map(
+ (key) =>
+ ({
+ local: {
+ label: getLocalTimeZone(),
+ shortLabel: new Date()
+ .toLocaleTimeString("en-US", { timeZoneName: "short" })
+ .split(" ")[2],
+ successMessageLabel: "local timestamp",
+ value: date.toLocaleString("en-US", commonFormat),
+ },
+ utc: {
+ label: "UTC",
+ shortLabel: "UTC",
+ successMessageLabel: "UTC timestamp",
+ value: new Date(date.getTime()).toLocaleString("en-US", {
+ ...commonFormat,
+ timeZone: "UTC",
+ }),
+ },
+ unix: {
+ label: "Timestamp",
+ successMessageLabel: "timestamp",
+ value: Math.floor(date.getTime()).toString(),
+ valueMono: true,
+ },
+ })[key]!,
+ ),
+ [rows, date],
+ );
+
+ const shortLabels = items.every(({ shortLabel }) => shortLabel);
+
+ // Re-render every second to update the relative time
+ const [_, setRenderCount] = useState(0);
+ useEffect(() => {
+ const interval = setInterval(() => setRenderCount((c) => c + 1), 1000);
+ return () => clearInterval(interval);
+ }, []);
+
+ return (
+ <div className="flex max-w-[360px] flex-col gap-2 px-2.5 py-2 text-left text-xs">
+ <table>
+ {items.map((row, idx) => (
+ <tr
+ key={idx}
+ className={cn(
+ interactive &&
+ "relative select-none before:absolute before:-inset-x-1 before:inset-y-0 before:rounded before:bg-muted before:opacity-0 before:content-[''] hover:cursor-copy hover:before:opacity-60 active:before:opacity-100",
+ )}
+ onClick={
+ interactive
+ ? async () => {
+ try {
+ await navigator.clipboard.writeText(row.value);
+ toast.success(
+ `Copied ${row.successMessageLabel} to clipboard`,
+ );
+ } catch (e) {
+ toast.error(
+ `Failed to copy ${row.successMessageLabel} to clipboard`,
+ );
+ console.error(
+ `Failed to copy ${row.successMessageLabel} to clipboard`,
+ e,
+ );
+ }
+ }
+ : undefined
+ }
+ >
+ <td className="relative py-0.5">
+ <span
+ className={cn(
+ "truncate text-muted-foreground",
+ shortLabels && "rounded bg-muted px-1 font-mono",
+ )}
+ title={shortLabels ? row.label : undefined}
+ >
+ {shortLabels ? row.shortLabel : row.label}
+ </span>
+ </td>
+ <td
+ className={cn(
+ "relative whitespace-nowrap py-0.5 pl-3 text-foreground",
+ shortLabels && "pl-2",
+ row.valueMono && "font-mono",
+ )}
+ >
+ {row.value}
+ </td>
+ </tr>
+ ))}
+ {diff > 0 && (
+ <tr
+ className={cn(
+ interactive &&
+ "relative select-none before:absolute before:-inset-x-1 before:inset-y-0 before:rounded before:bg-muted before:opacity-0 before:content-[''] hover:cursor-copy hover:before:opacity-60 active:before:opacity-100",
+ )}
+ onClick={
+ interactive
+ ? async () => {
+ try {
+ await navigator.clipboard.writeText(relative);
+ toast.success("Copied relative time to clipboard");
+ } catch (e) {
+ toast.error("Failed to copy relative time to clipboard");
+ console.error("Failed to copy relative time", e);
+ }
+ }
+ : undefined
+ }
+ >
+ <td className="relative py-0.5">
+ <span
+ className={cn(
+ "truncate text-muted-foreground",
+ shortLabels && "rounded bg-muted px-1 font-mono",
+ )}
+ >
+ Relative
+ </span>
+ </td>
+ <td
+ className={cn(
+ "relative whitespace-nowrap py-0.5 pl-3 text-foreground",
+ shortLabels && "pl-2",
+ )}
+ >
+ {relative}
+ </td>
+ </tr>
+ )}
+ </table>
+ </div>
+ );
+}
+
+export default TimestampTooltip;
diff --git a/components/visitors/contacts-document-table.tsx b/components/visitors/contacts-document-table.tsx
index 7dbb7d17..ec4a67f1 100644
--- a/components/visitors/contacts-document-table.tsx
+++ b/components/visitors/contacts-document-table.tsx
@@ -31,6 +31,7 @@ import {
TableHeader,
TableRow,
} from "@/components/ui/table";
+import { TimestampTooltip } from "@/components/ui/timestamp-tooltip";
type ViewerView = {
documentId: string;
@@ -181,9 +182,18 @@ export function ContactsDocumentsTable({
cell: ({ row }) => {
const view = row.original;
return (
- <time dateTime={new Date(view.lastViewed).toISOString()}>
- {timeAgo(view.lastViewed)}
- </time>
+ <TimestampTooltip
+ timestamp={view.lastViewed}
+ side="right"
+ rows={["local", "utc", "unix"]}
+ >
+ <time
+ className="select-none"
+ dateTime={new Date(view.lastViewed).toISOString()}
+ >
+ {timeAgo(view.lastViewed)}
+ </time>
+ </TimestampTooltip>
);
},
sortingFn: (rowA, rowB) => {
diff --git a/components/visitors/contacts-table.tsx b/components/visitors/contacts-table.tsx
index f02a060b..496a37ed 100644
--- a/components/visitors/contacts-table.tsx
+++ b/components/visitors/contacts-table.tsx
@@ -27,6 +27,7 @@ import {
TableHeader,
TableRow,
} from "@/components/ui/table";
+import { TimestampTooltip } from "@/components/ui/timestamp-tooltip";
import { VisitorAvatar } from "@/components/visitors/visitor-avatar";
import { Skeleton } from "../ui/skeleton";
@@ -172,12 +173,18 @@ export function ContactsTable({
cell: ({ row }) => {
const lastView = row.original.lastViewed;
return lastView ? (
- <time
- dateTime={new Date(lastView).toISOString()}
- className="text-sm text-muted-foreground"
+ <TimestampTooltip
+ timestamp={lastView}
+ side="right"
+ rows={["local", "utc", "unix"]}
>
- {timeAgo(lastView)}
- </time>
+ <time
+ className="select-none text-sm text-muted-foreground"
+ dateTime={new Date(lastView).toISOString()}
+ >
+ {timeAgo(lastView)}
+ </time>
+ </TimestampTooltip>
) : (
<div className="text-sm text-muted-foreground">-</div>
);
diff --git a/components/visitors/dataroom-viewers.tsx b/components/visitors/dataroom-viewers.tsx
index 9936da13..f06505fd 100644
--- a/components/visitors/dataroom-viewers.tsx
+++ b/components/visitors/dataroom-viewers.tsx
@@ -24,6 +24,7 @@ import {
TableHeader,
TableRow,
} from "@/components/ui/table";
+import { TimestampTooltip } from "@/components/ui/timestamp-tooltip";
import { BadgeTooltip } from "@/components/ui/tooltip";
import DataroomVisitHistory from "./dataroom-visitors-history";
@@ -131,13 +132,24 @@ export default function DataroomViewersTable({
</TableCell> */}
{/* Last Viewed */}
<TableCell className="text-sm text-muted-foreground">
- <time
- dateTime={new Date(viewer.lastViewedAt).toISOString()}
- >
- {viewer.lastViewedAt
- ? timeAgo(viewer.lastViewedAt)
- : "-"}
- </time>
+ {viewer.lastViewedAt ? (
+ <TimestampTooltip
+ timestamp={viewer.lastViewedAt}
+ side="right"
+ rows={["local", "utc", "unix"]}
+ >
+ <time
+ className="select-none"
+ dateTime={new Date(
+ viewer.lastViewedAt,
+ ).toISOString()}
+ >
+ {timeAgo(viewer.lastViewedAt)}
+ </time>
+ </TimestampTooltip>
+ ) : (
+ "-"
+ )}
</TableCell>
{/* Actions */}
<TableCell className="cursor-pointer p-0 text-center sm:text-right">
@@ -164,19 +176,20 @@ export default function DataroomViewersTable({
</TableCell>
<TableCell>
- <div>
+ <TimestampTooltip
+ timestamp={view.viewedAt}
+ side="right"
+ rows={["local", "utc", "unix"]}
+ >
<time
- className="truncate text-sm text-muted-foreground"
+ className="select-none truncate text-sm text-muted-foreground"
dateTime={new Date(
view.viewedAt,
- ).toLocaleString()}
- title={new Date(
- view.viewedAt,
- ).toLocaleString()}
+ ).toISOString()}
>
{timeAgo(view.viewedAt)}
</time>
- </div>
+ </TimestampTooltip>
</TableCell>
<TableCell className="table-cell"></TableCell>
</TableRow>
@@ -191,19 +204,20 @@ export default function DataroomViewersTable({
</TableCell>
<TableCell>
- <div>
+ <TimestampTooltip
+ timestamp={view.downloadedAt}
+ side="right"
+ rows={["local", "utc", "unix"]}
+ >
<time
- className="truncate text-sm text-muted-foreground"
+ className="select-none truncate text-sm text-muted-foreground"
dateTime={new Date(
view.downloadedAt,
- ).toLocaleString()}
- title={new Date(
- view.downloadedAt,
- ).toLocaleString()}
+ ).toISOString()}
>
{timeAgo(view.downloadedAt)}
</time>
- </div>
+ </TimestampTooltip>
</TableCell>
<TableCell className="table-cell"></TableCell>
</TableRow>
diff --git a/components/visitors/dataroom-visitors-history.tsx b/components/visitors/dataroom-visitors-history.tsx
index a37f3eb2..31356ac9 100644
--- a/components/visitors/dataroom-visitors-history.tsx
+++ b/components/visitors/dataroom-visitors-history.tsx
@@ -19,6 +19,7 @@ import {
import { ScrollArea } from "@/components/ui/scroll-area";
import { Skeleton } from "@/components/ui/skeleton";
import { TableCell, TableRow } from "@/components/ui/table";
+import { TimestampTooltip } from "@/components/ui/timestamp-tooltip";
export default function DataroomVisitHistory({
viewId,
@@ -151,13 +152,18 @@ export default function DataroomVisitHistory({
</div>
</TableCell>
<TableCell>
- <time
- className="truncate text-sm text-muted-foreground"
- dateTime={event.timestamp.toISOString()}
- title={event.timestamp.toLocaleString()}
+ <TimestampTooltip
+ timestamp={event.timestamp}
+ side="right"
+ rows={["local", "utc", "unix"]}
>
- {timeAgo(event.timestamp)}
- </time>
+ <time
+ className="select-none truncate text-sm text-muted-foreground"
+ dateTime={event.timestamp.toISOString()}
+ >
+ {timeAgo(event.timestamp)}
+ </time>
+ </TimestampTooltip>
</TableCell>
<TableCell className="table-cell">
<div className="flex items-center justify-end space-x-4">
@@ -253,13 +259,18 @@ export default function DataroomVisitHistory({
</div>
</TableCell>
<TableCell>
- <time
- className="truncate text-sm text-muted-foreground"
- dateTime={event.timestamp.toISOString()}
- title={event.timestamp.toLocaleString()}
+ <TimestampTooltip
+ timestamp={event.timestamp}
+ side="right"
+ rows={["local", "utc", "unix"]}
>
- {timeAgo(event.timestamp)}
- </time>
+ <time
+ className="select-none truncate text-sm text-muted-foreground"
+ dateTime={event.timestamp.toISOString()}
+ >
+ {timeAgo(event.timestamp)}
+ </time>
+ </TimestampTooltip>
</TableCell>
<TableCell className="table-cell"></TableCell>
</TableRow>
@@ -277,13 +288,18 @@ export default function DataroomVisitHistory({
</div>
</TableCell>
<TableCell>
- <time
- className="truncate text-sm text-muted-foreground"
- dateTime={event.timestamp.toISOString()}
- title={event.timestamp.toLocaleString()}
+ <TimestampTooltip
+ timestamp={event.timestamp}
+ side="right"
+ rows={["local", "utc", "unix"]}
>
- {timeAgo(event.timestamp)}
- </time>
+ <time
+ className="select-none truncate text-sm text-muted-foreground"
+ dateTime={event.timestamp.toISOString()}
+ >
+ {timeAgo(event.timestamp)}
+ </time>
+ </TimestampTooltip>
</TableCell>
<TableCell className="table-cell">
<div className="flex items-center justify-end space-x-4">
@@ -309,13 +325,18 @@ export default function DataroomVisitHistory({
</div>
</TableCell>
<TableCell>
- <time
- className="truncate text-sm text-muted-foreground"
- dateTime={event.timestamp.toISOString()}
- title={event.timestamp.toLocaleString()}
+ <TimestampTooltip
+ timestamp={event.timestamp}
+ side="right"
+ rows={["local", "utc", "unix"]}
>
- {timeAgo(event.timestamp)}
- </time>
+ <time
+ className="select-none truncate text-sm text-muted-foreground"
+ dateTime={event.timestamp.toISOString()}
+ >
+ {timeAgo(event.timestamp)}
+ </time>
+ </TimestampTooltip>
</TableCell>
<TableCell className="table-cell">
<div className="flex items-center justify-end space-x-4">
diff --git a/components/visitors/dataroom-visitors-table.tsx b/components/visitors/dataroom-visitors-table.tsx
index 9e33e27f..91c40a57 100644
--- a/components/visitors/dataroom-visitors-table.tsx
+++ b/components/visitors/dataroom-visitors-table.tsx
@@ -31,6 +31,7 @@ import {
TableHeader,
TableRow,
} from "@/components/ui/table";
+import { TimestampTooltip } from "@/components/ui/timestamp-tooltip";
import { BadgeTooltip } from "@/components/ui/tooltip";
import { ExportVisitsModal } from "../datarooms/export-visits-modal";
@@ -165,9 +166,18 @@ export default function DataroomVisitorsTable({
</TableCell> */}
{/* Last Viewed */}
<TableCell className="text-sm text-muted-foreground">
- <time dateTime={new Date(view.viewedAt).toISOString()}>
- {timeAgo(view.viewedAt)}
- </time>
+ <TimestampTooltip
+ timestamp={view.viewedAt}
+ side="right"
+ rows={["local", "utc", "unix"]}
+ >
+ <time
+ className="select-none"
+ dateTime={new Date(view.viewedAt).toISOString()}
+ >
+ {timeAgo(view.viewedAt)}
+ </time>
+ </TimestampTooltip>
</TableCell>
{/* Actions */}
<TableCell className="cursor-pointer p-0 text-center sm:text-right">
@@ -200,17 +210,18 @@ export default function DataroomVisitorsTable({
</TableCell>
<TableCell>
- <div>
+ <TimestampTooltip
+ timestamp={view.viewedAt}
+ side="right"
+ rows={["local", "utc", "unix"]}
+ >
<time
- className="truncate text-sm text-muted-foreground"
- dateTime={new Date(
- view.viewedAt,
- ).toLocaleString()}
- title={new Date(view.viewedAt).toLocaleString()}
+ className="select-none truncate text-sm text-muted-foreground"
+ dateTime={new Date(view.viewedAt).toISOString()}
>
{timeAgo(view.viewedAt)}
</time>
- </div>
+ </TimestampTooltip>
</TableCell>
<TableCell className="table-cell"></TableCell>
</TableRow>
@@ -225,19 +236,20 @@ export default function DataroomVisitorsTable({
</TableCell>
<TableCell>
- <div>
+ <TimestampTooltip
+ timestamp={view.downloadedAt}
+ side="right"
+ rows={["local", "utc", "unix"]}
+ >
<time
- className="truncate text-sm text-muted-foreground"
+ className="select-none truncate text-sm text-muted-foreground"
dateTime={new Date(
view.downloadedAt,
- ).toLocaleString()}
- title={new Date(
- view.downloadedAt,
- ).toLocaleString()}
+ ).toISOString()}
>
{timeAgo(view.downloadedAt)}
</time>
- </div>
+ </TimestampTooltip>
</TableCell>
<TableCell className="table-cell"></TableCell>
</TableRow>
diff --git a/components/visitors/visitors-table.tsx b/components/visitors/visitors-table.tsx
index b00d3169..93b79291 100644
--- a/components/visitors/visitors-table.tsx
+++ b/components/visitors/visitors-table.tsx
@@ -40,6 +40,7 @@ import {
TableHeader,
TableRow,
} from "@/components/ui/table";
+import { TimestampTooltip } from "@/components/ui/timestamp-tooltip";
import { BadgeTooltip } from "@/components/ui/tooltip";
import { UpgradePlanModal } from "../billing/upgrade-plan-modal";
@@ -206,9 +207,18 @@ export default function VisitorsTable({
</TableCell>
{/* Last Viewed */}
<TableCell className="text-sm text-muted-foreground">
- <time dateTime={new Date(view.viewedAt).toISOString()}>
- {timeAgo(view.viewedAt)}
- </time>
+ <TimestampTooltip
+ timestamp={view.viewedAt}
+ side="right"
+ rows={["local", "utc", "unix"]}
+ >
+ <time
+ className="select-none"
+ dateTime={new Date(view.viewedAt).toISOString()}
+ >
+ {timeAgo(view.viewedAt)}
+ </time>
+ </TimestampTooltip>
</TableCell>
{/* Actions */}
@@ -353,11 +363,18 @@ export default function VisitorsTable({
</TableCell>
{/* Last Viewed */}
<TableCell className="text-sm text-muted-foreground">
- <time
- dateTime={new Date(view.viewedAt).toISOString()}
+ <TimestampTooltip
+ timestamp={view.viewedAt}
+ side="right"
+ rows={["local", "utc", "unix"]}
>
- {timeAgo(view.viewedAt)}
- </time>
+ <time
+ className="select-none"
+ dateTime={new Date(view.viewedAt).toISOString()}
+ >
+ {timeAgo(view.viewedAt)}
+ </time>
+ </TimestampTooltip>
</TableCell>
{/* Actions */}
diff --git a/lib/utils.ts b/lib/utils.ts
index 2c1ac162..236a2986 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -162,21 +162,20 @@ export function capitalize(str: string) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
-export const timeAgo = (timestamp?: Date): string => {
+export const timeAgo = (timestamp?: Date | string | number): string => {
if (!timestamp) return "Just now";
- const diff = Date.now() - new Date(timestamp).getTime();
+ const date = new Date(timestamp);
+ const diff = Date.now() - date.getTime();
if (diff < 60000) {
// less than 1 second
return "Just now";
} else if (diff > 82800000) {
// more than 23 hours – similar to how Twitter displays timestamps
- return new Date(timestamp).toLocaleDateString("en-US", {
+ return date.toLocaleDateString("en-US", {
month: "short",
day: "numeric",
year:
- new Date(timestamp).getFullYear() !== new Date().getFullYear()
- ? "numeric"
- : undefined,
+ date.getFullYear() !== new Date().getFullYear() ? "numeric" : undefined,
});
}
return `${ms(diff)} ago`;