fix: deduplicate formatDateShort into shared/format-utils (#1032)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
5657f302a6
commit
4407c24522
3 changed files with 12 additions and 14 deletions
|
|
@ -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 '';
|
||||
|
|
|
|||
|
|
@ -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 '';
|
||||
|
|
|
|||
|
|
@ -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. */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue