Skip to content

Commit 7401cf1

Browse files
fix: don't render epoch-zero image timestamps as 1970 in the GUI (#55)
Apple's `container image ls` reports a zeroed creationDate ("1970-01-01T00:00:00Z") for images it can't date — builder and intermediate images. ImagesView rendered `img.created` raw, so those rows showed a literal 1970 stamp; the image-inspect Layers tab used a local `ago()` helper that guarded empty/NaN but not epoch-zero (Date.parse("1970-...Z") is 0, not NaN), so it would have shown a bogus "56y ago". Adds a shared `fmtCreated()` in components.tsx (epoch-zero / empty / unparseable -> "—", else relative age), uses it in both ImagesView and the Layers tab, and removes the now-redundant local `ago()`. Also stops the Images list showing a misleading "0" in the Layers column: `image ls` doesn't expose a layer count (we hardcode 0), so the row now shows "—" rather than implying zero layers. The real count is still shown per-layer in the inspect modal. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent a098be6 commit 7401cf1

4 files changed

Lines changed: 51 additions & 23 deletions

File tree

‎app/src/components.test.tsx‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, it, expect } from 'vitest';
22
import { render } from '@testing-library/react';
3-
import { fmtBytes, Sparkline, StatusDot, Bar, fmtAgo } from './components';
3+
import { fmtBytes, Sparkline, StatusDot, Bar, fmtAgo, fmtCreated } from './components';
44
import { getTheme } from './theme';
55

66
const t = getTheme(true);
@@ -70,6 +70,27 @@ describe('fmtAgo', () => {
7070
});
7171
});
7272

73+
describe('fmtCreated', () => {
74+
const now = Date.parse('2026-06-16T00:00:00Z');
75+
it("returns '—' for missing / unparseable input", () => {
76+
expect(fmtCreated('', now)).toBe('—');
77+
expect(fmtCreated('not a date', now)).toBe('—');
78+
});
79+
it("returns '—' for an epoch-zero stamp (the 1970 bug)", () => {
80+
// Date.parse here is 0, not NaN — the case the old `ago` helper missed.
81+
expect(fmtCreated('1970-01-01T00:00:00Z', now)).toBe('—');
82+
});
83+
it('formats a real timestamp as a relative age', () => {
84+
// Hours bucket runs up to 48h, so 24h ago reads as "24h ago".
85+
expect(fmtCreated('2026-06-15T00:00:00Z', now)).toBe('24h ago');
86+
expect(fmtCreated('2026-06-13T00:00:00Z', now)).toBe('3d ago');
87+
expect(fmtCreated('2026-04-17T00:00:00Z', now)).toBe('2mo ago');
88+
});
89+
it('accepts a date-only string (fixture shape)', () => {
90+
expect(fmtCreated('2026-06-13', now)).toBe('3d ago');
91+
});
92+
});
93+
7394
describe('Bar', () => {
7495
it('clamps fill to 100% even when pct exceeds it', () => {
7596
const { container } = render(<Bar pct={250} color="#f00" bg="#000" />);

‎app/src/components.tsx‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,30 @@ export function fmtAgo(lastMs: number, nowMs: number = Date.now()): string {
314314
return `${h}h ago`;
315315
}
316316

317+
// Format an ISO-8601 timestamp (image / layer creation time) as a short
318+
// relative age. Returns "—" for missing, unparseable, OR epoch-zero
319+
// values: Apple's `container` reports a zeroed creationDate
320+
// ("1970-01-01T00:00:00Z") for images it can't date — builder and
321+
// intermediate images — and that must not leak into the UI as a literal
322+
// 1970 stamp or a bogus "56y ago". `Date.parse` of the epoch is 0, not
323+
// NaN, so the `<= 0` guard is the one that actually catches this.
324+
export function fmtCreated(iso: string, nowMs: number = Date.now()): string {
325+
if (!iso) return '—';
326+
const ms = Date.parse(iso);
327+
if (Number.isNaN(ms) || ms <= 0) return '—';
328+
const sec = Math.max(0, Math.floor((nowMs - ms) / 1000));
329+
if (sec < 60) return `${sec}s ago`;
330+
const min = Math.floor(sec / 60);
331+
if (min < 60) return `${min}m ago`;
332+
const hr = Math.floor(min / 60);
333+
if (hr < 48) return `${hr}h ago`;
334+
const day = Math.floor(hr / 24);
335+
if (day < 30) return `${day}d ago`;
336+
const mo = Math.floor(day / 30);
337+
if (mo < 24) return `${mo}mo ago`;
338+
return `${Math.floor(day / 365)}y ago`;
339+
}
340+
317341
export function StatusBar({ t, runtime, tab, lastTickAt }: {
318342
t: ThemeTokens; runtime: Runtime; tab: Tab;
319343
lastTickAt?: number;

‎app/src/modals.tsx‎

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import React, { Fragment, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
44
import type { ThemeTokens } from './theme';
55
import type { Container, Image, Severity, Stack, Tab, TrivyFinding, TrivyResult, Update, DoctorCheck, DoctorFix, HistoryPoint, VulnHistory, Runtime, DiskUsage, DiskUsageRow } from './types';
6-
import { Icon, Bar, Sparkline, iconBtn, pillBtn } from './components';
6+
import { Icon, Bar, Sparkline, iconBtn, pillBtn, fmtCreated } from './components';
77
import { api } from './api';
88
import { withToast } from './toast';
99

@@ -1243,23 +1243,6 @@ function prettyCmd(s: string): string {
12431243

12441244
// Best-effort relative "n ago" without pulling a date library. Returns
12451245
// "—" for missing / un-parseable timestamps so the column degrades.
1246-
function ago(iso: string): string {
1247-
if (!iso) return '—';
1248-
const ms = Date.parse(iso);
1249-
if (Number.isNaN(ms)) return '—';
1250-
const sec = Math.max(0, Math.floor((Date.now() - ms) / 1000));
1251-
if (sec < 60) return `${sec}s ago`;
1252-
const min = Math.floor(sec / 60);
1253-
if (min < 60) return `${min}m ago`;
1254-
const hr = Math.floor(min / 60);
1255-
if (hr < 48) return `${hr}h ago`;
1256-
const day = Math.floor(hr / 24);
1257-
if (day < 30) return `${day}d ago`;
1258-
const mo = Math.floor(day / 30);
1259-
if (mo < 24) return `${mo}mo ago`;
1260-
return `${Math.floor(day / 365)}y ago`;
1261-
}
1262-
12631246
export function ImageInspectModal({ t, reference, onClose }: {
12641247
t: ThemeTokens; reference: string; onClose: () => void;
12651248
}) {
@@ -1354,7 +1337,7 @@ export function ImageInspectModal({ t, reference, onClose }: {
13541337
)}
13551338
</div>
13561339
<div style={{ textAlign: 'right' }}>
1357-
<div style={{ fontFamily: t.mono, fontSize: 10, color: t.fg3, whiteSpace: 'nowrap' }}>{ago(l.created)}</div>
1340+
<div style={{ fontFamily: t.mono, fontSize: 10, color: t.fg3, whiteSpace: 'nowrap' }}>{fmtCreated(l.created)}</div>
13581341
{l.emptyLayer && (
13591342
<div style={{ fontFamily: t.mono, fontSize: 9, color: t.fg3, marginTop: 2, letterSpacing: '0.04em', textTransform: 'uppercase' }}>empty</div>
13601343
)}

‎app/src/views.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { Fragment, useEffect, useMemo, useRef, useState } from 'react';
55
import type { ThemeTokens } from './theme';
66
import type { Container, Image, Volume, Network, Stack } from './types';
7-
import { Icon, Sparkline, Bar, StatusDot, BulkActionBar, SelectCheckbox, iconBtn, pillBtn, tableHeader, tableRow } from './components';
7+
import { Icon, Sparkline, Bar, StatusDot, BulkActionBar, SelectCheckbox, iconBtn, pillBtn, tableHeader, tableRow, fmtCreated } from './components';
88
import { api } from './api';
99
import { withToast } from './toast';
1010

@@ -371,8 +371,8 @@ export function ImagesView({ t, search, onScan, onRun, onInspect, reloadKey = 0
371371
<div style={{ textAlign: 'right', fontFamily: t.mono, fontSize: 12, color: t.fg1, fontVariantNumeric: 'tabular-nums' }}>
372372
{img.size.toFixed(img.size < 1 ? 2 : 1)} <span style={{ color: t.fg3, fontSize: 11 }}>{img.sizeUnit}</span>
373373
</div>
374-
<div style={{ textAlign: 'right', fontFamily: t.mono, fontSize: 12, color: t.fg2 }}>{img.layers}</div>
375-
<div style={{ fontFamily: t.mono, fontSize: 12, color: t.fg3 }}>{img.created}</div>
374+
<div style={{ textAlign: 'right', fontFamily: t.mono, fontSize: 12, color: t.fg2 }}>{img.layers || '—'}</div>
375+
<div style={{ fontFamily: t.mono, fontSize: 12, color: t.fg3 }}>{fmtCreated(img.created)}</div>
376376
<div style={{ display: 'flex', gap: 4, justifyContent: 'flex-end' }}>
377377
<button onClick={() => onInspect(img)} style={iconBtn()} title="Inspect"><Icon name="info" size={13} color={t.fg2} /></button>
378378
<button onClick={() => onTag(img)} style={iconBtn()} title="Tag"><Icon name="tag" size={13} color={t.fg2} /></button>

0 commit comments

Comments
 (0)