Skip to content

Commit

Permalink
dayChange now uses timestamps.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daveiano committed Nov 2, 2023
1 parent b270a40 commit 426e5bd
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions skins/weewx-wdc/src/js/live-updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ const onConnectionLost = (responseObject: any) => {
const onMessageArrived = (message: Message) => {
const payLoad = JSON.parse(message.payloadString);

console.log(payLoad);

notfication!.setAttribute(
"subtitle",
`Last update was ${dayjs.unix(payLoad.dateTime).format("HH:mm:ss")}`
Expand All @@ -484,29 +486,26 @@ const onMessageArrived = (message: Message) => {
const lastUpdate_ts = localStorage.getItem(
`weewx.weewx_wdc.mqtt-last-udpate-${key}`
),
lastGenerated_ts = (window as any).weewxWdcConfig.time,
lastUpdate_formatted = lastUpdate_ts
? dayjs(lastUpdate_ts).format("YYYY-MM-DD")
? dayjs.unix(parseInt(lastUpdate_ts)).format("YYYY-MM-DD")
: null;
let dayChange = false;

console.log("lastUpdate_formatted", lastUpdate_formatted);
console.log(dayjs.unix(payLoad.dateTime).format("YYYY-MM-DD"));
console.log(dayjs.unix(parseInt(payLoad.dateTime)).format("YYYY-MM-DD"));

// Day changed, reset min/max/sum.
if (
lastUpdate_ts &&
lastUpdate_formatted !==
dayjs.unix(payLoad.dateTime).format("YYYY-MM-DD") &&
lastUpdate_ts > lastGenerated_ts
lastUpdate_formatted !== dayjs.unix(payLoad.dateTime).format("YYYY-MM-DD")
) {
dayChange = true;
console.log("MQTT WS: Day changed, resetting min/max/sum for ." + key);
}

localStorage.setItem(
`weewx.weewx_wdc.mqtt-last-udpate-${key}`,
dayjs.unix(payLoad.dateTime).toString()
payLoad.dateTime
);

// Alternative layout.
Expand Down Expand Up @@ -626,3 +625,5 @@ client.connect({
useSSL: mqtt_ssl === "1",
reconnect: true,
});

alert("test 3");

0 comments on commit 426e5bd

Please sign in to comment.