Text Input Time Picker Returns Incorrect ms From Midnight

That is a very good question, and I hope it will change in the new dashboard being developed. Text Input Widget timestamp and date input formats · Issue #147 · FlowFuse/node-red-dashboard · GitHub

For the moment though I don't think any breaking changes can be made in the current dashboard. The question is why is your system behaving differently to others. I wonder if it is a peculiarity of PDT.

Is there anyone else out there using PDT?

Could you configure a default Inject node please, which will inject the timestamp, and feed that straight into a default debug node. Then screenshot what that shows in the debug pane and paste it here. Also tell us what time it is when you do it.

Also please (if you have not already done so) make sure your pi has the latest packages installed by running
sudo apt update && sudo apt full-upgrade
and making sure no errors are seen.
Then restart node-red.

Also do you have any more node-red systems? Can you try on them?

I updated the Pi using the command provided above. No errors. I did notice that Node was updated but it did not fix the offset problem from the Text Input control.

I injected a timestamp straight into a debug node. I also added a parallel function node to convert the timestamp into a string date and then back into a timestamp. The results match the current local system time. There is a small offset between the raw input timestamp and the timestamp back-calculated from the converted string date (probably attributable to execution time). I will spin up a Docker container on my Windows computer and and get back to you shortly on the results from that. I appreciate your helping me out with this!

Debug output plus debug.warn() statements from parallel function node:

8/25/2023, 11:41:48 AM node: debug 103
msg.payload : number
1692988908165
8/25/2023, 11:41:48 AM node: function 4
function : (warn)
"toLocalString = 8/25/2023, 11:41:48 AM"
8/25/2023, 11:41:48 AM node: function 4
function : (warn)
"back to timestamp = 1692988908000"
8/25/2023, 11:41:48 AM node: function 4
function : (warn)
"timestamp delta = 165 ms"

Parallel function node code that produces above warn statements

const date = new Date(msg.payload);
const stringDate = date.toLocaleString();
const timeStamp = Date.parse(stringDate);
node.warn(`toLocalString = ${stringDate}`);
node.warn(`back to timestamp = ${timeStamp}`);
node.warn(`timestamp delta = ${msg.payload - timeStamp} ms`)
return;

I read your flowforge comment and could not agree more!

I happened to have a Docker Container on one of my Windows machines (running under WSL2) with an older version of my flows.json file from when I created it (January of this year). The node-red version is 3.0.2 and the dashboard version is 3.2.3. If I add a Text Input node and send the output to a Debug node I get the CORRECT result! I will update to the latest (first the dashboard and then nodered) and see if either change impacts the results.

1 Like

What do you define as correct, in terms of what comes out of the text node?

Am I right in thinking that you have to tell the container what the timezone is?

By correct I mean the correct number of ms since midnight. In my production flow I have to subtract 8 hrs worth of ms from the output to get the correct result. I do not tell the container what the timezone is as the node, according to documentation, simply takes a time formatted as hh:mm AM/PM, and then returns ms from midnight (e.g. 12:00 AM should output 0 ms, 01:00 AM should output 3.6E6 ms etc.).

Which is why I do not think, at least in time mode, the Text Input should have any dependency on system time. It simply calculates the number of ms between hh:mm AM/PM and 00:00 AM.

I failed to answer you last question. The container time is the same as my main system time which is the same time as my Pi.

Have you double checked that?

Hmmmm......you were correct to point that out. The date command in the container reports UTC time.

Which oddly enough is a 7 hour offset. PDT is an 8 hour offset but I think that may be a result of UTC being based on PST (does not account for daylight savings)? Again, I have to correct the output by 8 hrs (not 7) to get the correct ms from midnight from the Text Input controller. Time/dates.....I appreciate they are more complicated than one might think!

If the timezone is UTC and you enter a time of 00:00 into the node then you should get 0 out.

Yes....and I do in the containerized version but not the Pi. The date command in Pi reports PDT. The date command in the container is using UTC.

I am thinking.....this is just not worth chasing. I can create a different UI input controller (using a Template node or Text Input without mode set to time) and handle it myself. As you stated, even if there is a bug, the current version of the dashboard is deprecated. So there is no expectation on my part, it will be updated. It is always a good learning process to try and debug something. I've become much more edumacated on how the underlying dashboard code works, but I can work around this rather easily and I don't want to waste your time on what is, a relatively minor issue.

1 Like

I have watched many hours of Nick on YouTube updating the underlying code. I'm not a programmer but get the general concepts and can understand maybe 25%, 50% on a good day. Suffice it to say, I am impressed by all the contributors knowledge and greatly appreciate their efforts! Open source is awesome. As a 54 year old engineer, I have a hard time wrapping my brain around the concept of people giving up so much of their time for free. Kudos to all!

2 Likes

With that said, do you and/or the nodered team have a patreon account. I feel compelled to contribute.

Not me.

What happens if you set the timezone of the container to PDT? Does the text input node behave the same as on your pi?

I planned on checking that, along with update of dashboard, and then by update of node-red proper. I followed this link on how to change the timezone Alpine Linux Timezone. However, the command apt add tzdata returned a apt: command not found. One option, I think.....total Docker novice but plan is to migrate off the Pi.....is to alter the image to install tzdata and set to my timezone. Or, maybe it is because I am using a bash terminal rather than the default Alpine terminal (installed that manually). I'm sure I can figure that part out and will post the results as it could be helpful to others going forward. The wife has other chores/plans for me today.....happy wife...happy life!