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

[#424] A cron-utils bug by week #449

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private ExecutionTimeResult potentialPreviousClosestMatch(final ZonedDateTime da
final List<Integer> year = yearsValueGenerator.generateCandidates(date.getYear(), date.getYear());
final Optional<TimeNode> optionalDays = generateDays(cronDefinition, date);
TimeNode days;
if (optionalDays.isPresent()) {
if (optionalDays.isPresent() && optionalDays.get().getValues().stream().anyMatch(i -> i <= date.getDayOfMonth())) {
days = optionalDays.get();
} else {
return new ExecutionTimeResult(toEndOfPreviousMonth(date), false);
Expand Down
31 changes: 0 additions & 31 deletions src/test/java/com/cronutils/Issue424Test.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.util.Date;
import java.util.Optional;
import java.util.TimeZone;
Expand Down Expand Up @@ -841,6 +842,24 @@ public void testLastExecutionIssue312() {
}
}

/**
* Issue #424
* https://github.com/jmrozanec/cron-utils/issues/424
* Last execution time incorrectly calculated when using day of week expression
*/
@Test
public void testLastExecutionIssue424() {
// Every day at 20:00
ExecutionTime executionTime = 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 = executionTime.lastExecution(dateTime).orElse(null);
assertEquals(LocalDateTime.of(2020, 12 - index, 1, 12, 0, 0).with(TemporalAdjusters.dayOfWeekInMonth(4, DayOfWeek.SUNDAY)), dateTime.toLocalDateTime());
}
}

private Duration getMinimumInterval(final String quartzPattern) {
final ExecutionTime executionTime = ExecutionTime.forCron(parser.parse(quartzPattern));
final ZonedDateTime coolDay = ZonedDateTime.of(2016, 1, 1, 0, 0, 0, 0, UTC);
Expand Down