node-cron
node-cron copied to clipboard
NextDate not calculated correctly
The commit to fix the next execution time in https://github.com/kelektiv/node-cron/commit/c08522ff80b3987843e9930c307b76d5fe38b5dc seems to have introduced a bug.
Tested against version v1.7.1 and v1.8.1.
Expected Behavior The following should schedule the job for the first Monday of each month:
const job = new CronJob('0 0 12 1-7 * Mon', () => {});
job.nextDate(); // should be the first Monday of next month
Actual Behavior
The above code causes the job to be scheduled for every day other than the 7th of the month. job.nextDate()
is incorrect when compared to the cron pattern.
Current resolution
Downgrading to v1.7.0 fixes the issue.
You may misunderstand the cron string.
From crontab's man page:
Note: The day of a command's execution can be specified by two fields — day of month, and day of week. If both fields are restricted (i.e., aren't *), the command will be run when either field matches the cur‐ rent time. For example, ``30 4 1,15 * 5'' would cause a command to be run at 4:30 am on the 1st and 15th of each month, plus every Friday. One can, however, achieve the desired result by adding a test to the command (see the last exam‐ ple in EXAMPLE CRON FILE below).