UI: Update date to force date ISO Format
This commit is contained in:
parent
f55182d79c
commit
734c2b7108
|
@ -7356,7 +7356,7 @@
|
||||||
"rows": null
|
"rows": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "Date (DD/MM/YYYY, UTC)",
|
"label": "Date (YYYY-MM-DD, UTC)",
|
||||||
"value": "object_date",
|
"value": "object_date",
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"required": true,
|
"required": true,
|
||||||
|
@ -7414,7 +7414,7 @@
|
||||||
"rows": null
|
"rows": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "Date (DD/MM/YYYY, UTC)",
|
"label": "Date (YYYY-MM-DD, UTC)",
|
||||||
"value": "object_date",
|
"value": "object_date",
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"required": true,
|
"required": true,
|
||||||
|
@ -7472,7 +7472,7 @@
|
||||||
"rows": null
|
"rows": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "Date (DD/MM/YYYY, UTC)",
|
"label": "Date (YYYY-MM-DD, UTC)",
|
||||||
"value": "object_date_end",
|
"value": "object_date_end",
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"required": true,
|
"required": true,
|
||||||
|
@ -7509,7 +7509,7 @@
|
||||||
"type": "function",
|
"type": "function",
|
||||||
"z": "b771c342.49603",
|
"z": "b771c342.49603",
|
||||||
"name": "Validate Form",
|
"name": "Validate Form",
|
||||||
"func": "function ConvertDDMMToDD(input) {\n // Input Format 36°57.4439' N, 110°4.2100' W\n // From https://stackoverflow.com/questions/1140189/converting-latitude-and-longitude-to-decimal-values\n var parts = input.split(/[^\\d\\w]+/)\n var dd = Number(parts[0]) + (Number(parts[1]) + Number(parts[2])/10000)/60\n return dd.toFixed(6) + parts[3]\n}\n\nfunction ValidateCoordinates(input, lat){\n // Input Format 36.574439° N, 110.42100° W\n var direction = input.match(/[NSEW]/)\n var position = input.match(/[\\+\\-\\d\\.]+/)\n var error = {}\n \n if (direction === null){\n error.topic = \"Error with the \"\n error.payload = \"You need to explicitely enter N/S/E/W\"\n return [null, error]\n }\n \n // Test that position is only made of digits!\n if(/^[\\+\\-]/.test(position)){\n error.topic = \"Error with the \"\n error.payload = \"Use of +/- sign is inconsistent with N/S/E/W letter! Please only use N/S/E/W!\"\n return [null, error]\n }\n \n var dd = Number(position)\n if (lat){\n // Check latitude\n if (direction == \"S\" || direction == \"N\") {\n if (dd>90.0){\n error.topic = \"Error with the \"\n error.payload = \"Latitude is more than 90°\"\n return [null, error]\n }\n }\n if (direction == \"W\" || direction == \"E\") {\n error.topic = \"Error with the \"\n error.payload = \"This is not a Latitude!\"\n return [null, error]\n }\n }\n else{\n // Check longitude\n if (direction == \"W\" || direction == \"E\") {\n if (dd>180.0){\n error.topic = \"Error with the \"\n error.payload = \"Longitude is more than 180°\"\n return [null, error]\n }\n }\n if (direction == \"N\" || direction == \"S\") {\n error.topic = \"Error with the \"\n error.payload = \"This is not a Longitude!\"\n return [null, error]\n }\n }\n \n if (direction == \"S\" || direction == \"W\") {\n dd = dd * -1\n } // Don't do anything for N or E\n return [dd.toFixed(4), null]\n\n}\nvar ret\n\nif (msg.topic == \"net_retrieval_location\"){\n if (flow.get(\"coordinates_type\") == \"ddm\"){\n msg.payload.object_lat_end = ConvertDDMMToDD(msg.payload.object_lat_end)\n msg.payload.object_lon_end = ConvertDDMMToDD(msg.payload.object_lon_end)\n }\n ret = ValidateCoordinates(msg.payload.object_lat_end, true);\n if (ret[1] !== null){\n msg.topic = ret[1].topic + \" Latitude\"\n msg.payload = ret[1].payload\n return msg\n }\n global.set(\"object_lat_end\", ret[0])\n ret = ValidateCoordinates(msg.payload.object_lon_end, false)\n if (ret[1] !== null){\n msg.topic = ret[1].topic + \" Longitude\"\n msg.payload = ret[1].payload\n return msg\n }\n global.set(\"object_lon_end\", ret[0]);\n \n var date = new Date(msg.payload.object_date_end)\n global.set(\"object_date_end\", date.toISOString().split('T')[0].replace(/-/gi, ''))\n\n var time = msg.payload.object_time_end.replace(/\\D/g, \"\") // remove non-digit characters\n if (time.length<5) time += \"00\"\n global.set(\"object_time_end\", time)\n}\nelse{\n if (flow.get(\"coordinates_type\") == \"ddm\"){\n msg.payload.object_lat = ConvertDDMMToDD(msg.payload.object_lat)\n msg.payload.object_lon = ConvertDDMMToDD(msg.payload.object_lon)\n }\n ret = ValidateCoordinates(msg.payload.object_lat, true);\n if (ret[1] !== null){\n msg.topic = ret[1].topic + \" Latitude\";\n msg.payload = ret[1].payload\n return msg\n }\n global.set(\"object_lat\", ret[0]);\n ret = ValidateCoordinates(msg.payload.object_lon, false);\n if (ret[1] !== null){\n msg.topic = ret[1].topic + \" Longitude\"\n msg.payload = ret[1].payload\n return msg\n }\n global.set(\"object_lon\", ret[0])\n \n var date = new Date(msg.payload.object_date)\n global.set(\"object_date\", date.toISOString().split('T')[0].replace(/-/gi, ''))\n \n var time = msg.payload.object_time.replace(/\\D/g, \"\"); // remove non-digit characters\n if (time.length<5) time += \"00\";\n global.set(\"object_time\", time)\n}\nreturn {topic: \"Coordinates valid!\", payload: \"All good!\"}\n",
|
"func": "function ConvertDDMMToDD(input) {\n // Input Format 36°57.4439' N, 110°4.2100' W\n // From https://stackoverflow.com/questions/1140189/converting-latitude-and-longitude-to-decimal-values\n var parts = input.split(/[^\\d\\w]+/)\n var dd = Number(parts[0]) + (Number(parts[1]) + Number(parts[2])/10000)/60\n return dd.toFixed(6) + parts[3]\n}\n\nfunction ValidateCoordinates(input, lat){\n // Input Format 36.574439° N, 110.42100° W\n var direction = input.match(/[NSEW]/)\n var position = input.match(/[\\+\\-\\d\\.]+/)\n var error = {}\n \n if (direction === null){\n error.topic = \"Error with the \"\n error.payload = \"You need to explicitely enter N/S/E/W\"\n return [null, error]\n }\n \n // Test that position is only made of digits!\n if(/^[\\+\\-]/.test(position)){\n error.topic = \"Error with the \"\n error.payload = \"Use of +/- sign is inconsistent with N/S/E/W letter! Please only use N/S/E/W!\"\n return [null, error]\n }\n \n var dd = Number(position)\n if (lat){\n // Check latitude\n if (direction == \"S\" || direction == \"N\") {\n if (dd>90.0){\n error.topic = \"Error with the \"\n error.payload = \"Latitude is more than 90°\"\n return [null, error]\n }\n }\n if (direction == \"W\" || direction == \"E\") {\n error.topic = \"Error with the \"\n error.payload = \"This is not a Latitude!\"\n return [null, error]\n }\n }\n else{\n // Check longitude\n if (direction == \"W\" || direction == \"E\") {\n if (dd>180.0){\n error.topic = \"Error with the \"\n error.payload = \"Longitude is more than 180°\"\n return [null, error]\n }\n }\n if (direction == \"N\" || direction == \"S\") {\n error.topic = \"Error with the \"\n error.payload = \"This is not a Longitude!\"\n return [null, error]\n }\n }\n \n if (direction == \"S\" || direction == \"W\") {\n dd = dd * -1\n } // Don't do anything for N or E\n return [dd.toFixed(4), null]\n\n}\nvar ret\n\nif (msg.topic == \"net_retrieval_location\"){\n if (flow.get(\"coordinates_type\") == \"ddm\"){\n msg.payload.object_lat_end = ConvertDDMMToDD(msg.payload.object_lat_end)\n msg.payload.object_lon_end = ConvertDDMMToDD(msg.payload.object_lon_end)\n }\n ret = ValidateCoordinates(msg.payload.object_lat_end, true);\n if (ret[1] !== null){\n msg.topic = ret[1].topic + \" Latitude\"\n msg.payload = ret[1].payload\n return msg\n }\n global.set(\"object_lat_end\", ret[0])\n ret = ValidateCoordinates(msg.payload.object_lon_end, false)\n if (ret[1] !== null){\n msg.topic = ret[1].topic + \" Longitude\"\n msg.payload = ret[1].payload\n return msg\n }\n global.set(\"object_lon_end\", ret[0]);\n \n if (! /\\d{4}-\\d{2}-\\d{2}/.test(msg.payload.object_date)){\n msg.topic = \"Error with the date\"\n msg.payload = \"The date should respect the ISO format YYYY-MM-DD\"\n return msg\n }\n global.set(\"object_date\", msg.payload.object_date)\n \n var time = msg.payload.object_time_end.replace(/\\D/g, \"\") // remove non-digit characters\n if (time.length<5) time += \"00\"\n global.set(\"object_time_end\", time)\n}\nelse{\n if (flow.get(\"coordinates_type\") == \"ddm\"){\n msg.payload.object_lat = ConvertDDMMToDD(msg.payload.object_lat)\n msg.payload.object_lon = ConvertDDMMToDD(msg.payload.object_lon)\n }\n ret = ValidateCoordinates(msg.payload.object_lat, true);\n if (ret[1] !== null){\n msg.topic = ret[1].topic + \" Latitude\";\n msg.payload = ret[1].payload\n return msg\n }\n global.set(\"object_lat\", ret[0]);\n ret = ValidateCoordinates(msg.payload.object_lon, false);\n if (ret[1] !== null){\n msg.topic = ret[1].topic + \" Longitude\"\n msg.payload = ret[1].payload\n return msg\n }\n global.set(\"object_lon\", ret[0])\n \n if (! /\\d{4}-\\d{2}-\\d{2}/.test(msg.payload.object_date)){\n msg.topic = \"Error with the date\"\n msg.payload = \"The date should respect the ISO format YYYY-MM-DD\"\n return msg\n }\n global.set(\"object_date\", msg.payload.object_date)\n \n var time = msg.payload.object_time.replace(/\\D/g, \"\"); // remove non-digit characters\n if (time.length<5) time += \"00\";\n global.set(\"object_time\", time)\n}\nreturn {topic: \"Coordinates valid!\", payload: \"All good!\"}\n",
|
||||||
"outputs": 1,
|
"outputs": 1,
|
||||||
"noerr": 0,
|
"noerr": 0,
|
||||||
"initialize": "",
|
"initialize": "",
|
||||||
|
|
Loading…
Reference in a new issue