Fix RangeError when using stepping with year field wildcard#374
Conversation
Agent-Logs-Url: https://github.com/Hexagon/croner/sessions/2c0b791a-520e-4aca-ad18-b61b1149f657 Co-authored-by: Hexagon <419737+Hexagon@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Hexagon/croner/sessions/2c0b791a-520e-4aca-ad18-b61b1149f657 Co-authored-by: Hexagon <419737+Hexagon@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes year-field stepping with wildcards (e.g., */2) so it no longer attempts to start from year index 0 (invalid under the supported year range 1–9999), and updates the edge-case test to validate the corrected behavior.
Changes:
- Adjust
handleSteppingto start wildcard stepping at year1when the part type is"year". - Update the edge-case test to assert
*/2in the year field produces the expected next run years instead of throwing.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/pattern.ts |
Starts wildcard year stepping at 1 to avoid invalid year 0. |
test/new-edge-cases.test.ts |
Replaces the previous “should throw” assertion with expectations for odd-year stepping results. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot If other steppings use even ticks for */2, i believe years should too. Is this covered by ocps? If not, change implememtation to handle even year without breaking anything. Keep changes minimal. |
… fields Agent-Logs-Url: https://github.com/Hexagon/croner/sessions/a8a68674-46d7-4ee8-a9b1-044499335bb3 Co-authored-by: Hexagon <419737+Hexagon@users.noreply.github.com>
OCPS doesn't specify this behavior. Changed the implementation in 85a8293 — now |
|
@copilot Make an unreleased changelog entry and check if docs needs a note somewhere. |
Agent-Logs-Url: https://github.com/Hexagon/croner/sessions/f4ac483d-391f-4baf-8b57-19c29f1159cb Co-authored-by: Hexagon <419737+Hexagon@users.noreply.github.com>
Added unreleased changelog entry in 05503c5. Checked the docs — year field stepping is already documented in the pattern table ( |
|
This needs to be clarified in ocps before merging, pausing. |
*/2in the year field throwsRangeError: CronPattern: Invalid value for year: 0 (supported range: 1-9999)becausehandleSteppingstarts the loop at index 0, which is invalid for years (valid range 1–9999).The fix keeps the loop start at 0 (consistent with all other fields) but skips invalid year index 0, so
*/2for years produces even years (2024, 2026, 2028, ...) — matching the even-tick behavior of other fields like seconds (*/2→ 0, 2, 4, ...).src/pattern.ts: Skip year index 0 in thehandleSteppingloop to avoid the RangeError while preserving even-tick alignmenttest/new-edge-cases.test.ts: Update test to assert*/2works correctly (produces even years) rather than expecting a throw