Support SUN as minimum of range in CronExpression
This commit makes sure that SUN can be used at the beginning of a range, like SUN-FRI. Closes gh-26598
This commit is contained in:
@@ -165,6 +165,10 @@ final class BitsCronField extends CronField {
|
||||
int max = Integer.parseInt(value.substring(hyphenPos + 1));
|
||||
min = type.checkValidValue(min);
|
||||
max = type.checkValidValue(max);
|
||||
if (type == Type.DAY_OF_WEEK && min == 7) {
|
||||
// If used as a minimum in a range, Sunday means 0 (not 7)
|
||||
min = 0;
|
||||
}
|
||||
return ValueRange.of(min, max);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,8 @@ class BitsCronFieldTests {
|
||||
assertThat(BitsCronField.parseMonth("1")).has(set(1)).has(clearRange(2, 12));
|
||||
|
||||
assertThat(BitsCronField.parseDaysOfWeek("0")).has(set(7, 7)).has(clearRange(0, 6));
|
||||
|
||||
assertThat(BitsCronField.parseDaysOfWeek("7-5")).has(clear(0)).has(setRange(1, 5)).has(clear(6)).has(set(7));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1242,5 +1242,25 @@ class CronExpressionTests {
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sundayToFriday() {
|
||||
CronExpression expression = CronExpression.parse("0 0 0 ? * SUN-FRI");
|
||||
|
||||
LocalDateTime last = LocalDateTime.of(2021, 2, 25, 15, 0);
|
||||
LocalDateTime expected = LocalDateTime.of(2021, 2, 26, 0, 0);
|
||||
LocalDateTime actual = expression.next(last);
|
||||
assertThat(actual).isNotNull();
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
assertThat(actual.getDayOfWeek()).isEqualTo(FRIDAY);
|
||||
|
||||
last = actual;
|
||||
expected = LocalDateTime.of(2021, 2, 28, 0, 0);
|
||||
actual = expression.next(last);
|
||||
assertThat(actual).isNotNull();
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
assertThat(actual.getDayOfWeek()).isEqualTo(SUNDAY);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user