toISOString getting warnings but code works

Every time I deploy since a few months I get a warning that a function node is not correctly configured.
When I open the node toISOString is marked with red.
The function works just as expected but it's getting to always hit the deploy anyway button.

What is the issue with this? What can I do about it?
I need to warn you, I'm really bad with JavaScript. I realize there are some things that could be done better, but I'm really fumbling around in the dark with JavaScript.

var array = {};
var time = "";

time = new Date(msg.payload.approvedTime);
var offset = time.getTimezoneOffset(); 
time = new Date(time.getTime() - (offset*60*1000)); 
msg.state = time.toISOString().replace("T", " ").substring(0,16)


for (var index in msg.payload.timeSeries.slice(0,70)) {
    time = new Date(msg.payload.timeSeries[index].validTime);
    offset = time.getTimezoneOffset();
    time = new Date(time.getTime() - (offset * 60 * 1000)); 

    array[time.toISOString().replace("T", " ").substring(0, 16)] = { "temp": 0, "wind": 0, "gust": 0, "nederbord": 0, "symbol" : 0 };
    for (var val in msg.payload.timeSeries[index].parameters) {
        if (msg.payload.timeSeries[index].parameters[val]["name"] == "t") {
            array[time.toISOString().replace("T", " ").substring(0, 16)].temp = msg.payload.timeSeries[index].parameters[val].values[0];   //  { "temp": Math.round(msg.payload.timeSeries[index].parameters[val].values[0]) }
        }else if (msg.payload.timeSeries[index].parameters[val]["name"] == "ws"){
            array[time.toISOString().replace("T", " ").substring(0,16)].wind =  msg.payload.timeSeries[index].parameters[val].values[0];  
        }else if (msg.payload.timeSeries[index].parameters[val]["name"] == "gust"){
            array[time.toISOString().replace("T", " ").substring(0,16)].gust =  msg.payload.timeSeries[index].parameters[val].values[0];  
        }else if (msg.payload.timeSeries[index].parameters[val]["name"] == "pmean") {
            array[time.toISOString().replace("T", " ").substring(0, 16)].nederbord = msg.payload.timeSeries[index].parameters[val].values[0];  
        } else if (msg.payload.timeSeries[index].parameters[val]["name"] == "Wsymb2") {
            array[time.toISOString().replace("T", " ").substring(0, 16)].symbol = msg.payload.timeSeries[index].parameters[val].values[0];
        }
    }
}
msg.offset = offset;
msg.arr = array;
return msg;

The code loops through an array with weather data.
This is the first item of the array just to get a feel for the data

[
  {
    "validTime": "2024-07-18T08:00:00Z",
    "parameters": [
      {
        "name": "spp",
        "levelType": "hl",
        "level": 0,
        "unit": "percent",
        "values": [
          -9
        ]
      },
      {
        "name": "pcat",
        "levelType": "hl",
        "level": 0,
        "unit": "category",
        "values": [
          0
        ]
      },
      {
        "name": "pmin",
        "levelType": "hl",
        "level": 0,
        "unit": "kg/m2/h",
        "values": [
          0
        ]
      },
      {
        "name": "pmean",
        "levelType": "hl",
        "level": 0,
        "unit": "kg/m2/h",
        "values": [
          0
        ]
      },
      {
        "name": "pmax",
        "levelType": "hl",
        "level": 0,
        "unit": "kg/m2/h",
        "values": [
          0
        ]
      },
      {
        "name": "pmedian",
        "levelType": "hl",
        "level": 0,
        "unit": "kg/m2/h",
        "values": [
          0
        ]
      },
      {
        "name": "tcc_mean",
        "levelType": "hl",
        "level": 0,
        "unit": "octas",
        "values": [
          6
        ]
      },
      {
        "name": "lcc_mean",
        "levelType": "hl",
        "level": 0,
        "unit": "octas",
        "values": [
          6
        ]
      },
      {
        "name": "mcc_mean",
        "levelType": "hl",
        "level": 0,
        "unit": "octas",
        "values": [
          0
        ]
      },
      {
        "name": "hcc_mean",
        "levelType": "hl",
        "level": 0,
        "unit": "octas",
        "values": [
          0
        ]
      },
      {
        "name": "t",
        "levelType": "hl",
        "level": 2,
        "unit": "Cel",
        "values": [
          17.1
        ]
      },
      {
        "name": "msl",
        "levelType": "hmsl",
        "level": 0,
        "unit": "hPa",
        "values": [
          1020.7
        ]
      },
      {
        "name": "vis",
        "levelType": "hl",
        "level": 2,
        "unit": "km",
        "values": [
          20.9
        ]
      },
      {
        "name": "wd",
        "levelType": "hl",
        "level": 10,
        "unit": "degree",
        "values": [
          286
        ]
      },
      {
        "name": "ws",
        "levelType": "hl",
        "level": 10,
        "unit": "m/s",
        "values": [
          5.2
        ]
      },
      {
        "name": "r",
        "levelType": "hl",
        "level": 2,
        "unit": "percent",
        "values": [
          76
        ]
      },
      {
        "name": "tstm",
        "levelType": "hl",
        "level": 0,
        "unit": "percent",
        "values": [
          0
        ]
      },
      {
        "name": "gust",
        "levelType": "hl",
        "level": 10,
        "unit": "m/s",
        "values": [
          10.1
        ]
      },
      {
        "name": "Wsymb2",
        "levelType": "hl",
        "level": 0,
        "unit": "category",
        "values": [
          4
        ]
      }
    ]
  },
....
]

You declare time as a string var time = ""
Then time becomes a time object when you call new date(), but the monaco parser thinks it should be type string as declared.
You can just declare time with out assigning a type var time;.
Also try using let or const before using var.

1 Like

Oh my god..
That was the issue. I thought it was the ISO thing since it was marked in red.

Thank you!!

ToISOString() was marked as it is not a method that can be used on a type string

Makes sense...

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