Merge pull request #363 from bluewave-labs/fix/uptime-refactor
Refactored uptime calculation for efficiency and clarity
This commit is contained in:
1 file changed
+7
-20
@@ -101,28 +101,15 @@ const DetailsPage = () => {
|
|||||||
if (!checks || checks.length === 0) {
|
if (!checks || checks.length === 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
const latestCheck = new Date(checks[0].createdAt);
|
||||||
const arr = [...checks];
|
let latestDownCheck = 0;
|
||||||
|
for (let i = 0; i < checks.length; i++) {
|
||||||
let lastDownTimestamp = null;
|
if (checks[i].status === false) {
|
||||||
let lastUpTimestamp = null;
|
latestDownCheck = new Date(checks[i].createdAt);
|
||||||
|
break;
|
||||||
arr.sort((a, b) => new Date(a.createdAt) - new Date(b.createdAt));
|
|
||||||
arr.forEach((check) => {
|
|
||||||
if (check.status === false) {
|
|
||||||
lastDownTimestamp = new Date(check.createdAt);
|
|
||||||
} else if (check.status === true) {
|
|
||||||
lastUpTimestamp = new Date(check.createdAt);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
if (lastDownTimestamp === null) {
|
|
||||||
return new Date() - new Date(arr[0].createdAt);
|
|
||||||
} else if (lastUpTimestamp === null) {
|
|
||||||
return 0;
|
|
||||||
} else if (lastDownTimestamp && lastUpTimestamp) {
|
|
||||||
return lastUpTimestamp - lastDownTimestamp;
|
|
||||||
}
|
}
|
||||||
|
return latestCheck - latestDownCheck;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user