我正在尝试比较两个时间戳,如果它大于 x 秒的差异,则表示“离线”。这是我在小部件的 js 编辑器中的内容:
// Example: Convert temp from C to F and truncate to 2 decimal places.
// return (datasources["MyDatasource"].sensor.tempInF * 1.8 + 32).toFixed(2);
console.log("Checking Time Difference")
var timediff = (new Date) - datasources["ConsentDS"].Timestamp
console.log(timediff)
if timediff > 1 * 60 * 1000 {
return 1
} else {
return 0
}
即使差异应该大于 30 秒,该指标也始终保持“在线”。它甚至没有像我期望的那样写入控制台。
我找不到任何文档,所以我什至不确定我是否应该返回 1 或 true 或大象 :(