UNPKG

integreat

Version:
31 lines 1.01 kB
import { CronExpressionParser } from 'cron-parser'; import { isDate } from '../utils/is.js'; export default class Schedule { cron; tz; constructor(job) { this.cron = typeof job.cron === 'string' ? job.cron : undefined; this.tz = typeof job.tz === 'string' ? job.tz : undefined; } shouldRun(start, end) { if (typeof this.cron === 'string') { if (!isDate(start) || !isDate(end) || Number.isNaN(start.getTime()) || Number.isNaN(end.getTime())) { throw new Error('Missing start or end date'); } const options = { currentDate: start, endDate: end, tz: this.tz }; const interval = CronExpressionParser.parse(this.cron, options); try { interval.next(); return true; } catch { return false; } } return false; } } //# sourceMappingURL=Schedule.js.map