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

Cron Builder/Parser fails on Every X years #148

Closed
Mythra opened this issue Jan 2, 2017 · 4 comments
Closed

Cron Builder/Parser fails on Every X years #148

Mythra opened this issue Jan 2, 2017 · 4 comments

Comments

@Mythra
Copy link

Mythra commented Jan 2, 2017

The quartz cron builder (and presumably other cron builders) fail when using every N years. With a:

java.lang.IllegalArgumentException: Value N not in range [1970, 2099]
        at com.cronutils.model.field.expression.visitor.ValidationFieldExpressionVisitor.isInRange(ValidationFieldExpressionVisitor.java:152)
        at com.cronutils.model.field.expression.visitor.ValidationFieldExpressionVisitor.visit(ValidationFieldExpressionVisitor.java:119)
        at com.cronutils.model.field.expression.visitor.ValidationFieldExpressionVisitor.visit(ValidationFieldExpressionVisitor.java:60)
        at com.cronutils.model.field.expression.FieldExpression.accept(FieldExpression.java:42)
        at com.cronutils.builder.CronBuilder.addField(CronBuilder.java:81)
        at com.cronutils.builder.CronBuilder.withYear(CronBuilder.java:45)

Some reproduction code is:

CronBuilder.cron(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ)).withDoM(FieldExpressionFactory.on(1))
                        .withDoW(FieldExpressionFactory.questionMark())
                        .withYear(FieldExpressionFactory.every(4))
                        .withMonth(FieldExpressionFactory.on(0))
                        .withHour(FieldExpressionFactory.on(0))
                        .withMinute(FieldExpressionFactory.on(0))
                        .withSecond(FieldExpressionFactory.on(0))

The result I'm looking for is: Every N years on the first month/first hour/first second something runs.

@Mythra
Copy link
Author

Mythra commented Jan 2, 2017

I also seem to be running into this when trying to parse a cron manually:

ZonedDateTime zdt = ZonedDateTime.now();
                int year = zdt.getYear();
                CronParser cp = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ));
                Cron cron;
                try {
                    cron = cp.parse(String.format("0 0 0 1 0 ? %d/%d", year, 4));
                } catch (Exception e1) {
                    System.err.println(e1.getMessage());
                }

@Mythra Mythra changed the title Quartz Cron Builder fails on Every X years Cron Builder/Parser fails on Every X years Jan 2, 2017
jmrozanec added a commit that referenced this issue Mar 11, 2017
meincs added a commit to meincs/cron-utils that referenced this issue May 10, 2017
added unit tests
@jmrozanec
Copy link
Owner

@meincs the contributed code does not seem to fix #148 Please note the test at CronParserQuartzIntegrationTest#testEveryXYears() Thanks!

@meincs
Copy link
Contributor

meincs commented May 12, 2017

Problem was due to a bug in the test. Issue should be fixed and can be closed now.

@jmrozanec
Copy link
Owner

jmrozanec commented May 12, 2017

@meincs you are right! Thank you for contributing the fix! 😄

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

No branches or pull requests

3 participants