Hi there!!
I’m pulling some calendar events from Nextcloud to shove it into FarmOS and also display it on the Node-Red dashboard.
I managed to get the events into Node-Red, but i’m struggling with the formatting of the DTSTAMP of the event to a readable format on the dashbard.
The msg object is stripped down to only contain event SUMMARY and DTSTAMP.
With a switch node I manage to run a JSONata to format it if it’s a single timestamp. But I can’t figure it out when it’s a part of the msg.payload array.
This happens to me sometimes… I’m stuck, ask for help, and then suddenly find the solution myself
I added a split-node. This node splits the array, so I can run the format the date-node on each element in the array. Then I joined it back to an array, with a more readable date format
To reformat the date for farmOS in a function node, something like this, I think should split up the date and join it back together with the hyphens (and add a preceding 0 of day or month is a single digit) .
function padZero(i) {
return i < 10 ? "0"+i : i;
}
date = new Date(eventdate);
const farmosdate = date.getFullYear()+'-' + (padZero(date.getMonth()+1)) + '-'+padZero(date.getDate());
Dates can be messy between different API’s and I’ve had to reformat them in a few ways, but I think that’s the version that suits your situation.
Well done on finding another solution anyway, if we just wrote everything in a function node with pure JavaScript all the time then you’d need less nodes but also defeat the purpose of Node-Red, the beauty of it is being able to mix code with no code/low code. Nothing wrong with either approach though.