mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
💥 Change how Date&Time-Node works
This commit is contained in:
parent
b471c0f8b2
commit
012c0ef4b8
|
@ -2,6 +2,27 @@
|
||||||
|
|
||||||
This list shows all the versions which include breaking changes and how to upgrade
|
This list shows all the versions which include breaking changes and how to upgrade
|
||||||
|
|
||||||
|
## 0.52.0
|
||||||
|
|
||||||
|
### What changed?
|
||||||
|
|
||||||
|
To make sure that all nodes work similarly, to allow to easily use the value
|
||||||
|
from other parts of the workflow and to be able to construct the source-date
|
||||||
|
manually in an expression, the node had to be changed. Instead of getting the
|
||||||
|
source-date directly from the flow the value has now to be manually set via
|
||||||
|
an expression.
|
||||||
|
|
||||||
|
### When is action necessary?
|
||||||
|
|
||||||
|
If you currently use "Date & Time"-Nodes.
|
||||||
|
|
||||||
|
### How to upgrade:
|
||||||
|
|
||||||
|
Open the "Date & Time"-Nodes and reference the date that should be converted
|
||||||
|
via an expression. Also, set the "Property Name" to the name of the property the
|
||||||
|
converted date should be set on.
|
||||||
|
|
||||||
|
|
||||||
## 0.37.0
|
## 0.37.0
|
||||||
|
|
||||||
### What changed?
|
### What changed?
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import * as moment from 'moment-timezone';
|
import * as moment from 'moment-timezone';
|
||||||
import { get, set } from 'lodash';
|
import { set } from 'lodash';
|
||||||
|
|
||||||
import { IExecuteFunctions } from 'n8n-core';
|
import { IExecuteFunctions } from 'n8n-core';
|
||||||
import {
|
import {
|
||||||
|
@ -41,20 +41,35 @@ export class DateTime implements INodeType {
|
||||||
default: 'format',
|
default: 'format',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Key Name',
|
displayName: 'Value',
|
||||||
name: 'keyName',
|
name: 'value',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
action:[
|
action: [
|
||||||
'format',
|
'format',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
description: 'The name of the key of which the value should be converted.',
|
description: 'The value that should be converted.',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Property Name',
|
||||||
|
name: 'dataPropertyName',
|
||||||
|
type: 'string',
|
||||||
|
default: 'data',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
action: [
|
||||||
|
'format',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
description: 'Name of the property to which to write the converted date.',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Custom Format',
|
displayName: 'Custom Format',
|
||||||
name: 'custom',
|
name: 'custom',
|
||||||
|
@ -155,6 +170,13 @@ export class DateTime implements INodeType {
|
||||||
placeholder: 'Add Option',
|
placeholder: 'Add Option',
|
||||||
default: {},
|
default: {},
|
||||||
options: [
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'From Format',
|
||||||
|
name: 'fromFormat',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: 'In case the input format is not recognized you can provide the format ',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'From Timezone',
|
displayName: 'From Timezone',
|
||||||
name: 'fromTimezone',
|
name: 'fromTimezone',
|
||||||
|
@ -165,20 +187,6 @@ export class DateTime implements INodeType {
|
||||||
default: 'UTC',
|
default: 'UTC',
|
||||||
description: 'The timezone to convert from.',
|
description: 'The timezone to convert from.',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
displayName: 'From Format',
|
|
||||||
name: 'fromFormat',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
description: 'In case the input format is not recognized you can provide the format ',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'New Key Name',
|
|
||||||
name: 'newKeyName',
|
|
||||||
type: 'string',
|
|
||||||
default: 'newDate',
|
|
||||||
description: 'If set will the new date be added under the new key name and the existing one will not be touched.',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
displayName: 'To Timezone',
|
displayName: 'To Timezone',
|
||||||
name: 'toTimezone',
|
name: 'toTimezone',
|
||||||
|
@ -226,20 +234,20 @@ export class DateTime implements INodeType {
|
||||||
item = items[i];
|
item = items[i];
|
||||||
|
|
||||||
if (action === 'format') {
|
if (action === 'format') {
|
||||||
const keyName = this.getNodeParameter('keyName', i) as string;
|
const currentDate = this.getNodeParameter('value', i) as string;
|
||||||
|
const dataPropertyName = this.getNodeParameter('dataPropertyName', i) as string;
|
||||||
const toFormat = this.getNodeParameter('toFormat', i) as string;
|
const toFormat = this.getNodeParameter('toFormat', i) as string;
|
||||||
const options = this.getNodeParameter('options', i) as IDataObject;
|
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||||
let newDate;
|
let newDate;
|
||||||
const currentDate = get(item.json, keyName);
|
|
||||||
|
|
||||||
if (currentDate === undefined) {
|
if (currentDate === undefined) {
|
||||||
throw new Error(`The key ${keyName} does not exist on the input data`);
|
continue;
|
||||||
}
|
}
|
||||||
if (!moment(currentDate as string | number).isValid()) {
|
if (!moment(currentDate as string | number).isValid()) {
|
||||||
throw new Error('The date input format could not be recognized. Please set the "From Format" field');
|
throw new Error('The date input format could not be recognized. Please set the "From Format" field');
|
||||||
}
|
}
|
||||||
if (Number.isInteger(currentDate as number)) {
|
if (Number.isInteger(currentDate as unknown as number)) {
|
||||||
newDate = moment.unix(currentDate as number);
|
newDate = moment.unix(currentDate as unknown as number);
|
||||||
} else {
|
} else {
|
||||||
if (options.fromTimezone || options.toTimezone) {
|
if (options.fromTimezone || options.toTimezone) {
|
||||||
const fromTimezone = options.fromTimezone || workflowTimezone;
|
const fromTimezone = options.fromTimezone || workflowTimezone;
|
||||||
|
@ -267,15 +275,15 @@ export class DateTime implements INodeType {
|
||||||
newDate = newDate.format(toFormat);
|
newDate = newDate.format(toFormat);
|
||||||
|
|
||||||
let newItem: INodeExecutionData;
|
let newItem: INodeExecutionData;
|
||||||
if (keyName.includes('.')) {
|
if (dataPropertyName.includes('.')) {
|
||||||
// Uses dot notation so copy all data
|
// Uses dot notation so copy all data
|
||||||
newItem = {
|
newItem = {
|
||||||
json: JSON.parse(JSON.stringify(items[i].json)),
|
json: JSON.parse(JSON.stringify(item.json)),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
// Does not use dot notation so shallow copy is enough
|
// Does not use dot notation so shallow copy is enough
|
||||||
newItem = {
|
newItem = {
|
||||||
json: { ...items[i].json },
|
json: { ...item.json },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,11 +291,7 @@ export class DateTime implements INodeType {
|
||||||
newItem.binary = item.binary;
|
newItem.binary = item.binary;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.newKeyName) {
|
set(newItem, `json.${dataPropertyName}`, newDate);
|
||||||
set(newItem, `json.${options.newKeyName}`, newDate);
|
|
||||||
} else {
|
|
||||||
set(newItem, `json.${keyName}`, newDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
returnData.push(newItem);
|
returnData.push(newItem);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue