diff --git a/spring-context/src/main/java/org/springframework/scheduling/support/BitsCronField.java b/spring-context/src/main/java/org/springframework/scheduling/support/BitsCronField.java index 1cb0dca6b47d..947e3217612e 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/support/BitsCronField.java +++ b/spring-context/src/main/java/org/springframework/scheduling/support/BitsCronField.java @@ -165,6 +165,10 @@ private static ValueRange parseRange(String value, Type type) { 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); } } diff --git a/spring-context/src/test/java/org/springframework/scheduling/support/BitsCronFieldTests.java b/spring-context/src/test/java/org/springframework/scheduling/support/BitsCronFieldTests.java index 906e98ea5202..37d6b30d4fd3 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/support/BitsCronFieldTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/support/BitsCronFieldTests.java @@ -48,6 +48,8 @@ void parse() { 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 diff --git a/spring-context/src/test/java/org/springframework/scheduling/support/CronExpressionTests.java b/spring-context/src/test/java/org/springframework/scheduling/support/CronExpressionTests.java index c7e1bb5c2b61..28230e51ad04 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/support/CronExpressionTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/support/CronExpressionTests.java @@ -1242,5 +1242,25 @@ void quartzLastFridayOfTheMonthEveryHour() { 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); + } + + }