-
-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect Date Conversion in nodered, moment.js works fine. #20
Comments
Well, it's definitely not a problem in the output (formatting) -- even if I use the default ISO-8601 formatting, the UTC "timestamp" returned is However, if I use plain JavaScript to parse that date string, it is correctly interpreted:
So what is happening inside the
So the next question is... what input format is being determined by the
Interesting -- but also clearly wrong! So the six digits representing microseconds were interpreted as 3-digits (SSS), followed by the day of the month (D), followed by a literal number (2), followed by the UTC timezone (Z). Removing the extra 3 decimals of precision does fix the problem:
So this is clearly a bug in the underlying dependent library, which according to package.json is version 2.2.1 -- let's see if the new version 3.0.0 from 11 days ago has the same issue:
Yep, no better -- time to open an issue against that library. As you are the one who found the bug, I'll leave that up to you. Good catch! |
Steve, Thanks for that excellent diagnosis. I will get this issue created on the library. --Brian |
Guys, many thanks for sorting this without my input!! :) 💯 |
This issue is going to come up again as the Home Assistant/Node Red combo becomes more and more popular I think. I have a relative time moment node converting my timestamps to "fromNow". Mostly they work, occasionally they are in the future, and sometimes they are way too far in the past. Some examples: "2019-02-27T11:02:04.709227+00:00" --> "2019-02-27T11:02:52.887109+00:00" "2019-02-27T11:04:23.209098+00:00" --> "2019-02-27T11:05:40.271300+00:00" "2019-02-27T11:03:06.609682+00:00" --> "2019-02-27T11:03:09.012704+00:00" I will strip the precision from the timestamp and hopefully the issue will be resolved. |
From Home Assistant, I get the following data:
entity_id: "binary_sensor.garage_camera_motion"
last_changed: "2018-06-01T18:13:03.909192+00:00"
Then using this project, i am taking that last_changed value and converting to "dddd, MMMM Do YYYY, h:mm:ss a" the result I get is Tuesday, June 19th 2018, 11:13:03 am. Which is off by 18 days. The time is correct as I have it converting from UTC to US/Pacific time.
If I take that exact time string and use https://codepen.io/widmoser/pen/NNOQEx?editors=1111 to test moment.js using the following, its correct.
const time = moment('2018-06-01T18:13:03.909192+00:00').format("dddd, MMMM Do YYYY, h:mm:ss a");
alert(time);
Am I doing something wrong using the plugin?
The text was updated successfully, but these errors were encountered: