Fix CronExpression roll-forward issue
This commit makes sure that BitsCronField rolls the date forward in cases where we cannot find a next bit to elapse to. Closes: gh-26964
This commit is contained in:
parent
1e2e114e3c
commit
4203e90655
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -192,6 +192,11 @@ final class BitsCronField extends CronField {
|
|||
while (current != next && count++ < CronExpression.MAX_ATTEMPTS) {
|
||||
temporal = type().elapseUntil(temporal, next);
|
||||
current = type().get(temporal);
|
||||
next = nextSetBit(current);
|
||||
if (next == -1) {
|
||||
temporal = type().rollForward(temporal);
|
||||
next = nextSetBit(0);
|
||||
}
|
||||
}
|
||||
if (count >= CronExpression.MAX_ATTEMPTS) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -497,6 +497,29 @@ class CronExpressionTests {
|
|||
assertThat(actual.getDayOfMonth()).isEqualTo(13);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyTenDays() {
|
||||
CronExpression cronExpression = CronExpression.parse("0 15 12 */10 1-8 5");
|
||||
|
||||
LocalDateTime last = LocalDateTime.parse("2021-04-30T12:14:59");
|
||||
LocalDateTime expected = LocalDateTime.parse("2021-05-21T12:15");
|
||||
LocalDateTime actual = cronExpression.next(last);
|
||||
assertThat(actual).isNotNull();
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
|
||||
last = actual;
|
||||
expected = LocalDateTime.parse("2021-06-11T12:15");
|
||||
actual = cronExpression.next(last);
|
||||
assertThat(actual).isNotNull();
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
|
||||
last = actual;
|
||||
expected = LocalDateTime.parse("2022-01-21T12:15");
|
||||
actual = cronExpression.next(last);
|
||||
assertThat(actual).isNotNull();
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
void yearly() {
|
||||
CronExpression expression = CronExpression.parse("@yearly");
|
||||
|
|
|
|||
Loading…
Reference in New Issue