Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Update TimestampInfo to accept a UTC timestamp by default (#31167)

Jordi Enriced69371b76f9
diff --git a/apps/studio/components/interfaces/Auth/Users/UserLogs.tsx b/apps/studio/components/interfaces/Auth/Users/UserLogs.tsx
index b42598509c0..2ec1e4f43d8 100644
--- a/apps/studio/components/interfaces/Auth/Users/UserLogs.tsx
+++ b/apps/studio/components/interfaces/Auth/Users/UserLogs.tsx
@@ -112,7 +112,7 @@ export const UserLogs = ({ user }: UserLogsProps) => {
className="flex items-center transition font-mono px-2 py-1.5 bg-surface-100 divide-x"
>
<p className="text-xs text-foreground-light min-w-[125px] w-[125px] px-1">
- <TimestampInfo value={log.timestamp / 1000} />
+ <TimestampInfo utcTimestamp={log.timestamp / 1000} />
</p>
<div className="flex items-center text-xs text-foreground-light h-[22px] min-w-[70px] w-[70px] px-2">
<div
diff --git a/apps/studio/components/interfaces/Database/Backups/RestoreToNewProject/BackupsList.tsx b/apps/studio/components/interfaces/Database/Backups/RestoreToNewProject/BackupsList.tsx
index 39d049e64a9..cc7495d3e53 100644
--- a/apps/studio/components/interfaces/Database/Backups/RestoreToNewProject/BackupsList.tsx
+++ b/apps/studio/components/interfaces/Database/Backups/RestoreToNewProject/BackupsList.tsx
@@ -1,11 +1,11 @@
+import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import Panel from 'components/ui/Panel'
-import BackupsEmpty from '../BackupsEmpty'
import { useCloneBackupsQuery } from 'data/projects/clone-query'
-import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
import { Badge, Button } from 'ui'
import { TimestampInfo } from 'ui-patterns'
+import BackupsEmpty from '../BackupsEmpty'
interface BackupsListProps {
onSelectRestore: (id: number) => void
@@ -37,7 +37,7 @@ export const BackupsList = ({ onSelectRestore, disabled }: BackupsListProps) =>
return (
<div className="grid grid-cols-4 gap-4 items-center p-4" key={backup.id}>
<div>
- <TimestampInfo value={backup.inserted_at} />
+ <TimestampInfo utcTimestamp={backup.inserted_at} />
</div>
<div>
<Badge>{JSON.stringify(backup.status).replaceAll('"', '')}</Badge>
diff --git a/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/AuthColumnRenderer.tsx b/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/AuthColumnRenderer.tsx
index 32401f8ffd5..6262a2ef899 100644
--- a/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/AuthColumnRenderer.tsx
+++ b/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/AuthColumnRenderer.tsx
@@ -16,7 +16,7 @@ const columns: Column<LogData>[] = [
return (
<RowLayout>
- <TimestampInfo value={props.row.timestamp!} />
+ <TimestampInfo utcTimestamp={props.row.timestamp!} />
{props.row.level && <SeverityFormatter value={props.row.level as string} />}
<TextFormatter
className="w-full"
diff --git a/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/DatabaseApiColumnRender.tsx b/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/DatabaseApiColumnRender.tsx
index 422f4765102..8eac7a4f6bf 100644
--- a/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/DatabaseApiColumnRender.tsx
+++ b/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/DatabaseApiColumnRender.tsx
@@ -14,7 +14,7 @@ const columns: Column<LogData>[] = [
}
return (
<RowLayout>
- <TimestampInfo value={props.row.timestamp!} />
+ <TimestampInfo utcTimestamp={props.row.timestamp!} />
<ResponseCodeFormatter row={props} value={props.row.status_code} />
<TextFormatter className="w-20" value={props.row.method as string} />
<TextFormatter className="w-full" value={props.row.path as string} />
diff --git a/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/DatabasePostgresColumnRender.tsx b/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/DatabasePostgresColumnRender.tsx
index 46e8f5aa4ed..6692a29465d 100644
--- a/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/DatabasePostgresColumnRender.tsx
+++ b/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/DatabasePostgresColumnRender.tsx
@@ -14,7 +14,7 @@ const columns: Column<LogData>[] = [
}
return (
<RowLayout>
- <TimestampInfo value={props.row.timestamp!} />
+ <TimestampInfo utcTimestamp={props.row.timestamp!} />
<SeverityFormatter value={props.row.error_severity as string} />
<TextFormatter className="w-full" value={props.row.event_message} />
</RowLayout>
diff --git a/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/DefaultPreviewColumnRenderer.tsx b/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/DefaultPreviewColumnRenderer.tsx
index 5025e2b513e..997361ffbb9 100644
--- a/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/DefaultPreviewColumnRenderer.tsx
+++ b/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/DefaultPreviewColumnRenderer.tsx
@@ -5,7 +5,7 @@ import { TimestampInfo } from 'ui-patterns/TimestampInfo'
export const defaultRenderCell = (props: RenderCellProps<LogData, unknown>) => (
<RowLayout>
- <TimestampInfo value={props.row.timestamp!} />
+ <TimestampInfo utcTimestamp={props.row.timestamp!} />
<TextFormatter className="w-full" value={props.row.event_message} />
</RowLayout>
)
diff --git a/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/FunctionsEdgeColumnRender.tsx b/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/FunctionsEdgeColumnRender.tsx
index 147732803d3..9d76d5a880f 100644
--- a/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/FunctionsEdgeColumnRender.tsx
+++ b/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/FunctionsEdgeColumnRender.tsx
@@ -14,7 +14,7 @@ const columns: Column<LogData>[] = [
}
return (
<RowLayout>
- <TimestampInfo value={props.row.timestamp!} />
+ <TimestampInfo utcTimestamp={props.row.timestamp!} />
<ResponseCodeFormatter row={props} value={props.row.status_code} />
<TextFormatter value={props.row.method as string} />
<TextFormatter value={props.row.id} />
diff --git a/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/FunctionsLogsColumnRender.tsx b/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/FunctionsLogsColumnRender.tsx
index ba43620699f..9fcb99c4216 100644
--- a/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/FunctionsLogsColumnRender.tsx
+++ b/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/FunctionsLogsColumnRender.tsx
@@ -14,7 +14,7 @@ const columns: Column<LogData>[] = [
}
return (
<RowLayout>
- <TimestampInfo value={props.row.timestamp!} />
+ <TimestampInfo utcTimestamp={props.row.timestamp!} />
{props.row.event_type === 'uncaughtException' ? (
<SeverityFormatter value={props.row.event_type} uppercase={false} />
) : (
diff --git a/apps/studio/pages/project/[ref]/database/backups/restore-to-new-project.tsx b/apps/studio/pages/project/[ref]/database/backups/restore-to-new-project.tsx
index c9fc727a6f1..a4ffed86e90 100644
--- a/apps/studio/pages/project/[ref]/database/backups/restore-to-new-project.tsx
+++ b/apps/studio/pages/project/[ref]/database/backups/restore-to-new-project.tsx
@@ -150,7 +150,7 @@ const RestoreToNewProject = () => {
<div>
<TimestampInfo
className="font-mono text-xs text-foreground-lighter"
- value={clone.inserted_at ?? ''}
+ utcTimestamp={clone.inserted_at ?? ''}
/>
</div>
</div>
@@ -168,7 +168,7 @@ const RestoreToNewProject = () => {
<div>
<TimestampInfo
className="font-mono text-xs text-foreground-lighter"
- value={clone.inserted_at ?? ''}
+ utcTimestamp={clone.inserted_at ?? ''}
/>
</div>
<div className="flex items-center justify-end text-foreground-lighter group-hover:text-foreground">
diff --git a/packages/ui-patterns/TimestampInfo/index.tsx b/packages/ui-patterns/TimestampInfo/index.tsx
index c7f49108553..fe843c5d2d2 100644
--- a/packages/ui-patterns/TimestampInfo/index.tsx
+++ b/packages/ui-patterns/TimestampInfo/index.tsx
@@ -20,37 +20,52 @@ const isUnixMicro = (unix: string | number): boolean => {
return isNum && digitLength
}
-const timestampLocalFormatter = (value: string | number) => {
- const timestamp = isUnixMicro(value) ? unixMicroToIsoTimestamp(value) : value
- return dayjs(timestamp).format('DD MMM HH:mm:ss')
+type TimestampFormatter = {
+ utcTimestamp: string | number
+ format?: string
}
-const timestampUtcFormatter = (value: string | number) => {
- const timestamp = isUnixMicro(value) ? unixMicroToIsoTimestamp(value) : value
- return dayjs(timestamp).utc().format('DD MMM HH:mm:ss')
+const timestampLocalFormatter = ({ utcTimestamp, format }: TimestampFormatter) => {
+ const timestamp = isUnixMicro(utcTimestamp) ? unixMicroToIsoTimestamp(utcTimestamp) : utcTimestamp
+ return dayjs.utc(timestamp).local().format(format)
}
-const timestampRelativeFormatter = (value: string | number) => {
- const timestamp = isUnixMicro(value) ? unixMicroToIsoTimestamp(value) : value
- return dayjs(timestamp).fromNow()
+const timestampUtcFormatter = ({ utcTimestamp, format }: TimestampFormatter) => {
+ const timestamp = isUnixMicro(utcTimestamp) ? unixMicroToIsoTimestamp(utcTimestamp) : utcTimestamp
+ return dayjs.utc(timestamp).format(format)
}
+const timestampRelativeFormatter = ({ utcTimestamp }: TimestampFormatter) => {
+ const timestamp = isUnixMicro(utcTimestamp) ? unixMicroToIsoTimestamp(utcTimestamp) : utcTimestamp
+ return dayjs.utc(timestamp).fromNow()
+}
+
+/**
+ * TimestampInfo component displays a timestamp with a tooltip showing various time formats.
+ * @param {string|number} props.utcTimestamp - UTC timestamp value. Can be either:
+ * - ISO 8601 string (e.g., "2024-01-01T00:00:00Z")
+ * - Unix microseconds (16-digit number)
+ * @param {string} [props.format="DD MMM HH:mm:ss"] - Display format for the timestamp (using dayjs format)
+ * @returns {JSX.Element} Timestamp display with tooltip showing UTC, local, relative, and raw timestamp values
+ */
export const TimestampInfo = ({
- value,
+ utcTimestamp,
className,
+ format = 'DD MMM HH:mm:ss',
}: {
className?: string
- value: string | number
+ utcTimestamp: string | number
+ format?: string
}) => {
- const local = timestampLocalFormatter(value)
- const utc = timestampUtcFormatter(value)
- const relative = timestampRelativeFormatter(value)
+ const local = timestampLocalFormatter({ utcTimestamp, format })
+ const utc = timestampUtcFormatter({ utcTimestamp, format })
+ const relative = timestampRelativeFormatter({ utcTimestamp })
const [align, setAlign] = useState<'start' | 'end'>('start')
const triggerRef = useRef<HTMLButtonElement>(null)
const localTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone
// Calculate alignment based on trigger position
- // Needed so that the tooltip isn't hidden behind the header on top rows
+ // Needed so that the tooltip isn't hidden behind the header on top rows (in logs)
useEffect(() => {
const updateAlignment = () => {
if (triggerRef.current) {
@@ -77,6 +92,7 @@ export const TimestampInfo = ({
<span
onClick={(e) => {
e.stopPropagation()
+ e.preventDefault()
navigator.clipboard.writeText(value)
setCopied(true)
@@ -110,13 +126,13 @@ export const TimestampInfo = ({
ref={triggerRef}
className={`text-xs ${className} border-b border-transparent hover:border-dashed hover:border-foreground-light`}
>
- <span>{timestampLocalFormatter(value)}</span>
+ <span>{timestampLocalFormatter({ utcTimestamp, format })}</span>
</TooltipTrigger>
<TooltipContent align={align} side="right" className="font-mono p-0 py-1">
<TooltipRow label="UTC" value={utc} />
<TooltipRow label={`${localTimezone}`} value={local} />
<TooltipRow label="Relative" value={relative} />
- <TooltipRow label="Timestamp" value={String(value)} />
+ <TooltipRow label="Timestamp" value={String(utcTimestamp)} />
</TooltipContent>
</Tooltip>
)