Cannot get to work

Describe the problem/error/question

I was using a template created by someone. Link is here, https://n8n.io/workflows/2158-send-daily-meetings-in-google-calendar-to-telegram/. I got it to work wonderfully yesterday and then all of a sudden today it did not work. I went in and in my code block I have this error.

What is the error message (if any)?

Node type

n8n-nodes-base.code

Node version

2 (Latest)

n8n version

1.88.0 (Self Hosted)

Stack trace

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

Please share your workflow

Information on your n8n setup

  • n8n version: 1.88.0
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system:

Hi plddle99

Hope you are well!

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.

Hello. Could you send a photo of the section that you mention as “missing value” or the section of code that generated this doubt?

It works be in the workflow

Is it working as you would like?

It did yesterday. Today it crashed at line 17

Share the section that fell at line 17

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.