Null-safety migration + DOM/DOW correctness fixes - #10
Open
justintout wants to merge 2 commits into
Open
Conversation
Bump the SDK constraint to ^3.0.0 and make the library null-safe so it can be consumed by modern Dart 3 / Flutter. Private fields set once in the constructor become `late final`; test fixtures and helpers gain the type annotations sound null safety requires. Bump version 0.1.1 -> 0.2.0 (breaking change under 0.x semantics). Fixes #6 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Fix the day-of-month / day-of-week matching so results follow POSIX cron: - The single field evaluator now honors a restricted day-of-month. The old `dayOfMonthMatches` iterated over the day-of-week field in its skip branch and the hour/DOM/month/DOW range branches fell through to `int.parse` on a range string, so a restricted day like `7` in `0 19 7 8 *` was effectively ignored and the search returned the 1st of the month instead of the 7th. - `matches` now applies the POSIX day rule: when BOTH day-of-month and day-of-week are restricted, a time matches if EITHER matches; when only one is restricted, only that field applies. This is why `0 0 1 * *` / @monthly returned "tomorrow" instead of the 1st of the following month. Replace the malformed `* * *,* * SUN` "the bug" test expression with the valid `* * 13 * SUN`, and add regression tests taken directly from the issue reports. Fixes #3 Fixes #4 Fixes #5 Fixes #8 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Migrates the package to sound null safety (Dart 3) and fixes the day-of-month / day-of-week matching bugs reported by several users.
Issues addressed
0 19 7 8 *returns2021-08-01 19:00:00#5 —0 19 7 8 *returns2021-08-01 19:00:00dart format)Root cause of the DOM/DOW bug
Two defects combined:
The POSIX day rule was not implemented.
matches()always ANDed theday-of-month and day-of-week fields (
dayOfMonthMatches && dayOfWeekMatches).POSIX cron treats these two fields specially: when both are restricted
(neither is
*), a time matches if either field matches; when only oneis restricted, only that field applies. Because the code always used AND, the
both-restricted case was wrong — this is the "cron bug" that Test "Cron matchers day of week we pass a test for 'the bug'" is failing #8's test was
meant to cover.
dayOfMonthMatchesevaluated the wrong field, and range parsing threw.The day-of-month matcher's skip (
/) branch split_dayOfWeekFieldinsteadof
_dayOfMonthField, and the hour/day-of-month/month/day-of-week matchersiterated a range (
a-b) without acontinue, then fell through toint.parse(value)on the range string. The net effect was that a restrictedday-of-month such as the
7in0 19 7 8 *was effectively ignored, so theforward search stopped on the 1st of the month (
2021-08-01) instead of the7th (
2021-08-07). Likewise0 0 1 * */@monthlymatched "tomorrow"rather than the 1st of the following month.
What changed
>=2.7.0 <3.0.0→^3.0.0;testbumped to^1.24.0; version0.1.1→0.2.0(breaking change under 0.x semantics).late finalforfields initialized in the constructor). The five per-field matchers now
delegate to one shared
_fieldMatcheshelper that correctly handlesasterisks, skips, exact values, ranges, and comma-separated sets — fixing the
wrong-field and range fall-through bugs at their root.
matches()now appliesthe POSIX OR-vs-AND day rule. Public API surface is unchanged.
* * *,* * SUN"the bug" expression with the valid* * 13 * SUN; added aregressionsgroup with tests taken verbatim from issues Cron Next & Next Relative To set the next day. #3, Scheduling cron for day of month / weekday does not work #4, and Day parameter seems buggy, e. g.0 19 7 8 *returns2021-08-01 19:00:00#5(exact expressions and expected values).
dart format(80-column default) across the repository.Verification
dart analyze— no issues found.dart test— all 26 tests pass, including the new regression tests.dart format --set-exit-if-changed .— clean.🤖 Generated with Claude Code