Hello, I am reasonably proficient with Node Red, but at the moment, I don't have a solution to my problem.
I use Dashboard to display a graph of data over time. It works great. If I'm on the West Coast, the "last three hours" uses the correct times as x axis. I changed Windows to say I'm on the East Coast, and the x axis times update perfectly without a page refresh. Fabulous!
On the same page, I pull longer-term data from InfluxDB. I run the results thru a function node (called "prettify graph") where I massage the database's results into human friendly results. Part of that is, naturally, rendering the (user's) time.
Sharing my code will help the context of my question:
now = new Date();
const user_timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
now.toLocaleString('en-US', { timeZone: user_timezone })
node.log("user_timezone is "+user_timezone);
node.log("TZ offset is "+now.getTimezoneOffset(user_timezone) );
for (var x in rtn.labels) {
var this_time = Date.parse(rtn.labels[x]);
rtn.labels[x] = new Intl.DateTimeFormat('en-US', { date:false, hour:'numeric',minute:'numeric', hour12: true, timeZone:user_timezone }).format(this_time);
}
So, const user_timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
is great for finding what the Browser sees is the timezone. BUT, I'm running node red on a linux host unchanged as UTC, and I'm doing the sensible thing of keeping it that way, because I may have viewers from any timezone. When I look at the node log on the server, alas and of course, I see
[function:Prettify graph] user_timezone is UTC
[function:Prettify graph] TZ offset is 0
The question: How do I get the browser's results of const user_timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
into the context of the server's node/javascript/vm execution environment? I bet it's "simple", but I can't think of it nor find it. (I cited that Dashboard's Line Chart node behaves correctly, but I think that's a because it does the rendering on the browser, not the server.)
Thanks in advance for pondering my question!