Month shifting with iCalendar node

Hi,

Using the iCalendar node,
I’m experiencing a problem with shifting of the month, by one month less.

image

Not sure if this is a bug.
I have found this : JavaScript getMonth() Method
But my technical skills do not allow me to go further.

Thank you

Hey @alexandre!

Welcome to the community :sparkling_heart:

Can you share some more details? How are you getting the state date and end date? Is this passed from a node prior to the iCalendar node? Can you share your workflow? You can copy the nodes and paste them here (check this out: How can I contribute? | Docs).

If you want to perform operations on Date and Time, you can use the Date & Time node.

Here is my workflow.
Dates are passed from the Strava node.
“Format Start” and “Format End” nodes were set to test another date format but it changes nothing.

{
  "nodes": [
    {
      "parameters": {
        "object": "activity",
        "event": "create",
        "options": {}
      },
      "name": "Strava Trigger",
      "type": "n8n-nodes-base.stravaTrigger",
      "typeVersion": 1,
      "position": [
        250,
        450
      ],
      "webhookId": "0e1bbd68-36e6-4586-9b2f-3a582a8e417c",
      "credentials": {
        "stravaOAuth2Api": "Strava AG"
      }
    },
    {
      "parameters": {
        "title": "=Strava - {{$node[\"Strava Trigger\"].json[\"object_data\"][\"type\"]}} - {{$node[\"Strava Trigger\"].json[\"object_data\"][\"distance\"]}}",
        "start": "={{$node[\"Format Start\"].json[\"start_date_time\"]}}",
        "end": "={{$node[\"Format End\"].json[\"end_date_time\"]}}",
        "additionalFields": {
          "description": "=Créé avec n8n.\n\nDebug :\nDateDebut\n{{$node[\"Strava Trigger\"].json[\"object_data\"][\"start_date_local\"]}}\n{{$node[\"Format Start\"].json[\"start_date_time\"]}}\nDateFin\n{{$node[\"AddDuration\"].json[\"end_date\"]}}\n{{$node[\"Format End\"].json[\"end_date_time\"]}}",
          "url": "=https://www.strava.com/activities/{{$node[\"Strava Trigger\"].json[\"object_data\"][\"id\"]}}"
        }
      },
      "name": "iCalendar",
      "type": "n8n-nodes-base.iCal",
      "typeVersion": 1,
      "position": [
        1050,
        450
      ]
    },
    {
      "parameters": {
        "fromEmail": "[email protected]",
        "toEmail": "[email protected]",
        "subject": "=Strava - {{$node[\"Strava Trigger\"].json[\"object_data\"][\"type\"]}} - {{$node[\"Strava Trigger\"].json[\"object_data\"][\"distance\"]}}",
        "attachments": "=data",
        "options": {}
      },
      "name": "Send Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 1,
      "position": [
        1250,
        450
      ],
      "credentials": {
        "smtp": "Fastmail"
      }
    },
    {
      "parameters": {
        "value": "={{$node[\"Strava Trigger\"].json[\"object_data\"][\"start_date_local\"]}}",
        "dataPropertyName": "start_date_time",
        "custom": true,
        "toFormat": "=YYYYMMDDTHHmmss",
        "options": {
          "fromFormat": ""
        }
      },
      "name": "Format Start",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 1,
      "position": [
        450,
        450
      ]
    },
    {
      "parameters": {
        "value": "={{$node[\"AddDuration\"].json[\"end_date\"]}}",
        "dataPropertyName": "end_date_time",
        "custom": true,
        "toFormat": "YYYYMMDDTHHmmss",
        "options": {}
      },
      "name": "Format End",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 1,
      "position": [
        850,
        450
      ]
    },
    {
      "parameters": {
        "action": "calculate",
        "value": "={{$node[\"Strava Trigger\"].json[\"object_data\"][\"start_date_local\"]}}",
        "duration": "={{$node[\"Strava Trigger\"].json[\"object_data\"][\"elapsed_time\"]}}",
        "timeUnit": "seconds",
        "dataPropertyName": "end_date",
        "options": {}
      },
      "name": "AddDuration",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 1,
      "position": [
        650,
        450
      ]
    }
  ],
  "connections": {
    "Strava Trigger": {
      "main": [
        [
          {
            "node": "Format Start",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "iCalendar": {
      "main": [
        [
          {
            "node": "Send Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Start": {
      "main": [
        [
          {
            "node": "AddDuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format End": {
      "main": [
        [
          {
            "node": "iCalendar",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AddDuration": {
      "main": [
        [
          {
            "node": "Format End",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Thanks for sharing this. Can you also share the output return by the Strava Trigger node? Please replace any sensitive information that gets returned. I am interested in the dates that are returned

I’m using these 2 parameters :

  • start_date_local
  • elapsed_time to calculate the end time

Hey @alexandre!

Thank you for sharing the output. I took a look at the workflow that you shared. The Add Duration node is adding 3600 seconds (= 1 hour). If you want to add a month change the Time Unit to Months. Below is a workflow that might be helpful

{
  "nodes": [
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n    \"aspect-type\": \"something\",\n    \"object-data\":{\n      \"elapsed_time\": 3600,\n      \"start_date_local\": \"2021-07-02T14:20:00Z\"\n    }\n    }\n  }\n];"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        700,
        300
      ]
    },
    {
      "parameters": {
        "title": "=Strava - {{$node[\"Strava Trigger\"].json[\"object_data\"][\"type\"]}} - {{$node[\"Strava Trigger\"].json[\"object_data\"][\"distance\"]}}",
        "start": "={{$json[\"object-data\"][\"start_date_local\"]}}",
        "end": "={{$json[\"end_date\"]}}",
        "additionalFields": {
          "description": "=Créé avec n8n.\n\nDebug :\nDateDebut\n{{$node[\"Strava Trigger\"].json[\"object_data\"][\"start_date_local\"]}}\n{{$node[\"Format Start\"].json[\"start_date_time\"]}}\nDateFin\n{{$node[\"AddDuration\"].json[\"end_date\"]}}\n{{$node[\"Format End\"].json[\"end_date_time\"]}}",
          "url": "=https://www.strava.com/activities/{{$node[\"Strava Trigger\"].json[\"object_data\"][\"id\"]}}"
        }
      },
      "name": "iCalendar",
      "type": "n8n-nodes-base.iCal",
      "typeVersion": 1,
      "position": [
        1100,
        300
      ]
    },
    {
      "parameters": {
        "fromEmail": "[email protected]",
        "toEmail": "[email protected]",
        "subject": "=Strava - {{$node[\"Strava Trigger\"].json[\"object_data\"][\"type\"]}} - {{$node[\"Strava Trigger\"].json[\"object_data\"][\"distance\"]}}",
        "attachments": "data",
        "options": {}
      },
      "name": "Send Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 1,
      "position": [
        1300,
        300
      ],
      "credentials": {
        "smtp": "Outlook Burner Credentials"
      }
    },
    {
      "parameters": {
        "action": "calculate",
        "value": "={{$json[\"object-data\"][\"start_date_local\"]}}",
        "duration": 1,
        "timeUnit": "months",
        "dataPropertyName": "end_date",
        "options": {}
      },
      "name": "AddDuration",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 1,
      "position": [
        900,
        300
      ]
    }
  ],
  "connections": {
    "Function": {
      "main": [
        [
          {
            "node": "AddDuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "iCalendar": {
      "main": [
        [
          {
            "node": "Send Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AddDuration": {
      "main": [
        [
          {
            "node": "iCalendar",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like

Thanks @harshil1712, it works now.
However, isn’t this a bug of the iCalendar node?

Hey @alexandre,

The iCalendar node doesn’t have a bug. You were adding 3600 seconds (1 hour) to the start time and then passing the value to the iCalendar node. The workflow that I shared, adds a month instead of 3600 seconds and then passes the value to the iCalendar node. Let me know if you need more details :slight_smile:

1 Like