Skip to content

Commit

Permalink
Merge branch '424-fix-last-execution-with-day-of-week' of https://git…
Browse files Browse the repository at this point in the history
…hub.com/IndeedSi/cron-utils into IndeedSi-424-fix-last-execution-with-day-of-week
  • Loading branch information
jmrozanec committed Oct 12, 2020
2 parents 6fc84a7 + 0eb50c9 commit 93fa7db
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 32 deletions.
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

0 comments on commit 93fa7db

Please sign in to comment.