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

Bug with interesting leap year pattern? #122

Closed
DABH opened this issue May 14, 2018 · 4 comments · Fixed by #135
Closed

Bug with interesting leap year pattern? #122

DABH opened this issue May 14, 2018 · 4 comments · Fixed by #135
Assignees

Comments

@DABH
Copy link

DABH commented May 14, 2018

I'm trying to parse a cron with the following pattern:
0 2 29 2 0
However, when I try, I get the error:
Invalid explicit day of month definition
This pattern should match all February 29th's that are on a Sunday (accounting for leap years in some reasonable way). This is enough of an edge case that I figure it might actually be a bug. Any ideas what's going on and how to fix this?

@harrisiirak
Copy link
Owner

harrisiirak commented May 15, 2018

@DABH thanks for reporting? Can i ask which version of the library you're using?
Latest version is currently producing results as such:

const parser = require('cron-parser');
const results = parser.parseExpression('0 2 29 2 0');

console.log(results.next().toDate()); // 2019-02-03T00:00:00.000Z
console.log(results.next().toDate()); // 2019-02-10T00:00:00.000Z

@harrisiirak harrisiirak self-assigned this May 15, 2018
@harrisiirak
Copy link
Owner

@DABH +1

@fishcharlie
Copy link
Contributor

I'm not getting any errors with @DABH's code he posted in the original issue. That being said, I'm getting this error in the latest version (2.6.0) of this package, using the code I have attached below.

const parser = require('cron-parser');
const results = parser.parseExpression('0 0 29 2 *');

console.log(results.next().toDate());

I'm running on Node.js version v10.8.0.

Below is the output I get when running the code above.

/Users/me/Desktop/tmp/node_modules/cron-parser/lib/expression.js:456
        throw new Error('Invalid explicit day of month definition');
        ^

Error: Invalid explicit day of month definition
    at CronExpression._findSchedule (/Users/me/Desktop/tmp/node_modules/cron-parser/lib/expression.js:456:15)
    at CronExpression.next (/Users/me/Desktop/tmp/node_modules/cron-parser/lib/expression.js:549:23)
    at Object.<anonymous> (/Users/me/Desktop/tmp/index.js:4:21)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:266:19)

As you can see from this link the code above should print 2020-02-29T00:00:00.000Z.

fishcharlie added a commit to fishcharlie/cron-parser that referenced this issue Nov 5, 2018
fishcharlie added a commit to fishcharlie/cron-parser that referenced this issue Nov 5, 2018
@fishcharlie
Copy link
Contributor

I have created a PR for this fix (#135). Let me know if you have any questions!

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

Successfully merging a pull request may close this issue.

3 participants