From 4407c24522c1e1e2283b857eaee5d3094e87ef59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=82CHES?= Date: Tue, 17 Mar 2026 18:29:54 -0600 Subject: [PATCH] fix: deduplicate formatDateShort into shared/format-utils (#1032) Co-authored-by: Claude Opus 4.6 (1M context) --- src/resources/extensions/gsd/export-html.ts | 8 +------- src/resources/extensions/gsd/reports.ts | 8 +------- src/resources/extensions/shared/format-utils.ts | 10 ++++++++++ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/resources/extensions/gsd/export-html.ts b/src/resources/extensions/gsd/export-html.ts index df7eb316d..07456fa12 100644 --- a/src/resources/extensions/gsd/export-html.ts +++ b/src/resources/extensions/gsd/export-html.ts @@ -25,7 +25,7 @@ import type { VisualizerMilestone, VisualizerSlice, } from './visualizer-data.js'; -import { formatDuration } from '../shared/format-utils.js'; +import { formatDateShort, formatDuration } from '../shared/format-utils.js'; import { formatCost, formatTokenCount } from './metrics.js'; // ─── Public API ──────────────────────────────────────────────────────────────── @@ -767,12 +767,6 @@ function formatDateLong(iso: string): string { } catch { return iso; } } -function formatDateShort(iso: string): string { - try { - const d = new Date(iso); - return d.toLocaleString('en-US', { month: 'short', day: 'numeric', year: 'numeric', hour: '2-digit', minute: '2-digit' }); - } catch { return iso; } -} function esc(s: string | undefined | null): string { if (s == null) return ''; diff --git a/src/resources/extensions/gsd/reports.ts b/src/resources/extensions/gsd/reports.ts index 4901456db..4f4adc60a 100644 --- a/src/resources/extensions/gsd/reports.ts +++ b/src/resources/extensions/gsd/reports.ts @@ -18,7 +18,7 @@ import { writeFileSync, readFileSync, mkdirSync, existsSync } from 'node:fs'; import { join, basename } from 'node:path'; import { gsdRoot } from './paths.js'; import { formatCost, formatTokenCount } from './metrics.js'; -import { formatDuration } from '../shared/format-utils.js'; +import { formatDateShort, formatDuration } from '../shared/format-utils.js'; // ─── Types ──────────────────────────────────────────────────────────────────── @@ -382,12 +382,6 @@ function buildCostSparkline(entries: ReportEntry[]): string { // ─── Helpers ────────────────────────────────────────────────────────────────── -function formatDateShort(iso: string): string { - try { - const d = new Date(iso); - return d.toLocaleString('en-US', { month: 'short', day: 'numeric', year: 'numeric', hour: '2-digit', minute: '2-digit' }); - } catch { return iso; } -} function esc(s: string | number | undefined | null): string { if (s == null) return ''; diff --git a/src/resources/extensions/shared/format-utils.ts b/src/resources/extensions/shared/format-utils.ts index 3b9d2ce75..53b5656d0 100644 --- a/src/resources/extensions/shared/format-utils.ts +++ b/src/resources/extensions/shared/format-utils.ts @@ -87,6 +87,16 @@ export function sparkline(values: number[]): string { return values.map(v => chars[Math.min(7, Math.floor((v / max) * 7))]).join(""); } +// ─── Date Formatting ───────────────────────────────────────────────────────── + +/** Format an ISO date string as a compact locale string (e.g. "Mar 17, 2025, 02:30 PM"). */ +export function formatDateShort(iso: string): string { + try { + const d = new Date(iso); + return d.toLocaleString('en-US', { month: 'short', day: 'numeric', year: 'numeric', hour: '2-digit', minute: '2-digit' }); + } catch { return iso; } +} + // ─── ANSI Stripping ─────────────────────────────────────────────────────────── /** Strip ANSI escape sequences from a string. */