Skip to content

Automate browser based workflows with AI

Fix TOTP credentials page: display timestamps in local timezone with UTC on hover (#4993)

Cody Rayment7ebd91f5a299
diff --git a/skyvern-frontend/src/routes/credentials/CredentialsTotpTab.tsx b/skyvern-frontend/src/routes/credentials/CredentialsTotpTab.tsx
index 868347330..6ba1cd8a2 100644
--- a/skyvern-frontend/src/routes/credentials/CredentialsTotpTab.tsx
+++ b/skyvern-frontend/src/routes/credentials/CredentialsTotpTab.tsx
@@ -24,22 +24,12 @@ import {
import { Badge } from "@/components/ui/badge";
import type { OtpType, TotpCode } from "@/api/types";
import { Skeleton } from "@/components/ui/skeleton";
+import { basicLocalTimeFormat, basicTimeFormat } from "@/util/timeFormat";
type OtpTypeFilter = "all" | OtpType;
const LIMIT_OPTIONS = [25, 50, 100] as const;
-function formatDateTime(value: string | null): string {
- if (!value) {
- return "—";
- }
- const date = new Date(value);
- if (Number.isNaN(date.getTime())) {
- return value;
- }
- return date.toLocaleString();
-}
-
function renderCodeContent(code: TotpCode): string {
if (!code.code) {
return "—";
@@ -230,11 +220,23 @@ function CredentialsTotpTab() {
<TableCell className="text-xs">
{code.workflow_run_id ?? "—"}
</TableCell>
- <TableCell className="text-xs">
- {formatDateTime(code.created_at)}
+ <TableCell
+ className="text-xs"
+ title={basicTimeFormat(code.created_at)}
+ >
+ {basicLocalTimeFormat(code.created_at)}
</TableCell>
- <TableCell className="text-xs">
- {formatDateTime(code.expired_at)}
+ <TableCell
+ className="text-xs"
+ title={
+ code.expired_at
+ ? basicTimeFormat(code.expired_at)
+ : undefined
+ }
+ >
+ {code.expired_at
+ ? basicLocalTimeFormat(code.expired_at)
+ : "—"}
</TableCell>
</TableRow>
))}
diff --git a/skyvern-frontend/src/util/timeFormat.test.ts b/skyvern-frontend/src/util/timeFormat.test.ts
new file mode 100644
index 000000000..321ce7d29
--- /dev/null
+++ b/skyvern-frontend/src/util/timeFormat.test.ts
@@ -0,0 +1,42 @@
+// ABOUTME: Tests for timeFormat utility functions used across the frontend.
+// ABOUTME: Ensures UTC timestamps (with and without 'Z' suffix) are parsed correctly.
+import { describe, test, expect } from "vitest";
+import { basicLocalTimeFormat, basicTimeFormat } from "./timeFormat";
+
+describe("basicLocalTimeFormat", () => {
+ test("appends Z to parse a no-suffix UTC timestamp as UTC, not local time", () => {
+ // Backend returns naive UTC timestamps without 'Z', e.g. "2026-03-04T18:30:00.000000".
+ // Without the Z fix, JS would parse this as local time, which is wrong for non-UTC users.
+ // We verify the function produces the same output as if the Z were already present.
+ const withoutZ = "2026-03-04T18:30:00.000000";
+ const withZ = "2026-03-04T18:30:00.000000Z";
+ expect(basicLocalTimeFormat(withoutZ)).toBe(basicLocalTimeFormat(withZ));
+ });
+
+ test("handles timestamps already ending in Z", () => {
+ const result = basicLocalTimeFormat("2026-03-04T18:30:00Z");
+ expect(result).toContain("at");
+ expect(typeof result).toBe("string");
+ expect(result.length).toBeGreaterThan(0);
+ });
+
+ test("trims microseconds to milliseconds before parsing", () => {
+ const withMicros = "2026-03-04T18:30:00.123456";
+ const withMillis = "2026-03-04T18:30:00.123";
+ expect(basicLocalTimeFormat(withMicros)).toBe(
+ basicLocalTimeFormat(withMillis),
+ );
+ });
+});
+
+describe("basicTimeFormat", () => {
+ test("appends UTC label to the formatted string", () => {
+ const result = basicTimeFormat("2026-03-04T18:30:00Z");
+ expect(result).toMatch(/UTC$/);
+ });
+
+ test("includes date and time separated by 'at'", () => {
+ const result = basicTimeFormat("2026-03-04T18:30:00Z");
+ expect(result).toContain(" at ");
+ });
+});