Merge branch '7.0.x'

This commit is contained in:
Brian Clozel
2026-06-04 10:49:36 +02:00
3 changed files with 39 additions and 2 deletions
@@ -177,7 +177,11 @@ final class BitsCronField extends CronField {
int next = nextSetBit(current);
if (next == -1) {
temporal = type().rollForward(temporal);
next = nextSetBit(0);
next = nextSetBit(type().get(temporal));
if (next == -1) {
temporal = type().rollForward(temporal);
next = nextSetBit(0);
}
}
if (next == current) {
return temporal;
@@ -191,7 +195,12 @@ final class BitsCronField extends CronField {
next = nextSetBit(current);
if (next == -1) {
temporal = type().rollForward(temporal);
next = nextSetBit(0);
next = nextSetBit(type().get(temporal));
if (next == -1) {
temporal = type().rollForward(temporal);
next = nextSetBit(0);
}
current = type().get(temporal);
}
}
if (count >= CronExpression.MAX_ATTEMPTS) {
@@ -16,6 +16,7 @@
package org.springframework.scheduling.support;
import java.time.ZonedDateTime;
import java.util.Arrays;
import org.assertj.core.api.Condition;
@@ -29,6 +30,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
*
* @author Arjen Poutsma
* @author Sam Brannen
* @author Brian Clozel
*/
class BitsCronFieldTests {
@@ -112,6 +114,24 @@ class BitsCronFieldTests {
.has(clear(0)).has(setRange(1, 7));
}
@Test
void nextOrSameWithMidnightGap() {
BitsCronField field = BitsCronField.parseHours("0-23/2");
ZonedDateTime last = ZonedDateTime.parse("2025-04-24T23:00:00+02:00[Africa/Cairo]");
ZonedDateTime expected = ZonedDateTime.parse("2025-04-25T02:00:00+03:00[Africa/Cairo]");
ZonedDateTime actual = field.nextOrSame(last);
assertThat(actual).isEqualTo(expected);
}
@Test
void nextOrSameWithGapAfterRollForward() {
BitsCronField field = BitsCronField.parseHours("0,2");
ZonedDateTime last = ZonedDateTime.parse("2026-03-08T01:00:00-05:00[America/New_York]");
ZonedDateTime expected = ZonedDateTime.parse("2026-03-09T00:00:00-04:00[America/New_York]");
ZonedDateTime actual = field.nextOrSame(last);
assertThat(actual).isEqualTo(expected);
}
private static Condition<BitsCronField> set(int... indices) {
return new Condition<>(String.format("set bits %s", Arrays.toString(indices))) {
@@ -1367,6 +1367,14 @@ class CronExpressionTests {
actual = cronExpression.next(last);
assertThat(actual).isNotNull();
assertThat(actual).isEqualTo(expected);
cronExpression = CronExpression.parse("0 0 */2 * * ?");
last = ZonedDateTime.parse("2025-04-24T22:00:00+02:00[Africa/Cairo]");
expected = ZonedDateTime.parse("2025-04-25T02:00:00+03:00[Africa/Cairo]");
actual = cronExpression.next(last);
assertThat(actual).isNotNull();
assertThat(actual).isEqualTo(expected);
}
@Test