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

A cron-utils bug by week #424

Closed
HongZhaoHua opened this issue Apr 27, 2020 · 5 comments · Fixed by #449
Closed

A cron-utils bug by week #424

HongZhaoHua opened this issue Apr 27, 2020 · 5 comments · Fixed by #449
Milestone

Comments

@HongZhaoHua
Copy link

use cron "0 0 12 ? * SUN#4 2020"

and use dateTime = ZonedDateTime.of(2021, 1, 1, 0, 0, 0, ZoneOffset.UTC);

now, run execution.lastExecution(dateTime);

you will get the result is 2022-11-27T12:00

but in fact, the result must be 2020-12-27T12:00

@jmrozanec
Copy link
Owner

@HongZhaoHua thank you for reporting this. May we ask you a PR with a test? Thanks!

@HongZhaoHua
Copy link
Author

@jmrozanec sure.

here is the test, plz check it.

@Test
public void test() {
    CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);
    CronParser parser = new CronParser(cronDefinition);
    ExecutionTime execution = ExecutionTime.forCron(parser.parse("0 0 12 ? * SUN#4 2020"));
    LocalDate date = LocalDate.of(2021, 1, 1);
    LocalTime time = LocalTime.of(0, 0, 0);
    ZonedDateTime dateTime = ZonedDateTime.of(date, time, ZoneOffset.UTC);
    for (int index = 0, size = 12; index < size; index++) {
        dateTime = execution.lastExecution(dateTime).orElse(null);
        Assert.assertEquals(LocalDateTime.of(2020, 12 - index, 1, 12, 0, 0).with(TemporalAdjusters.dayOfWeekInMonth(4, DayOfWeek.SUNDAY)), dateTime.toLocalDateTime());
    }
}

@jmrozanec
Copy link
Owner

@HongZhaoHua thanks! 😄

@HongZhaoHua
Copy link
Author

@jmrozanec u r welcome.
^^

jmrozanec added a commit that referenced this issue May 1, 2020
IndeedSi added a commit to IndeedSi/cron-utils that referenced this issue Oct 12, 2020
@jmrozanec jmrozanec added this to the next milestone Oct 12, 2020
@jmrozanec
Copy link
Owner

@HongZhaoHua the issue is now fixed!

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

Successfully merging a pull request may close this issue.

2 participants