Skip to content

Commit 2902694

Browse files
committed
feat: added format time functions
1 parent 7157d41 commit 2902694

7 files changed

Lines changed: 45 additions & 32 deletions

File tree

src/features/database/components/MigrationsPanel.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ScrollArea } from "@/components/ui/scroll-area";
66
import { MigrationsData } from "@/features/database/types";
77
import { useMigrationsPanel } from "../hooks/useMigrationsPanel";
88
import { cn } from "@/lib/utils";
9+
import { formatTimestamp } from "@/lib/utils";
910

1011
interface MigrationsPanelProps {
1112
migrations: MigrationsData;
@@ -72,7 +73,7 @@ export default function MigrationsPanel({ migrations, baselined, dbId }: Migrati
7273
<div className="bg-muted/30 rounded-lg p-3 border border-border/30">
7374
<div className="text-xs text-muted-foreground mb-1">Pending</div>
7475
<div className="text-2xl font-bold text-foreground">
75-
{local.length - applied.length}
76+
{allMigrations.filter(m => m.status === "pending").length}
7677
</div>
7778
</div>
7879
</div>
@@ -183,16 +184,9 @@ function MigrationItem({ migration, onApply, onRollback, onDelete, onViewSQL }:
183184
{migration.name}
184185
</p>
185186
{migration.appliedAt && (
187+
console.log(formatTimestamp(migration.appliedAt)),
186188
<p className="text-xs text-muted-foreground/70 mt-1">
187-
Applied: {new Date(migration.appliedAt).toLocaleString('en-IN', {
188-
year: 'numeric',
189-
month: 'short',
190-
day: 'numeric',
191-
hour: '2-digit',
192-
minute: '2-digit',
193-
hour12: true,
194-
timeZone: 'Asia/Kolkata'
195-
})}
189+
Applied: {formatTimestamp(migration.appliedAt)}
196190
</p>
197191
)}
198192
</div>

src/features/home/components/ConnectionDetails.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
22
import { DatabaseConnection } from "@/features/database/types"
3+
import { formatTimestamp } from "@/lib/utils"
34

45
export function ConnectionDetails({ database }: { database: DatabaseConnection }) {
56
return (
@@ -41,7 +42,7 @@ export function ConnectionDetails({ database }: { database: DatabaseConnection }
4142
<div className="flex items-center justify-between py-2">
4243
<span className="text-sm text-muted-foreground">Created</span>
4344
<span className="text-sm">
44-
{new Date(database.createdAt).toLocaleDateString()}
45+
{formatTimestamp(database.createdAt)}
4546
</span>
4647
</div>
4748
</CardContent>

src/features/home/components/DatabaseOverviewPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Card, CardAction, CardContent, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
22
import { Clock, Database, HardDrive, Table2, Layers, GitBranch, FileCode2 } from "lucide-react";
3-
import { formatRelativeTime } from "../utils";
3+
import { formatRelativeTime } from "@/lib/utils";
44
import { DatabaseConnection } from "@/features/database/types";
55
import { ConnectionDetails } from "./ConnectionDetails";
66
import { MigrationStatusCard } from "./MigrationStatusCard";

src/features/home/components/WelcomeView.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ import {
99
Layers,
1010
} from "lucide-react";
1111
import { Button } from "@/components/ui/button";
12-
import { cn } from "@/lib/utils";
12+
import { cn, formatRelativeTime } from "@/lib/utils";
1313
import { WelcomeViewProps } from "../types";
14-
import { formatRelativeTime } from "../utils";
1514
import { DiscoveredDatabasesCard } from "./DiscoveredDatabasesCard";
1615
import { Spinner } from "@/components/ui/spinner";
1716
import { Card, CardAction, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";

src/features/home/components/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ export { AddConnectionDialog } from "./AddConnectionDialog";
55
export { DeleteDialog } from "./DeleteDialog";
66
export { DiscoveredDatabasesCard } from "./DiscoveredDatabasesCard";
77
export * from "../types";
8-
export * from "../utils";

src/features/home/utils.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/lib/utils.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,40 @@ import { twMerge } from "tailwind-merge"
44
export function cn(...inputs: ClassValue[]) {
55
return twMerge(clsx(inputs))
66
}
7+
8+
/**
9+
* Format an ISO timestamp string to a readable local date/time.
10+
* e.g. "2026-06-12T12:46:20.671Z" → "12 Jun 2026, 12:46 pm"
11+
*/
12+
export function formatTimestamp(dateString?: string | null): string {
13+
if (!dateString) return "—";
14+
const date = new Date(dateString);
15+
if (isNaN(date.getTime())) return dateString;
16+
return date.toLocaleString(undefined, {
17+
day: "2-digit",
18+
month: "short",
19+
year: "numeric",
20+
hour: "2-digit",
21+
minute: "2-digit",
22+
hour12: true,
23+
});
24+
}
25+
26+
/**
27+
* Show relative time for recent events, fall back to formatTimestamp for older ones.
28+
* e.g. "5m ago", "2h ago", "3d ago", or "12 Jun 2026, 12:46 pm"
29+
*/
30+
export function formatRelativeTime(dateString?: string | null): string {
31+
if (!dateString) return "Never";
32+
const date = new Date(dateString);
33+
if (isNaN(date.getTime())) return dateString;
34+
const diffMs = Date.now() - date.getTime();
35+
const diffMins = Math.floor(diffMs / 60000);
36+
const diffHours = Math.floor(diffMs / 3600000);
37+
const diffDays = Math.floor(diffMs / 86400000);
38+
if (diffMins < 1) return "Just now";
39+
if (diffMins < 60) return `${diffMins}m ago`;
40+
if (diffHours < 24) return `${diffHours}h ago`;
41+
if (diffDays < 7) return `${diffDays}d ago`;
42+
return formatTimestamp(dateString);
43+
}

0 commit comments

Comments
 (0)