Skip to content

Commit 6467fca

Browse files
committed
Polishing contribution
This fixes a potential regression introduced by the previous commit. Because the current value was not updated after the temporal was rolled forward, there were new cases where entire days would be skipped. Closes gh-36865
1 parent cddc671 commit 6467fca

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

spring-context/src/main/java/org/springframework/scheduling/support/BitsCronField.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ private static ValueRange parseRange(String value, Type type) {
200200
temporal = type().rollForward(temporal);
201201
next = nextSetBit(0);
202202
}
203+
current = type().get(temporal);
203204
}
204205
}
205206
if (count >= CronExpression.MAX_ATTEMPTS) {

spring-context/src/test/java/org/springframework/scheduling/support/BitsCronFieldTests.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.scheduling.support;
1818

19+
import java.time.ZonedDateTime;
1920
import java.util.Arrays;
2021

2122
import org.assertj.core.api.Condition;
@@ -29,6 +30,7 @@
2930
*
3031
* @author Arjen Poutsma
3132
* @author Sam Brannen
33+
* @author Brian Clozel
3234
*/
3335
class BitsCronFieldTests {
3436

@@ -112,6 +114,24 @@ void names() {
112114
.has(clear(0)).has(setRange(1, 7));
113115
}
114116

117+
@Test
118+
void nextOrSameWithMidnightGap() {
119+
BitsCronField field = BitsCronField.parseHours("0-23/2");
120+
ZonedDateTime last = ZonedDateTime.parse("2025-04-24T23:00:00+02:00[Africa/Cairo]");
121+
ZonedDateTime expected = ZonedDateTime.parse("2025-04-25T02:00:00+03:00[Africa/Cairo]");
122+
ZonedDateTime actual = field.nextOrSame(last);
123+
assertThat(actual).isEqualTo(expected);
124+
}
125+
126+
@Test
127+
void nextOrSameWithGapAfterRollForward() {
128+
BitsCronField field = BitsCronField.parseHours("0,2");
129+
ZonedDateTime last = ZonedDateTime.parse("2026-03-08T01:00:00-05:00[America/New_York]");
130+
ZonedDateTime expected = ZonedDateTime.parse("2026-03-09T00:00:00-04:00[America/New_York]");
131+
ZonedDateTime actual = field.nextOrSame(last);
132+
assertThat(actual).isEqualTo(expected);
133+
}
134+
115135

116136
private static Condition<BitsCronField> set(int... indices) {
117137
return new Condition<>(String.format("set bits %s", Arrays.toString(indices))) {

0 commit comments

Comments
 (0)