How I get Date.now() with the local Timezone defined in Workflow-Settings?

Hi,
I’m new in the n8n.io world.

New Event data from Google Calendar to Mautic

I would like to transfer data from Google Calendar (with Google Calendar Trigger) to my Newsletter-Automation (Mautic) in the n8n.io App.

Problem: All Events instead of only the new ones

Unfortunately the Google Calendar Trigger set to «Event Created» get not only new Events in the output. I seams this trigger get all Created Events stored in the particular Calendar (Calendar Name/ID)

Found a solution, BUT … Timezone seams to be wrong in the n8n.io also with different setting

So I guess, I have to use IF-node to check first if the Event is older then 5 Minutes (The Trigger is executed all 5 Minutes).

I tried with Date.now() then subtract 5 Minutes and would like to check if create-time of the Google Calendar item is not before this timestamp.

Unfortunately the time «Timezone» setting in the Workflow > Settings, does not have any effect.
When I do the Date.now() I get a time different 1h to the Timezone set in the settings.
I guess it is the system-Timezone.

Questions

What I have to do to make the setting in the Workflow>Setting impactful, so I would not have to change something when the time changeover will take action?
Do I have to choose a different JS-function?

Or does someone have a working workflow with Google Event Trigger, where only the new created Events are processing?

Would be great to get help or also a link to the right place in documentation.
Have found a few Entries with «Problems» with Google Calendar but there are no solutions for…

Cheers
Martin

Hi @mad99, welcome to the community!

The workflow timezone would be respected by the Cron node, but not by JavaScript code (unless you read it). You can, however, use the Date & Time node to convert a JS Date value into a specific timezone:

This should, however, not be necessary. A value such as 2022-10-10T15:22:46Z would have Z as the indicator for the Zulu time (which has a UTC offset of 0). Virtually all services will be able to correctly parse this.

Example Workflow
{
  "nodes": [
    {
      "parameters": {
        "value": "={{new Date()}}",
        "custom": true,
        "toFormat": "YYYY-MM-DDTHH:mm:ssZ",
        "options": {
          "toTimezone": "Europe/Vienna"
        }
      },
      "name": "Date & Time",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 1,
      "position": [
        680,
        300
      ]
    }
  ],
  "connections": {}
}

I am very surprised to hear your Google Calendar Trigger would return all new events though. It wouldn’t do that to me using these settings:

So maybe you could share your trigger settings? And confirm whether all events are returned when manually clicking Execute Workflow/Execute Node or when running in production mode after activating your workflow (in this case, the data would only be available through the executions list)?

Hey @MutedJam,
Thank you for your help.

I am very surprised to hear your Google Calendar Trigger would return all new events though. It wouldn’t do that to me using these settings:

To be honest, maybe I missunderstand something and wrote these part not correctly in detail.
My Google Calendar Settings looks like yours:

And you are right, there are not «all events» listed, as I wrote. There is only «Items: 1» like in your printScreen.

BUT:
The item in the Data-Area is from around 3 month ago. It was the first Event I created in Google Calendar. But I like to have only «new created Events» not all the old ones…
So I deleted this particular «old» Event.
But then only the next «very old» Event from around 2.7 month ago was arise.
Did the same: Delted > next, Deleted > next …
And so on.

So I’ve assumed, that «instead of get only the current new created events» the Google Calendar Trigger-Node get ALL also old Events Bite by bite from the beginning of the Calendar-filling-time…

I guessed the setting «Event Created» get only «new created Events» in the stream-output.
Maybe:

  • Do I have to change some settings to get only Events when in Google Calendar there is a new Event created (now, or at least not older than the last Poll Time (1 Minute)?

  • Or do I have to filter by «create-time of Event not before Date.now() - 1 Minute»?
    (then I would be on the right track. Unfortunately in Google Calendar there is the timezone of UTH+1.
    But now I see the create-time is formated as 2021-09-04T03:16:26.000Z (so as you wrote «Z» for Zulu).
    Maybe I don’t have to calculate for the filtering. But for the «start» and «end» time I guess.

Have to try and error with Mautic when all the other stuff is done.
But would help, if I could change he Google Calendar Trigger to only fire when there IS a new Event created right now.

  • Do you (or anyone else) have any idea? Do I have to filter or is there a part in the Trigger-Settings for?

Ah, I think I know what’s happening here - when manually executing your workflow (by clicking the Execute Workflow or Execute Node button), the node would fetch an old event to give you some data to work with when building out your workflow.

Once you activate your workflow it will run continuously in the background and will only execute for new events it receives (or at least that’s how it should be :wink:). So you would not need to create any additional filtering.

If you want to double check this, create a simple workflow consisting only of your Google Calendar Trigger node and save it. Then activate it via the toggle in the upper right corner:
image

Now create a new Google Calendar Event and wait for the polling interval to pass. Afterwards you should be able to see the execution in the list accessible through the side bar in the left:
image

You can then open the execution data using this button:

This production data should no longer contain an old event but the one you have just created. These steps assume you are actually storing execution data (if not, you would need to update the respective settings first).

Hope this helps!

1 Like

Hey @MutedJam,
You are my hero of the day :hugs:!!

I tried in the desktop App, as @jon has mentioned (NewbyQuestion > to have more executions left in cloudApp. => so it took a little longer because of the different Credential Oauth2 with Google Calendar)

And there is after activating the Workflow really only the one (1) «NEW» Event => Created before a few seconds!!

Thank you a lot for your help, you saved me hours of coding and try&error !!!
Martin

1 Like

Awesome, glad to hear this works and thanks so much for confirming!