Skip to content

currentDate is not included in timespan range #356

@Eomm

Description

@Eomm

Hi,
given the following example:

const cronParser = require('cron-parser');

// START DATE NOT INCLUDED
try {
  const intervalCron = cronParser.parseExpression('0 12 * * *', {
    tz: 'UTC',
    currentDate: new Date('2020-02-19T12:00:00.000000+00:00'),
    endDate: new Date('2020-02-19T13:00:00.000000+00:00'),
  });

  const nextRun = intervalCron.next().toDate();
  console.log({ nextRun });
} catch (error) {
  console.error(error.message);
}

// END DATE INCLUDED
const intervalCron = cronParser.parseExpression('0 13 * * *', {
  tz: 'UTC',
  currentDate: new Date('2020-02-19T12:00:00.000000+00:00'),
  endDate: new Date('2020-02-19T13:00:00.000000+00:00'),
});
const nextRun = intervalCron.next().toDate();
console.log({ nextRun });

By using the currentDate and endDate as the timespan range, it seems that the endDate is included while currentDate is not: currentDate < next-cron <= endDate.

I think the currentDate should be included and the first example should work without throwing the Out of the timespan range error.

WDYT?

Metadata

Metadata

Assignees

Labels

bugpriority-highHigh priority feature/enhancement

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions