Last active
September 13, 2021 10:11
-
-
Save vkushnir/9b470fe26aa363d2e81b0cfe59cd2d0a to your computer and use it in GitHub Desktop.
GeineACS Uptime Human Readble
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Unified across Device and InternetGatewayDevice | |
let v1 = declare("Device.DeviceInfo.UpTime", {value: Date.now()}); | |
let v2 = declare("InternetGatewayDevice.DeviceInfo.UpTime", {value: Date.now()}); | |
let totalSecs = 0 | |
if (typeof v1.value !== "undefined") { | |
totalSecs = v1.value[0]; | |
} else { | |
totalSecs = v2.value[0]; | |
} | |
let y = Math.floor(totalSecs / (86400*365)); | |
let rSec = totalSecs % (86400*365); | |
let mm = Math.floor(rSec / (86400*30.5)); | |
rSec = rSec % (86400*30.5); | |
let d = Math.floor(rSec / 86400); | |
rSec = rSec % 86400; | |
let h = Math.floor(rSec / 3600); | |
rSec = rSec % 3600; | |
let m = Math.floor(rSec % 60); | |
let s = rSec % 60; | |
let dDisplay = ""; | |
let hDisplay = ""; | |
let mDisplay = ""; | |
let sDisplay = ""; | |
let mmDisplay = mm > 0 ? mm + (mm == 1 ? " month, " : " months, ") : ""; | |
if (mm < 3) { | |
dDisplay = d > 0 ? d + (d == 1 ? " day, " : " days, ") : ""; | |
if (d < 7) { | |
hDisplay = h > 0 ? h + (h == 1 ? " hour, " : " hours, "): ""; | |
if (h < 12 && d < 1 ){ | |
mDisplay = m > 0 ? m + " min, " : ""; | |
if (m < 15 && h < 1 && d < 1) { | |
sDisplay = s > 0 ? s + " sec, ": ""; | |
} | |
} | |
} | |
} | |
let uptime = (mmDisplay + dDisplay + hDisplay + mDisplay + sDisplay).slice(0, -2); | |
if (uptime === "") { | |
uptime = "Just started" | |
} | |
return {writable: false, value: [uptime, "xsd:string"]}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment