{ "nodes": [ { "name": "On clicking 'execute'", "type": "n8n-nodes-base.manualTrigger", "position": [ 250, 300 ], "parameters": {}, "typeVersion": 1, "id": "dmy-to-mdy-date-converter-trigger" }, { "id": "dmy-to-mdy-date-converter-convert", "name": "Validate and format calendar date", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 520, 300 ], "parameters": { "mode": "runOnceForEachItem", "jsCode": "const value = '14/02/2020';\nfunction convertDmyDate(value) {\n if (typeof value !== 'string' || value.length !== 10) throw new Error('Enter a date in DD/MM/YYYY format');\n const match = /^([0-9]{2})\\/([0-9]{2})\\/([0-9]{4})$/.exec(value);\n if (!match) throw new Error('Enter a date in DD/MM/YYYY format');\n const [, dayText, monthText, yearText] = match;\n const day = Number(dayText), month = Number(monthText), year = Number(yearText);\n const leap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);\n const monthDays = [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];\n if (month < 1 || month > 12 || day < 1 || day > monthDays[month - 1]) throw new Error('Enter a valid calendar date');\n return monthText + '/' + dayText + '/' + yearText;\n}\nasync function dmyDate({ value }) {\n return { data: convertDmyDate(value) };\n}\n\nreturn { json: { data: convertDmyDate(value) } };" } } ], "connections": { "On clicking 'execute'": { "main": [ [ { "node": "Validate and format calendar date", "type": "main", "index": 0 } ] ] } }, "name": "DMY to MDY Date Converter", "settings": { "executionOrder": "v1" }, "active": false, "pinData": {} }