Repository navigation
[DayOfMonth] Allow 'L' (last day of month) as a member of a day-of-month list - #224
Open
AjmalAlkhaledi wants to merge 1 commit into
Open
AjmalAlkhaledi wants to merge 1 commit into
AjmalAlkhaledi wants to merge 1 commit into
Conversation
The day-of-month validator rejected any list containing 'L', so a valid expression such as "L,15" (the last day of the month or the 15th) threw InvalidArgumentException at construction — even though the matching path (CronExpression::getRunDate splits the list and evaluates each member) and increment already handle 'L' inside a list correctly. Only 'W' (nearest weekday) is documented as single-day-only, so the list guard now rejects 'W' in a list and allows 'L'. "5W,L" and other W-in-list values remain invalid. Fixes dragonmantank#189.
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.
Summary
The day-of-month field validator rejects any list that contains
L, so avalid expression such as
L,15("the last day of the month or the 15th")throws
InvalidArgumentExceptionat construction — even though the rest of theengine already handles
Linside a list correctly.Fixes #189.
Problem
Lis documented as an allowed day-of-month character, and lists (,) areallowed too, but the two cannot currently be combined. Users who want "run on
the 15th and on the last day of the month" have no way to express it in a single
field.
Root cause
DayOfMonthField::validate()contains a guard that rejects a list if itcontains either
WorL:The restriction is correct for
W: the class docblock states thatW"can onlybe specified when the day-of-month is a single day, not a range or list of
days." There is no such restriction for
L, and none is needed:Lin a list.CronExpression::getRunDate()splits a comma list and calls
isSatisfiedBy()on each member, soL,15evaluates
isSatisfiedBy($date, 'L')(last-day check) ORisSatisfiedBy($date, '15')(day 15).AbstractField::validate()validates list members individually, and
DayOfMonthField::validate('L')returns
true.So the single over-broad guard is the only thing rejecting
L,15.Solution
Reject a list only when it contains
W; allowL:No change to matching or increment is required — they already behave correctly.
Tests
Added to
tests/Cron/DayOfMonthFieldTest.php:testIssue189ListMayContainLastDayOfMonth()—L,15,15,L,L,1-5,L,15,20validate;5W,L,5W,15,15,5Wremain invalid.testIssue189ListWithLastDayOfMonthSchedules()—0 0 L,15 * *schedules onthe 15th and the last day of each month, across a leap February
(…
2024-02-15,2024-02-29,2024-03-15,2024-03-31).The validation assertions fail on the unmodified code (
validate('L,15')returns
false) and pass with this change. The existing assertionassertFalse($f->validate('5W,L'))still holds (that value containsW).Run:
Backward compatibility
No behavior change for any expression that already validated. Expressions that
previously threw (
Lin a list) now construct and schedule as documented. Thedocumented
W-single-day restriction is unchanged.