feat: compute next run
This commit is contained in:
13
server/src/utils/schedule.ts
Normal file
13
server/src/utils/schedule.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import cronParser from 'cron-parser';
|
||||
import moment from 'moment-timezone';
|
||||
|
||||
// Function to compute next run date based on the cron pattern and timezone
|
||||
function computeNextRun(cronExpression: string, timezone: string) {
|
||||
try {
|
||||
const interval = cronParser.parseExpression(cronExpression, { tz: timezone });
|
||||
return interval.next().toDate();
|
||||
} catch (err) {
|
||||
console.error('Error parsing cron expression:', err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user