fix: different cronexpr rules between ui and pocketbase
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
export const validCronExpression = (expr: string): boolean => {
|
||||
try {
|
||||
parseExpression(expr);
|
||||
|
||||
if (expr.trim().split(" ").length !== 5) return false; // pocketbase 后端仅支持五段式的表达式
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
@@ -10,19 +12,15 @@ export const validCronExpression = (expr: string): boolean => {
|
||||
};
|
||||
|
||||
export const getNextCronExecutions = (expr: string, times = 1): Date[] => {
|
||||
if (!expr) return [];
|
||||
if (!validCronExpression(expr)) return [];
|
||||
|
||||
try {
|
||||
const now = new Date();
|
||||
const cron = parseExpression(expr, { currentDate: now, iterator: true });
|
||||
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 [];
|
||||
const result: Date[] = [];
|
||||
for (let i = 0; i < times; i++) {
|
||||
const next = cron.next();
|
||||
result.push(next.value.toDate());
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user