Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect next run times when both DOM and DOW are used #267

Closed
tomasz-michalski opened this issue Dec 3, 2024 · 1 comment
Closed

Incorrect next run times when both DOM and DOW are used #267

tomasz-michalski opened this issue Dec 3, 2024 · 1 comment
Labels

Comments

@tomasz-michalski
Copy link

Describe the bug
When both day of month and day of week are specified in the pattern, the next run times returned are incorrect.

To Reproduce
Run the following code:

import { Cron } from "croner";

function getNextRuns(pattern) {
  const cron = new Cron(pattern, { timezone: "UTC" });
  const nextRuns = cron.nextRuns(3, "2024-12-01T00:00:00Z");
  return nextRuns.map((d) => d.toISOString());
}

console.log(getNextRuns("0 0 * * 4"));
// correct: ['2024-12-05T00:00:00.000Z', '2024-12-12T00:00:00.000Z', '2024-12-19T00:00:00.000Z']

console.log(getNextRuns("0 0 1-31 * 4"));
// incorrect: ['2024-12-02T00:00:00.000Z', '2024-12-03T00:00:00.000Z', '2024-12-04T00:00:00.000Z']

Expected behavior
The output for 0 0 1-31 * 4 should match the output for 0 0 * * 4.

System:

  • OS: Linux
  • Runtime: Node.js
  • Runtime Version: 22
  • Croner Version: 9.0.0

Additional context
The issue also occurs with other day of month expressions, such as 0 0 1,2 * 4 or 0 0 3,4,5 * 4.

@tomasz-michalski
Copy link
Author

Actually, this is expected behavior - I overlooked this section in the documentation:

Croner also allows you to change how the day-of-week and day-of-month conditions are combined. By default, Croner (and Vixie cron) will trigger when either the day-of-month OR the day-of-week conditions match. For example, 0 20 1 * MON will trigger on the first of the month as well as each Monday. If you want to use AND (so that it only triggers on Mondays that are also the first of the month), you can pass { legacyMode: false }. For more information, see issue #53.

https://croner.56k.guru/usage/pattern/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant