Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8037

Other programming languages • Re: javascript - node red Ordinal Day Of Year.

$
0
0
Since I want day of year to trigger actions every other day and the current timestamp is the payload of the incoming flow message

Code:

`msg.payload = Math.floor(msg.payload  /  86400000) %  2;`
provides the Boolean result required;)

beats my initial plod through

Code:

const aDay = 1000 * 60 * 60 * 24;var dt = new Date(msg.payload);var st = new Date();var DayOfYear = 0;  st.setDate(1);  st.setMonth(0);  st.setHours(0);  st.setMinutes(0);  st.setSeconds(0);  st.setMilliseconds(0);    DayOfYear =  Math.trunc((dt.getTime() - st.getTime())/ aDay) + 1; msg.payload = DayOfYear; return msg;
which required an additional odd/even evaluation step.

Statistics: Posted by Lbox1 — Mon May 05, 2025 2:20 am



Viewing all articles
Browse latest Browse all 8037

Trending Articles