CUB-196: fix future timestamps, negative battery clamp, boundary tests

Grimm review fixes:
- formatRelativeTime: guard future timestamps (clock skew) → 'unknown'
- battery display: clamp negative values to 0%
- formatTimeLeft: floor fractional seconds
- Tests: +4 (future timestamp, negative battery, 15%/50% boundaries)
This commit is contained in:
2026-05-21 14:07:57 +00:00
parent 08d5ceb792
commit db4663380b
2 changed files with 32 additions and 2 deletions
+3 -2
View File
@@ -8,6 +8,7 @@ function formatRelativeTime(iso: string): string {
if (isNaN(then)) return 'unknown'
const diffSec = Math.floor((Date.now() - then) / 1000)
if (diffSec < 0) return 'unknown'
if (diffSec < 10) return 'just now'
if (diffSec < 60) return `${diffSec}s ago`
@@ -32,7 +33,7 @@ function batteryColor(pct: number | null): { bar: string; text: string } {
function formatTimeLeft(sec: number): string {
if (sec <= 0 || !isFinite(sec)) return '--'
const m = Math.floor(sec / 60)
const s = sec % 60
const s = Math.floor(sec % 60)
return `${m}m ${s}s left`
}
@@ -138,7 +139,7 @@ export default function CameraCard({ camera }: CameraCardProps) {
Battery
</span>
<span className={`font-mono text-xs ${batt.text}`}>
{battery_pct !== null ? `${battery_pct}%` : 'N/A'}
{battery_pct !== null ? `${Math.max(0, battery_pct)}%` : 'N/A'}
</span>
</div>
<div