Node "moment", output format "calendar", different results

Of course @TotallyInformation

And the input data examples? Just the data, you can capture that by putting a debug node attached to the output from your initial node. Then in the debug sidebar there is a small icon that lets you copy the data.

Input data strings are bottom lines of first post screenshots:

Or do you ask for the complete input object?

Stick a debug node on the output of the moment node so display when the format changes or is it possibel when you send the data to the api-call-service node something is happening to the date after that??

For correct formating is enough or it have to be for wrong one? As I did try to make it by hand and as for now all the answers was ok.

Sorry I don’t understand what you mean

OK, we got it.

This is what is getting into the moment (with marked most important data):

This is what is going out of the moment:

This is what we have on call-service node:

When you post a screenshot, we cannot copy it into a flow. You need to post as JSON output.

However, I can now finally see what the issue is. There is a bug in MomentJS that I've raised previously and they have refused to fix.

If you specify an input with more than 3 decimal places on the seconds value, MomentJS will misinterpret the timestamp.

Please feel free to raise this with the authors of Moment as it is a pain. I've put a work-around into the moment node but it doesn't seem to handle the format you've provided. If you remove the timezone offset from the end, it should work.

Here is the workaround code. If you are good with Regular Expressions, perhaps you can extend it to cover your case and I will be happy to publish a new version.

/** Catch & correct input strings in ISO format with seconds >3dp
 * since parseFormat has an unfixed bug (Issue #24)
 * @param {string} inp Input date/time string
function catchDp(inp) {
    // If ISO string w/ seconds >3dp, then process else exit
    if ( inp.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{4,}/) ) {
        inp = inp.replace(/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3})\d*(.*)/, '$1$2')

    return inp

Otherwise, you will need to tweak the input values before sending them to the moment node so that the decimal seconds have no more than 3dp.

I've actually reproduced the issue and will take a deeper look in a bit but my lap has been taken over by my three year old grand daughter. :smiling_face_with_three_hearts:

1 Like

@QbaF Do you have any control the format of the date coming in to the moment node?

There is always possibility to control incoming data by changing it. That is what for I used moment node;) But what I receive from state node it is, as I know, standard "last changed" data format.

I am not sure is it problem of "more than 3 decimal places" as in both cases (good and wrong) there are more than 3 decimal places.
Formating values to send them to format in moment does seems as a double work.
Anyway thanks.

57.501133 seconds is not standard and most likely completely ridiculous. 0.000003 seconds is three microseconds. Few systems outside specialist high-performance scientific and industrial systems will ever be able to measure to this accuracy. :grinning:

You would need to look up the issue I raised, I was quite a while back now and I can't remember the details.

Indeed, a pain.

I recommend at least trying the data with the shortened seconds to see if that is the problem.

The format of the date/time being passed to the moment node is causing the issue. What you could do is to add another rule to the change node to truncate the data after the period (.)

Add another 'set' and set and use this jsonata expression
$substringBefore(data.new_state.last_changed, '.') & '+00:00'
See if that works for you


57.501133 seconds is not standard and most likely completely ridiculous.

I am not sure that all nodes, even most has this format for last changed / last updated but at least a lot does. Isn't moment repairable?
But can not disagree about the "ridiculous"

Could You please send link to the issue mentioned. I can see only two issues connected with moment but no one is yours.

Thank you. I will get it a try.
But maybe for future use need to find and try better working node.

I assume you ment this for me. When I said I reproduced the issue I ment what I said. I caused it to happen in my node-red. Somethng about the incoming date is causing an issue with the moment node. Since you don't seem to be able to control the format of the date being sent to your flow, I created a 'get arround' for you. I have not opened an issue in the moment node because the date format is not what I would call standard.

UPDATE: you may want to go read this post about the moment node

No, TotallyInformation says:

You would need to look up the issue I raised

But thank you. Especially for that link you gave (also because in that link is now the link I was asking for). Rest about this work around was completely clear and I appreciate it.

I saw it. My question is why 3+ digital point is issue only in same (minor) cases?

Yes, sorry, I had a memory failure. It is actually the parser that is wrong not MomentJS. The last time I tested Moment, it could handle up to 9dp's I think.

It is the way that the parser uses a regular expression. It ends up with an incorrect date being used.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.