Fix monitor duration semantics

This commit is contained in:
seo
2026-06-15 19:33:58 +09:00
parent 7c2deb9ec1
commit 2eb396cdfe
2 changed files with 26 additions and 2 deletions
+17 -2
View File
@@ -572,7 +572,8 @@ if (isset($_GET['mode']) && $_GET['mode'] === 'ajax') {
'stale' => $isStale,
'stale_reason' => $staleReason,
'latest_tcp' => $latestTcp,
'state_duration' => current_engine_state_duration($pdo, $latest),
'state_duration' => current_state_duration($pdo, $latest),
'engine_state_duration' => current_engine_state_duration($pdo, $latest),
'poll_interval' => $isFastPollState ? 5 : 10,
'log_count' => count($logs),
'chart_count' => count($chart),
@@ -1775,13 +1776,27 @@ if (isset($_GET['mode']) && $_GET['mode'] === 'usage') {
});
}
function parseLocalTimestamp(value) {
const match = String(value || '').match(/^(\d{4})-(\d{2})-(\d{2})[ T](\d{2}):(\d{2}):(\d{2})/);
if (!match) return null;
return new Date(
Number(match[1]),
Number(match[2]) - 1,
Number(match[3]),
Number(match[4]),
Number(match[5]),
Number(match[6])
).getTime();
}
function updateLogs(logs) {
const tbody = document.getElementById('log-table-body');
const html = logs.map(log => {
const cmdCode = String(log.cmd || '').toLowerCase();
const cmd = CMD_MAP[cmdCode] || { label: '', icon: 'fa-terminal', bg: 'rgba(128,128,128,0.1)', color: 'var(--text-secondary)' };
const cmdText = cmd.label ? t(cmd.label) : (cmdCode.toUpperCase() || '-');
const ageSec = Math.max(0, Math.floor((Date.now() - new Date(log.ts).getTime()) / 1000));
const logMs = parseLocalTimestamp(log.ts);
const ageSec = logMs === null ? 0 : Math.max(0, Math.floor((Date.now() - logMs) / 1000));
const doors = doorSummary(log);
const remote = remoteSummary(log);
const trim = escapeHtml(log.raw_trim || '-');