mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
Add timezone option for current date
This commit is contained in:
parent
a744332cf5
commit
7b38555281
|
@ -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.',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
|
|
@ -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') {
|
||||
|
|
Loading…
Reference in a new issue