RangeError: Invalid time value
at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:17:6
at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:30:2
at VM2 Wrapper.apply (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/bridge.js:490:11)
at NodeVM.run (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/nodevm.js:497:23)
at JavaScriptSandbox.runCodeAllItems (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code/JavaScriptSandbox.js:73:39)
at ExecuteContext.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code/Code.node.js:155:31)
at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/workflow-execute.js:681:50)
at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/workflow-execute.js:915:62
at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/workflow-execute.js:1246:20
The error “RangeError: Invalid time value” indicates that the value you are trying to use in new Date(item.json.Time.dateTime) is not formatted correctly or is empty
In the code provided, the error may be occurring due to:
Missing Date/Time Values:
item.json.Time.dateTime may not be available or is empty.
item.json.Time.timeZone may not be provided.
Invalid Date Formatting:
new Date() requires the dateTime field to be in the format it recognizes
Adjust your code in the Code node to ensure that all date values are valid before processing them
Here is a suggestion that may help you.
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0');
var yyyy = today.getFullYear();
today = mm + '/' + dd + '/' + yyyy;
let message = "*Your meetings today, " + today + ", are:* \n";
for (let item of items) {
if (item.json.Time?.dateTime) {
const time = new Date(item.json.Time.dateTime);
const formattedTime = new Intl.DateTimeFormat('en-US', {
hour: 'numeric',
minute: 'numeric',
timeZone: item.json.Time.timeZone || 'UTC'
}).format(time);
message += `* ${item.json.Name} | ${formattedTime}\n`;
if (item.json.Location && item.json.Location.trim() !== '') {
message += ` Location: ${item.json.Location}\n`;
}
} else {
message += `* ${item.json.Name} | Invalid or Missing Date\n`;
}
}
return [{ json: { message } }];
Test and debug your code by generating some flows with intentionally incomplete data (missing Time.dateTime and Time.timeZone) to test.
Then run the flow partially up to the Code node and inspect the items value to verify inputs.
I hope I have helped you in some way.
Best regards
You said missing value and that made me think. Could it be because I have an event on my Google calendar today that is marked as all day with no time? Is there a way to add a go around for that. I want that event still but it has no time, just the date.
Hi @plddle99, could you kindly mark my previous post as the solution (blue box with check mark) so that this ongoing discussion does not distract others who want to find out the answer to the original question? Thanks.