Skip to content

Fix SUN-SUN day-of-week range in CronExpression - #37576

Merged
bclozel merged 1 commit into
spring-projects:7.0.xfrom
CCCLL:fix/cron-sunday-only-range
Nov 12, 2026
Merged

bclozel merged 1 commit into
spring-projects:7.0.xfrom
CCCLL:fix/cron-sunday-only-range

Conversation

@CCCLL

@CCCLL CCCLL commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

A cron expression whose day-of-week range starts and ends with Sunday,
such as 0 0 2 * * SUN-SUN or 0 0 2 * * 7-7, fires every day instead
of only on Sundays. SUN, 7 and 0-0 behave as expected.

CronExpression expression = CronExpression.parse("0 0 0 * * SUN-SUN");
expression.next(LocalDateTime.of(2021, 2, 25, 15, 0));  // 2021-02-26T00:00, a Friday

To support ranges like SUN-FRI (gh-26598), BitsCronField.parseRange()
turns a day-of-week range minimum of 7 into 0. When the maximum is 7 as
well, the range becomes 0-7, which matches every day. This change
keeps 7-7 as is, so it only matches Sundays. Ranges such as SUN-FRI,
SUN-SAT and FRI-SUN are not affected.

The new assertion in BitsCronFieldTests and the new sundayToSunday()
test, next to sundayToFriday() in CronExpressionTests, fail without
the change and pass with it. ./gradlew :spring-context:check passes on
JDK 25.

This is a regression from gh-26598 in 5.3.5, so 7.0.x is affected as
well: in 5.3.4, CronExpression treated SUN-SUN as Sundays only, as
CronSequenceGenerator and Quartz do.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 23, 2026
@bclozel
bclozel changed the base branch from main to 7.0.x November 12, 2026 15:43
Prior to this commit, a day-of-week range that starts and ends with
Sunday, such as `SUN-SUN` or `7-7`, matched every day of the week.
Since spring-projectsgh-26598, a range minimum of 7 is turned into 0 so that ranges
like `SUN-FRI` are supported, but that also turned `7-7` into `0-7`.

This commit only applies that conversion if the range does not end with
Sunday as well, so that `SUN-SUN` matches Sundays only, as `SUN`, `7`
and `0-0` already do.

Signed-off-by: Jialin Chen <cccll2019@gmail.com>
@bclozel
bclozel force-pushed the fix/cron-sunday-only-range branch from c20b569 to 1f083db Compare November 12, 2026 16:11
@bclozel
bclozel merged commit 1f083db into spring-projects:7.0.x Nov 12, 2026
2 checks passed
@bclozel bclozel added this to the 7.0.11 milestone Nov 12, 2026
@bclozel bclozel added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 12, 2026
@bclozel bclozel self-assigned this Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants