mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
Feat get in between date operation
This commit is contained in:
parent
d0038812d7
commit
97d486c52f
|
@ -16,6 +16,8 @@ import { AddToDateDescription } from './AddToDateDescription';
|
||||||
import { SubtractFromDateDescription } from './SubtractFromDateDescription';
|
import { SubtractFromDateDescription } from './SubtractFromDateDescription';
|
||||||
import { FormatDateDescription } from './FormatDateDescription';
|
import { FormatDateDescription } from './FormatDateDescription';
|
||||||
import { RoundDateDescription } from './RoundDateDescription';
|
import { RoundDateDescription } from './RoundDateDescription';
|
||||||
|
import { GetTimeBetweenDates } from './GetTimeBetweenDates';
|
||||||
|
import { DateTime, DurationUnit } from 'luxon';
|
||||||
|
|
||||||
export class DateTimeV2 implements INodeType {
|
export class DateTimeV2 implements INodeType {
|
||||||
description: INodeTypeDescription;
|
description: INodeTypeDescription;
|
||||||
|
@ -73,6 +75,7 @@ export class DateTimeV2 implements INodeType {
|
||||||
...SubtractFromDateDescription,
|
...SubtractFromDateDescription,
|
||||||
...FormatDateDescription,
|
...FormatDateDescription,
|
||||||
...RoundDateDescription,
|
...RoundDateDescription,
|
||||||
|
...GetTimeBetweenDates,
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -179,6 +182,22 @@ export class DateTimeV2 implements INodeType {
|
||||||
} catch {
|
} catch {
|
||||||
throw new NodeOperationError(this.getNode(), 'Invalid date format');
|
throw new NodeOperationError(this.getNode(), 'Invalid date format');
|
||||||
}
|
}
|
||||||
|
} else if (operation === 'getTimeBetweenDates') {
|
||||||
|
const startDate = this.getNodeParameter('startDate', i) as string;
|
||||||
|
const endDate = this.getNodeParameter('endDate', i) as string;
|
||||||
|
const unit = this.getNodeParameter('units', i) as DurationUnit[];
|
||||||
|
const outputFieldName = this.getNodeParameter('outputFieldName', i) as string;
|
||||||
|
let luxonStartDate;
|
||||||
|
let luxonEndDate;
|
||||||
|
|
||||||
|
try {
|
||||||
|
luxonStartDate = DateTime.fromISO(moment.tz(startDate, workflowTimezone).toISOString());
|
||||||
|
luxonEndDate = DateTime.fromISO(moment.tz(endDate, workflowTimezone).toISOString());
|
||||||
|
} catch {
|
||||||
|
throw new NodeOperationError(this.getNode(), 'Invalid date format');
|
||||||
|
}
|
||||||
|
const duration = luxonEndDate.diff(luxonStartDate, unit);
|
||||||
|
responseData.push({ [outputFieldName]: duration.toObject() });
|
||||||
}
|
}
|
||||||
const executionData = this.helpers.constructExecutionMetaData(
|
const executionData = this.helpers.constructExecutionMetaData(
|
||||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||||
|
|
83
packages/nodes-base/nodes/DateTime/V2/GetTimeBetweenDates.ts
Normal file
83
packages/nodes-base/nodes/DateTime/V2/GetTimeBetweenDates.ts
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
import type { INodeProperties } from 'n8n-workflow';
|
||||||
|
|
||||||
|
export const GetTimeBetweenDates: INodeProperties[] = [
|
||||||
|
{
|
||||||
|
displayName: 'Start Date',
|
||||||
|
name: 'startDate',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: ['getTimeBetweenDates'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'End Date',
|
||||||
|
name: 'endDate',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: ['getTimeBetweenDates'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Units',
|
||||||
|
name: 'units',
|
||||||
|
type: 'multiOptions',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Day',
|
||||||
|
value: 'day',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Hour',
|
||||||
|
value: 'hour',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Millisecond',
|
||||||
|
value: 'millisecond',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Minute',
|
||||||
|
value: 'minute',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Month',
|
||||||
|
value: 'month',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Second',
|
||||||
|
value: 'second',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Week',
|
||||||
|
value: 'week',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Year',
|
||||||
|
value: 'year',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: ['getTimeBetweenDates'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Output Field Name',
|
||||||
|
name: 'outputFieldName',
|
||||||
|
type: 'string',
|
||||||
|
default: 'timeDifference',
|
||||||
|
description: 'Name of the field to put the output in',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: ['getTimeBetweenDates'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
Loading…
Reference in a new issue