Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange Date/Timezone Bug is misleading in IF-Node #1380

Closed
ixidion opened this issue Jan 25, 2021 · 17 comments
Closed

Strange Date/Timezone Bug is misleading in IF-Node #1380

ixidion opened this issue Jan 25, 2021 · 17 comments
Assignees
Labels
node/issue Issue with a node

Comments

@ixidion
Copy link

ixidion commented Jan 25, 2021

Describe the bug
Creating a Date() in an expression applies Timezone-Settings for the UI.

To Reproduce
Steps to reproduce the behavior:

  1. Own Timezone should not be UTC. UTC+1 in my case (Berlin-Time)
  2. Create an IF-Node
  3. Enter 1611273600000 for "2021-01-22T00:00:00.000Z" as Param1
  4. {{new Date(2021,0,22,0,0,0,0).getTime()}} as Param 2
  5. In the preview box the result is shown as: 1611270000000
  6. The IF-Node will evaluate to true (would expect that), even those shown numbers are different.

Expected behavior
The Box should show "1611273600000" as expected with no Timezone-Settings applied. But maybe it's more complicated cause of the timezones.

Environment (please complete the following information):

  • OS: Debian
  • n8n Version 0.102.0
  • Node.js Version (from official Docker-Image)

Additional context
Add any other context about the problem here.

@naskio
Copy link

naskio commented Feb 13, 2022

Hey @ixidion
Thanks for reporting. Are you using Postgres ?

@ixidion
Copy link
Author

ixidion commented Feb 14, 2022

@naskio Yes, I think there was also a Postgres-Node somewhere, but it's not necessary to reproduce.

@Joffcom
Copy link
Member

Joffcom commented Apr 25, 2022

Hey @ixidion,

I am just running through some of the older issues and have attempted to reproduce this one but I have not had any luck. I have set my default timezone in the container and the TZ variable to Europe/Berlin instead of my normal Europe/London setting and the expressions seems to evaluate correctly.

Are you still seeing this issue on the latest release?

@Joffcom Joffcom self-assigned this Apr 25, 2022
@naskio
Copy link

naskio commented Apr 25, 2022

Hey @ixidion,

I am just running through some of the older issues and have attempted to reproduce this one but I have not had any luck. I have set my default timezone in the container and the TZ variable to Europe/Berlin instead of my normal Europe/London setting and the expressions seems to evaluate correctly.

Are you still seeing this issue on the latest release?

Hey @Joffcom
The problem still exists
I opened #2813 which should fix it (you can find more details about the PR at #2810)
Good luck

@Joffcom
Copy link
Member

Joffcom commented Apr 25, 2022

Hey @naskio,

That is interesting, I can't see what the link could be though 🤔

For the UI to display the date from the expression I wouldn't have thought the database would be touched.

I will test in the morning using a Postgres DB and see if that changes anything, I take it you have been able to reproduce this issue?

@naskio
Copy link

naskio commented Apr 26, 2022

Hey @naskio,

That is interesting, I can't see what the link could be though 🤔

For the UI to display the date from the expression I wouldn't have thought the database would be touched.

I will test in the morning using a Postgres DB and see if that changes anything, I take it you have been able to reproduce this issue?

Hey @Joffcom
My bad, I just checked and found out that it is not really related to the other issue.
The problem here is that during the evaluation of the expression {{new Date(2021,0,22,0,0,0,0).getTime()}} the displayed value (in GMT+2) is different from the actual value (in GMT) that is being used in the comparison
(The problem here is only related to the UI assuming that we should use GMT during the expression's evaluation)
You can run the following workflow to get more details:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        560,
        400
      ]
    },
    {
      "parameters": {},
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1320,
        380
      ]
    },
    {
      "parameters": {},
      "name": "NoOp1",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1320,
        720
      ]
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": 1611273600000,
              "operation": "equal",
              "value2": "={{new Date(2021,0,22,0,0,0,0).getTime()}}"
            }
          ]
        }
      },
      "name": "IF using new Date(",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        860,
        700
      ]
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": 1611273600000,
              "operation": "equal",
              "value2": "={{Date.UTC(2021, 0, 22, 0, 0, 0, 0)}}"
            }
          ]
        }
      },
      "name": "IF using Date.UTC",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        860,
        400
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "IF using Date.UTC",
            "type": "main",
            "index": 0
          },
          {
            "node": "IF using new Date(",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF using new Date(": {
      "main": [
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "NoOp1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF using Date.UTC": {
      "main": [
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "NoOp1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
// I am on GMT+2
let dateTZ = new Date(2021, 0, 22, 0, 0, 0, 0);
console.log("dateTZ", dateTZ.getTime()); // dateTZ 1611270000000
let dateUTC = Date.UTC(2021, 0, 22, 0, 0, 0, 0);
console.log("dateUTC", dateUTC); // dateUTC 1611273600000

@ixidion
Copy link
Author

ixidion commented Apr 26, 2022

@naskio Yes, I think there was also a Postgres-Node somewhere, but it's not necessary to reproduce.
Sorry, that was misleading. I use Postgres as DB-Backend for n8n.

@ixidion
Copy link
Author

ixidion commented Apr 26, 2022

Still exists in 0.174.0
image

@Joffcom
Copy link
Member

Joffcom commented Apr 26, 2022

Interesting, For me on 174 I am not seeing the issue.

image

Can you tell me what you have generic timezone and tz environment variables set to?

@naskio
Copy link

naskio commented Apr 26, 2022

@Joffcom
In my case, the environment variables are set to GMT+2
I noticed that the displayed value is being calculated in the Frontend (and since the result is true, the actual value that is being used during comparison on the server is different from the one being displayed)

Hey @naskio,
That is interesting, I can't see what the link could be though 🤔
For the UI to display the date from the expression I wouldn't have thought the database would be touched.
I will test in the morning using a Postgres DB and see if that changes anything, I take it you have been able to reproduce this issue?

Hey @Joffcom My bad, I just checked and found out that it is not really related to the other issue. The problem here is that during the evaluation of the expression {{new Date(2021,0,22,0,0,0,0).getTime()}} the displayed value (in GMT+2) is different from the actual value (in GMT) that is being used in the comparison (The problem here is only related to the UI assuming that we should use GMT during the expression's evaluation) You can run the following workflow to get more details:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        560,
        400
      ]
    },
    {
      "parameters": {},
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1320,
        380
      ]
    },
    {
      "parameters": {},
      "name": "NoOp1",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1320,
        720
      ]
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": 1611273600000,
              "operation": "equal",
              "value2": "={{new Date(2021,0,22,0,0,0,0).getTime()}}"
            }
          ]
        }
      },
      "name": "IF using new Date(",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        860,
        700
      ]
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": 1611273600000,
              "operation": "equal",
              "value2": "={{Date.UTC(2021, 0, 22, 0, 0, 0, 0)}}"
            }
          ]
        }
      },
      "name": "IF using Date.UTC",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        860,
        400
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "IF using Date.UTC",
            "type": "main",
            "index": 0
          },
          {
            "node": "IF using new Date(",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF using new Date(": {
      "main": [
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "NoOp1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF using Date.UTC": {
      "main": [
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "NoOp1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
// I am on GMT+2
let dateTZ = new Date(2021, 0, 22, 0, 0, 0, 0);
console.log("dateTZ", dateTZ.getTime()); // dateTZ 1611270000000
let dateUTC = Date.UTC(2021, 0, 22, 0, 0, 0, 0);
console.log("dateUTC", dateUTC); // dateUTC 1611273600000

@Joffcom
Copy link
Member

Joffcom commented Apr 26, 2022

Hey @naskio,

Can you send me the environment variables you have set? In thoery I should be seeing an incorrect value as my machine is set to GMT but n8n is set to +2 but I see the +2 result in the browser so I am wondering if maybe this is more of a config issue or there is another option that I am missing.

@naskio
Copy link

naskio commented Apr 26, 2022

Hey @naskio,

Can you send me the environment variables you have set? In thoery I should be seeing an incorrect value as my machine is set to GMT but n8n is set to +2 but I see the +2 result in the browser so I am wondering if maybe this is more of a config issue or there is another option that I am missing.

My n8n environment:

GENERIC_TIMEZONE=Etc/GMT
TZ=Etc/GMT

(Sorry, I forgot that I switched to GMT because I faced many issues while using my local timezone)

My machine is set to GMT+2

@ixidion
Copy link
Author

ixidion commented Apr 26, 2022

Interesting, For me on 174 I am not seeing the issue.

image

Can you tell me what you have generic timezone and tz environment variables set to?

My local time is set to CEST (is: UTC+2).
GENERIC_TIMEZONE=Europe/Berlin
TZ was not set for the container, but did it now. -> no change

I have run your code snippet.
UTC-Branch (looks ok)
image

new Date (looks not ok)
image

@Joffcom
Copy link
Member

Joffcom commented Apr 26, 2022

This is very odd, maybe I need to change my desktop timezone to see the problem 🤔

@RicardoE105 you are on a different timezone to me, are you able to reproduce this?

@michael-radency
Copy link
Contributor

Hello @ixidion , I do not think this is a bug, here for example from browser's console when timezone isn't specified:
image
behavior is reproducible, but it's nothing specific to IF node:
date1: just string
date2: {{DateTime.fromISO("2021-01-22T00:00:00.000Z").toMillis()}}
date3: {{new Date('2021-01-22T00:00:00.000Z').getTime()}}
date4: {{new Date('2021-01-22T00:00:00').getTime()}}
image

@ixidion
Copy link
Author

ixidion commented Oct 16, 2022

@michael-radency Thank you for elaborating. So, it seems like it is a JavaScript/Browser Pitfall. I'm with you, doesn't look like a IF-Node bug.

@michael-radency
Copy link
Contributor

Hello @ixidion , thanks for replying, as we agree that this behavior is not a n8n bug and it's not related to IF node I'll close this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
node/issue Issue with a node
Projects
None yet
Development

No branches or pull requests

4 participants