Hi all, first time poster here.
Node-RED version: v3.1.9
Node.js version: v18.20.4
Linux 5.15.0-119-generic x64 LE
I'm trying to get my feet wet with node-red as home automation software and thus far am enjoying the possibilities.
I'm trying to use the date-fns-tz module so that times that are entered for when a particular event happens can by entered in local time (America/New_York) but internally everything happens in UTC (which my Linux system runs as).
I have installed date-fns and date-fns-tz using npm from the .node-red directory and have set them up in settings.js like this:
functionExternalModules: true,
and
functionGlobalContext: {
os:require('os'),
tplinkApiModule: require('tplink-smarthome-api'),
dateFns: require('date-fns'),
dateFnsTz: require('date-fns-tz')
},
but from there things are a bit fuzzy for me.
I have tried a function node with
and then have code like:
const date = new Date();
const timeZone = env.get("TZ");
const zonedDate = utcToZonedTime(date, timeZone);
const offset = zonedDate.getTimezoneOffset();
node.warn(`${date} - ${zonedDate} - ${offset}`);
but I get this error:
I feel like I'm close but can't seem to get the right combination of directives.
Perhaps there is another way to do what I'm trying to do, but I'd like to be able to use additional modules in any case.
Any help greatly appreciated.