From a052318c059d3cffa8d2c04a501d521797da35d2 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sat, 26 Oct 2024 00:42:52 +0530 Subject: [PATCH] feat: compute next run --- server/src/utils/schedule.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 server/src/utils/schedule.ts diff --git a/server/src/utils/schedule.ts b/server/src/utils/schedule.ts new file mode 100644 index 00000000..2cc02bfc --- /dev/null +++ b/server/src/utils/schedule.ts @@ -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; + } +}