Skip to content

Commit e1e1c52

Browse files
committed
Preflight timestamp affordances
1 parent 81a3394 commit e1e1c52

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

‎tests/test_pcb_preflight.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,10 @@ def test_report_is_html_and_escapes_external_values(self):
328328
output,
329329
)
330330
self.assertNotIn("manual CAM gate", output)
331+
self.assertIn('<time id="generated-time"', output)
332+
self.assertIn('<span id="generated-age">0 seconds ago</span>', output)
333+
self.assertIn("function updateGeneratedAge()", output)
334+
self.assertIn("window.setInterval(updateGeneratedAge, 1000)", output)
331335
self.assertIn("Example &lt;check&gt;", output)
332336
self.assertIn("safe &amp; complete", output)
333337
self.assertIn('id="net-n001"', output)

‎tools/pcb_preflight.py‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,9 @@ def write_report(
13611361
<h1>{html_cell(profile['board'])} manufacturing preflight</h1>
13621362
<div class="summary">
13631363
<span class="status {result_class}">{result}</span>
1364-
<span>Generated {html_cell(generated)}</span>
1364+
<span>Generated <time id="generated-time"
1365+
datetime="{html_cell(generated)}">{html_cell(generated)}</time>
1366+
(<span id="generated-age">0 seconds ago</span>)</span>
13651367
</div>
13661368
<p class="muted">Discovered netlist SHA-256:
13671369
<code>{html_cell(netlist_hash)}</code></p>
@@ -1546,6 +1548,32 @@ def write_report(
15461548
lines.extend(["""
15471549
</main>
15481550
<script>
1551+
function updateGeneratedAge() {
1552+
const timestamp = document.getElementById('generated-time');
1553+
const label = document.getElementById('generated-age');
1554+
if (!timestamp || !label) return;
1555+
const seconds = Math.max(
1556+
0, Math.floor((Date.now() - Date.parse(timestamp.dateTime)) / 1000));
1557+
let value;
1558+
let unit;
1559+
if (seconds < 60) {
1560+
value = seconds;
1561+
unit = 'second';
1562+
} else if (seconds < 60 * 60) {
1563+
value = Math.floor(seconds / 60);
1564+
unit = 'minute';
1565+
} else if (seconds < 24 * 60 * 60) {
1566+
value = Math.floor(seconds / (60 * 60));
1567+
unit = 'hour';
1568+
} else {
1569+
value = Math.floor(seconds / (24 * 60 * 60));
1570+
unit = 'day';
1571+
}
1572+
label.textContent = `${value} ${unit}${value === 1 ? '' : 's'} ago`;
1573+
}
1574+
updateGeneratedAge();
1575+
window.setInterval(updateGeneratedAge, 1000);
1576+
15491577
function highlightPad(anchor) {
15501578
const target = document.getElementById(anchor);
15511579
if (!target || !target.closest('.device-pads')) return;

0 commit comments

Comments
 (0)