Hi !
I am working on a node, that should give me a future date, based on todays date and a numerical value.
I want to forecast the future date of a maintenance based on total work hours and dayly work hours.
Example:
A machine needs maintenance at 800 work hours.
Work hours counter is at 350 now, meaning maintenance is due in 450 work hours.
That would be in (450/24) = 18,75 days if it would run 24 h/day.
But machine is running only 12 hours a day.
Therefore it will reach 800 at ((24/12)*(450/24)) = 37,5 days.
So I want to add 37,5 day to current date and display the future date.
How do I do this?
tried to calculate 37,5 days into millisecound and add it to timestamp, but this newly generated number I could not show as date.
I take current timestamp, and calculated milisecounds, and would like to get the future date,
tried several aproaches, non of them worked. What am I missing here ?
[
{
"id": "b23e867bc679ecbc",
"type": "function",
"z": "515b0c7217284cb8",
"name": "add to timestamp",
"func": "// 37,5 days are 900 hours, 54.000 minutes, 3.240.000 secounds, 3.240.000.000 millisecounds \nmsg.timestamp = msg.timestamp + 3240000000;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 630,
"y": 1280,
"wires": [
[
"20abace1d174c667"
]
]
},
{
"id": "a963518aa448d6c1",
"type": "inject",
"z": "515b0c7217284cb8",
"name": "Today",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 430,
"y": 1280,
"wires": [
[
"b23e867bc679ecbc"
]
]
},
{
"id": "59663b9cbe337e20",
"type": "debug",
"z": "515b0c7217284cb8",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1110,
"y": 1320,
"wires": []
},
{
"id": "20abace1d174c667",
"type": "function",
"z": "515b0c7217284cb8",
"name": "Convert timestamp to date",
"func": "if ( !msg.timestamp ) msg.timestamp = Math.round(+new Date());\n\nvar dt = new Date(msg.timestamp);\nvar msg = {\n\t'month':\tdt.getMonth() + 1,\n\t'day':\t\tdt.getDate(),\n\t'year':\t\tdt.getFullYear(),\n\t'hours':\tdt.getHours(),\n\t'mins':\t\tdt.getMinutes(),\n\t'msecs':\tdt.getMilliseconds()\n}\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 880,
"y": 1320,
"wires": [
[
"59663b9cbe337e20"
]
]
},
{
"id": "c8b755a91d6ac6e5",
"type": "inject",
"z": "515b0c7217284cb8",
"name": "Today",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 430,
"y": 1320,
"wires": [
[
"20abace1d174c667"
]
]
},
{
"id": "2cfd1aa75f8d1ea6",
"type": "function",
"z": "515b0c7217284cb8",
"name": "add to timestamp",
"func": "// 37,5 days are 900 hours, 54.000 minutes, 3.240.000 secounds, 3.240.000.000 millisecounds \nvar newtimestamp = msg.timestamp + 3240000000;\nmsg.timestamp = newtimestamp;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 630,
"y": 1240,
"wires": [
[
"20abace1d174c667"
]
]
},
{
"id": "d1f5de434b4e91c2",
"type": "inject",
"z": "515b0c7217284cb8",
"name": "Today",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 430,
"y": 1240,
"wires": [
[
"2cfd1aa75f8d1ea6"
]
]
},
{
"id": "9b587e722ece8efa",
"type": "function",
"z": "515b0c7217284cb8",
"name": "set timestamp",
"func": "// use a fix number\nmsg.timestamp = 1000000000;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 620,
"y": 1360,
"wires": [
[
"20abace1d174c667"
]
]
},
{
"id": "472c163894bc80e9",
"type": "inject",
"z": "515b0c7217284cb8",
"name": "Today",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 430,
"y": 1360,
"wires": [
[
"9b587e722ece8efa"
]
]
}
]