diff --git a/packages/nodes-base/nodes/DateTime/V2/CurrentDateDescription.ts b/packages/nodes-base/nodes/DateTime/V2/CurrentDateDescription.ts index 143a091f29..d90f968099 100644 --- a/packages/nodes-base/nodes/DateTime/V2/CurrentDateDescription.ts +++ b/packages/nodes-base/nodes/DateTime/V2/CurrentDateDescription.ts @@ -37,4 +37,26 @@ export const CurrentDateDescription: INodeProperties[] = [ }, }, }, + { + displayName: 'Additional Fields', + name: 'additionalFields', + type: 'collection', + placeholder: 'Add Field', + displayOptions: { + show: { + operation: ['getCurrentDate'], + }, + }, + default: {}, + options: [ + { + displayName: 'Timezone', + name: 'timezone', + type: 'string', + placeholder: 'America/New_York', + default: '', + description: 'The timezone to use. If not set, the timezone of the workflow will be used.', + }, + ], + }, ]; diff --git a/packages/nodes-base/nodes/DateTime/V2/DateTimeV2.node.ts b/packages/nodes-base/nodes/DateTime/V2/DateTimeV2.node.ts index e3840b82c5..ba9297b3e5 100644 --- a/packages/nodes-base/nodes/DateTime/V2/DateTimeV2.node.ts +++ b/packages/nodes-base/nodes/DateTime/V2/DateTimeV2.node.ts @@ -6,6 +6,7 @@ import type { INodeTypeBaseDescription, INodeTypeDescription, } from 'n8n-workflow'; +import { NodeOperationError } from 'n8n-workflow'; import { CurrentDateDescription } from './CurrentDateDescription'; import { AddToDateDescription } from './AddToDateDescription'; @@ -91,11 +92,21 @@ export class DateTimeV2 implements INodeType { if (operation === 'getCurrentDate') { const includeTime = this.getNodeParameter('includeTime', i) as boolean; const outputFieldName = this.getNodeParameter('outputFieldName', i) as string; + const { timezone } = this.getNodeParameter('additionalFields', i) as { + timezone: string; + }; + const newLocal = timezone ? timezone : workflowTimezone; + if (DateTime.now().setZone(newLocal).invalidReason === 'unsupported zone') { + throw new NodeOperationError( + this.getNode(), + `The timezone ${newLocal} is not valid. Please check the timezone.`, + ); + } responseData.push( includeTime - ? { [outputFieldName]: DateTime.now().setZone(workflowTimezone) } + ? { [outputFieldName]: DateTime.now().setZone(newLocal) } : { - [outputFieldName]: DateTime.now().setZone(workflowTimezone).startOf('day'), + [outputFieldName]: DateTime.now().setZone(newLocal).startOf('day'), }, ); } else if (operation === 'addToDate') {