mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
fix(Schedule Trigger Node): Follow the correct Unix cron format for month and days of the week (#6401)
* Handle conversion to correct unix format * Fix intervals, ranges for months * fix regex to match 10, 11, 12 --------- Co-authored-by: Marcus <marcus@n8n.io>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import type { IDataObject } from 'n8n-workflow';
|
||||
import type { IRecurencyRule } from './SchedulerInterface';
|
||||
import moment from 'moment';
|
||||
|
||||
@@ -55,3 +56,28 @@ export function recurencyCheck(
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function convertMonthToUnix(expression: string): string {
|
||||
if (!isNaN(parseInt(expression)) || expression.includes('-') || expression.includes(',')) {
|
||||
let matches = expression.match(/([0-9])+/g) as string[];
|
||||
if (matches) {
|
||||
matches = matches.map((match) =>
|
||||
parseInt(match) !== 0 ? String(parseInt(match) - 1) : match,
|
||||
);
|
||||
}
|
||||
expression = matches?.join(expression.includes('-') ? '-' : ',') || '';
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
|
||||
export function convertToUnixFormat(interval: IDataObject) {
|
||||
const expression = (interval.expression as string).split(' ');
|
||||
if (expression.length === 5) {
|
||||
expression[3] = convertMonthToUnix(expression[3]);
|
||||
expression[4] = expression[4].replace('7', '0');
|
||||
} else if (expression.length === 6) {
|
||||
expression[4] = convertMonthToUnix(expression[4]);
|
||||
expression[5] = expression[5].replace('7', '0');
|
||||
}
|
||||
interval.expression = expression.join(' ');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user