Fix CronExpression not always returning correct next schedule for weekdayonly and month flags #2838
Merged
lahma merged 4 commits intoMar 1, 2026
Merged
Conversation
…kdayonly and month flags (quartznet#2341) (Backported from 211255c)
There was a problem hiding this comment.
Pull request overview
Backports a fix to CronExpression.GetTimeAfter so monthly schedules using the W (weekday-only) modifier (and related month selection logic) compute the correct next fire time, especially around weekend adjustments and shorter months.
Changes:
- Replaced
SortedSet“tail set” logic withTryGetMinValueStartingFromhelpers for selecting next candidate values. - Fixed month/day calculation to avoid invalid dates when the next month is shorter (e.g.,
31Wtransitioning into February). - Added new unit test scenarios for
W/monthly behavior and the short-month regression case.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Quartz/Util/SortedSetExtensions.cs | Adds helper methods to find the next minimum value from a starting point. |
| src/Quartz/TriggerConstants.cs | Introduces a shared earliest-year constant used by cron parsing/docs. |
| src/Quartz/CronExpressionConstants.cs | Adds internal constants used by cron-related helpers. |
| src/Quartz/CronExpression.cs | Updates GetTimeAfter selection logic and adds short-month clamping; includes small doc/cleanup edits. |
| src/Quartz.Tests.Unit/Impl/Calendar/CronCalendarTest.cs | Minor formatting adjustment in a test. |
| src/Quartz.Tests.Unit/CronExpressionTest.cs | Adds new parameterized cron scenarios + a regression test for 31W across shorter months. |
TryGetMinValueStartingFrom(DateTimeOffset, ...) reads set.Min before checking set.Count == 0. If set is empty, this will throw InvalidOperationException, making the later empty-check dead code. Consider early-returning when set.Count == 0 (and initializing minimumDay to a safe value) before accessing Min/Max. Co-authored-by: Copilot <[email protected]>
Set Timezone to Utc for Tests. Co-authored-by: Copilot <[email protected]>
|
This was referenced Mar 2, 2026
Closed
Merged
Closed
Merged
This was referenced Apr 15, 2026
Closed
This was referenced Apr 22, 2026
This was referenced May 1, 2026
This was referenced May 12, 2026
This was referenced May 22, 2026
This was referenced Jun 7, 2026
This was referenced Jun 14, 2026
This was referenced Jun 21, 2026
This was referenced Jun 28, 2026
This was referenced Jul 5, 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.



backport 211255c from main
Fix CronExpression not always returning correct next schedule for weekdayonly and month flags (#2341)