File tree Expand file tree Collapse file tree
main/java/org/springframework/scheduling/support
test/java/org/springframework/scheduling/support Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -200,6 +200,7 @@ public <T extends Temporal & Comparable<? super T>> T nextOrSame(T temporal) {
200200 temporal = type ().rollForward (temporal );
201201 next = nextSetBit (0 );
202202 }
203+ current = type ().get (temporal );
203204 }
204205 }
205206 if (count >= CronExpression .MAX_ATTEMPTS ) {
Original file line number Diff line number Diff line change 1616
1717package org .springframework .scheduling .support ;
1818
19+ import java .time .ZonedDateTime ;
1920import java .util .Arrays ;
2021
2122import org .assertj .core .api .Condition ;
2930 *
3031 * @author Arjen Poutsma
3132 * @author Sam Brannen
33+ * @author Brian Clozel
3234 */
3335class 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 ))) {
You can’t perform that action at this time.
0 commit comments