mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
refactor(core): Remove linting exceptions in nodes-base (no-changelog) (#4944)
This commit is contained in:
@@ -14,6 +14,37 @@ import { set } from 'lodash';
|
||||
|
||||
import moment from 'moment-timezone';
|
||||
|
||||
function parseDateByFormat(this: IExecuteFunctions, value: string, fromFormat: string) {
|
||||
const date = moment(value, fromFormat, true);
|
||||
if (moment(date).isValid()) return date;
|
||||
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'Date input cannot be parsed. Please recheck the value and the "From Format" field.',
|
||||
);
|
||||
}
|
||||
|
||||
function getIsoValue(this: IExecuteFunctions, value: string) {
|
||||
try {
|
||||
return new Date(value).toISOString(); // may throw due to unpredictable input
|
||||
} catch (error) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'Unrecognized date input. Please specify a format in the "From Format" field.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function parseDateByDefault(this: IExecuteFunctions, value: string) {
|
||||
const isoValue = getIsoValue.call(this, value);
|
||||
if (moment(isoValue).isValid()) return moment(isoValue);
|
||||
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'Unrecognized date input. Please specify a format in the "From Format" field.',
|
||||
);
|
||||
}
|
||||
|
||||
export class DateTime implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Date & Time',
|
||||
@@ -399,7 +430,7 @@ export class DateTime implements INodeType {
|
||||
newDate = moment.unix(currentDate as unknown as number);
|
||||
} else {
|
||||
if (options.fromTimezone || options.toTimezone) {
|
||||
const fromTimezone = options.fromTimezone || workflowTimezone;
|
||||
const fromTimezone = options.fromTimezone ?? workflowTimezone;
|
||||
if (options.fromFormat) {
|
||||
newDate = moment.tz(
|
||||
currentDate,
|
||||
@@ -517,34 +548,3 @@ export class DateTime implements INodeType {
|
||||
return this.prepareOutputData(returnData);
|
||||
}
|
||||
}
|
||||
|
||||
function parseDateByFormat(this: IExecuteFunctions, value: string, fromFormat: string) {
|
||||
const date = moment(value, fromFormat, true);
|
||||
if (moment(date).isValid()) return date;
|
||||
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'Date input cannot be parsed. Please recheck the value and the "From Format" field.',
|
||||
);
|
||||
}
|
||||
|
||||
function parseDateByDefault(this: IExecuteFunctions, value: string) {
|
||||
const isoValue = getIsoValue.call(this, value);
|
||||
if (moment(isoValue).isValid()) return moment(isoValue);
|
||||
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'Unrecognized date input. Please specify a format in the "From Format" field.',
|
||||
);
|
||||
}
|
||||
|
||||
function getIsoValue(this: IExecuteFunctions, value: string) {
|
||||
try {
|
||||
return new Date(value).toISOString(); // may throw due to unpredictable input
|
||||
} catch (error) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'Unrecognized date input. Please specify a format in the "From Format" field.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user