chore(ui): upgrade cron-parser

main
Fu Diwei 2025-03-07 00:18:39 +08:00
parent 52e9341dab
commit 48f3cc419b
1 changed files with 4 additions and 9 deletions

View File

@ -1,8 +1,8 @@
import { parseExpression } from "cron-parser";
import { CronExpressionParser } from "cron-parser";
export const validCronExpression = (expr: string): boolean => {
try {
parseExpression(expr);
CronExpressionParser.parse(expr);
if (expr.trim().split(" ").length !== 5) return false; // pocketbase 后端仅支持五段式的表达式
return true;
@ -15,12 +15,7 @@ export const getNextCronExecutions = (expr: string, times = 1): Date[] => {
if (!validCronExpression(expr)) return [];
const now = new Date();
const cron = parseExpression(expr, { currentDate: now, iterator: true });
const cron = CronExpressionParser.parse(expr, { currentDate: now });
const result: Date[] = [];
for (let i = 0; i < times; i++) {
const next = cron.next();
result.push(next.value.toDate());
}
return result;
return cron.take(times).map((date) => date.toDate());
};