fix(Cron): do not skip earlier days when the upcoming day is missing from the month#6285
Merged
fubhy merged 1 commit intoJun 23, 2026
Conversation
🦋 Changeset detectedLatest commit: 333590e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Member
|
Good find. Thanks! |
fubhy
approved these changes
Jun 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Cron.nextcould skip a scheduled run when the next matching day-of-month does not exist in the current month.Reproduction
The same happens for any expression whose day set contains a day (e.g.
31) that is absent from the current month, including*/15(which expands to days[1, 16, 31]).Root cause
In the day-of-month branch of
stepCron(packages/effect/src/Cron.ts), when there is still a matching day>= currentDayin the table, the step is computed asb = nextDay - currentDayand applied withsetUTCDate(currentDay + b). IfnextDayis larger than the number of days in the current month (e.g.31in February),setUTCDateoverflows into the next month and lands on the wrong day. The subsequent loop iteration then finds the next matching day within that overshot month (e.g. the 16th), skipping the earlier matching days (e.g. the 1st).Fix
When the selected
nextDaydoes not exist in the current month, wrap to the first matching day of the next month instead — reusing the exact formula already used for the "no matching day left this month" case. This mirrors the behaviour ofCron.prev(which already has an analogousday 31test) and matches other cron implementations (verified againstcron-parser).The change is scoped to the forward direction (
!prev); forprev,nextDay <= currentDay <= daysInMonth, so the new condition is always false and that path is untouched.Tests
Cron > next does not skip earlier days when the upcoming day is missing from the month, covering1,16,31,*/15, and a 30-day-month case. The test fails without the fix (returns2020-03-16) and passes with it.Cronsuite: 25/25 pass. Typecheck (tsc -b) and ESLint clean.Cron.nextagainstcron-parserover 8000 randomly generated expressions/start times: 0 mismatches with the fix (the failures above were present before).A changeset is included (
effect, patch).