Repository navigation
Fix day-of-week ranges that use day names - #226
Open
waw666waw666 wants to merge 1 commit into
Open
waw666waw666 wants to merge 1 commit into
waw666waw666 wants to merge 1 commit into
Conversation
SUN is stored as 7, and the range normalisation and the 'N'/'w' format choice only looked at the raw text, so named ranges were evaluated wrongly: SAT-SUN and FRI-SUN never matched Sunday, SUN-THU never matched at all, and MON-FRI/2 was read as 0-0 and fired on Sundays only. Convert the range bounds to numbers before normalising them, treat a Sunday as matching when the value covers either 0 or 7, and convert literals in stepped ranges so JAN-MAR/2 no longer throws.
srFix day-of-week ranges that use day namesc/Cron/DayOfWeekField.php).
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.
Day-of-week ranges written with names are evaluated wrongly, because
SUNis stored as 7 and the range handling only looks at the raw text:FRI-SUNalso skips Sunday. The numeric forms (6-7,0-4,1-5/2) work, so this only bites people who use names, e.g.->cron('0 10 * * SAT-SUN')in a Laravel schedule, which silently stops running on Sundays.Cause
DayOfWeekField::isSatisfiedBy()swaps 7→0 / 0→7 on the raw range strings, then picks theN(Sunday = 7) orw(Sunday = 0) date format by looking for a literal7character.SAT-SUNcontains no7, so it is checked withw, whileisInRange()convertsSUNto 7: Sunday (0) never falls in 6-7.SUN-THUbecomes 7-4 and matches nothing.AbstractField::isInIncrementsOfRanges()casts the bounds with(int)without converting literals, soMON-FRI/2becomes0-0/2andJAN-MAR/2starts at 0 and throws.Fix
SUN-THU→ 0-4,5-0→ 5-7, as before for numbers).wand let a Sunday also match when the value covers 7. This replaces theN/wguess, so0-7/2now includes Sunday and0-0/7-7mean Sunday only (they used to match every day).isInIncrementsOfRanges().Tests
Added
DayOfWeekFieldTest::testNamedRangesIncludeSunday,MonthFieldTest::testNamedRangeWithStepandCronExpressionTest::testNamedDayOfWeekRangesThatEndOrStartOnSunday; all three fail on master (2 failures, 1 OutOfRangeException) and pass with the fix. Full suite: 180 tests, 873 assertions, OK (4 skipped, same as master). PHPStan: no errors.Behavior change
This also changes the result for some purely numeric day-of-week values. I compared every value of the form
a,a-b,a-b/sand*/s(a, b in 0-7, s in 1-8) before and after: 83 of the 592 values change, and all of them are corrections:0-7/2), where it was missed before.0-0and7-7now mean Sunday only; before they matched every day.5-0/2-style values (a range ending on Sunday as 0, with a step) no longer throw.No other numeric value changes.