devices listing now looks at the timestamp of status readings to determine if a column should exist

This commit is contained in:
Carter 2025-10-15 11:49:26 -06:00
parent c0b960e826
commit 30f0b4468e
4 changed files with 194 additions and 12 deletions

View file

@ -114,6 +114,29 @@ export default function StatusDust(props: Props) {
)
}
function compareTimestamps(timestamp1: string, timestamp2: string): number {
const date1 = new Date(timestamp1);
const date2 = new Date(timestamp2);
// Check if dates are valid
if (isNaN(date1.getTime()) || isNaN(date2.getTime())) {
throw new Error("Invalid RFC3339 timestamp format");
}
// Compare using getTime() for millisecond precision
return date1.getTime() - date2.getTime();
}
if (device.status.sen5x?.timestamp) {
const now = new Date();
const oneDayAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000);
if (compareTimestamps(device.status.sen5x?.timestamp, oneDayAgo.toISOString()) < 0) {
return null
}
} else {
return null
}
return (
<Tooltip title={tooltip()}>
<PulseBox color={color} className={classes.box} >