fix: OR day-of-month and day-of-week when a field is a full-coverage range#1070
Open
spokodev wants to merge 1 commit into
Open
fix: OR day-of-month and day-of-week when a field is a full-coverage range#1070spokodev wants to merge 1 commit into
spokodev wants to merge 1 commit into
Conversation
…range Per crontab(5), when both day fields are restricted (neither contains a literal "*"), a job runs when either field matches. The criterion is the "*" character, not whether the value-set covers every value. getNextDateFrom decided "restricted?" by cardinality (Object.keys(dayOfMonth).length !== 31, dayOfWeek !== 7), which treats a full-coverage range such as "1-31", "0-6" or "*/1" as a wildcard even though it is not "*". As a result "0 0 12 1-31 * 1" fired only on Mondays instead of every day. cron-parser 5.6.1 and croniter 6.2.2 both return every day for that expression from 2026-06-01 (Jun 1, 2, 3, 4); node-cron returned only Mondays (Jun 1, 8, 15, 22). Capture whether each day field was a literal "*" at parse time and use those flags in the day-advance condition instead of the cardinality proxy.
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.
Problem
Per crontab(5):
The criterion is the literal
*character, not whether the value-set covers every value. node-cron breaks this when one day field is a full-coverage range or step (1-31,0-6,*/1,0,1,...,6) instead of a literal*.Repro
Expression
0 0 12 1-31 * 1(day-of-month =1-31, day-of-week = Monday), starting2026-06-01T00:00:00Z, UTC:Both
1-31and1are restricted (neither is*), so the two day fields are OR'd and the job runs every day. node-cron applies AND and fires only on Mondays.Root cause
getNextDateFrominsrc/time.tsdecides whether each day field is "restricted" by cardinality:That is a proxy for "the field is not
*". A full-coverage range such as1-31has full cardinality yet is not*, so the proxy misclassifies it as a wildcard and falls back to AND. The parser never recorded whether the raw token was literally*.Fix
dayOfMonthWildcard/dayOfWeekWildcardat parse time, set when the raw field contains the*character (before the*tolow-highexpansion).This keys the OR/AND decision on the
*character exactly as crontab(5) specifies.*/1and other step-wildcards keep their existing wildcard treatment because they contain*.Tests
Added a
crontimetest asserting0 0 12 1-31 * 1fires Jun 1, 2, 3, 4 from2026-06-01. It fails onmain(returns Jun 1, 8, 15, 22) and passes with the fix. Full suite stays green (162/162 underTZ='Europe/Paris').