feat(ui): new WorkflowStartNodeForm using antd
This commit is contained in:
26
ui/src/utils/cron.ts
Normal file
26
ui/src/utils/cron.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { parseExpression } from "cron-parser";
|
||||
|
||||
export const validCronExpression = (expr: string): boolean => {
|
||||
try {
|
||||
parseExpression(expr);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export const getNextCronExecutions = (expr: string, times = 1): Date[] => {
|
||||
try {
|
||||
const now = new Date();
|
||||
const cron = parseExpression(expr, { currentDate: now, iterator: true });
|
||||
|
||||
const result: Date[] = [];
|
||||
for (let i = 0; i < times; i++) {
|
||||
const next = cron.next();
|
||||
result.push(next.value.toDate());
|
||||
}
|
||||
return result;
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user