Adding Time Bug Error

Good Morning,

After the new Ui.Vision update to version 6.2.8, my adding time script is no longer functioning correctly.

My script is “var d= new Date(new Date().getTime() + 24 * 60 * 60 * 1000 * 5); var m=((d.getMonth()+1)<10)?‘0’+(d.getMonth()+1):(d.getMonth()+1); m=d.getFullYear()+m+d.getDate().toString().padStart(2, “0”); return m”

That script would put in the date five days from today in the correct format that I wanted which will be “20211009”.

Ever since the update, the date is coming up as “203109” which is incorrect. Did something change within my script from the new update? Please advise.

I tested with V6.2.6 Firefox and V6.2.8 Chrome => Both return 203109.

But I found the bug in the script: You need to add + "" + to the string building in the last line. Otherwise the strings are treated as numbers and not concatenated as string. The macro below works ok:

{
  "Name": "5fromtoday",
  "CreationDate": "2021-10-4",
  "Commands": [
    {
      "Command": "executeScript_Sandbox",
      "Target": "var d= new Date(new Date().getTime() + 24 * 60 * 60 * 1000 * 5); \nvar m=((d.getMonth()+1)<10)?\"0\"+(d.getMonth()+1):(d.getMonth()+1); \nm=d.getFullYear()+m+d.getDate().toString().padStart(2, \"0\"); \nreturn m",
      "Value": "m",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "Wrong: ${m}",
      "Value": "blue",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var d= new Date(new Date().getTime() + 24 * 60 * 60 * 1000 * 5); \nvar m=((d.getMonth()+1)<10)?'0'+(d.getMonth()+1):(d.getMonth()+1); \nm=d.getFullYear()+\"\"+m+\"\"+d.getDate(); \nreturn m",
      "Value": "n",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "This works: ${n}",
      "Value": "green",
      "Description": ""
    }
  ]
}

That’s weird because it was working fine for me for months until the upgrade, but the script you just provided me is throwing me an error “Error in executeScript_Sandbox code: Invalid or unexpected token”.

executeScript_Sandbox | var d= new Date(new Date().getTime() + 24 * 60 * 60 * 1000 * 5); \nvar m=((d.getMonth()+1)<10)?‘0’+(d.getMonth()+1):(d.getMonth()+1); \nm=d.getFullYear()+""+m+""+d.getDate(); \nreturn m | Plus5Days

Type | id=… | ${Plus5Days}

If you copy the code make sure the " symbols are correct. Best will be to retype them. Your ‘0’ and “0” did not work for me until I replaced them with "

I got it to work again by putting:

var d= new Date(new Date().getTime() + 24 * 60 * 60 * 1000 * 5); var m=((d.getMonth()+1) < 10)?‘0’+(d.getMonth()+1):(d.getMonth()+1); m=d.getFullYear()+""+m+""+d.getDate().toString().padStart(2, “0”); return m

1 Like