Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

refactor: consolidate six formatDate helpers into a shared lib/format helper (#887)

Boboa51a527cbbd4
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/citations/url/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/citations/url/page.tsx
index 503f2dd2b..d3f446468 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/citations/url/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/citations/url/page.tsx
@@ -52,20 +52,12 @@ import {
Target,
TrendingUp,
} from 'lucide-react';
+import { formatDate } from '@/lib/format';
import { cn } from '@/lib/utils';
const CITED_IN_PAGE_SIZE = 10;
const DATE_PRESET_VALUES: CitationsDatePreset[] = ['24h', '7d', '30d', '90d', 'all', 'custom'];
-function formatDate(iso: string | null): string {
- if (!iso) return '—';
- return new Date(iso).toLocaleDateString('en-US', {
- year: 'numeric',
- month: 'short',
- day: 'numeric',
- });
-}
-
function KpiCard({
title,
value,
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/reports/[id]/_report-pdf.tsx b/web/src/app/[locale]/(dashboard)/dashboard/reports/[id]/_report-pdf.tsx
index baae007be..c9383d608 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/reports/[id]/_report-pdf.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/reports/[id]/_report-pdf.tsx
@@ -23,6 +23,7 @@ import {
Line,
} from '@react-pdf/renderer';
import type { Report, ReportPromptPerf } from '@/lib/actions/reports';
+import { formatDate } from '@/lib/format';
Font.register({
family: 'Inter',
@@ -228,14 +229,6 @@ function PromptTable({ title, prompts }: { title: string; prompts: ReportPromptP
);
}
-function formatDate(iso: string) {
- return new Date(iso).toLocaleDateString('en-US', {
- year: 'numeric',
- month: 'short',
- day: 'numeric',
- });
-}
-
export function ReportPdfDocument({ report }: { report: Report }) {
const { payload } = report;
// Every metric field is optional — templates only gather their own
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/reports/[id]/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/reports/[id]/page.tsx
index b01496ce1..b41122b0d 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/reports/[id]/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/reports/[id]/page.tsx
@@ -26,20 +26,13 @@ import {
TableRow,
} from '@/components/ui/table';
import { ArrowLeft, FileDown, Loader2 } from 'lucide-react';
+import { formatDate } from '@/lib/format';
import { cn } from '@/lib/utils';
import { PLATFORM_LABELS } from '@/config/platform-labels';
import { REPORT_TEMPLATES } from '@/lib/reports/templates';
const KNOWN_TEMPLATE_IDS = new Set<string>(REPORT_TEMPLATES.map((tpl) => tpl.id));
-function formatDate(iso: string) {
- return new Date(iso).toLocaleDateString('en-US', {
- year: 'numeric',
- month: 'short',
- day: 'numeric',
- });
-}
-
/** Signed percentage delta, or an explicit raw count for a new zero-base metric. */
function Delta({ value, zeroBaseCount }: { value: number | null; zeroBaseCount?: number }) {
if (zeroBaseCount !== undefined) {
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/reports/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/reports/page.tsx
index e052b2280..9a3addd20 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/reports/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/reports/page.tsx
@@ -27,6 +27,7 @@ import {
TableRow,
} from '@/components/ui/table';
import { Check, FileBarChart, Loader2, Plus, Trash2 } from 'lucide-react';
+import { formatDate } from '@/lib/format';
import { cn } from '@/lib/utils';
import {
Select,
@@ -61,14 +62,6 @@ function getDateRange(preset: DatePreset, custom: { from: string; to: string })
return { dateFrom: from.toISOString(), dateTo: to.toISOString() };
}
-function formatDate(iso: string) {
- return new Date(iso).toLocaleDateString('en-US', {
- year: 'numeric',
- month: 'short',
- day: 'numeric',
- });
-}
-
export default function ReportsPage() {
const t = useTranslations('reports');
const tc = useTranslations('common');
diff --git a/web/src/components/settings/agent-section.tsx b/web/src/components/settings/agent-section.tsx
index 1cc115474..a100068b5 100644
--- a/web/src/components/settings/agent-section.tsx
+++ b/web/src/components/settings/agent-section.tsx
@@ -11,6 +11,7 @@ import { Skeleton } from '@/components/ui/skeleton';
import { Loader2, Lock, Sparkles, Trash2, CheckCircle2 } from 'lucide-react';
import { useTranslations } from 'next-intl';
import { useUserRole } from '@/hooks/use-user-role';
+import { formatDate } from '@/lib/format';
import {
Dialog,
DialogClose,
@@ -28,15 +29,6 @@ interface KeyState {
setByEmail: string | null;
}
-function formatDate(iso: string | null): string {
- if (!iso) return '—';
- return new Date(iso).toLocaleDateString(undefined, {
- year: 'numeric',
- month: 'short',
- day: 'numeric',
- });
-}
-
/**
* Settings → Agent.
*
diff --git a/web/src/components/settings/api-keys-section.tsx b/web/src/components/settings/api-keys-section.tsx
index 939d6e95d..ba988bf86 100644
--- a/web/src/components/settings/api-keys-section.tsx
+++ b/web/src/components/settings/api-keys-section.tsx
@@ -19,6 +19,7 @@ import { Skeleton } from '@/components/ui/skeleton';
import { Badge } from '@/components/ui/badge';
import { Copy, KeyRound, Loader2, Plus, Trash2 } from 'lucide-react';
import { useTranslations } from 'next-intl';
+import { formatDate } from '@/lib/format';
interface ApiKey {
id: string;
@@ -36,15 +37,6 @@ function getMcpEndpoint(): string {
return `${appUrl}/api/mcp`;
}
-function formatDate(iso: string | null): string {
- if (!iso) return '—';
- return new Date(iso).toLocaleDateString(undefined, {
- year: 'numeric',
- month: 'short',
- day: 'numeric',
- });
-}
-
export function ApiKeysSection() {
const t = useTranslations('settings');
const tCommon = useTranslations('common');
diff --git a/web/src/lib/format.ts b/web/src/lib/format.ts
index ac0f0124e..f54104470 100644
--- a/web/src/lib/format.ts
+++ b/web/src/lib/format.ts
@@ -15,3 +15,12 @@ export function formatCompactNumber(value: number): string {
return value.toLocaleString();
}
+
+export function formatDate(iso: string | null): string {
+ if (!iso) return '—';
+ return new Date(iso).toLocaleDateString('en-US', {
+ year: 'numeric',
+ month: 'short',
+ day: 'numeric',
+ });
+}