From 51680c5c917f48aef7cb5f7c4aa5f2c56564cfd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Wed, 7 Feb 2024 18:24:59 +0100 Subject: [PATCH 1/4] fix(Wait node): Account for workflow timezone in Wait node datetime --- packages/core/src/NodeExecuteFunctions.ts | 3 +-- packages/nodes-base/nodes/Wait/Wait.node.ts | 16 ++++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/core/src/NodeExecuteFunctions.ts b/packages/core/src/NodeExecuteFunctions.ts index 9ae33f6b963e3..a3f3178eccb9f 100644 --- a/packages/core/src/NodeExecuteFunctions.ts +++ b/packages/core/src/NodeExecuteFunctions.ts @@ -150,7 +150,6 @@ import Container from 'typedi'; import type { BinaryData } from './BinaryData/types'; import merge from 'lodash/merge'; import { InstanceSettings } from './InstanceSettings'; -import { toUtcDate } from './utils'; axios.defaults.timeout = 300000; // Prevent axios from adding x-form-www-urlencoded headers by default @@ -3537,7 +3536,7 @@ export function getExecuteFunctions( binaryToBuffer: async (body: Buffer | Readable) => await Container.get(BinaryDataService).toBuffer(body), async putExecutionToWait(waitTill: Date): Promise { - runExecutionData.waitTill = toUtcDate(waitTill, getTimezone(workflow)); + runExecutionData.waitTill = waitTill; if (additionalData.setExecutionStatus) { additionalData.setExecutionStatus('waiting'); } diff --git a/packages/nodes-base/nodes/Wait/Wait.node.ts b/packages/nodes-base/nodes/Wait/Wait.node.ts index 888994a4a7651..4ea45136e92ec 100644 --- a/packages/nodes-base/nodes/Wait/Wait.node.ts +++ b/packages/nodes-base/nodes/Wait/Wait.node.ts @@ -1,3 +1,4 @@ +import { DateTime } from 'luxon'; import type { IExecuteFunctions, INodeExecutionData, @@ -29,7 +30,6 @@ import { } from '../Form/common.descriptions'; import { formWebhook } from '../Form/utils'; import { updateDisplayOptions } from '../../utils/utilities'; - import { Webhook } from '../Webhook/Webhook.node'; const waitTimeProperties: INodeProperties[] = [ @@ -420,12 +420,16 @@ export class Wait extends Webhook { waitAmount *= 1000; - waitTill = new Date(new Date().getTime() + waitAmount); + waitTill = DateTime.now() + .setZone(context.getTimezone()) + .plus({ milliseconds: waitAmount }) + .toUTC() + .toJSDate(); } else { - // resume: dateTime - const dateTime = context.getNodeParameter('dateTime', 0) as string; - - waitTill = new Date(dateTime); + const dateTimeStr = context.getNodeParameter('dateTime', 0) as string; + const FORMAT = "yyyy-MM-dd'T'HH:mm:ss"; + const tz = { zone: context.getTimezone() }; + waitTill = DateTime.fromFormat(dateTimeStr, FORMAT, tz).toUTC().toJSDate(); } const waitValue = Math.max(waitTill.getTime() - new Date().getTime(), 0); From ef98dd3e61bbd62b4d4291566e98da248a71e38b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Thu, 8 Feb 2024 10:34:34 +0100 Subject: [PATCH 2/4] Handle separately --- packages/nodes-base/nodes/Wait/Wait.node.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/nodes-base/nodes/Wait/Wait.node.ts b/packages/nodes-base/nodes/Wait/Wait.node.ts index 4ea45136e92ec..125cc139e59c6 100644 --- a/packages/nodes-base/nodes/Wait/Wait.node.ts +++ b/packages/nodes-base/nodes/Wait/Wait.node.ts @@ -420,16 +420,22 @@ export class Wait extends Webhook { waitAmount *= 1000; - waitTill = DateTime.now() - .setZone(context.getTimezone()) + const original = new Date(new Date().getTime() + waitAmount); + + waitTill = DateTime.fromISO(original.toISOString().slice(0, -1), { + zone: context.getTimezone(), + }) .plus({ milliseconds: waitAmount }) .toUTC() .toJSDate(); } else { const dateTimeStr = context.getNodeParameter('dateTime', 0) as string; - const FORMAT = "yyyy-MM-dd'T'HH:mm:ss"; - const tz = { zone: context.getTimezone() }; - waitTill = DateTime.fromFormat(dateTimeStr, FORMAT, tz).toUTC().toJSDate(); + + waitTill = DateTime.fromFormat(dateTimeStr, "yyyy-MM-dd'T'HH:mm:ss", { + zone: context.getTimezone(), + }) + .toUTC() + .toJSDate(); } const waitValue = Math.max(waitTill.getTime() - new Date().getTime(), 0); From bb9bb0f188b7f282e06829a7c4afef90c7a46155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Thu, 8 Feb 2024 10:42:42 +0100 Subject: [PATCH 3/4] Use `slice()` to ignore incoming TZ --- packages/nodes-base/nodes/Wait/Wait.node.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/nodes-base/nodes/Wait/Wait.node.ts b/packages/nodes-base/nodes/Wait/Wait.node.ts index 125cc139e59c6..4bb1febd06486 100644 --- a/packages/nodes-base/nodes/Wait/Wait.node.ts +++ b/packages/nodes-base/nodes/Wait/Wait.node.ts @@ -422,12 +422,7 @@ export class Wait extends Webhook { const original = new Date(new Date().getTime() + waitAmount); - waitTill = DateTime.fromISO(original.toISOString().slice(0, -1), { - zone: context.getTimezone(), - }) - .plus({ milliseconds: waitAmount }) - .toUTC() - .toJSDate(); + waitTill = DateTime.fromISO(original.toISOString().slice(0, -1)).toUTC().toJSDate(); } else { const dateTimeStr = context.getNodeParameter('dateTime', 0) as string; From 5dc2ef9b21fde6696c222e13ea59615d7622ab69 Mon Sep 17 00:00:00 2001 From: Omar Ajoue Date: Wed, 14 Feb 2024 14:26:44 +0000 Subject: [PATCH 4/4] fix: Remove timezone information from relative dates --- packages/nodes-base/nodes/Wait/Wait.node.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/nodes-base/nodes/Wait/Wait.node.ts b/packages/nodes-base/nodes/Wait/Wait.node.ts index 4bb1febd06486..d640569394a91 100644 --- a/packages/nodes-base/nodes/Wait/Wait.node.ts +++ b/packages/nodes-base/nodes/Wait/Wait.node.ts @@ -420,9 +420,9 @@ export class Wait extends Webhook { waitAmount *= 1000; - const original = new Date(new Date().getTime() + waitAmount); - - waitTill = DateTime.fromISO(original.toISOString().slice(0, -1)).toUTC().toJSDate(); + // Timezone does not change relative dates, since they are just + // a number of seconds added to the current timestamp + waitTill = new Date(new Date().getTime() + waitAmount); } else { const dateTimeStr = context.getNodeParameter('dateTime', 0) as string;